// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include #include #include #include #include #include #include #include #include LOG_SETUP("document_db_reference_test"); using namespace proton; using search::AttributeFactory; using search::AttributeVector; using search::IDocumentMetaStoreContext; using search::attribute::BasicType; using search::attribute::ImportedAttributeVector; using search::attribute::ReadableAttributeVector; using search::attribute::ReferenceAttribute; ImportedAttributesRepo::UP makeImportedAttributesRepo() { ImportedAttributesRepo::UP result = std::make_unique(); ImportedAttributeVector::SP attr = std::make_shared("imported", std::shared_ptr(), std::shared_ptr(), std::shared_ptr(), std::shared_ptr(), false); result->add("imported", std::move(attr)); return result; } struct Fixture { std::shared_ptr attrMgr; DocumentDBReference ref; Fixture() : attrMgr(std::make_shared()), ref(attrMgr, std::shared_ptr(), std::shared_ptr()) { attrMgr->addAttribute("regular", AttributeFactory::createAttribute("regular", {BasicType::INT32})); attrMgr->setImportedAttributes(makeImportedAttributesRepo()); } }; TEST_F("regular attribute vector can be retrieved", Fixture) { auto attr = f.ref.getAttribute("regular"); EXPECT_TRUE(attr.get()); const AttributeVector *attrPtr = dynamic_cast(attr.get()); EXPECT_TRUE(attrPtr != nullptr); } TEST_F("imported attribute vector can be retrieved", Fixture) { auto attr = f.ref.getAttribute("imported"); EXPECT_TRUE(attr.get()); const ImportedAttributeVector *importedPtr = dynamic_cast(attr.get()); EXPECT_TRUE(importedPtr != nullptr); } TEST_F("nullptr is returned for non-existing attribute vector", Fixture) { auto attr = f.ref.getAttribute("non-existing"); EXPECT_FALSE(attr.get()); } TEST_MAIN() { TEST_RUN_ALL(); }