1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- #include "tests/SplitStringTests.h"
- #include "tests/Test.h"
- #include "utils/SplitString.h"
- #include "utils/List.h"
- typedef StringBuffer<60> String;
- typedef SplitString<60> Split;
- typedef List<String, 10> 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").add("aaa").add("bbbb");
- checkList(test, "test aaa bbbb", list, "three arguments");
- }
- static void testFourArguments(Test& test) {
- StringList list;
- list.add("test").add("aaa").add("bbbb").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").add("aaa").add("bbbb");
- checkList(test, "test aaa bbbb", list, "three arguments and spaces");
- }
- static void testTwoArgumentsWithQuotationMarks(Test& test) {
- StringList list;
- list.add("test").add("aaa bbbb");
- checkList(test, "test \"aaa bbbb\"", list, "two arguments and quotation marks");
- }
- static void testThreeArgumentsWithQuotationMarks(Test& test) {
- StringList list;
- list.add("test").add("aaa bbbb").add("ccc");
- checkList(test, "test \"aaa bbbb\" ccc", list, "three arguments and quotation marks");
- }
- static void testFourArgumentsWithQuotationMarks(Test& test) {
- StringList list;
- list.add("test").add("ddd").add("aaa bbbb").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").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();
- }
|