diff options
author | Tor Brede Vekterli <vekterli@yahoo-inc.com> | 2017-02-03 14:46:38 +0100 |
---|---|---|
committer | Tor Brede Vekterli <vekterli@yahoo-inc.com> | 2017-02-06 13:16:41 +0100 |
commit | 3ef1af8be251d1854d9e2829eea915eaaae5e31c (patch) | |
tree | 3e1f301293d23136efa80713db17921e69ed87cd /document/src/tests/serialization | |
parent | f4ace23e3314e4dd3708044c38453c1ac15c2a5e (diff) |
Add Java/C++ cross-language serialization tests for references
Diffstat (limited to 'document/src/tests/serialization')
-rw-r--r-- | document/src/tests/serialization/vespadocumentserializer_test.cpp | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/document/src/tests/serialization/vespadocumentserializer_test.cpp b/document/src/tests/serialization/vespadocumentserializer_test.cpp index a1436b954e7..fe065e563ba 100644 --- a/document/src/tests/serialization/vespadocumentserializer_test.cpp +++ b/document/src/tests/serialization/vespadocumentserializer_test.cpp @@ -100,9 +100,9 @@ DocumenttypesConfig getDocTypesConfig() { Struct("my_type.body") .addField(predicate_field_name, DataType::T_PREDICATE)); builder.document(doc_with_ref_type_id, doc_with_ref_name, - Struct(doc_with_ref_name + ".header"), - Struct(doc_with_ref_name + ".body") - .addField(ref_field_name, ref_type_id)) + Struct(doc_with_ref_name + ".header") + .addField(ref_field_name, ref_type_id), + Struct(doc_with_ref_name + ".body")) .referenceType(ref_type_id, doc_type_id); return builder.config(); } @@ -879,7 +879,8 @@ TEST("Require that tensor deserialization matches Java") { } struct RefFixture { - FixedTypeRepo fixed_repo{doc_repo, *doc_repo.getDocumentType(doc_with_ref_type_id)}; + const DocumentType* ref_doc_type{doc_repo.getDocumentType(doc_with_ref_type_id)}; + FixedTypeRepo fixed_repo{doc_repo, *ref_doc_type}; const ReferenceDataType& ref_type() const { auto* raw_type = fixed_repo.getDataType(ref_type_id); @@ -895,6 +896,18 @@ struct RefFixture { VespaDocumentDeserializer deserializer(fixed_repo, stream, serialization_version); deserializer.read(dest); } + + void verify_cross_language_serialization(const string& file_base_name, + const ReferenceFieldValue& value) { + const string data_dir = TEST_PATH("../../test/resources/reference/"); + serializeToFile(value, data_dir + file_base_name + "__cpp", + ref_doc_type, "ref_field"); + + deserializeAndCheck(data_dir + file_base_name + "__cpp", + value, fixed_repo, "ref_field"); + deserializeAndCheck(data_dir + file_base_name + "__java", + value, fixed_repo, "ref_field"); + } }; TEST_F("Empty ReferenceFieldValue can be roundtrip serialized", RefFixture) { @@ -927,6 +940,17 @@ TEST_F("ReferenceFieldValue with ID has changed-flag cleared after deserializati EXPECT_FALSE(dest.hasChanged()); } +TEST_F("Empty ReferenceFieldValue serialization matches Java", RefFixture) { + ReferenceFieldValue value(f.ref_type()); + f.verify_cross_language_serialization("empty_reference", value); +} + +TEST_F("ReferenceFieldValue with ID serialization matches Java", RefFixture) { + ReferenceFieldValue value( + f.ref_type(), DocumentId("id:ns:" + doc_name + "::bar")); + f.verify_cross_language_serialization("reference_with_id", value); +} + } // namespace TEST_MAIN() { TEST_RUN_ALL(); } |