1 #include "../json/reflector-chronoutilities.h"
2 #include "../json/serializable.h"
4 #include <c++utilities/tests/testutils.h>
6 #include <cppunit/TestFixture.h>
7 #include <cppunit/extensions/HelperMacros.h>
9 #include <rapidjson/document.h>
10 #include <rapidjson/stringbuffer.h>
11 #include <rapidjson/writer.h>
18 using namespace CPPUNIT_NS;
19 using namespace RAPIDJSON_NAMESPACE;
20 using namespace CppUtilities;
21 using namespace CppUtilities::Literals;
31 CPPUNIT_TEST(testSerializeing);
32 CPPUNIT_TEST(testDeserializeing);
33 CPPUNIT_TEST(testErroHandling);
34 CPPUNIT_TEST_SUITE_END();
39 void testSerializeing();
40 void testDeserializeing();
41 void testErroHandling();
44 const DateTime m_dateTime;
45 const TimeSpan m_timeSpan;
46 const string m_string;
52 : m_dateTime(DateTime::fromDateAndTime(2017, 4, 2, 15, 31, 21, 165.125))
53 , m_timeSpan(TimeSpan::fromHours(3.25) + TimeSpan::fromSeconds(19.125))
54 , m_string(
"[\"2017-04-02T15:31:21.165125\",\"03:15:19.125\"]")
63 Document doc(kArrayType);
64 Document::AllocatorType &alloc = doc.GetAllocator();
66 Document::Array array(doc.GetArray());
72 Writer<StringBuffer> jsonWriter(strbuf);
73 doc.Accept(jsonWriter);
74 CPPUNIT_ASSERT_EQUAL(m_string,
string(strbuf.GetString()));
82 Document doc(kArrayType);
84 doc.Parse(m_string.data(), m_string.size());
85 auto array = doc.GetArray().begin();
93 CPPUNIT_ASSERT_EQUAL(0_st, errors.size());
94 CPPUNIT_ASSERT_EQUAL(m_dateTime.toIsoString(), dateTime.toIsoString());
95 CPPUNIT_ASSERT_EQUAL(m_timeSpan.toString(), timeSpan.toString());
103 Document doc(kArrayType);
105 doc.Parse(
"[\"2017-04-31T15:31:21.165125\",\"03:15:19.125\"]");
106 auto array = doc.GetArray().begin();
114 CPPUNIT_ASSERT_EQUAL(1_st, errors.size());
115 CPPUNIT_ASSERT(dateTime.isNull());
116 CPPUNIT_ASSERT_EQUAL(m_timeSpan.toString(), timeSpan.toString());