1 /* -*- Mode: C; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the Mozilla Public License Version 2.0.
7 // See license.mkd for licensing and copyright information.
8 // -------------------------------------------------------------------------*/
13 #include "sjme/util.h"
17 /** The max string length. */
20 /** The number of strings to test. */
23 /** The input test strings. */
24 typedef struct testString
26 /** The input string to decode. */
27 sjme_jbyte in
[MAX_LEN
];
29 /** The resultant output. */
33 /** The actual test strings. */
34 static const testString testStrings
[NUM_STRINGS
] =
37 {0x53, 0x71, 0x75, 0x65, 0x61, 0x6b, 0},
41 {0x61, 0xc0, 0x80, 0x62, 0},
45 {0x43, 0x7a, 0x65, 0xc5, 0x9b, 0xc4,
51 {0xe4, 0xbd, 0xa0, 0xe5, 0xa5, 0xbd, 0},
55 /* Invalid sequence. */
57 {0xbd, 0xa0, 0xe5, 0xa5, 0xbd, 0},
62 SJME_TEST_DECLARE(testStringLength
)
64 const testString
* testing
;
65 sjme_jint i
, len
, limitLen
;
68 /* Test all the strings. */
69 for (i
= 0; i
< NUM_STRINGS
; i
++)
71 /* Which string are we testing? */
72 testing
= &testStrings
[i
];
73 string
= (sjme_lpcstr
)testing
->in
;
75 /* Calculate length. */
76 len
= sjme_string_length(string
);
78 /* Was it calculated correctly? */
79 sjme_unit_equalI(test
, len
, testing
->out
,
80 "Input %d has invalid length?", i
);
82 /* Calculate length with limit. */
83 limitLen
= sjme_string_lengthN(string
, strlen(string
));
85 /* Was it calculated correctly? */
86 sjme_unit_equalI(test
, len
, limitLen
,
87 "Input %d has incorrect length with limit?", i
);
91 return SJME_TEST_RESULT_PASS
;