forked from github/server
narrowing down the memory leak in jsonconf.test.c, by adding a similar
test to umlaut.test.c that exhibits the same behavior in a simpler setting.
This commit is contained in:
parent
fa729ba972
commit
8aec1c3e7f
|
@ -26,9 +26,51 @@ static void test_transliterate(CuTest * tc)
|
||||||
CuAssertStrEquals(tc, "h?", buffer);
|
CuAssertStrEquals(tc, "h?", buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_transliterations(CuTest *tc) {
|
||||||
|
const char * umlauts = "\xc3\xa4\xc3\xb6\xc3\xbc\xc3\x9f"; /* auml ouml uuml szlig nul */
|
||||||
|
void * tokens = 0;
|
||||||
|
variant id;
|
||||||
|
int result;
|
||||||
|
|
||||||
|
id.i = 3;
|
||||||
|
addtoken(&tokens, umlauts, id);
|
||||||
|
/* transliteration is the real magic */
|
||||||
|
result = findtoken(tokens, "AEoeUEss", &id);
|
||||||
|
CuAssertIntEquals(tc, E_TOK_SUCCESS, result);
|
||||||
|
CuAssertIntEquals(tc, 3, id.i);
|
||||||
|
|
||||||
|
result = findtoken(tokens, umlauts, &id);
|
||||||
|
CuAssertIntEquals(tc, E_TOK_SUCCESS, result);
|
||||||
|
CuAssertIntEquals(tc, 3, id.i);
|
||||||
|
|
||||||
|
freetokens(tokens);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_directions(CuTest * tc)
|
||||||
|
{
|
||||||
|
void * tokens = 0;
|
||||||
|
variant id;
|
||||||
|
int result;
|
||||||
|
|
||||||
|
id.i = 1;
|
||||||
|
addtoken(&tokens, "OSTEN", id);
|
||||||
|
addtoken(&tokens, "O", id);
|
||||||
|
|
||||||
|
id.i = 2;
|
||||||
|
addtoken(&tokens, "nw", id);
|
||||||
|
addtoken(&tokens, "northwest", id);
|
||||||
|
|
||||||
|
result = findtoken(tokens, "ost", &id);
|
||||||
|
CuAssertIntEquals(tc, E_TOK_SUCCESS, result);
|
||||||
|
CuAssertIntEquals(tc, 1, id.i);
|
||||||
|
result = findtoken(tokens, "northw", &id);
|
||||||
|
CuAssertIntEquals(tc, E_TOK_SUCCESS, result);
|
||||||
|
CuAssertIntEquals(tc, 2, id.i);
|
||||||
|
freetokens(tokens);
|
||||||
|
}
|
||||||
|
|
||||||
static void test_umlaut(CuTest * tc)
|
static void test_umlaut(CuTest * tc)
|
||||||
{
|
{
|
||||||
const char * umlauts = "\xc3\xa4\xc3\xb6\xc3\xbc\xc3\x9f"; /* auml ouml uuml szlig nul */
|
|
||||||
void * tokens = 0;
|
void * tokens = 0;
|
||||||
variant id;
|
variant id;
|
||||||
int result;
|
int result;
|
||||||
|
@ -41,8 +83,7 @@ static void test_umlaut(CuTest * tc)
|
||||||
addtoken(&tokens, "herpderp", id);
|
addtoken(&tokens, "herpderp", id);
|
||||||
id.i = 2;
|
id.i = 2;
|
||||||
addtoken(&tokens, "derp", id);
|
addtoken(&tokens, "derp", id);
|
||||||
id.i = 3;
|
addtoken(&tokens, "d", id);
|
||||||
addtoken(&tokens, umlauts, id);
|
|
||||||
|
|
||||||
/* we can find substrings if they are significant */
|
/* we can find substrings if they are significant */
|
||||||
result = findtoken(tokens, "herp", &id);
|
result = findtoken(tokens, "herp", &id);
|
||||||
|
@ -57,15 +98,6 @@ static void test_umlaut(CuTest * tc)
|
||||||
CuAssertIntEquals(tc, E_TOK_SUCCESS, findtoken(tokens, "DERP", &id));
|
CuAssertIntEquals(tc, E_TOK_SUCCESS, findtoken(tokens, "DERP", &id));
|
||||||
CuAssertIntEquals(tc, 2, id.i);
|
CuAssertIntEquals(tc, 2, id.i);
|
||||||
|
|
||||||
result = findtoken(tokens, umlauts, &id);
|
|
||||||
CuAssertIntEquals(tc, E_TOK_SUCCESS, result);
|
|
||||||
CuAssertIntEquals(tc, 3, id.i);
|
|
||||||
|
|
||||||
/* transliteration is the real magic */
|
|
||||||
result = findtoken(tokens, "AEoeUEss", &id);
|
|
||||||
CuAssertIntEquals(tc, E_TOK_SUCCESS, result);
|
|
||||||
CuAssertIntEquals(tc, 3, id.i);
|
|
||||||
|
|
||||||
result = findtoken(tokens, "herp-a-derp", &id);
|
result = findtoken(tokens, "herp-a-derp", &id);
|
||||||
CuAssertIntEquals(tc, E_TOK_NOMATCH, result);
|
CuAssertIntEquals(tc, E_TOK_NOMATCH, result);
|
||||||
|
|
||||||
|
@ -76,6 +108,8 @@ CuSuite *get_umlaut_suite(void)
|
||||||
{
|
{
|
||||||
CuSuite *suite = CuSuiteNew();
|
CuSuite *suite = CuSuiteNew();
|
||||||
SUITE_ADD_TEST(suite, test_umlaut);
|
SUITE_ADD_TEST(suite, test_umlaut);
|
||||||
|
SUITE_ADD_TEST(suite, test_directions);
|
||||||
SUITE_ADD_TEST(suite, test_transliterate);
|
SUITE_ADD_TEST(suite, test_transliterate);
|
||||||
|
SUITE_ADD_TEST(suite, test_transliterations);
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue