Unit Tests

- Added unit test to ensure correct F4 and JSON parse/compose.
This commit is contained in:
Paul Beckingham 2013-06-03 00:44:25 -04:00
parent 58084f6d7a
commit 8c11c6c895
2 changed files with 28 additions and 2 deletions

View file

@ -36,7 +36,12 @@ Context context;
////////////////////////////////////////////////////////////////////////////////
int main (int argc, char** argv)
{
UnitTest t (2);
UnitTest t (9);
Task::attributes["description"] = "string";
Task::attributes["entry"] = "date";
Task::attributes["tags"] = "string";
Task::attributes["uuid"] = "string";
bool good = true;
try {Task t1 ("{}");}
@ -44,10 +49,30 @@ int main (int argc, char** argv)
t.ok (good, "Task::Task ('{}')");
good = true;
try {Task t2 ("{\"uuid\":\"00000000-0000-0000-000000000001\",\"description\":\"foo\",\"entry\":1234567890}");}
try {Task t2 ("{\"uuid\":\"00000000-0000-0000-000000000001\",\"description\":\"foo\",\"entry\":\"1234567890\"}");}
catch (const std::string& e){t.diag (e); good = false;}
t.ok (good, "Task::Task ('{<minimal>}')");
// Verify tag handling is correct between F4 and JSON.
Task t3;
t3.set ("entry", "20130602T224000Z");
t3.set ("description", "DESC");
t3.addTag ("tag1");
t.is (t3.composeF4 (), "[description:\"DESC\" entry:\"20130602T224000Z\" tags:\"tag1\"]", "F4 good");
t.is (t3.composeJSON (), "{\"description\":\"DESC\",\"entry\":\"20130602T224000Z\",\"tags\":[\"tag1\"]}", "JSON good");
t3.addTag ("tag2");
t.is (t3.composeF4 (), "[description:\"DESC\" entry:\"20130602T224000Z\" tags:\"tag1,tag2\"]", "F4 good");
t.is (t3.composeJSON (), "{\"description\":\"DESC\",\"entry\":\"20130602T224000Z\",\"tags\":[\"tag1\",\"tag2\"]}", "JSON good");
good = true;
Task t4;
try {t4 = Task ("{\"description\":\"DESC\",\"entry\":\"20130602T224000Z\",\"tags\":[\"tag1\",\"tag2\"]}");}
catch (const std::string& e){t.diag (e); good = false;}
t.ok (good, "Task::Task ('{two tags}')");
t.is (t4.composeF4 (), "[description:\"DESC\" entry:\"1370212800\" tags:\"tag1,tag2\"]", "F4 good");
t.is (t4.composeJSON (), "{\"description\":\"DESC\",\"entry\":\"20130602T224000Z\",\"tags\":[\"tag1\",\"tag2\"]}", "JSON good");
return 0;
}