| 974 | }; |
| 975 | |
| 976 | TEST(ValueMarshallerRegistry, canMarshallSimpleObject) { |
| 977 | auto schemaRegistry = makeShared<ValueSchemaRegistry>(); |
| 978 | auto valueMarshallerRegistry = makeShared<TestValueMarshallerRegistry>(schemaRegistry); |
| 979 | |
| 980 | auto schema = ValueSchema::parse("c 'MyObject'{'aString': s, 'aDouble': d}"); |
| 981 | |
| 982 | ASSERT_TRUE(schema) << schema.description(); |
| 983 | |
| 984 | auto identifier = schemaRegistry->registerSchema(schema.value()); |
| 985 | |
| 986 | SimpleExceptionTracker exceptionTracker; |
| 987 | auto object = |
| 988 | Value().setMapValue("aString", Value(STRING_LITERAL("Hello world"))).setMapValue("aDouble", Value(42.0)); |
| 989 | |
| 990 | auto result = valueMarshallerRegistry->unmarshall(identifier, object, exceptionTracker); |
| 991 | |
| 992 | ASSERT_TRUE(exceptionTracker) << exceptionTracker.extractError().toString(); |
| 993 | |
| 994 | auto testObject = result.getTypedRef<TestObject>(); |
| 995 | ASSERT_TRUE(testObject != nullptr); |
| 996 | |
| 997 | ASSERT_EQ(static_cast<size_t>(2), testObject->getPropertiesSize()); |
| 998 | |
| 999 | ASSERT_EQ(Value(STRING_LITERAL("Hello world")), testObject->getProperty(0)); |
| 1000 | ASSERT_EQ(Value(42.0), testObject->getProperty(1)); |
| 1001 | |
| 1002 | // Now attempt marshalling |
| 1003 | |
| 1004 | testObject->setProperty(0, Value(STRING_LITERAL("Goodbye"))); |
| 1005 | testObject->setProperty(1, Value(90.0)); |
| 1006 | |
| 1007 | auto marshalledValue = valueMarshallerRegistry->marshall(identifier, Value(testObject), exceptionTracker); |
| 1008 | |
| 1009 | ASSERT_TRUE(exceptionTracker) << exceptionTracker.extractError().toString(); |
| 1010 | |
| 1011 | ASSERT_EQ(Value(ValueTypedObject::make(schema.value().getClassRef(), |
| 1012 | {Value(StaticString::makeUTF8("Goodbye")), Value(90.0)})), |
| 1013 | marshalledValue); |
| 1014 | |
| 1015 | ASSERT_EQ( |
| 1016 | Value().setMapValue("aString", Value(StaticString::makeUTF8("Goodbye"))).setMapValue("aDouble", Value(90.0)), |
| 1017 | Value(marshalledValue.getTypedObject()->toValueMap(true))); |
| 1018 | } |
| 1019 | |
| 1020 | TEST(ValueMarshallerRegistry, performsTypeValidationWhileUnmarshalling) { |
| 1021 | auto schemaRegistry = makeShared<ValueSchemaRegistry>(); |
nothing calls this directly
no test coverage detected