MCPcopy Create free account
hub / github.com/Snapchat/Valdi / TEST

Function TEST

valdi/test/runtime/ValueMarshallerRegistry_tests.cpp:976–1018  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

974};
975
976TEST(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
1020TEST(ValueMarshallerRegistry, performsTypeValidationWhileUnmarshalling) {
1021 auto schemaRegistry = makeShared<ValueSchemaRegistry>();

Callers

nothing calls this directly

Calls 15

optionalFunction · 0.85
flattenValueFunction · 0.85
descriptionMethod · 0.80
extractErrorMethod · 0.80
getClassRefMethod · 0.80
getArrayRefMethod · 0.80
asBoxedMethod · 0.80
getParameterMethod · 0.80
getTypedObjectRefMethod · 0.80
getTasksCountMethod · 0.80

Tested by

no test coverage detected