diff options
3 files changed, 167 insertions, 118 deletions
diff --git a/searchcore/src/tests/proton/docsummary/docsummary.cpp b/searchcore/src/tests/proton/docsummary/docsummary.cpp index 4ede2aeb4cf..1098de4438f 100644 --- a/searchcore/src/tests/proton/docsummary/docsummary.cpp +++ b/searchcore/src/tests/proton/docsummary/docsummary.cpp @@ -35,6 +35,8 @@ #include <vespa/searchlib/tensor/tensor_attribute.h> #include <vespa/searchlib/transactionlog/nosyncproxy.h> #include <vespa/searchlib/transactionlog/translogserver.h> +#include <vespa/searchsummary/docsummary/i_docsum_store_document.h> +#include <vespa/searchsummary/docsummary/summaryfieldconverter.h> #include <vespa/vespalib/data/simple_buffer.h> #include <vespa/vespalib/data/slime/json_format.h> #include <vespa/vespalib/data/slime/slime.h> @@ -93,6 +95,26 @@ private: vespalib::string _dir; }; +DocsumBlobEntryFilter make_blob_entry_filter() +{ + return DocsumBlobEntryFilter(). + add_skip(RES_INT). + add_skip(RES_SHORT). + add_skip(RES_BOOL). + add_skip(RES_BYTE). + add_skip(RES_FLOAT). + add_skip(RES_DOUBLE). + add_skip(RES_INT64). + add_skip(RES_STRING). + add_skip(RES_DATA). + add_skip(RES_LONG_STRING). + add_skip(RES_LONG_DATA). + add_skip(RES_JSONSTRING). + add_skip(RES_TENSOR). + add_skip(RES_FEATUREDATA); +} + + class BuildContext { public: @@ -159,8 +181,10 @@ vespalib::string asVstring(const Inspector &value) { return asVstring(value.asString()); } -void decode(const ResEntry *entry, vespalib::Slime &slime) { - vespalib::Memory mem(entry->_dataval, entry->_datalen); +void decode(const FieldValue &fv, vespalib::Slime &slime) { + auto& raw_fv = dynamic_cast<const RawFieldValue&>(fv); + auto value_ref = raw_fv.getValueRef(); + vespalib::Memory mem(value_ref.data(), value_ref.size()); size_t decodeRes = BinaryFormat::decode(mem, slime); ASSERT_EQUAL(decodeRes, mem.size); } @@ -307,13 +331,11 @@ public: }; GeneralResultPtr -getResult(DocumentStoreAdapter & dsa, uint32_t docId) +getResult(DocumentStoreAdapter & dsa, const DocsumStoreValue& docsum) { - DocsumStoreValue docsum = dsa.getMappedDocsum(docId); ASSERT_TRUE(docsum.pt() != nullptr); auto retval = std::make_unique<GeneralResult>(dsa.getResultClass()); - // skip the 4 byte class id - ASSERT_TRUE(retval->unpack(docsum.pt() + 4, docsum.len() - 4)); + ASSERT_TRUE(retval->inplaceUnpack(docsum)); return retval; } @@ -321,9 +343,19 @@ bool assertString(const std::string & exp, const std::string & fieldName, DocumentStoreAdapter &dsa, uint32_t id) { - GeneralResultPtr res = getResult(dsa, id); - return EXPECT_EQUAL(exp, std::string(res->GetPresentEntry(fieldName.c_str())->_stringval, - res->GetPresentEntry(fieldName.c_str())->_stringlen)); + auto docsum = dsa.getMappedDocsum(id); + GeneralResultPtr res = getResult(dsa, docsum); + return EXPECT_EQUAL(exp, res->get_field_value(fieldName)->getAsString()); +} + +bool +assertAnnotatedString(const std::string & exp, const std::string & fieldName, + DocumentStoreAdapter &dsa, uint32_t id) +{ + auto docsum = dsa.getMappedDocsum(id); + GeneralResultPtr res = getResult(dsa, docsum); + auto document = res->get_document(); + return EXPECT_EQUAL(exp, document->get_juniper_input(fieldName).get_value()); } void @@ -391,25 +423,20 @@ TEST_F("requireThatAdapterHandlesAllFieldTypes", Fixture) f.getResultConfig(), "class0", bc.createFieldCacheRepo(f.getResultConfig())->getFieldCache("class0"), f.getMarkupFields()); - GeneralResultPtr res = getResult(dsa, 0); - EXPECT_EQUAL(255u, res->GetPresentEntry("a")->_intval); - EXPECT_EQUAL(32767u, res->GetPresentEntry("b")->_intval); - EXPECT_EQUAL(2147483647u, res->GetPresentEntry("c")->_intval); - EXPECT_EQUAL(2147483648u, res->GetPresentEntry("d")->_int64val); - EXPECT_APPROX(1234.56, res->GetPresentEntry("e")->_doubleval, 10e-5); - EXPECT_APPROX(9876.54, res->GetPresentEntry("f")->_doubleval, 10e-5); - EXPECT_EQUAL("foo", std::string(res->GetPresentEntry("g")->_stringval, - res->GetPresentEntry("g")->_stringlen)); - EXPECT_EQUAL("bar", std::string(res->GetPresentEntry("h")->_stringval, - res->GetPresentEntry("h")->_stringlen)); - EXPECT_EQUAL("baz", std::string(res->GetPresentEntry("i")->_dataval, - res->GetPresentEntry("i")->_datalen)); - EXPECT_EQUAL("qux", std::string(res->GetPresentEntry("j")->_dataval, - res->GetPresentEntry("j")->_datalen)); - EXPECT_EQUAL("<foo>", std::string(res->GetPresentEntry("k")->_stringval, - res->GetPresentEntry("k")->_stringlen)); - EXPECT_EQUAL("{foo:10}", std::string(res->GetPresentEntry("l")->_stringval, - res->GetPresentEntry("l")->_stringlen)); + auto docsum = dsa.getMappedDocsum(0); + GeneralResultPtr res = getResult(dsa, docsum); + EXPECT_EQUAL(-1, res->get_field_value("a")->getAsInt()); + EXPECT_EQUAL(32767, res->get_field_value("b")->getAsInt()); + EXPECT_EQUAL(2147483647, res->get_field_value("c")->getAsInt()); + EXPECT_EQUAL(INT64_C(2147483648), res->get_field_value("d")->getAsLong()); + EXPECT_APPROX(1234.56, res->get_field_value("e")->getAsFloat(), 10e-5); + EXPECT_APPROX(9876.54, res->get_field_value("f")->getAsDouble(), 10e-5); + EXPECT_EQUAL("foo", res->get_field_value("g")->getAsString()); + EXPECT_EQUAL("bar", res->get_field_value("h")->getAsString()); + EXPECT_EQUAL("baz", res->get_field_value("i")->getAsString()); + EXPECT_EQUAL("qux", res->get_field_value("j")->getAsString()); + EXPECT_EQUAL("<foo>", res->get_field_value("k")->getAsString()); + EXPECT_EQUAL("{foo:10}", res->get_field_value("l")->getAsString()); } TEST_F("requireThatAdapterHandlesMultipleDocuments", Fixture) @@ -432,20 +459,23 @@ TEST_F("requireThatAdapterHandlesMultipleDocuments", Fixture) bc.createFieldCacheRepo(f.getResultConfig())->getFieldCache("class1"), f.getMarkupFields()); { // doc 0 - GeneralResultPtr res = getResult(dsa, 0); - EXPECT_EQUAL(1000u, res->GetPresentEntry("a")->_intval); + auto docsum = dsa.getMappedDocsum(0); + GeneralResultPtr res = getResult(dsa, docsum); + EXPECT_EQUAL(1000, res->get_field_value("a")->getAsInt()); } { // doc 1 - GeneralResultPtr res = getResult(dsa, 1); - EXPECT_EQUAL(2000u, res->GetPresentEntry("a")->_intval); + auto docsum = dsa.getMappedDocsum(1); + GeneralResultPtr res = getResult(dsa, docsum); + EXPECT_EQUAL(2000, res->get_field_value("a")->getAsInt()); } { // doc 2 - DocsumStoreValue docsum = dsa.getMappedDocsum(2); + auto docsum = dsa.getMappedDocsum(2); EXPECT_TRUE(docsum.pt() == nullptr); } { // doc 0 (again) - GeneralResultPtr res = getResult(dsa, 0); - EXPECT_EQUAL(1000u, res->GetPresentEntry("a")->_intval); + auto docsum = dsa.getMappedDocsum(0); + GeneralResultPtr res = getResult(dsa, docsum); + EXPECT_EQUAL(1000, res->get_field_value("a")->getAsInt()); } EXPECT_EQUAL(0u, bc._str.lastSyncToken()); uint64_t flushToken = bc._str.initFlush(bc._serialNum - 1); @@ -465,9 +495,12 @@ TEST_F("requireThatAdapterHandlesDocumentIdField", Fixture) DocumentStoreAdapter dsa(bc._str, *bc._repo, f.getResultConfig(), "class4", bc.createFieldCacheRepo(f.getResultConfig())->getFieldCache("class4"), f.getMarkupFields()); - GeneralResultPtr res = getResult(dsa, 0); - EXPECT_EQUAL("id:ns:searchdocument::0", std::string(res->GetPresentEntry("documentid")->_stringval, - res->GetPresentEntry("documentid")->_stringlen)); + auto docsum = dsa.getMappedDocsum(0); + GeneralResultPtr res = getResult(dsa, docsum); + vespalib::Slime slime; + vespalib::slime::SlimeInserter inserter(slime); + res->get_document()->insert_document_id(inserter); + EXPECT_EQUAL("id:ns:searchdocument::0", slime.get().asString().make_string()); } GlobalId gid1 = DocumentId("id:ns:searchdocument::1").getGlobalId(); // lid 1 @@ -805,11 +838,11 @@ TEST_F("requireThatAnnotationsAreUsed", Fixture) bc.createFieldCacheRepo(f.getResultConfig())->getFieldCache("class0"), f.getMarkupFields()); EXPECT_TRUE(assertString("foo bar", "g", dsa, 1)); - EXPECT_TRUE(assertString(TERM_EMPTY + "foo" + TERM_SEP + - " " + TERM_SEP + - TERM_ORIG + "bar" + TERM_INDEX + "baz" + TERM_END + - TERM_SEP, - "dynamicstring", dsa, 1)); + EXPECT_TRUE(assertAnnotatedString(TERM_EMPTY + "foo" + TERM_SEP + + " " + TERM_SEP + + TERM_ORIG + "bar" + TERM_INDEX + "baz" + TERM_END + + TERM_SEP, + "dynamicstring", dsa, 1)); } TEST_F("requireThatUrisAreUsed", Fixture) @@ -955,19 +988,19 @@ TEST_F("requireThatUrisAreUsed", Fixture) DocumentStoreAdapter dsa(store, *bc._repo, f.getResultConfig(), "class0", bc.createFieldCacheRepo(f.getResultConfig())->getFieldCache("class0"), f.getMarkupFields()); - - EXPECT_TRUE(assertString("http://www.example.com:81/fluke?ab=2#4", "urisingle", dsa, 1)); - GeneralResultPtr res = getResult(dsa, 1); + auto docsum = dsa.getMappedDocsum(1); + GeneralResultPtr res = getResult(dsa, docsum); + EXPECT_EQUAL("http://www.example.com:81/fluke?ab=2#4", SummaryFieldConverter::convertSummaryField(false, *res->get_field_value("urisingle"))->getAsString()); { vespalib::Slime slime; - decode(res->GetPresentEntry("uriarray"), slime); + decode(*SummaryFieldConverter::convertSummaryField(false, *res->get_field_value("uriarray")), slime); EXPECT_TRUE(slime.get().valid()); EXPECT_EQUAL("http://www.example.com:82/fluke?ab=2#8", asVstring(slime.get()[0])); EXPECT_EQUAL("http://www.flickr.com:82/fluke?ab=2#9", asVstring(slime.get()[1])); } { vespalib::Slime slime; - decode(res->GetPresentEntry("uriwset"), slime); + decode(*SummaryFieldConverter::convertSummaryField(false, *res->get_field_value("uriwset")), slime); EXPECT_TRUE(slime.get().valid()); EXPECT_EQUAL(4L, slime.get()[0]["weight"].asLong()); EXPECT_EQUAL(7L, slime.get()[1]["weight"].asLong()); @@ -1086,17 +1119,18 @@ TEST_F("requireThatRawFieldsWorks", Fixture) ASSERT_TRUE(assertString(raw1s, "i", dsa, 1)); - GeneralResultPtr res = getResult(dsa, 1); + auto docsum = dsa.getMappedDocsum(1); + GeneralResultPtr res = getResult(dsa, docsum); { vespalib::Slime slime; - decode(res->GetPresentEntry("araw"), slime); + decode(*SummaryFieldConverter::convertSummaryField(false, *res->get_field_value("araw")), slime); EXPECT_TRUE(slime.get().valid()); EXPECT_EQUAL(vespalib::Base64::encode(raw1a0), b64encode(slime.get()[0])); EXPECT_EQUAL(vespalib::Base64::encode(raw1a1), b64encode(slime.get()[1])); } { vespalib::Slime slime; - decode(res->GetPresentEntry("wraw"), slime); + decode(*SummaryFieldConverter::convertSummaryField(false, *res->get_field_value("wraw")), slime); EXPECT_TRUE(slime.get().valid()); EXPECT_EQUAL(46L, slime.get()[0]["weight"].asLong()); EXPECT_EQUAL(45L, slime.get()[1]["weight"].asLong()); @@ -1121,7 +1155,7 @@ TEST_F("requireThatFieldCacheRepoCanReturnDefaultFieldCache", Fixture) Fixture::Fixture() : _summaryCfg(), - _resultCfg(), + _resultCfg(make_blob_entry_filter()), _markupFields() { std::string cfgId("summary"); diff --git a/searchsummary/src/tests/docsummary/matched_elements_filter/matched_elements_filter_test.cpp b/searchsummary/src/tests/docsummary/matched_elements_filter/matched_elements_filter_test.cpp index 82aa9ceba92..06ff6b1fbe7 100644 --- a/searchsummary/src/tests/docsummary/matched_elements_filter/matched_elements_filter_test.cpp +++ b/searchsummary/src/tests/docsummary/matched_elements_filter/matched_elements_filter_test.cpp @@ -64,6 +64,7 @@ constexpr uint32_t doc_id = 2; class DocsumStore { private: + DocsumBlobEntryFilter _docsum_blob_entry_filter; ResultConfig _config; ResultPacker _packer; DocumentType _doc_type; @@ -78,26 +79,19 @@ private: return result; } - void write_field_value(const FieldValue& value) { - auto converted = SummaryFieldConverter::convertSummaryField(false, value); - const auto* raw_field = dynamic_cast<const RawFieldValue*>(converted.get()); - ASSERT_TRUE(raw_field); - auto raw_buf = raw_field->getAsRaw(); - bool result = _packer.AddLongString(raw_buf.first, raw_buf.second); - ASSERT_TRUE(result); - } - public: DocsumStore() - : _config(), + : _docsum_blob_entry_filter(DocsumBlobEntryFilter().add_skip(ResType::RES_JSONSTRING)), + _config(_docsum_blob_entry_filter), _packer(&_config), _doc_type("test"), _elem_type(make_struct_elem_type()), _array_type(*_elem_type), _map_type(*DataType::STRING, *_elem_type) { - _doc_type.addField(Field("array_in_doc", _array_type)); - _doc_type.addField(Field("map_in_doc", _map_type)); + _doc_type.addField(Field("array", _array_type)); + _doc_type.addField(Field("map", _map_type)); + _doc_type.addField(Field("map2", _map_type)); auto* result_class = _config.AddResultClass("test", class_id); EXPECT_TRUE(result_class->AddConfigEntry("array", ResType::RES_JSONSTRING)); @@ -116,21 +110,19 @@ public: array_value.append(make_elem_value("a", 3)); array_value.append(make_elem_value("b", 5)); array_value.append(make_elem_value("c", 7)); - write_field_value(array_value); - doc->setValue("array_in_doc", array_value); + doc->setValue("array", array_value); } { MapFieldValue map_value(_map_type); map_value.put(StringFieldValue("a"), *make_elem_value("a", 3)); map_value.put(StringFieldValue("b"), *make_elem_value("b", 5)); map_value.put(StringFieldValue("c"), *make_elem_value("c", 7)); - write_field_value(map_value); - doc->setValue("map_in_doc", map_value); + doc->setValue("map", map_value); } { MapFieldValue map2_value(_map_type); map2_value.put(StringFieldValue("dummy"), *make_elem_value("dummy", 2)); - write_field_value(map2_value); + doc->setValue("map2", map2_value); } const char* buf; uint32_t buf_len; @@ -241,18 +233,7 @@ TEST_F(MatchedElementsFilterTest, filters_elements_in_array_field_value) expect_filtered("array", {0, 1, 2}, "[{'name':'a','weight':3}," "{'name':'b','weight':5}," "{'name':'c','weight':7}]"); -} - -TEST_F(MatchedElementsFilterTest, filters_elements_in_array_field_value_when_input_field_is_not_in_docsum_blob) -{ - expect_filtered("array_in_doc", {}, "[]"); - expect_filtered("array_in_doc", {0}, "[{'name':'a','weight':3}]"); - expect_filtered("array_in_doc", {1}, "[{'name':'b','weight':5}]"); - expect_filtered("array_in_doc", {2}, "[{'name':'c','weight':7}]"); - expect_filtered("array_in_doc", {0, 1, 2}, "[{'name':'a','weight':3}," - "{'name':'b','weight':5}," - "{'name':'c','weight':7}]"); - expect_filtered("array_in_doc", {0, 1, 100}, "[]"); + expect_filtered("array", {0, 1, 100}, "[]"); } TEST_F(MatchedElementsFilterTest, matching_elements_fields_is_setup_for_array_field_value) @@ -272,18 +253,7 @@ TEST_F(MatchedElementsFilterTest, filters_elements_in_map_field_value) expect_filtered("map", {0, 1, 2}, "[{'key':'a','value':{'name':'a','weight':3}}," "{'key':'b','value':{'name':'b','weight':5}}," "{'key':'c','value':{'name':'c','weight':7}}]"); -} - -TEST_F(MatchedElementsFilterTest, filters_elements_in_map_field_value_when_input_field_is_not_in_docsum_blob) -{ - expect_filtered("map_in_doc", {}, "[]"); - expect_filtered("map_in_doc", {0}, "[{'key':'a','value':{'name':'a','weight':3}}]"); - expect_filtered("map_in_doc", {1}, "[{'key':'b','value':{'name':'b','weight':5}}]"); - expect_filtered("map_in_doc", {2}, "[{'key':'c','value':{'name':'c','weight':7}}]"); - expect_filtered("map_in_doc", {0, 1, 2}, "[{'key':'a','value':{'name':'a','weight':3}}," - "{'key':'b','value':{'name':'b','weight':5}}," - "{'key':'c','value':{'name':'c','weight':7}}]"); - expect_filtered("map_in_doc", {0, 1, 100}, "[]"); + expect_filtered("map", {0, 1, 100}, "[]"); } TEST_F(MatchedElementsFilterTest, matching_elements_fields_is_setup_for_map_field_value) diff --git a/searchsummary/src/tests/docsummary/slime_summary/slime_summary_test.cpp b/searchsummary/src/tests/docsummary/slime_summary/slime_summary_test.cpp index 5855dd0e8fd..13ae741c8a0 100644 --- a/searchsummary/src/tests/docsummary/slime_summary/slime_summary_test.cpp +++ b/searchsummary/src/tests/docsummary/slime_summary/slime_summary_test.cpp @@ -1,9 +1,21 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include <vespa/document/base/documentid.h> +#include <vespa/document/datatype/documenttype.h> +#include <vespa/document/fieldvalue/document.h> +#include <vespa/document/fieldvalue/bytefieldvalue.h> +#include <vespa/document/fieldvalue/doublefieldvalue.h> +#include <vespa/document/fieldvalue/floatfieldvalue.h> +#include <vespa/document/fieldvalue/intfieldvalue.h> +#include <vespa/document/fieldvalue/longfieldvalue.h> +#include <vespa/document/fieldvalue/rawfieldvalue.h> +#include <vespa/document/fieldvalue/shortfieldvalue.h> +#include <vespa/document/fieldvalue/stringfieldvalue.h> #include <vespa/vespalib/testkit/test_kit.h> #include <vespa/searchlib/common/matching_elements.h> #include <vespa/searchsummary/docsummary/docsumwriter.h> #include <vespa/searchsummary/docsummary/resultpacker.h> #include <vespa/searchsummary/docsummary/docsumstate.h> +#include <vespa/searchsummary/docsummary/docsum_store_document.h> #include <vespa/vespalib/data/slime/slime.h> #include <vespa/searchlib/util/slime_output_raw_buf_adapter.h> #include <vespa/vespalib/util/size_literals.h> @@ -11,6 +23,21 @@ using namespace vespalib::slime::convenience; using namespace search::docsummary; using search::MatchingElements; +using document::ByteFieldValue; +using document::DataType; +using document::Document; +using document::DocumentId; +using document::DocumentType; +using document::DoubleFieldValue; +using document::Field; +using document::FloatFieldValue; +using document::IntFieldValue; +using document::LongFieldValue; +using document::RawFieldValue; +using document::ShortFieldValue; +using document::StringFieldValue; +using document::StructDataType; +using document::StructFieldValue; namespace { @@ -31,8 +58,11 @@ struct FieldBlock { }; struct DocsumFixture : IDocsumStore, GetDocsumsStateCallback { + DocsumBlobEntryFilter docsum_blob_entry_filter; std::unique_ptr<DynamicDocsumWriter> writer; std::unique_ptr<ResultPacker> packer; + StructDataType int_pair_type; + DocumentType doc_type; GetDocsumsState state; DocsumFixture(); ~DocsumFixture(); @@ -51,27 +81,27 @@ struct DocsumFixture : IDocsumStore, GetDocsumsStateCallback { DocsumStoreValue getMappedDocsum(uint32_t docid) override { EXPECT_EQUAL(1u, docid); EXPECT_TRUE(packer->Init(0)); - EXPECT_TRUE(packer->AddInteger(4)); - EXPECT_TRUE(packer->AddShort(2)); - EXPECT_TRUE(packer->AddByte(1)); - EXPECT_TRUE(packer->AddFloat(4.5)); - EXPECT_TRUE(packer->AddDouble(8.75)); - EXPECT_TRUE(packer->AddInt64(8)); - EXPECT_TRUE(packer->AddString( "string", - strlen("string"))); - EXPECT_TRUE(packer->AddData( "data", - strlen("data"))); - EXPECT_TRUE(packer->AddLongString( "long_string", - strlen("long_string"))); - EXPECT_TRUE(packer->AddLongData( "long_data", - strlen("long_data"))); - FieldBlock jsf1("{foo:1, bar:2}"); - EXPECT_TRUE(packer->AddLongData(jsf1.data(), jsf1.dataLen())); - EXPECT_TRUE(packer->AddLongString("abc", 3)); + auto doc = std::make_unique<Document>(doc_type, DocumentId("id:test:test::0")); + doc->setValue("int_field", IntFieldValue(4)); + doc->setValue("short_field", ShortFieldValue(2)); + doc->setValue("byte_field", ByteFieldValue(1)); + doc->setValue("float_field", FloatFieldValue(4.5)); + doc->setValue("double_field", DoubleFieldValue(8.75)); + doc->setValue("int64_field", LongFieldValue(8)); + doc->setValue("string_field", StringFieldValue("string")); + doc->setValue("data_field", RawFieldValue("data")); + doc->setValue("longstring_field", StringFieldValue("long_string")); + doc->setValue("longdata_field", RawFieldValue("long_data")); + { + StructFieldValue int_pair(int_pair_type); + int_pair.setValue("foo", IntFieldValue(1)); + int_pair.setValue("bar", IntFieldValue(2)); + doc->setValue("int_pair_field", int_pair); + } const char *buf; uint32_t len; EXPECT_TRUE(packer->GetDocsumBlob(&buf, &len)); - return DocsumStoreValue(buf, len); + return DocsumStoreValue(buf, len, std::make_unique<DocsumStoreDocument>(std::move(doc))); } uint32_t getSummaryClassId() const override { return 0; } void FillSummaryFeatures(GetDocsumsState *, IDocsumEnvironment *) override { } @@ -81,9 +111,13 @@ struct DocsumFixture : IDocsumStore, GetDocsumsStateCallback { DocsumFixture::DocsumFixture() - : writer(), packer(), state(*this) + : docsum_blob_entry_filter(DocsumBlobEntryFilter().add_skip(RES_INT).add_skip(RES_SHORT).add_skip(RES_BYTE).add_skip(RES_FLOAT).add_skip(RES_DOUBLE).add_skip(RES_INT64).add_skip(RES_STRING).add_skip(RES_DATA).add_skip(RES_LONG_STRING).add_skip(RES_LONG_DATA).add_skip(RES_JSONSTRING)), + writer(), packer(), + int_pair_type("int_pair"), + doc_type("test"), + state(*this) { - ResultConfig *config = new ResultConfig(); + ResultConfig *config = new ResultConfig(docsum_blob_entry_filter); ResultClass *cfg = config->AddResultClass("default", 0); EXPECT_TRUE(cfg != 0); EXPECT_TRUE(cfg->AddConfigEntry("int_field", RES_INT)); @@ -96,11 +130,23 @@ DocsumFixture::DocsumFixture() EXPECT_TRUE(cfg->AddConfigEntry("data_field", RES_DATA)); EXPECT_TRUE(cfg->AddConfigEntry("longstring_field", RES_LONG_STRING)); EXPECT_TRUE(cfg->AddConfigEntry("longdata_field", RES_LONG_DATA)); - EXPECT_TRUE(cfg->AddConfigEntry("jsonstring_field", RES_JSONSTRING)); - EXPECT_TRUE(cfg->AddConfigEntry("bad_jsonstring_field", RES_JSONSTRING)); + EXPECT_TRUE(cfg->AddConfigEntry("int_pair_field", RES_JSONSTRING)); config->CreateEnumMaps(); writer.reset(new DynamicDocsumWriter(config, 0)); packer.reset(new ResultPacker(writer->GetResultConfig())); + int_pair_type.addField(Field("foo", *DataType::INT)); + int_pair_type.addField(Field("bar", *DataType::INT)); + doc_type.addField(Field("int_field", *DataType::INT)); + doc_type.addField(Field("short_field", *DataType::SHORT)); + doc_type.addField(Field("byte_field", *DataType::BYTE)); + doc_type.addField(Field("float_field", *DataType::FLOAT)); + doc_type.addField(Field("double_field", *DataType::DOUBLE)); + doc_type.addField(Field("int64_field", *DataType::LONG)); + doc_type.addField(Field("string_field", *DataType::STRING)); + doc_type.addField(Field("data_field", *DataType::RAW)); + doc_type.addField(Field("longstring_field", *DataType::STRING)); + doc_type.addField(Field("longdata_field", *DataType::RAW)); + doc_type.addField(Field("int_pair_field", int_pair_type)); } DocsumFixture::~DocsumFixture() {} @@ -118,9 +164,8 @@ TEST_FF("require that docsum can be written as slime", DocsumFixture(), Slime()) EXPECT_EQUAL(f2.get()["data_field"].asData().make_string(), std::string("data")); EXPECT_EQUAL(f2.get()["longstring_field"].asString().make_string(), std::string("long_string")); EXPECT_EQUAL(f2.get()["longdata_field"].asData().make_string(), std::string("long_data")); - EXPECT_EQUAL(f2.get()["jsonstring_field"]["foo"].asLong(), 1u); - EXPECT_EQUAL(f2.get()["jsonstring_field"]["bar"].asLong(), 2u); - EXPECT_EQUAL(f2.get()["bad_jsonstring_field"].type().getId(), 0u); + EXPECT_EQUAL(f2.get()["int_pair_field"]["foo"].asLong(), 1u); + EXPECT_EQUAL(f2.get()["int_pair_field"]["bar"].asLong(), 2u); } TEST_MAIN() { TEST_RUN_ALL(); } |