implementation of a simple "token enumerator"

This commit is contained in:
Martin Willi
2008-07-02 08:09:07 +00:00
parent 2f2b99282a
commit fca4d3ee03
6 changed files with 209 additions and 3 deletions
+2 -1
View File
@@ -24,6 +24,7 @@ DEFINE_TEST("linked_list_t->remove()", test_list_remove, FALSE)
DEFINE_TEST("simple enumerator", test_enumerate, FALSE)
DEFINE_TEST("nested enumerator", test_enumerate_nested, FALSE)
DEFINE_TEST("filtered enumerator", test_enumerate_filtered, FALSE)
DEFINE_TEST("token enumerator", test_enumerate_token, TRUE)
DEFINE_TEST("auth info", test_auth_info, FALSE)
DEFINE_TEST("FIPS PRF", fips_prf_test, FALSE)
DEFINE_TEST("CURL get", test_curl_get, FALSE)
@@ -34,5 +35,5 @@ DEFINE_TEST("RSA key generation", test_rsa_gen, FALSE)
DEFINE_TEST("RSA subjectPublicKeyInfo loading", test_rsa_load_any, FALSE)
DEFINE_TEST("Mediation database key fetch", test_med_db, FALSE)
DEFINE_TEST("AES-128 encryption", test_aes128, FALSE)
DEFINE_TEST("AES-XCBC", test_aes_xcbc, TRUE)
DEFINE_TEST("AES-XCBC", test_aes_xcbc, FALSE)
DEFINE_TEST("Base64 converter", test_chunk_base64, FALSE)
@@ -16,8 +16,6 @@
#include <library.h>
#include <daemon.h>
#define countof(array) (sizeof(array)/sizeof(typeof(array[0])))
/*******************************************************************************
* Base64 encoding/decoding test
******************************************************************************/
@@ -212,3 +212,53 @@ bool test_enumerate_filtered()
list->destroy(list);
return !bad_data;
}
/*******************************************************************************
* token parser test
******************************************************************************/
bool test_enumerate_token()
{
enumerator_t *enumerator;
char *token;
int i, num;
struct {
char *string;
char *sep;
char *trim;
} tests[] = {
{"abc, cde, efg", ",", " "},
{" abc 1:2 cde;3 4efg5. ", ":;.,", " 12345"},
{"abc.cde,efg", ",.", ""},
{" abc cde efg ", " ", " "},
};
for (num = 0; num < countof(tests); num++)
{
i = 0;
enumerator = enumerator_create_token(
tests[num].string, tests[num].sep, tests[num].trim);
while (enumerator->enumerate(enumerator, &token))
{
switch (i)
{
case 0:
if (!streq(token, "abc")) return FALSE;
break;
case 1:
if (!streq(token, "cde")) return FALSE;
break;
case 2:
if (!streq(token, "efg")) return FALSE;
break;
default:
return FALSE;
}
i++;
}
enumerator->destroy(enumerator);
}
return TRUE;
}