2014-12-22 14:21:24 +01:00
|
|
|
#include <platform.h>
|
|
|
|
#include "parser.h"
|
|
|
|
|
|
|
|
#include <CuTest.h>
|
|
|
|
|
2014-12-22 16:28:17 +01:00
|
|
|
static void test_gettoken(CuTest *tc) {
|
|
|
|
char token[128];
|
2014-12-22 14:21:24 +01:00
|
|
|
init_tokens_str("HELP ONE TWO THREE");
|
2014-12-22 16:28:17 +01:00
|
|
|
CuAssertStrEquals(tc, "HELP", gettoken(token, sizeof(token)));
|
|
|
|
CuAssertStrEquals(tc, "HELP", token);
|
|
|
|
CuAssertStrEquals(tc, "ONE", gettoken(token, sizeof(token)));
|
|
|
|
CuAssertStrEquals(tc, "TWO", gettoken(token, sizeof(token)));
|
|
|
|
CuAssertStrEquals(tc, "THREE", gettoken(token, sizeof(token)));
|
|
|
|
CuAssertPtrEquals(tc, NULL, (void *)gettoken(token, sizeof(token)));
|
|
|
|
CuAssertStrEquals(tc, "", token);
|
2014-12-22 14:21:24 +01:00
|
|
|
}
|
|
|
|
|
2014-12-24 15:55:55 +01:00
|
|
|
static void test_gettoken_short(CuTest *tc) {
|
|
|
|
char token[3];
|
|
|
|
init_tokens_str("HELP ONE TWO THREE");
|
|
|
|
CuAssertStrEquals(tc, "HE", gettoken(token, sizeof(token)));
|
|
|
|
CuAssertStrEquals(tc, "HE", token);
|
|
|
|
CuAssertStrEquals(tc, "ON", gettoken(token, sizeof(token)));
|
|
|
|
CuAssertStrEquals(tc, "TW", gettoken(token, sizeof(token)));
|
|
|
|
CuAssertStrEquals(tc, "TH", gettoken(token, sizeof(token)));
|
|
|
|
CuAssertPtrEquals(tc, NULL, (void *)gettoken(token, sizeof(token)));
|
|
|
|
CuAssertStrEquals(tc, "", token);
|
|
|
|
}
|
|
|
|
|
2014-12-22 16:31:10 +01:00
|
|
|
static void test_skip_token(CuTest *tc) {
|
|
|
|
char token[128];
|
|
|
|
init_tokens_str("HELP ONE TWO THREE");
|
|
|
|
skip_token();
|
|
|
|
CuAssertStrEquals(tc, "ONE", gettoken(token, sizeof(token)));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_getintegers(CuTest *tc) {
|
|
|
|
init_tokens_str("ii 666 666 -42 -42");
|
|
|
|
CuAssertIntEquals(tc, 666, getid());
|
|
|
|
CuAssertIntEquals(tc, 666, getint());
|
|
|
|
CuAssertIntEquals(tc, 666, getuint());
|
|
|
|
CuAssertIntEquals(tc, -42, getint());
|
|
|
|
CuAssertIntEquals(tc, 0, getuint());
|
|
|
|
CuAssertIntEquals(tc, 0, getint());
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_getstrtoken(CuTest *tc) {
|
|
|
|
init_tokens_str("HELP ONE TWO THREE");
|
|
|
|
CuAssertStrEquals(tc, "HELP", getstrtoken());
|
|
|
|
CuAssertStrEquals(tc, "ONE", getstrtoken());
|
|
|
|
CuAssertStrEquals(tc, "TWO", getstrtoken());
|
|
|
|
CuAssertStrEquals(tc, "THREE", getstrtoken());
|
|
|
|
CuAssertPtrEquals(tc, NULL, (void *)getstrtoken());
|
|
|
|
}
|
|
|
|
|
2014-12-23 09:23:37 +01:00
|
|
|
static void test_atoip(CuTest *tc) {
|
|
|
|
CuAssertIntEquals(tc, 42, atoip("42"));
|
|
|
|
CuAssertIntEquals(tc, 0, atoip("-42"));
|
|
|
|
CuAssertIntEquals(tc, 0, atoip("NOPE"));
|
|
|
|
}
|
|
|
|
|
2014-12-22 14:21:24 +01:00
|
|
|
CuSuite *get_parser_suite(void)
|
|
|
|
{
|
|
|
|
CuSuite *suite = CuSuiteNew();
|
2014-12-23 09:23:37 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_atoip);
|
2014-12-22 16:31:10 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_skip_token);
|
2014-12-22 16:28:17 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_gettoken);
|
2014-12-24 15:55:55 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_gettoken_short);
|
2014-12-22 16:31:10 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_getintegers);
|
|
|
|
SUITE_ADD_TEST(suite, test_getstrtoken);
|
2014-12-22 14:21:24 +01:00
|
|
|
return suite;
|
|
|
|
}
|