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>
18using namespace CPPUNIT_NS;
19using namespace RAPIDJSON_NAMESPACE;
20using namespace CppUtilities;
21using namespace CppUtilities::Literals;
34 CPPUNIT_TEST_SUITE_END();
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());
The JsonReflectorChronoUtilitiesTests class tests the custom (de)serialization of the chrono utilitie...
void testSerializeing()
Tests serializing DateTime and TimeSpan objects.
JsonReflectorChronoUtilitiesTests()
void testErroHandling()
Tests deserializing DateTime and TimeSpan objects (error case).
void testDeserializeing()
Tests deserializing DateTime and TimeSpan objects.
Contains functions for (de)serializing objects from the chrono utilities provided by the C++ utilitie...
Contains only the definition of the JsonSerializable template class which makes the reflection access...
CPPUNIT_TEST_SUITE_REGISTRATION(JsonReflectorChronoUtilitiesTests)
void pull(Type &reflectable, const RAPIDJSON_NAMESPACE::GenericValue< RAPIDJSON_NAMESPACE::UTF8< char > >::ConstObject &value, JsonDeserializationErrors *errors)
Pulls the reflectable which has a custom type from the specified object.
void push(const Type &reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
Pushes the specified reflectable to the specified value.
The JsonDeserializationErrors struct can be passed to fromJson() for error handling.