2018-09-30 19:47:34 +02:00
|
|
|
#ifdef _MSC_VER
|
2021-02-20 23:22:10 +01:00
|
|
|
#ifndef _CRT_SECURE_NO_WARNINGS
|
|
|
|
#define _CRT_SECURE_NO_WARNINGS
|
|
|
|
#endif
|
2018-09-30 19:47:34 +02:00
|
|
|
#endif
|
|
|
|
#include "order_parser.h"
|
|
|
|
#include "strings.h"
|
|
|
|
|
|
|
|
#include <CuTest.h>
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
static void test_parse_noop(CuTest *tc) {
|
|
|
|
OP_Parser parser;
|
|
|
|
parser = OP_ParserCreate();
|
|
|
|
CuAssertPtrNotNull(tc, parser);
|
|
|
|
CuAssertIntEquals(tc, OP_STATUS_OK, OP_Parse(parser, "Hello World", 11, 1));
|
|
|
|
OP_ParserFree(parser);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void copy_line(void *udata, const char *str) {
|
|
|
|
char *dst = (char *)udata;
|
|
|
|
if (dst) {
|
|
|
|
strcpy(dst, str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_parse_orders(CuTest *tc) {
|
|
|
|
OP_Parser parser;
|
|
|
|
char lastline[1024];
|
|
|
|
|
|
|
|
parser = OP_ParserCreate();
|
|
|
|
OP_SetUserData(parser, lastline);
|
|
|
|
OP_SetOrderHandler(parser, copy_line);
|
|
|
|
CuAssertPtrNotNull(tc, parser);
|
2018-10-03 10:37:34 +02:00
|
|
|
|
2018-10-01 02:26:31 +02:00
|
|
|
lastline[0] = 0;
|
2018-09-30 19:47:34 +02:00
|
|
|
CuAssertIntEquals(tc, OP_STATUS_OK, OP_Parse(parser, "Hello World", 11, 1));
|
|
|
|
CuAssertStrEquals(tc, "Hello World", lastline);
|
|
|
|
OP_ParserReset(parser);
|
2018-10-02 19:02:22 +02:00
|
|
|
|
2018-10-03 10:37:34 +02:00
|
|
|
lastline[0] = 0;
|
2018-10-03 19:47:32 +02:00
|
|
|
CuAssertIntEquals(tc, OP_STATUS_OK, OP_Parse(parser, "Error;\nHello World", 18, 1));
|
|
|
|
CuAssertStrEquals(tc, "Hello World", lastline);
|
|
|
|
OP_ParserReset(parser);
|
|
|
|
|
|
|
|
lastline[0] = 0;
|
|
|
|
CuAssertIntEquals(tc, OP_STATUS_OK, OP_Parse(parser, "Hello World;\\\nError", 19, 1));
|
|
|
|
CuAssertStrEquals(tc, "Hello World", lastline);
|
|
|
|
OP_ParserReset(parser);
|
|
|
|
|
|
|
|
lastline[0] = 0;
|
|
|
|
CuAssertIntEquals(tc, OP_STATUS_OK, OP_Parse(parser, "Hello World;\\", 13, 0));
|
|
|
|
CuAssertIntEquals(tc, OP_STATUS_OK, OP_Parse(parser, "\nError", 6, 1));
|
|
|
|
CuAssertStrEquals(tc, "Hello World", lastline);
|
|
|
|
OP_ParserReset(parser);
|
|
|
|
|
|
|
|
lastline[0] = 0;
|
|
|
|
CuAssertIntEquals(tc, OP_STATUS_OK, OP_Parse(parser, "Hello \\", 7, 0));
|
|
|
|
CuAssertIntEquals(tc, OP_STATUS_OK, OP_Parse(parser, "\nWorld", 6, 1));
|
2018-10-03 10:37:34 +02:00
|
|
|
CuAssertStrEquals(tc, "Hello World", lastline);
|
|
|
|
OP_ParserReset(parser);
|
|
|
|
|
2018-10-01 02:26:31 +02:00
|
|
|
lastline[0] = 0;
|
2018-09-30 19:47:34 +02:00
|
|
|
CuAssertIntEquals(tc, OP_STATUS_OK, OP_Parse(parser, "Hello World\n", 12, 1));
|
|
|
|
CuAssertStrEquals(tc, "Hello World", lastline);
|
|
|
|
OP_ParserReset(parser);
|
2018-10-02 19:02:22 +02:00
|
|
|
|
2018-10-01 02:26:31 +02:00
|
|
|
lastline[0] = 0;
|
2018-09-30 19:47:34 +02:00
|
|
|
CuAssertIntEquals(tc, OP_STATUS_OK, OP_Parse(parser, "Hello\\\n World", 13, 1));
|
|
|
|
CuAssertStrEquals(tc, "Hello World", lastline);
|
|
|
|
OP_ParserReset(parser);
|
2018-10-02 19:02:22 +02:00
|
|
|
|
2018-10-01 02:26:31 +02:00
|
|
|
lastline[0] = 0;
|
2018-09-30 19:47:34 +02:00
|
|
|
CuAssertIntEquals(tc, OP_STATUS_OK, OP_Parse(parser, "Hello;World", 11, 1));
|
|
|
|
CuAssertStrEquals(tc, "Hello", lastline);
|
|
|
|
OP_ParserReset(parser);
|
2018-10-02 19:02:22 +02:00
|
|
|
|
2018-10-01 02:26:31 +02:00
|
|
|
lastline[0] = 0;
|
2018-09-30 19:47:34 +02:00
|
|
|
CuAssertIntEquals(tc, OP_STATUS_OK, OP_Parse(parser, "Hello\\World", 11, 1));
|
|
|
|
CuAssertStrEquals(tc, "Hello\\World", lastline);
|
|
|
|
OP_ParserReset(parser);
|
2018-10-02 19:02:22 +02:00
|
|
|
|
2018-10-02 21:40:14 +02:00
|
|
|
lastline[0] = 0;
|
|
|
|
CuAssertIntEquals(tc, OP_STATUS_OK, OP_Parse(parser, ";\n", 2, 0));
|
|
|
|
CuAssertIntEquals(tc, OP_STATUS_OK, OP_Parse(parser, "Hello World", 11, 1));
|
|
|
|
CuAssertStrEquals(tc, "Hello World", lastline);
|
|
|
|
OP_ParserReset(parser);
|
|
|
|
|
2018-10-01 02:26:31 +02:00
|
|
|
lastline[0] = 0;
|
2018-10-02 19:02:22 +02:00
|
|
|
CuAssertIntEquals(tc, OP_STATUS_OK, OP_Parse(parser, ";Hello \\", 8, 0));
|
2018-10-02 21:40:14 +02:00
|
|
|
CuAssertIntEquals(tc, OP_STATUS_OK, OP_Parse(parser, "\nWorld\n", 7, 0));
|
2018-10-02 19:02:22 +02:00
|
|
|
CuAssertIntEquals(tc, OP_STATUS_OK, OP_Parse(parser, "Enno", 4, 1));
|
|
|
|
CuAssertStrEquals(tc, "Enno", lastline);
|
|
|
|
OP_ParserReset(parser);
|
|
|
|
|
|
|
|
lastline[0] = 0;
|
|
|
|
CuAssertIntEquals(tc, OP_STATUS_OK, OP_Parse(parser, ";Hello", 6, 0));
|
2018-10-02 21:40:14 +02:00
|
|
|
CuAssertIntEquals(tc, OP_STATUS_OK, OP_Parse(parser, "World\n", 6, 0));
|
2018-10-02 19:02:22 +02:00
|
|
|
CuAssertIntEquals(tc, OP_STATUS_OK, OP_Parse(parser, "Enno", 4, 1));
|
|
|
|
CuAssertStrEquals(tc, "Enno", lastline);
|
2018-09-30 19:47:34 +02:00
|
|
|
OP_ParserReset(parser);
|
2018-10-02 19:02:22 +02:00
|
|
|
|
2018-10-01 02:26:31 +02:00
|
|
|
lastline[0] = 0;
|
2018-09-30 19:47:34 +02:00
|
|
|
CuAssertIntEquals(tc, OP_STATUS_OK, OP_Parse(parser, "Hello\\World \\", 14, 1));
|
|
|
|
CuAssertStrEquals(tc, "Hello\\World ", lastline);
|
2018-10-01 02:26:31 +02:00
|
|
|
OP_ParserReset(parser);
|
2018-10-02 19:02:22 +02:00
|
|
|
|
|
|
|
lastline[0] = 0;
|
|
|
|
CuAssertIntEquals(tc, OP_STATUS_OK, OP_Parse(parser, "Hello\n", 6, 0));
|
|
|
|
CuAssertIntEquals(tc, OP_STATUS_OK, OP_Parse(parser, "World\n", 6, 1));
|
|
|
|
CuAssertStrEquals(tc, "World", lastline);
|
|
|
|
OP_ParserReset(parser);
|
|
|
|
|
2018-10-02 21:40:14 +02:00
|
|
|
lastline[0] = 0;
|
|
|
|
CuAssertIntEquals(tc, OP_STATUS_OK, OP_Parse(parser, "Hello\n", 6, 0));
|
|
|
|
CuAssertIntEquals(tc, OP_STATUS_OK, OP_Parse(parser, "World\n", 6, 1));
|
|
|
|
CuAssertStrEquals(tc, "World", lastline);
|
|
|
|
OP_ParserReset(parser);
|
2018-10-01 02:26:31 +02:00
|
|
|
lastline[0] = 0;
|
|
|
|
CuAssertIntEquals(tc, OP_STATUS_OK, OP_Parse(parser, "Hello \\", 7, 0));
|
|
|
|
CuAssertIntEquals(tc, OP_STATUS_OK, OP_Parse(parser, "\nWorld", 6, 1));
|
|
|
|
CuAssertStrEquals(tc, "Hello World", lastline);
|
2018-09-30 19:47:34 +02:00
|
|
|
OP_ParserFree(parser);
|
|
|
|
}
|
|
|
|
|
|
|
|
CuSuite *get_order_parser_suite(void)
|
|
|
|
{
|
|
|
|
CuSuite *suite = CuSuiteNew();
|
|
|
|
SUITE_ADD_TEST(suite, test_parse_noop);
|
|
|
|
SUITE_ADD_TEST(suite, test_parse_orders);
|
|
|
|
return suite;
|
|
|
|
}
|