123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- #include "tests/SplitStringTests.h"
- #include "data/List.h"
- #include "tests/Test.h"
- #include "utils/SplitString.h"
- typedef StringBuffer<60> String;
- typedef SplitString<60> Split;
- typedef List<String> StringList;
- static void checkList(Test& test, const char* str, const StringList& list,
- const char* message) {
- Split split(str);
- test.checkEqual(list.getLength(), split.getLength(),
- String(message).append(" - split amount"));
- for(int i = 0; i < list.getLength() && i < split.getLength(); i++) {
- test.checkEqual(list[i], String(split[i]),
- String(message).append(" ").append(i));
- }
- }
- static void testOneArgument(Test& test) {
- StringList list;
- list.add("test");
- checkList(test, "test", list, "one argument");
- }
- static void testThreeArguments(Test& test) {
- StringList list;
- list.add("test");
- list.add("aaa");
- list.add("bbbb");
- checkList(test, "test aaa bbbb", list, "three arguments");
- }
- static void testFourArguments(Test& test) {
- StringList list;
- list.add("test");
- list.add("aaa");
- list.add("bbbb");
- list.add("ccccc");
- checkList(test, "test aaa bbbb ccccc", list, "four arguments");
- }
- static void testOneArgumentWithSpaces(Test& test) {
- StringList list;
- list.add("test");
- checkList(test, "test ", list, "spaces");
- }
- static void testThreeArgumentsWithSpaces(Test& test) {
- StringList list;
- list.add("test");
- list.add("aaa");
- list.add("bbbb");
- checkList(test, "test aaa bbbb", list, "three arguments and spaces");
- }
- static void testTwoArgumentsWithQuotationMarks(Test& test) {
- StringList list;
- list.add("test");
- list.add("aaa bbbb");
- checkList(test, "test \"aaa bbbb\"", list,
- "two arguments and quotation marks");
- }
- static void testThreeArgumentsWithQuotationMarks(Test& test) {
- StringList list;
- list.add("test");
- list.add("aaa bbbb");
- list.add("ccc");
- checkList(test, "test \"aaa bbbb\" ccc", list,
- "three arguments and quotation marks");
- }
- static void testFourArgumentsWithQuotationMarks(Test& test) {
- StringList list;
- list.add("test");
- list.add("ddd");
- list.add("aaa bbbb");
- list.add("ccc");
- checkList(test, "test ddd \"aaa bbbb\" ccc", list,
- "four arguments and quotation marks");
- }
- static void testEmptyArgument(Test& test) {
- StringList list;
- list.add("test");
- list.add("");
- checkList(test, "test \"\"", list, "empty argument");
- }
- static void testSyntaxException(Test& test) {
- StringList list;
- checkList(test, "test \"", list, "syntax exception 1");
- checkList(test, "test aaa\"", list, "syntax exception 2");
- checkList(test, "test aaa\"bbb\"", list, "syntax exception 3");
- checkList(test, "test aaa \"bbb\"ccc", list, "syntax exception 4");
- checkList(test, "test aaa \"bbb ccc", list, "syntax exception 5");
- }
- void SplitStringTests::test() {
- Test test("SplitString");
- testOneArgument(test);
- testThreeArguments(test);
- testFourArguments(test);
- testOneArgumentWithSpaces(test);
- testThreeArgumentsWithSpaces(test);
- testTwoArgumentsWithQuotationMarks(test);
- testThreeArgumentsWithQuotationMarks(test);
- testFourArgumentsWithQuotationMarks(test);
- testEmptyArgument(test);
- testSyntaxException(test);
- test.finalize();
- }
|