#include "../traits.h" #include "../versioning.h" #include "../binary/serializable.h" #include #include // define structs for testing REFLECTIVE_RAPIDJSON_TREAT_AS_… struct Foo { }; struct Bar { }; // define structs for testing versioning struct VersionlessBase : public ReflectiveRapidJSON::BinarySerializable { }; struct VersionedDerived : public VersionlessBase, public ReflectiveRapidJSON::BinarySerializable { }; struct VersionedBase : public ReflectiveRapidJSON::BinarySerializable { }; struct VersionlessDerived : public VersionedBase, public ReflectiveRapidJSON::BinarySerializable { }; namespace ReflectiveRapidJSON { REFLECTIVE_RAPIDJSON_TREAT_AS_MAP_OR_HASH(Foo); REFLECTIVE_RAPIDJSON_TREAT_AS_MULTI_MAP_OR_HASH(Foo); REFLECTIVE_RAPIDJSON_TREAT_AS_SET(Bar); REFLECTIVE_RAPIDJSON_TREAT_AS_MULTI_SET(Foo); } // namespace ReflectiveRapidJSON using namespace std; using namespace ReflectiveRapidJSON; // test traits static_assert(IsArray>::value, "vector mapped to array"); static_assert(IsArray>::value, "list mapped to array"); static_assert(!IsArray>::value, "set not considered an array"); static_assert(!IsArray>::value, "multiset not considered an array"); static_assert(IsArrayOrSet>::value, "set is array or set"); static_assert(IsArrayOrSet>::value, "multiset is array or set"); static_assert(IsArrayOrSet::value, "Foo is array or set via TreatAsMultiSet"); static_assert(IsArrayOrSet::value, "Foo is array or set via TreatAsSet"); static_assert(!IsArrayOrSet::value, "string not mapped to array or set though it is iteratable"); static_assert(IsSet>::value, "set mapped to set"); static_assert(IsSet>::value, "unordered_set mapped to set"); static_assert(IsSet::value, "Bar mapped to set via TreatAsSet"); static_assert(!IsSet::value, "string not mapped to set"); static_assert(IsMultiSet>::value, "multiset"); static_assert(IsMultiSet::value, "Foo mapped to multiset via TreatAsMultiSet"); static_assert(!IsMultiSet::value, "string not mapped to multiset"); static_assert(!IsArray::value, "string not mapped to array though it is iteratable"); static_assert(IsMapOrHash>::value, "map mapped to object"); static_assert(IsMapOrHash>::value, "hash mapped to object"); static_assert(!IsMapOrHash>::value, "vector not mapped to object"); static_assert(IsMapOrHash::value, "Foo mapped to object via TreatAsMapOrHash"); static_assert(IsMultiMapOrHash>::value, "multimap mapped to object"); static_assert(IsMultiMapOrHash>::value, "unordered multimap mapped to object"); static_assert(!IsMultiMapOrHash>::value, "vector not mapped to object"); static_assert(IsMultiMapOrHash::value, "Foo mapped to object via TreatAsMultiMapOrHash"); static_assert(IsIteratableExceptString>::value, "vector is iteratable"); static_assert(!IsIteratableExceptString::value, "string not iteratable"); static_assert(!IsIteratableExceptString::value, "wstring not iteratable"); static_assert(!IsIteratableExceptString::value, "string not iteratable"); // test versioning traits static_assert(!Versioning::enabled, "versioning for built-in types not enabled"); static_assert(!Versioning::enabled, "versioning for standard types not enabled"); static_assert(!Versioning::enabled, "versioning not enabled by default"); static_assert(Versioning>::enabled, "versioning enabled if non-zero version parameter specified (derived)"); static_assert(Versioning::enabled, "versioning enabled if non-zero version parameter specified (base)"); static_assert(!Versioning>::enabled, "versioning disabled for derived, even if base is versioned"); static_assert(!Versioning>::enabled, "versioning disabled if zero-version specified"); static_assert(Versioning>::applyDefault(0) == 3, "default version returned"); static_assert(Versioning>::applyDefault(2) == 2, "default version overridden");