Make all NanoCoat types closeable; Make unrefing closeable the default.
[SquirrelJME.git] / nanocoat / tests / testStringLength.c
blob75e50382d0f209bb781951fb9fffa8f39203be83
1 /* -*- Mode: C; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
3 // SquirrelJME
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 // -------------------------------------------------------------------------*/
10 #include <string.h>
12 #include "proto.h"
13 #include "sjme/util.h"
14 #include "test.h"
15 #include "unit.h"
17 /** The max string length. */
18 #define MAX_LEN 32
20 /** The number of strings to test. */
21 #define NUM_STRINGS 5
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. */
30 sjme_jint out;
31 } testString;
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,
46 0x87, 0},
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;
66 sjme_lpcstr string;
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);
90 /* Success! */
91 return SJME_TEST_RESULT_PASS;