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 // -------------------------------------------------------------------------*/
11 #include "sjme/util.h"
15 /** The max string length. */
18 /** The number of strings to test. */
19 #define NUM_STRINGS 10
21 /** The input test strings. */
22 typedef struct testString
24 /** The input string to decode. */
25 sjme_jbyte in
[MAX_LEN
];
27 /** The resultant output. */
28 sjme_jint out
[MAX_LEN
];
31 /** The actual test strings. */
32 static const testString testStrings
[NUM_STRINGS
] =
40 {0x53, 0x71, 0x75, 0x65, 0x61, 0x6b, 0},
41 {0x53, 0x71, 0x75, 0x65, 0x61, 0x6b, -1}
45 {0x61, 0xc0, 0x80, 0x62, 0},
46 {0x61, 0x00, 0x62, -1}
50 {0x43, 0x7a, 0x65, 0xc5, 0x9b, 0xc4, 0x87,
52 {0x43, 0x7a, 0x65, 0x15b, 0x107, -1}
56 {0xe4, 0xbd, 0xa0, 0xe5, 0xa5, 0xbd, 0},
60 /* Invalid sequence. */
62 {0x61, 0x80, 0x62, 0},
66 /* Invalid sequence. */
68 {0x61, 0xc0, 0x62, 0},
72 /* Invalid sequence. */
74 {0xbd, 0xa0, 0xe5, 0xa5, 0xbd, 0},
78 /* Invalid sequence. */
80 {0xe4, 0xa0, 0xe5, 0xa5, 0xbd, 0},
84 /* Invalid sequence. */
86 {0xe4, 0xbd, 0xe5, 0xa5, 0xbd, 0},
92 * Tests the decoding of characters within modified-UTF style strings, using
93 * the function @c sjme_string_decodeChar .
97 SJME_TEST_DECLARE(testStringDecodeChar
)
99 const testString
* testing
;
100 sjme_jint i
, charIndex
;
105 /* Test all the strings. */
106 for (i
= 0; i
< NUM_STRINGS
; i
++)
108 /* Which string are we testing? */
109 testing
= &testStrings
[i
];
110 string
= (sjme_lpcstr
)testing
->in
;
112 /* Decode every character and check the input matches. */
114 for (p
= string
; *p
!= 0; charIndex
++)
116 /* These should never happen. */
117 if (charIndex
>= MAX_LEN
||
118 ((uintptr_t)p
- (uintptr_t)string
) >= MAX_LEN
)
119 sjme_unit_fail(test
, "Reading input/output too far in?");
122 c
= sjme_string_decodeChar(p
, &p
);
124 /* Must match the character index. */
125 sjme_unit_equalI(test
, c
, testing
->out
[charIndex
],
126 "For input %d with output #%d, invalid result?",
136 return SJME_TEST_RESULT_PASS
;