diff options
author | Tor Egge <Tor.Egge@online.no> | 2023-03-21 16:50:03 +0100 |
---|---|---|
committer | Tor Egge <Tor.Egge@online.no> | 2023-03-21 16:50:03 +0100 |
commit | a50527a2adb0da7080fabd297e804dcee7140b30 (patch) | |
tree | 3895d5c2dee274e18c43431277b5aa53ae3629e1 /searchlib/src/tests/attribute/extendattributes | |
parent | f16025dba172b33ab4e27d78e467f65b17d155e0 (diff) |
Add SingleRawExtAttribute, used by streaming search.
Diffstat (limited to 'searchlib/src/tests/attribute/extendattributes')
-rw-r--r-- | searchlib/src/tests/attribute/extendattributes/extendattribute.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/searchlib/src/tests/attribute/extendattributes/extendattribute.cpp b/searchlib/src/tests/attribute/extendattributes/extendattribute.cpp index a44965ffb31..98d79ebd50c 100644 --- a/searchlib/src/tests/attribute/extendattributes/extendattribute.cpp +++ b/searchlib/src/tests/attribute/extendattributes/extendattribute.cpp @@ -1,9 +1,20 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/vespalib/gtest/gtest.h> #include <vespa/searchlib/attribute/extendableattributes.h> +#include <vespa/searchlib/attribute/single_raw_ext_attribute.h> + +using search::attribute::SingleRawExtAttribute; namespace search { +std::vector<char> as_vector(vespalib::stringref value) { + return {value.data(), value.data() + value.size()}; +} + +std::vector<char> as_vector(vespalib::ConstArrayRef<char> value) { + return {value.data(), value.data() + value.size()}; +} + class ExtendAttributeTest : public ::testing::Test { protected: @@ -15,6 +26,8 @@ protected: void testExtendFloat(Attribute & attr); template <typename Attribute> void testExtendString(Attribute & attr); + template <typename Attribute> + void testExtendRaw(Attribute & attr); }; template <typename Attribute> @@ -132,6 +145,35 @@ void ExtendAttributeTest::testExtendString(Attribute & attr) } } +template <typename Attribute> +void ExtendAttributeTest::testExtendRaw(Attribute & attr) +{ + std::vector<char> zeros{10, 0, 0, 11}; + uint32_t docId(0); + EXPECT_EQ(0u, attr.getNumDocs()); + attr.addDoc(docId); + EXPECT_EQ(0u, docId); + EXPECT_EQ(1u, attr.getNumDocs()); + attr.add(as_vector("1.7"), 10); + auto buf = attr.get_raw(0); + EXPECT_EQ(as_vector("1.7"), as_vector(buf)); + attr.add(as_vector("2.3"), 20); + buf = attr.get_raw(0); + EXPECT_EQ(as_vector("2.3"), as_vector(buf)); + attr.addDoc(docId); + EXPECT_EQ(1u, docId); + EXPECT_EQ(attr.getNumDocs(), 2u); + attr.add(as_vector("3.6"), 30); + buf = attr.get_raw(1); + EXPECT_EQ(as_vector("3.6"), as_vector(buf)); + buf = attr.get_raw(0); + EXPECT_EQ(as_vector("2.3"), as_vector(buf)); + attr.addDoc(docId); + EXPECT_EQ(2u, docId); + attr.add(zeros, 40); + buf = attr.get_raw(2); + EXPECT_EQ(zeros, as_vector(buf)); +} TEST_F(ExtendAttributeTest, single_integer_ext_attribute) { @@ -196,6 +238,13 @@ TEST_F(ExtendAttributeTest, weighted_set_string_ext_attribute) testExtendString(wssattr); } +TEST_F(ExtendAttributeTest, single_raw_ext_attribute) +{ + SingleRawExtAttribute srattr("sr1"); + EXPECT_TRUE(! srattr.hasMultiValue()); + testExtendRaw(srattr); +} + } GTEST_MAIN_RUN_ALL_TESTS() |