summaryrefslogtreecommitdiffstats
path: root/documentapi
diff options
context:
space:
mode:
authorTor Brede Vekterli <vekterli@vespa.ai>2024-02-21 15:21:15 +0000
committerTor Brede Vekterli <vekterli@vespa.ai>2024-02-22 10:18:08 +0000
commitcfad2fdd2293397d32386291fcbe0dd96c0520e8 (patch)
tree0ed7876d848ada60eeb9c244ff0783a061515f2b /documentapi
parentc8ef0c31e8f489d49d2140f242443d17dcce7054 (diff)
Move C++ DocumentAPI message tests to GTest
Message-specific test cases are no longer delegated to a quasi-framework in a parent class, but implemented with regular test case functions. Clean up and move existing `TestBase` into a dedicated `MessageFixture` class. Use `std::filesystem::path` instead of plain strings for file paths. This also merges 3 standalone test apps into 1 GTest runner.
Diffstat (limited to 'documentapi')
-rw-r--r--documentapi/src/tests/messages/CMakeLists.txt26
-rw-r--r--documentapi/src/tests/messages/error_codes_test.cpp72
-rw-r--r--documentapi/src/tests/messages/message_fixture.cpp156
-rw-r--r--documentapi/src/tests/messages/message_fixture.h63
-rw-r--r--documentapi/src/tests/messages/messages60app.cpp5
-rw-r--r--documentapi/src/tests/messages/messages60test.cpp809
-rw-r--r--documentapi/src/tests/messages/messages60test.h52
-rw-r--r--documentapi/src/tests/messages/messages80test.cpp738
-rw-r--r--documentapi/src/tests/messages/messages_app.cpp8
-rw-r--r--documentapi/src/tests/messages/testbase.cpp228
-rw-r--r--documentapi/src/tests/messages/testbase.h69
11 files changed, 867 insertions, 1359 deletions
diff --git a/documentapi/src/tests/messages/CMakeLists.txt b/documentapi/src/tests/messages/CMakeLists.txt
index 3428c34786c..bbe29e4802a 100644
--- a/documentapi/src/tests/messages/CMakeLists.txt
+++ b/documentapi/src/tests/messages/CMakeLists.txt
@@ -1,27 +1,13 @@
# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-vespa_add_executable(documentapi_messages60_test_app TEST
+vespa_add_executable(documentapi_messages_test_app TEST
SOURCES
- testbase.cpp
+ error_codes_test.cpp
+ message_fixture.cpp
messages60test.cpp
- messages60app.cpp
- DEPENDS
- documentapi
-)
-vespa_add_test(NAME documentapi_messages60_test_app COMMAND documentapi_messages60_test_app)
-
-vespa_add_executable(documentapi_messages80_test_app TEST
- SOURCES
- testbase.cpp
messages80test.cpp
+ messages_app.cpp
DEPENDS
documentapi
+ GTest::GTest
)
-vespa_add_test(NAME documentapi_messages80_test_app COMMAND documentapi_messages80_test_app)
-
-vespa_add_executable(documentapi_error_codes_test_app_app TEST
- SOURCES
- error_codes_test.cpp
- DEPENDS
- documentapi
-)
-vespa_add_test(NAME documentapi_error_codes_test_app_app COMMAND documentapi_error_codes_test_app_app)
+vespa_add_test(NAME documentapi_messages_test_app COMMAND documentapi_messages_test_app)
diff --git a/documentapi/src/tests/messages/error_codes_test.cpp b/documentapi/src/tests/messages/error_codes_test.cpp
index 5a99914f3f9..653043053b9 100644
--- a/documentapi/src/tests/messages/error_codes_test.cpp
+++ b/documentapi/src/tests/messages/error_codes_test.cpp
@@ -1,36 +1,24 @@
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#include <vespa/vespalib/testkit/testapp.h>
#include <vespa/documentapi/messagebus/documentprotocol.h>
-#include <iostream>
+#include <vespa/vespalib/testkit/test_path.h>
+#include <gtest/gtest.h>
#include <fstream>
+#include <filesystem>
+#include <iostream>
+#include <map>
#include <sstream>
#include <string>
-#include <exception>
-#include <map>
using NamedErrorCodes = std::map<std::string, uint32_t>;
-// DocumentAPI C++ module uses Ye Olde Test Framework.
-class ErrorCodesTest : public vespalib::TestApp {
- int Main() override;
-
- void error_codes_match_java_definitions();
- void stringification_is_defined_for_all_error_codes();
-
- NamedErrorCodes all_document_protocol_error_codes();
- std::string path_prefixed(const std::string& file_name) const;
-};
-
-TEST_APPHOOK(ErrorCodesTest);
+namespace {
// ERROR_CODE_KV(FOO) -> {"FOO", DocumentProtocol::FOO}
#define ERROR_CODE_KV(code_name) \
{#code_name, DocumentProtocol::code_name}
-NamedErrorCodes
-ErrorCodesTest::all_document_protocol_error_codes()
-{
+NamedErrorCodes all_document_protocol_error_codes() {
using documentapi::DocumentProtocol;
return {
ERROR_CODE_KV(ERROR_MESSAGE_IGNORED),
@@ -66,19 +54,17 @@ ErrorCodesTest::all_document_protocol_error_codes()
#undef ERROR_CODE_KV
-namespace {
-
-std::string read_file(const std::string& file_name) {
+std::string read_file(const std::filesystem::path& file_name) {
std::ifstream ifs(file_name);
if (!ifs.is_open()) {
- throw std::runtime_error("file '" + file_name + "' does not exist");
+ throw std::runtime_error("file '" + file_name.native() + "' does not exist");
}
std::ostringstream oss;
oss << ifs.rdbuf();
return oss.str();
}
-void write_file(const std::string& file_name,
+void write_file(const std::filesystem::path& file_name,
const std::string& content)
{
std::ofstream ofs(file_name, std::ios_base::trunc);
@@ -98,16 +84,15 @@ std::string to_sorted_key_value_string(const NamedErrorCodes& codes) {
return os.str();
}
+std::filesystem::path path_prefixed(const std::string& file_name) {
+ return {TEST_PATH("../../../test/crosslanguagefiles/" + file_name)};
+}
+
} // anon ns
-std::string
-ErrorCodesTest::path_prefixed(const std::string& file_name) const {
- return TEST_PATH("../../../test/crosslanguagefiles/" + file_name);
-}
+namespace documentapi {
-void
-ErrorCodesTest::error_codes_match_java_definitions()
-{
+TEST(ErrorCodesTest, error_codes_match_java_definitions) {
NamedErrorCodes codes(all_document_protocol_error_codes());
auto cpp_golden_file = path_prefixed("HEAD-cpp-golden-error-codes.txt");
auto cpp_golden_data = to_sorted_key_value_string(codes);
@@ -115,34 +100,21 @@ ErrorCodesTest::error_codes_match_java_definitions()
auto java_golden_file = path_prefixed("HEAD-java-golden-error-codes.txt");
auto java_golden_data = read_file(java_golden_file);
- EXPECT_EQUAL(cpp_golden_data, java_golden_data);
+ EXPECT_EQ(cpp_golden_data, java_golden_data);
}
-void
-ErrorCodesTest::stringification_is_defined_for_all_error_codes()
-{
+TEST(ErrorCodesTest, stringification_is_defined_for_all_error_codes) {
using documentapi::DocumentProtocol;
NamedErrorCodes codes(all_document_protocol_error_codes());
- for (auto& kv : codes) {
+ for (const auto& kv : codes) {
// Ugh, special casing due to divergence between Java and C++ naming.
// Can we fix this without breaking anything in exciting ways?
if (kv.second != DocumentProtocol::ERROR_EXISTS) {
- EXPECT_EQUAL(kv.first, "ERROR_" +
- DocumentProtocol::getErrorName(kv.second));
+ EXPECT_EQ(kv.first, "ERROR_" + DocumentProtocol::getErrorName(kv.second));
} else {
- EXPECT_EQUAL("EXISTS", DocumentProtocol::getErrorName(kv.second));
+ EXPECT_EQ("EXISTS", DocumentProtocol::getErrorName(kv.second));
}
}
}
-int
-ErrorCodesTest::Main()
-{
- TEST_INIT("error_codes_test");
- error_codes_match_java_definitions();
- TEST_FLUSH();
- stringification_is_defined_for_all_error_codes();
- TEST_FLUSH();
- TEST_DONE();
-}
-
+} // documentapi
diff --git a/documentapi/src/tests/messages/message_fixture.cpp b/documentapi/src/tests/messages/message_fixture.cpp
new file mode 100644
index 00000000000..e134f62cfba
--- /dev/null
+++ b/documentapi/src/tests/messages/message_fixture.cpp
@@ -0,0 +1,156 @@
+// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#include "message_fixture.h"
+#include <vespa/document/repo/documenttyperepo.h>
+#include <vespa/document/base/testdocrepo.h>
+#include <vespa/vespalib/util/exception.h>
+#include <vespa/vespalib/util/stringfmt.h>
+#include <vespa/vespalib/testkit/test_path.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <cassert>
+#include <filesystem>
+
+#include <vespa/log/log.h>
+LOG_SETUP(".message_fixture");
+
+namespace documentapi {
+
+using document::DocumentTypeRepo;
+using document::readDocumenttypesConfig;
+using namespace vespalib::make_string_short;
+
+MessageFixture::MessageFixture()
+ : _repo(std::make_shared<DocumentTypeRepo>(readDocumenttypesConfig(TEST_PATH("../../../test/cfg/testdoctypes.cfg")))),
+ _data_path(TEST_PATH("../../../test/crosslanguagefiles")),
+ _protocol(_repo)
+{
+}
+
+MessageFixture::~MessageFixture() = default;
+
+mbus::Blob
+MessageFixture::truncate(mbus::Blob data, size_t bytes)
+{
+ assert(data.size() > bytes);
+ mbus::Blob res(data.size() - bytes);
+ memcpy(res.data(), data.data(), res.size());
+ return res;
+}
+
+mbus::Blob
+MessageFixture::pad(mbus::Blob data, size_t bytes)
+{
+ mbus::Blob res(data.size() + bytes);
+ memset(res.data(), 0, res.size());
+ memcpy(res.data(), data.data(), data.size());
+ return res;
+}
+
+bool MessageFixture::file_content_is_unchanged(const std::filesystem::path& filename, const mbus::Blob& data_to_write) {
+ if (!std::filesystem::exists(filename)) {
+ return false;
+ }
+ mbus::Blob existing = read_file(filename);
+ return ((existing.size() == data_to_write.size())
+ && (memcmp(existing.data(), data_to_write.data(), data_to_write.size()) == 0));
+}
+
+uint32_t
+MessageFixture::serialize(const std::string& filename, const mbus::Routable& routable, Tamper tamper)
+{
+ const vespalib::Version version = tested_protocol_version();
+ const auto path = path_to_file(version.toString() + "-cpp-" + filename + ".dat");
+ LOG(info, "Serializing to '%s'...", path.c_str());
+
+ mbus::Blob blob = tamper(_protocol.encode(version, routable));
+ if (file_content_is_unchanged(path, blob)) {
+ LOG(info, "Serialization for '%s' is unchanged; not overwriting it", path.c_str());
+ } else if (!write_file(path, blob)) {
+ LOG(error, "Could not open file '%s' for writing.", path.c_str());
+ throw vespalib::Exception(fmt("Could not open file '%s' for writing.", path.c_str()), VESPA_STRLOC);
+ }
+ mbus::Routable::UP obj = _protocol.decode(version, blob);
+ if (!obj) {
+ LOG(error, "Protocol failed to decode serialized data");
+ throw vespalib::Exception("Protocol failed to decode serialized data", VESPA_STRLOC);
+ }
+ if (routable.getType() != obj->getType()) {
+ LOG(error, "Expected class %d, got %d", routable.getType(), obj->getType());
+ throw vespalib::Exception(fmt("Expected class %d, got %d", routable.getType(), obj->getType()), VESPA_STRLOC);
+ }
+ return blob.size();
+}
+
+mbus::Routable::UP
+MessageFixture::deserialize(const std::string& filename, uint32_t classId, uint32_t lang)
+{
+ const vespalib::Version version = tested_protocol_version();
+ const auto path = path_to_file(version.toString() + (lang == LANG_JAVA ? "-java" : "-cpp") + "-" + filename + ".dat");
+ LOG(info, "Deserializing from '%s'...", path.c_str());
+
+ mbus::Blob blob = read_file(path);
+ if (blob.size() == 0) {
+ LOG(error, "Could not open file '%s' for reading", path.c_str());
+ throw vespalib::Exception(fmt("Could not open file '%s' for reading", path.c_str()), VESPA_STRLOC);
+ }
+ mbus::Routable::UP ret = _protocol.decode(version, blob);
+
+ if (!ret) {
+ LOG(error, "Unable to decode class %d", classId);
+ throw vespalib::Exception(fmt("Unable to decode class %d", classId), VESPA_STRLOC);
+ } else if (classId != ret->getType()) {
+ LOG(error, "Expected class %d, got %d", classId, ret->getType());
+ throw vespalib::Exception(fmt("Expected class %d, got %d", classId, ret->getType()), VESPA_STRLOC);
+ }
+ return ret;
+}
+
+void
+MessageFixture::dump(const mbus::Blob& blob)
+{
+ fprintf(stderr, "[%ld]: ", blob.size());
+ for(size_t i = 0; i < blob.size(); i++) {
+ if (blob.data()[i] > 32 && blob.data()[i] < 126) {
+ fprintf(stderr, "%c ", blob.data()[i]);
+ }
+ else {
+ fprintf(stderr, "%d ", blob.data()[i]);
+ }
+ }
+ fprintf(stderr, "\n");
+}
+
+
+bool
+MessageFixture::write_file(const std::filesystem::path& filename, const mbus::Blob& blob)
+{
+ int file = open(filename.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0644);
+ if (file == -1) {
+ return false;
+ }
+ if (write(file, blob.data(), blob.size()) != (ssize_t)blob.size()) {
+ throw vespalib::Exception("write failed");
+ }
+ close(file);
+ return true;
+}
+
+mbus::Blob
+MessageFixture::read_file(const std::filesystem::path& filename)
+{
+ int file = open(filename.c_str(), O_RDONLY);
+ int len = (file == -1) ? 0 : lseek(file, 0, SEEK_END);
+ mbus::Blob blob(len);
+ if (file != -1) {
+ lseek(file, 0, SEEK_SET);
+ if (read(file, blob.data(), len) != len) {
+ throw vespalib::Exception("read failed");
+ }
+ close(file);
+ }
+
+ return blob;
+}
+
+}
diff --git a/documentapi/src/tests/messages/message_fixture.h b/documentapi/src/tests/messages/message_fixture.h
new file mode 100644
index 00000000000..ad7ec9971dd
--- /dev/null
+++ b/documentapi/src/tests/messages/message_fixture.h
@@ -0,0 +1,63 @@
+// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+#pragma once
+
+#include <vespa/documentapi/messagebus/documentprotocol.h>
+#include <vespa/messagebus/routable.h>
+#include <vespa/vespalib/component/version.h>
+#include <gtest/gtest.h>
+#include <array>
+#include <filesystem>
+#include <functional>
+
+namespace documentapi {
+
+struct MessageFixture : ::testing::Test {
+ std::shared_ptr<const document::DocumentTypeRepo> _repo;
+ const std::filesystem::path _data_path;
+ DocumentProtocol _protocol;
+
+ // Declares what languages share serialization.
+ enum {
+ LANG_CPP = 0,
+ LANG_JAVA,
+ NUM_LANGUAGES
+ };
+
+ static constexpr std::array<uint32_t, 2> languages() noexcept {
+ return {LANG_CPP, LANG_JAVA};
+ }
+
+ MessageFixture();
+ ~MessageFixture() override;
+
+ [[nodiscard]] virtual vespalib::Version tested_protocol_version() const = 0;
+
+ using Tamper = std::function<mbus::Blob(mbus::Blob)>;
+ [[nodiscard]] static mbus::Blob truncate(mbus::Blob data, size_t bytes);
+ [[nodiscard]] static mbus::Blob pad(mbus::Blob data, size_t bytes);
+
+ [[nodiscard]] const document::DocumentTypeRepo& type_repo() const noexcept { return *_repo; }
+
+ [[nodiscard]] static bool write_file(const std::filesystem::path& filename, const mbus::Blob& blob);
+ [[nodiscard]] static mbus::Blob read_file(const std::filesystem::path& filename);
+ uint32_t serialize(const std::string& filename, const mbus::Routable& routable, Tamper tamper);
+ uint32_t serialize(const std::string& filename, const mbus::Routable& routable) {
+ return serialize(filename, routable, [](auto x) noexcept { return x; });
+ }
+ [[nodiscard]] mbus::Routable::UP deserialize(const std::string& filename, uint32_t classId, uint32_t lang);
+ static void dump(const mbus::Blob& blob);
+
+ [[nodiscard]] std::filesystem::path path_to_file(const std::string& filename) const {
+ return _data_path / filename;
+ }
+ [[nodiscard]] mbus::Blob encode(const mbus::Routable& obj) const {
+ return _protocol.encode(tested_protocol_version(), obj);
+ }
+ [[nodiscard]] mbus::Routable::UP decode(mbus::BlobRef data) const {
+ return _protocol.decode(tested_protocol_version(), data);
+ }
+private:
+ [[nodiscard]] static bool file_content_is_unchanged(const std::filesystem::path& filename, const mbus::Blob& data_to_write);
+};
+
+} // documentapi
diff --git a/documentapi/src/tests/messages/messages60app.cpp b/documentapi/src/tests/messages/messages60app.cpp
deleted file mode 100644
index e80a9f10adf..00000000000
--- a/documentapi/src/tests/messages/messages60app.cpp
+++ /dev/null
@@ -1,5 +0,0 @@
-// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-#include "messages60test.h"
-
-TEST_APPHOOK(Messages60Test);
diff --git a/documentapi/src/tests/messages/messages60test.cpp b/documentapi/src/tests/messages/messages60test.cpp
index 281e1123e54..2af523ce8e9 100644
--- a/documentapi/src/tests/messages/messages60test.cpp
+++ b/documentapi/src/tests/messages/messages60test.cpp
@@ -1,7 +1,7 @@
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
// @author Vegard Sjonfjell
-#include "messages60test.h"
+#include "message_fixture.h"
#include <vespa/document/bucket/bucketidfactory.h>
#include <vespa/document/datatype/documenttype.h>
#include <vespa/document/select/parser.h>
@@ -31,63 +31,20 @@ struct Unwrap {
const T *ptr = nullptr;
explicit Unwrap(mbus::Routable::UP value_in) : value(std::move(value_in)) {
ptr = dynamic_cast<T*>(value.get());
- ASSERT_TRUE(ptr != nullptr);
+ assert(ptr != nullptr);
}
const T *operator->() const noexcept { return ptr; }
};
-///////////////////////////////////////////////////////////////////////////////
-//
-// Setup
-//
-///////////////////////////////////////////////////////////////////////////////
+namespace documentapi {
-Messages60Test::Messages60Test()
-{
- // This list MUST mirror the list of routable factories from the DocumentProtocol constructor that support
- // version 5.0. When adding tests to this list, please KEEP THEM ORDERED alphabetically like they are now.
- putTest(DocumentProtocol::MESSAGE_CREATEVISITOR, TEST_METHOD(Messages60Test::testCreateVisitorMessage));
- putTest(DocumentProtocol::MESSAGE_DESTROYVISITOR, TEST_METHOD(Messages60Test::testDestroyVisitorMessage));
- putTest(DocumentProtocol::MESSAGE_DOCUMENTLIST, TEST_METHOD(Messages60Test::testDocumentListMessage));
- putTest(DocumentProtocol::MESSAGE_EMPTYBUCKETS, TEST_METHOD(Messages60Test::testEmptyBucketsMessage));
- putTest(DocumentProtocol::MESSAGE_GETBUCKETLIST, TEST_METHOD(Messages60Test::testGetBucketListMessage));
- putTest(DocumentProtocol::MESSAGE_GETBUCKETSTATE, TEST_METHOD(Messages60Test::testGetBucketStateMessage));
- putTest(DocumentProtocol::MESSAGE_GETDOCUMENT, TEST_METHOD(Messages60Test::testGetDocumentMessage));
- putTest(DocumentProtocol::MESSAGE_MAPVISITOR, TEST_METHOD(Messages60Test::testMapVisitorMessage));
- putTest(DocumentProtocol::MESSAGE_PUTDOCUMENT, TEST_METHOD(Messages60Test::testPutDocumentMessage));
- putTest(DocumentProtocol::MESSAGE_QUERYRESULT, TEST_METHOD(Messages60Test::testQueryResultMessage));
- putTest(DocumentProtocol::MESSAGE_REMOVEDOCUMENT, TEST_METHOD(Messages60Test::testRemoveDocumentMessage));
- putTest(DocumentProtocol::MESSAGE_REMOVELOCATION, TEST_METHOD(Messages60Test::testRemoveLocationMessage));
- putTest(DocumentProtocol::MESSAGE_STATBUCKET, TEST_METHOD(Messages60Test::testStatBucketMessage));
- putTest(DocumentProtocol::MESSAGE_UPDATEDOCUMENT, TEST_METHOD(Messages60Test::testUpdateDocumentMessage));
- putTest(DocumentProtocol::MESSAGE_VISITORINFO, TEST_METHOD(Messages60Test::testVisitorInfoMessage));
-
- putTest(DocumentProtocol::REPLY_CREATEVISITOR, TEST_METHOD(Messages60Test::testCreateVisitorReply));
- putTest(DocumentProtocol::REPLY_DESTROYVISITOR, TEST_METHOD(Messages60Test::testDestroyVisitorReply));
- putTest(DocumentProtocol::REPLY_DOCUMENTIGNORED, TEST_METHOD(Messages60Test::testDocumentIgnoredReply));
- putTest(DocumentProtocol::REPLY_DOCUMENTLIST, TEST_METHOD(Messages60Test::testDocumentListReply));
- putTest(DocumentProtocol::REPLY_EMPTYBUCKETS, TEST_METHOD(Messages60Test::testEmptyBucketsReply));
- putTest(DocumentProtocol::REPLY_GETBUCKETLIST, TEST_METHOD(Messages60Test::testGetBucketListReply));
- putTest(DocumentProtocol::REPLY_GETBUCKETSTATE, TEST_METHOD(Messages60Test::testGetBucketStateReply));
- putTest(DocumentProtocol::REPLY_GETDOCUMENT, TEST_METHOD(Messages60Test::testGetDocumentReply));
- putTest(DocumentProtocol::REPLY_MAPVISITOR, TEST_METHOD(Messages60Test::testMapVisitorReply));
- putTest(DocumentProtocol::REPLY_PUTDOCUMENT, TEST_METHOD(Messages60Test::testPutDocumentReply));
- putTest(DocumentProtocol::REPLY_QUERYRESULT, TEST_METHOD(Messages60Test::testQueryResultReply));
- putTest(DocumentProtocol::REPLY_REMOVEDOCUMENT, TEST_METHOD(Messages60Test::testRemoveDocumentReply));
- putTest(DocumentProtocol::REPLY_REMOVELOCATION, TEST_METHOD(Messages60Test::testRemoveLocationReply));
- putTest(DocumentProtocol::REPLY_STATBUCKET, TEST_METHOD(Messages60Test::testStatBucketReply));
- putTest(DocumentProtocol::REPLY_UPDATEDOCUMENT, TEST_METHOD(Messages60Test::testUpdateDocumentReply));
- putTest(DocumentProtocol::REPLY_VISITORINFO, TEST_METHOD(Messages60Test::testVisitorInfoReply));
- putTest(DocumentProtocol::REPLY_WRONGDISTRIBUTION, TEST_METHOD(Messages60Test::testWrongDistributionReply));
-}
-
-
-
-///////////////////////////////////////////////////////////////////////////////
-//
-// Tests
-//
-///////////////////////////////////////////////////////////////////////////////
+struct Messages60Test : public MessageFixture {
+ vespalib::Version tested_protocol_version() const override { return {6, 221}; }
+
+ static size_t serializedLength(const string& str) { return sizeof(int32_t) + str.size(); }
+
+ void tryVisitorReply(const string& filename, uint32_t type);
+};
static const int MESSAGE_BASE_LENGTH = 5;
@@ -103,27 +60,21 @@ createDoc(const DocumentTypeRepo &repo, const string &type_name, const string &i
} // namespace
-bool
-Messages60Test::testGetBucketListMessage()
-{
+TEST_F(Messages60Test, testGetBucketListMessage) {
GetBucketListMessage msg(document::BucketId(16, 123));
msg.setBucketSpace("beartato");
- EXPECT_EQUAL(MESSAGE_BASE_LENGTH + 12u + serializedLength("beartato"), serialize("GetBucketListMessage", msg));
+ EXPECT_EQ(MESSAGE_BASE_LENGTH + 12u + serializedLength("beartato"), serialize("GetBucketListMessage", msg));
for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
mbus::Routable::UP obj = deserialize("GetBucketListMessage", DocumentProtocol::MESSAGE_GETBUCKETLIST, lang);
- if (EXPECT_TRUE(obj)) {
- GetBucketListMessage &ref = static_cast<GetBucketListMessage&>(*obj);
- EXPECT_EQUAL(document::BucketId(16, 123), ref.getBucketId());
- EXPECT_EQUAL("beartato", ref.getBucketSpace());
- }
+ ASSERT_TRUE(obj);
+ auto& ref = dynamic_cast<GetBucketListMessage&>(*obj);
+ EXPECT_EQ(document::BucketId(16, 123), ref.getBucketId());
+ EXPECT_EQ("beartato", ref.getBucketSpace());
}
- return true;
}
-bool
-Messages60Test::testEmptyBucketsMessage()
-{
+TEST_F(Messages60Test, testEmptyBucketsMessage) {
std::vector<document::BucketId> bids;
for (size_t i=0; i < 13; ++i) {
bids.push_back(document::BucketId(16, i));
@@ -131,44 +82,36 @@ Messages60Test::testEmptyBucketsMessage()
EmptyBucketsMessage msg(bids);
- EXPECT_EQUAL(MESSAGE_BASE_LENGTH + 112u, serialize("EmptyBucketsMessage", msg));
+ EXPECT_EQ(MESSAGE_BASE_LENGTH + 112u, serialize("EmptyBucketsMessage", msg));
for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
mbus::Routable::UP obj = deserialize("EmptyBucketsMessage", DocumentProtocol::MESSAGE_EMPTYBUCKETS, lang);
- if (EXPECT_TRUE(obj)) {
- EmptyBucketsMessage &ref = static_cast<EmptyBucketsMessage&>(*obj);
- for (size_t i=0; i < 13; ++i) {
- EXPECT_EQUAL(document::BucketId(16, i), ref.getBucketIds()[i]);
- }
+ ASSERT_TRUE(obj);
+ auto& ref = dynamic_cast<EmptyBucketsMessage&>(*obj);
+ for (size_t i=0; i < 13; ++i) {
+ EXPECT_EQ(document::BucketId(16, i), ref.getBucketIds()[i]);
}
}
- return true;
}
-bool
-Messages60Test::testStatBucketMessage()
-{
+TEST_F(Messages60Test, testStatBucketMessage) {
StatBucketMessage msg(document::BucketId(16, 123), "id.user=123");
msg.setBucketSpace("andrei");
- EXPECT_EQUAL(MESSAGE_BASE_LENGTH + 27u + serializedLength("andrei"), serialize("StatBucketMessage", msg));
+ EXPECT_EQ(MESSAGE_BASE_LENGTH + 27u + serializedLength("andrei"), serialize("StatBucketMessage", msg));
for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
mbus::Routable::UP obj = deserialize("StatBucketMessage", DocumentProtocol::MESSAGE_STATBUCKET, lang);
- if (EXPECT_TRUE(obj)) {
- StatBucketMessage &ref = static_cast<StatBucketMessage&>(*obj);
- EXPECT_EQUAL(document::BucketId(16, 123), ref.getBucketId());
- EXPECT_EQUAL("id.user=123", ref.getDocumentSelection());
- EXPECT_EQUAL("andrei", ref.getBucketSpace());
- }
+ ASSERT_TRUE(obj);
+ auto& ref = dynamic_cast<StatBucketMessage&>(*obj);
+ EXPECT_EQ(document::BucketId(16, 123), ref.getBucketId());
+ EXPECT_EQ("id.user=123", ref.getDocumentSelection());
+ EXPECT_EQ("andrei", ref.getBucketSpace());
}
- return true;
}
-bool
-Messages60Test::testCreateVisitorMessage()
-{
+TEST_F(Messages60Test, testCreateVisitorMessage) {
CreateVisitorMessage tmp("SomeLibrary", "myvisitor", "newyork", "london");
tmp.setDocumentSelection("true and false or true");
tmp.getParameters().set("myvar", "somevalue");
@@ -179,143 +122,114 @@ Messages60Test::testCreateVisitorMessage()
tmp.setMaxBucketsPerVisitor(2);
tmp.setBucketSpace("bjarne");
- EXPECT_EQUAL(MESSAGE_BASE_LENGTH + serializedLength("bjarne") + 178, serialize("CreateVisitorMessage", tmp));
+ EXPECT_EQ(MESSAGE_BASE_LENGTH + serializedLength("bjarne") + 178, serialize("CreateVisitorMessage", tmp));
for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
mbus::Routable::UP obj = deserialize("CreateVisitorMessage", DocumentProtocol::MESSAGE_CREATEVISITOR, lang);
- if (EXPECT_TRUE(obj)) {
- auto& ref = dynamic_cast<CreateVisitorMessage&>(*obj);
-
- EXPECT_EQUAL(string("SomeLibrary"), ref.getLibraryName());
- EXPECT_EQUAL(string("myvisitor"), ref.getInstanceId());
- EXPECT_EQUAL(string("newyork"), ref.getControlDestination());
- EXPECT_EQUAL(string("london"), ref.getDataDestination());
- EXPECT_EQUAL(string("true and false or true"), ref.getDocumentSelection());
- EXPECT_EQUAL(string("foo bar"), ref.getFieldSet());
- EXPECT_EQUAL(uint32_t(8), ref.getMaximumPendingReplyCount());
- EXPECT_EQUAL(true, ref.visitRemoves());
- EXPECT_EQUAL(false, ref.visitInconsistentBuckets());
- EXPECT_EQUAL(size_t(1), ref.getBuckets().size());
- EXPECT_EQUAL(document::BucketId(16, 1234), ref.getBuckets()[0]);
- EXPECT_EQUAL(string("somevalue"), ref.getParameters().get("myvar"));
- EXPECT_EQUAL(uint64_t(34), ref.getParameters().get("anothervar", uint64_t(1)));
- EXPECT_EQUAL(uint32_t(2), ref.getMaxBucketsPerVisitor());
- EXPECT_EQUAL(string("bjarne"), ref.getBucketSpace());
- }
- }
- return true;
-}
-
-bool
-Messages60Test::testDestroyVisitorMessage()
-{
+ ASSERT_TRUE(obj);
+ auto& ref = dynamic_cast<CreateVisitorMessage&>(*obj);
+
+ EXPECT_EQ(string("SomeLibrary"), ref.getLibraryName());
+ EXPECT_EQ(string("myvisitor"), ref.getInstanceId());
+ EXPECT_EQ(string("newyork"), ref.getControlDestination());
+ EXPECT_EQ(string("london"), ref.getDataDestination());
+ EXPECT_EQ(string("true and false or true"), ref.getDocumentSelection());
+ EXPECT_EQ(string("foo bar"), ref.getFieldSet());
+ EXPECT_EQ(uint32_t(8), ref.getMaximumPendingReplyCount());
+ EXPECT_EQ(true, ref.visitRemoves());
+ EXPECT_EQ(false, ref.visitInconsistentBuckets());
+ EXPECT_EQ(size_t(1), ref.getBuckets().size());
+ EXPECT_EQ(document::BucketId(16, 1234), ref.getBuckets()[0]);
+ EXPECT_EQ(string("somevalue"), ref.getParameters().get("myvar"));
+ EXPECT_EQ(uint64_t(34), ref.getParameters().get("anothervar", uint64_t(1)));
+ EXPECT_EQ(uint32_t(2), ref.getMaxBucketsPerVisitor());
+ EXPECT_EQ(string("bjarne"), ref.getBucketSpace());
+ }
+}
+
+TEST_F(Messages60Test, testDestroyVisitorMessage) {
DestroyVisitorMessage tmp("myvisitor");
- EXPECT_EQUAL(MESSAGE_BASE_LENGTH + (size_t)17, serialize("DestroyVisitorMessage", tmp));
+ EXPECT_EQ(MESSAGE_BASE_LENGTH + (size_t)17, serialize("DestroyVisitorMessage", tmp));
for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
mbus::Routable::UP obj = deserialize("DestroyVisitorMessage", DocumentProtocol::MESSAGE_DESTROYVISITOR, lang);
- if (EXPECT_TRUE(obj)) {
- DestroyVisitorMessage &ref = static_cast<DestroyVisitorMessage&>(*obj);
- EXPECT_EQUAL(string("myvisitor"), ref.getInstanceId());
- }
+ ASSERT_TRUE(obj);
+ auto& ref = dynamic_cast<DestroyVisitorMessage&>(*obj);
+ EXPECT_EQ(string("myvisitor"), ref.getInstanceId());
}
- return true;
}
-bool
-Messages60Test::testDocumentListMessage()
-{
+TEST_F(Messages60Test, testDocumentListMessage) {
document::Document::SP doc =
- createDoc(getTypeRepo(), "testdoc", "id:scheme:testdoc:n=1234:1");
+ createDoc(type_repo(), "testdoc", "id:scheme:testdoc:n=1234:1");
DocumentListMessage::Entry entry(1234, doc, false);
DocumentListMessage tmp(document::BucketId(16, 1234));
tmp.getDocuments().push_back(entry);
- EXPECT_EQUAL(MESSAGE_BASE_LENGTH + 69ul, serialize("DocumentListMessage", tmp));
+ EXPECT_EQ(MESSAGE_BASE_LENGTH + 69ul, serialize("DocumentListMessage", tmp));
for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
mbus::Routable::UP obj = deserialize("DocumentListMessage", DocumentProtocol::MESSAGE_DOCUMENTLIST, lang);
- if (EXPECT_TRUE(obj)) {
- DocumentListMessage &ref = static_cast<DocumentListMessage&>(*obj);
-
- EXPECT_EQUAL("id:scheme:testdoc:n=1234:1", ref.getDocuments()[0].getDocument()->getId().toString());
- EXPECT_EQUAL(1234, ref.getDocuments()[0].getTimestamp());
- EXPECT_TRUE(!ref.getDocuments()[0].isRemoveEntry());
- }
+ ASSERT_TRUE(obj);
+ auto& ref = dynamic_cast<DocumentListMessage&>(*obj);
+ EXPECT_EQ("id:scheme:testdoc:n=1234:1", ref.getDocuments()[0].getDocument()->getId().toString());
+ EXPECT_EQ(1234, ref.getDocuments()[0].getTimestamp());
+ EXPECT_FALSE(ref.getDocuments()[0].isRemoveEntry());
}
- return true;
}
-
-bool
-Messages60Test::testRemoveLocationMessage()
-{
+TEST_F(Messages60Test, testRemoveLocationMessage) {
{
document::BucketIdFactory factory;
- document::select::Parser parser(getTypeRepo(), factory);
+ document::select::Parser parser(type_repo(), factory);
RemoveLocationMessage msg(factory, parser, "id.group == \"mygroup\"");
- EXPECT_EQUAL(MESSAGE_BASE_LENGTH + 29u, serialize("RemoveLocationMessage", msg));
+ EXPECT_EQ(MESSAGE_BASE_LENGTH + 29u, serialize("RemoveLocationMessage", msg));
for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
mbus::Routable::UP obj = deserialize("RemoveLocationMessage", DocumentProtocol::MESSAGE_REMOVELOCATION, lang);
- if (EXPECT_TRUE(obj)) {
- RemoveLocationMessage &ref = static_cast<RemoveLocationMessage&>(*obj);
- EXPECT_EQUAL(string("id.group == \"mygroup\""), ref.getDocumentSelection());
- // FIXME add to wire format, currently hardcoded.
- EXPECT_EQUAL(string(document::FixedBucketSpaces::default_space_name()), ref.getBucketSpace());
- }
+ ASSERT_TRUE(obj);
+ auto& ref = dynamic_cast<RemoveLocationMessage&>(*obj);
+ EXPECT_EQ(string("id.group == \"mygroup\""), ref.getDocumentSelection());
+ // FIXME add to wire format, currently hardcoded.
+ EXPECT_EQ(string(document::FixedBucketSpaces::default_space_name()), ref.getBucketSpace());
}
}
-
- return true;
}
-
-
-bool
-Messages60Test::testGetDocumentMessage()
-{
+TEST_F(Messages60Test, testGetDocumentMessage) {
GetDocumentMessage tmp(document::DocumentId("id:ns:testdoc::"), "foo bar");
- EXPECT_EQUAL(280u, sizeof(GetDocumentMessage));
- EXPECT_EQUAL(MESSAGE_BASE_LENGTH + (size_t)31, serialize("GetDocumentMessage", tmp));
+ EXPECT_EQ(280u, sizeof(GetDocumentMessage));
+ EXPECT_EQ(MESSAGE_BASE_LENGTH + (size_t)31, serialize("GetDocumentMessage", tmp));
for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
mbus::Routable::UP obj = deserialize("GetDocumentMessage", DocumentProtocol::MESSAGE_GETDOCUMENT, lang);
- if (EXPECT_TRUE(obj)) {
- GetDocumentMessage &ref = static_cast<GetDocumentMessage&>(*obj);
- EXPECT_EQUAL(string("id:ns:testdoc::"), ref.getDocumentId().toString());
- EXPECT_EQUAL(string("foo bar"), ref.getFieldSet());
- }
+ ASSERT_TRUE(obj);
+ auto& ref = dynamic_cast<GetDocumentMessage&>(*obj);
+ EXPECT_EQ(string("id:ns:testdoc::"), ref.getDocumentId().toString());
+ EXPECT_EQ(string("foo bar"), ref.getFieldSet());
}
- return true;
}
-bool
-Messages60Test::testMapVisitorMessage()
-{
+TEST_F(Messages60Test, testMapVisitorMessage) {
MapVisitorMessage tmp;
tmp.getData().set("foo", 3);
tmp.getData().set("bar", 5);
- EXPECT_EQUAL(MESSAGE_BASE_LENGTH + (size_t)32, serialize("MapVisitorMessage", tmp));
+ EXPECT_EQ(MESSAGE_BASE_LENGTH + (size_t)32, serialize("MapVisitorMessage", tmp));
for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
mbus::Routable::UP obj = deserialize("MapVisitorMessage", DocumentProtocol::MESSAGE_MAPVISITOR, lang);
- if (EXPECT_TRUE(obj)) {
- MapVisitorMessage &ref = static_cast<MapVisitorMessage&>(*obj);
- EXPECT_EQUAL(3, ref.getData().get("foo", 0));
- EXPECT_EQUAL(5, ref.getData().get("bar", 0));
- }
+ ASSERT_TRUE(obj);
+ auto& ref = dynamic_cast<MapVisitorMessage&>(*obj);
+ EXPECT_EQ(3, ref.getData().get("foo", 0));
+ EXPECT_EQ(5, ref.getData().get("bar", 0));
}
- return true;
}
-bool
-Messages60Test::testCreateVisitorReply()
-{
+TEST_F(Messages60Test, testCreateVisitorReply) {
CreateVisitorReply reply(DocumentProtocol::REPLY_CREATEVISITOR);
reply.setLastBucket(document::BucketId(16, 123));
vdslib::VisitorStatistics vs;
@@ -326,40 +240,36 @@ Messages60Test::testCreateVisitorReply()
vs.setBytesReturned(512000);
reply.setVisitorStatistics(vs);
- EXPECT_EQUAL(65u, serialize("CreateVisitorReply", reply));
+ EXPECT_EQ(65u, serialize("CreateVisitorReply", reply));
for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
mbus::Routable::UP obj = deserialize("CreateVisitorReply", DocumentProtocol::REPLY_CREATEVISITOR, lang);
- if (EXPECT_TRUE(obj)) {
- CreateVisitorReply &ref = static_cast<CreateVisitorReply&>(*obj);
-
- EXPECT_EQUAL(ref.getLastBucket(), document::BucketId(16, 123));
- EXPECT_EQUAL(ref.getVisitorStatistics().getBucketsVisited(), (uint32_t)3);
- EXPECT_EQUAL(ref.getVisitorStatistics().getDocumentsVisited(), (uint64_t)1000);
- EXPECT_EQUAL(ref.getVisitorStatistics().getBytesVisited(), (uint64_t)1024000);
- EXPECT_EQUAL(ref.getVisitorStatistics().getDocumentsReturned(), (uint64_t)123);
- EXPECT_EQUAL(ref.getVisitorStatistics().getBytesReturned(), (uint64_t)512000);
- }
+ ASSERT_TRUE(obj);
+ auto& ref = dynamic_cast<CreateVisitorReply&>(*obj);
+
+ EXPECT_EQ(ref.getLastBucket(), document::BucketId(16, 123));
+ EXPECT_EQ(ref.getVisitorStatistics().getBucketsVisited(), (uint32_t)3);
+ EXPECT_EQ(ref.getVisitorStatistics().getDocumentsVisited(), (uint64_t)1000);
+ EXPECT_EQ(ref.getVisitorStatistics().getBytesVisited(), (uint64_t)1024000);
+ EXPECT_EQ(ref.getVisitorStatistics().getDocumentsReturned(), (uint64_t)123);
+ EXPECT_EQ(ref.getVisitorStatistics().getBytesReturned(), (uint64_t)512000);
}
- return true;
}
-bool
-Messages60Test::testPutDocumentMessage()
-{
- auto doc = createDoc(getTypeRepo(), "testdoc", "id:ns:testdoc::");
+TEST_F(Messages60Test, testPutDocumentMessage) {
+ auto doc = createDoc(type_repo(), "testdoc", "id:ns:testdoc::");
PutDocumentMessage msg(doc);
msg.setTimestamp(666);
msg.setCondition(TestAndSetCondition("There's just one condition"));
- EXPECT_EQUAL(64u, sizeof(vespalib::string));
- EXPECT_EQUAL(sizeof(vespalib::string), sizeof(TestAndSetCondition));
- EXPECT_EQUAL(112u, sizeof(DocumentMessage));
- EXPECT_EQUAL(sizeof(TestAndSetCondition) + sizeof(DocumentMessage), sizeof(TestAndSetMessage));
- EXPECT_EQUAL(sizeof(TestAndSetMessage) + 32, sizeof(PutDocumentMessage));
+ EXPECT_EQ(64u, sizeof(vespalib::string));
+ EXPECT_EQ(sizeof(vespalib::string), sizeof(TestAndSetCondition));
+ EXPECT_EQ(112u, sizeof(DocumentMessage));
+ EXPECT_EQ(sizeof(TestAndSetCondition) + sizeof(DocumentMessage), sizeof(TestAndSetMessage));
+ EXPECT_EQ(sizeof(TestAndSetMessage) + 32, sizeof(PutDocumentMessage));
int size_of_create_if_non_existent_flag = 1;
- EXPECT_EQUAL(MESSAGE_BASE_LENGTH +
+ EXPECT_EQ(MESSAGE_BASE_LENGTH +
45u +
serializedLength(msg.getCondition().getSelection()) +
size_of_create_if_non_existent_flag,
@@ -367,150 +277,124 @@ Messages60Test::testPutDocumentMessage()
for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
auto routableUp = deserialize("PutDocumentMessage", DocumentProtocol::MESSAGE_PUTDOCUMENT, lang);
- if (EXPECT_TRUE(routableUp)) {
- auto & deserializedMsg = static_cast<PutDocumentMessage &>(*routableUp);
-
- EXPECT_EQUAL(msg.getDocument().getType().getName(), deserializedMsg.getDocument().getType().getName());
- EXPECT_EQUAL(msg.getDocument().getId().toString(), deserializedMsg.getDocument().getId().toString());
- EXPECT_EQUAL(msg.getTimestamp(), deserializedMsg.getTimestamp());
- EXPECT_EQUAL(72u, deserializedMsg.getApproxSize());
- EXPECT_EQUAL(msg.getCondition().getSelection(), deserializedMsg.getCondition().getSelection());
- EXPECT_EQUAL(false, deserializedMsg.get_create_if_non_existent());
- }
+ ASSERT_TRUE(routableUp);
+ auto& deserializedMsg = dynamic_cast<PutDocumentMessage &>(*routableUp);
+
+ EXPECT_EQ(msg.getDocument().getType().getName(), deserializedMsg.getDocument().getType().getName());
+ EXPECT_EQ(msg.getDocument().getId().toString(), deserializedMsg.getDocument().getId().toString());
+ EXPECT_EQ(msg.getTimestamp(), deserializedMsg.getTimestamp());
+ EXPECT_EQ(72u, deserializedMsg.getApproxSize());
+ EXPECT_EQ(msg.getCondition().getSelection(), deserializedMsg.getCondition().getSelection());
+ EXPECT_EQ(false, deserializedMsg.get_create_if_non_existent());
}
//-------------------------------------------------------------------------
- PutDocumentMessage msg2(createDoc(getTypeRepo(), "testdoc", "id:ns:testdoc::"));
+ PutDocumentMessage msg2(createDoc(type_repo(), "testdoc", "id:ns:testdoc::"));
msg2.set_create_if_non_existent(true);
uint32_t expected_message_size = MESSAGE_BASE_LENGTH + 45u +
serializedLength(msg2.getCondition().getSelection()) +
size_of_create_if_non_existent_flag;
auto trunc1 = [](mbus::Blob x) noexcept { return truncate(std::move(x), 1); };
auto pad1 = [](mbus::Blob x) noexcept { return pad(std::move(x), 1); };
- EXPECT_EQUAL(expected_message_size, serialize("PutDocumentMessage-create", msg2));
- EXPECT_EQUAL(expected_message_size - 1, serialize("PutDocumentMessage-create-truncate", msg2, trunc1));
- EXPECT_EQUAL(expected_message_size + 1, serialize("PutDocumentMessage-create-pad", msg2, pad1));
+ EXPECT_EQ(expected_message_size, serialize("PutDocumentMessage-create", msg2));
+ EXPECT_EQ(expected_message_size - 1, serialize("PutDocumentMessage-create-truncate", msg2, trunc1));
+ EXPECT_EQ(expected_message_size + 1, serialize("PutDocumentMessage-create-pad", msg2, pad1));
for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
auto decoded = Unwrap<PutDocumentMessage>(deserialize("PutDocumentMessage-create", DocumentProtocol::MESSAGE_PUTDOCUMENT, lang));
auto decoded_trunc = Unwrap<PutDocumentMessage>(deserialize("PutDocumentMessage-create-truncate", DocumentProtocol::MESSAGE_PUTDOCUMENT, lang));
auto decoded_pad = Unwrap<PutDocumentMessage>(deserialize("PutDocumentMessage-create-pad", DocumentProtocol::MESSAGE_PUTDOCUMENT, lang));
- EXPECT_EQUAL(true, decoded->get_create_if_non_existent());
- EXPECT_EQUAL(false, decoded_trunc->get_create_if_non_existent());
- EXPECT_EQUAL(true, decoded_pad->get_create_if_non_existent());
+ EXPECT_EQ(true, decoded->get_create_if_non_existent());
+ EXPECT_EQ(false, decoded_trunc->get_create_if_non_existent());
+ EXPECT_EQ(true, decoded_pad->get_create_if_non_existent());
}
-
- return true;
}
-bool
-Messages60Test::testGetBucketStateMessage()
-{
+TEST_F(Messages60Test, testGetBucketStateMessage) {
GetBucketStateMessage tmp;
tmp.setBucketId(document::BucketId(16, 666));
- EXPECT_EQUAL(MESSAGE_BASE_LENGTH + 12u, serialize("GetBucketStateMessage", tmp));
+ EXPECT_EQ(MESSAGE_BASE_LENGTH + 12u, serialize("GetBucketStateMessage", tmp));
for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
mbus::Routable::UP obj = deserialize("GetBucketStateMessage", DocumentProtocol::MESSAGE_GETBUCKETSTATE, lang);
- if (EXPECT_TRUE(obj)) {
- GetBucketStateMessage &ref = static_cast<GetBucketStateMessage&>(*obj);
+ ASSERT_TRUE(obj);
+ auto& ref = dynamic_cast<GetBucketStateMessage&>(*obj);
- EXPECT_EQUAL(16u, ref.getBucketId().getUsedBits());
- EXPECT_EQUAL(4611686018427388570ull, ref.getBucketId().getId());
- }
+ EXPECT_EQ(16u, ref.getBucketId().getUsedBits());
+ EXPECT_EQ(4611686018427388570ull, ref.getBucketId().getId());
}
- return true;
}
-bool
-Messages60Test::testPutDocumentReply()
-{
+TEST_F(Messages60Test, testPutDocumentReply) {
WriteDocumentReply reply(DocumentProtocol::REPLY_PUTDOCUMENT);
reply.setHighestModificationTimestamp(30);
- EXPECT_EQUAL(13u, serialize("PutDocumentReply", reply));
- EXPECT_EQUAL(112u, sizeof(WriteDocumentReply));
+ EXPECT_EQ(13u, serialize("PutDocumentReply", reply));
+ EXPECT_EQ(112u, sizeof(WriteDocumentReply));
for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
mbus::Routable::UP obj = deserialize("PutDocumentReply", DocumentProtocol::REPLY_PUTDOCUMENT, lang);
- if (EXPECT_TRUE(obj)) {
- WriteDocumentReply &ref = static_cast<WriteDocumentReply&>(*obj);
- EXPECT_EQUAL(30u, ref.getHighestModificationTimestamp());
- }
+ ASSERT_TRUE(obj);
+ auto& ref = dynamic_cast<WriteDocumentReply&>(*obj);
+ EXPECT_EQ(30u, ref.getHighestModificationTimestamp());
}
- return true;
}
-bool
-Messages60Test::testUpdateDocumentReply()
-{
+TEST_F(Messages60Test, testUpdateDocumentReply) {
UpdateDocumentReply reply;
reply.setWasFound(false);
reply.setHighestModificationTimestamp(30);
- EXPECT_EQUAL(14u, serialize("UpdateDocumentReply", reply));
- EXPECT_EQUAL(120u, sizeof(UpdateDocumentReply));
+ EXPECT_EQ(14u, serialize("UpdateDocumentReply", reply));
+ EXPECT_EQ(120u, sizeof(UpdateDocumentReply));
for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
mbus::Routable::UP obj = deserialize("UpdateDocumentReply", DocumentProtocol::REPLY_UPDATEDOCUMENT, lang);
- if (EXPECT_TRUE(obj)) {
- UpdateDocumentReply &ref = static_cast<UpdateDocumentReply&>(*obj);
- EXPECT_EQUAL(30u, ref.getHighestModificationTimestamp());
- EXPECT_EQUAL(false, ref.wasFound());
- }
+ ASSERT_TRUE(obj);
+ auto& ref = dynamic_cast<UpdateDocumentReply&>(*obj);
+ EXPECT_EQ(30u, ref.getHighestModificationTimestamp());
+ EXPECT_EQ(false, ref.wasFound());
}
- return true;
}
-bool
-Messages60Test::testRemoveDocumentMessage()
-{
+TEST_F(Messages60Test, testRemoveDocumentMessage) {
RemoveDocumentMessage msg(document::DocumentId("id:ns:testdoc::"));
msg.setCondition(TestAndSetCondition("There's just one condition"));
- EXPECT_EQUAL(sizeof(TestAndSetMessage) + 104, sizeof(RemoveDocumentMessage));
- EXPECT_EQUAL(MESSAGE_BASE_LENGTH + size_t(20) + serializedLength(msg.getCondition().getSelection()), serialize("RemoveDocumentMessage", msg));
+ EXPECT_EQ(sizeof(TestAndSetMessage) + 104, sizeof(RemoveDocumentMessage));
+ EXPECT_EQ(MESSAGE_BASE_LENGTH + size_t(20) + serializedLength(msg.getCondition().getSelection()), serialize("RemoveDocumentMessage", msg));
for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
auto routablePtr = deserialize("RemoveDocumentMessage", DocumentProtocol::MESSAGE_REMOVEDOCUMENT, lang);
-
- if (EXPECT_TRUE(routablePtr)) {
- auto & ref = static_cast<RemoveDocumentMessage &>(*routablePtr);
- EXPECT_EQUAL(string("id:ns:testdoc::"), ref.getDocumentId().toString());
- EXPECT_EQUAL(msg.getCondition().getSelection(), ref.getCondition().getSelection());
- }
+ ASSERT_TRUE(routablePtr);
+ auto& ref = dynamic_cast<RemoveDocumentMessage&>(*routablePtr);
+ EXPECT_EQ(string("id:ns:testdoc::"), ref.getDocumentId().toString());
+ EXPECT_EQ(msg.getCondition().getSelection(), ref.getCondition().getSelection());
}
- return true;
}
-bool
-Messages60Test::testRemoveDocumentReply()
-{
+TEST_F(Messages60Test, testRemoveDocumentReply) {
RemoveDocumentReply reply;
std::vector<uint64_t> ts;
reply.setWasFound(false);
reply.setHighestModificationTimestamp(30);
- EXPECT_EQUAL(120u, sizeof(RemoveDocumentReply));
+ EXPECT_EQ(120u, sizeof(RemoveDocumentReply));
- EXPECT_EQUAL(14u, serialize("RemoveDocumentReply", reply));
+ EXPECT_EQ(14u, serialize("RemoveDocumentReply", reply));
for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
mbus::Routable::UP obj = deserialize("RemoveDocumentReply", DocumentProtocol::REPLY_REMOVEDOCUMENT, lang);
- if (EXPECT_TRUE(obj)) {
- RemoveDocumentReply &ref = static_cast<RemoveDocumentReply&>(*obj);
- EXPECT_EQUAL(30u, ref.getHighestModificationTimestamp());
- EXPECT_EQUAL(false, ref.wasFound());
- }
+ ASSERT_TRUE(obj);
+ auto& ref = dynamic_cast<RemoveDocumentReply&>(*obj);
+ EXPECT_EQ(30u, ref.getHighestModificationTimestamp());
+ EXPECT_EQ(false, ref.wasFound());
}
- return true;
}
-bool
-Messages60Test::testUpdateDocumentMessage()
-{
- const DocumentTypeRepo & repo = getTypeRepo();
+TEST_F(Messages60Test, testUpdateDocumentMessage) {
+ const DocumentTypeRepo & repo = type_repo();
const document::DocumentType & docType = *repo.getDocumentType("testdoc");
auto docUpdate = std::make_shared<document::DocumentUpdate>(repo, docType, document::DocumentId("id:ns:testdoc::"));
@@ -522,82 +406,74 @@ Messages60Test::testUpdateDocumentMessage()
msg.setNewTimestamp(777u);
msg.setCondition(TestAndSetCondition("There's just one condition"));
- EXPECT_EQUAL(sizeof(TestAndSetMessage) + 32, sizeof(UpdateDocumentMessage));
- EXPECT_EQUAL(MESSAGE_BASE_LENGTH + 93u + serializedLength(msg.getCondition().getSelection()), serialize("UpdateDocumentMessage", msg));
+ EXPECT_EQ(sizeof(TestAndSetMessage) + 32, sizeof(UpdateDocumentMessage));
+ EXPECT_EQ(MESSAGE_BASE_LENGTH + 93u + serializedLength(msg.getCondition().getSelection()), serialize("UpdateDocumentMessage", msg));
for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
auto routableUp = deserialize("UpdateDocumentMessage", DocumentProtocol::MESSAGE_UPDATEDOCUMENT, lang);
-
- if (EXPECT_TRUE(routableUp)) {
- auto & deserializedMsg = static_cast<UpdateDocumentMessage &>(*routableUp);
- EXPECT_EQUAL(msg.getDocumentUpdate(), deserializedMsg.getDocumentUpdate());
- EXPECT_EQUAL(msg.getOldTimestamp(), deserializedMsg.getOldTimestamp());
- EXPECT_EQUAL(msg.getNewTimestamp(), deserializedMsg.getNewTimestamp());
- EXPECT_EQUAL(119u, deserializedMsg.getApproxSize());
- EXPECT_EQUAL(msg.getCondition().getSelection(), deserializedMsg.getCondition().getSelection());
- }
+ ASSERT_TRUE(routableUp);
+ auto& deserializedMsg = dynamic_cast<UpdateDocumentMessage&>(*routableUp);
+ EXPECT_EQ(msg.getDocumentUpdate(), deserializedMsg.getDocumentUpdate());
+ EXPECT_EQ(msg.getOldTimestamp(), deserializedMsg.getOldTimestamp());
+ EXPECT_EQ(msg.getNewTimestamp(), deserializedMsg.getNewTimestamp());
+ EXPECT_EQ(119u, deserializedMsg.getApproxSize());
+ EXPECT_EQ(msg.getCondition().getSelection(), deserializedMsg.getCondition().getSelection());
}
- return true;
}
-bool
-Messages60Test::testQueryResultMessage()
-{
+TEST_F(Messages60Test, testQueryResultMessage) {
QueryResultMessage srm;
vdslib::SearchResult & sr(srm.getSearchResult());
- EXPECT_EQUAL(srm.getSequenceId(), 0u);
- EXPECT_EQUAL(sr.getHitCount(), 0u);
- EXPECT_EQUAL(sr.getAggregatorList().getSerializedSize(), 4u);
- EXPECT_EQUAL(sr.getSerializedSize(), 20u);
- EXPECT_EQUAL(srm.getApproxSize(), 28u);
+ EXPECT_EQ(srm.getSequenceId(), 0u);
+ EXPECT_EQ(sr.getHitCount(), 0u);
+ EXPECT_EQ(sr.getAggregatorList().getSerializedSize(), 4u);
+ EXPECT_EQ(sr.getSerializedSize(), 20u);
+ EXPECT_EQ(srm.getApproxSize(), 28u);
- EXPECT_EQUAL(MESSAGE_BASE_LENGTH + size_t(32), serialize("QueryResultMessage-1", srm));
+ EXPECT_EQ(MESSAGE_BASE_LENGTH + size_t(32), serialize("QueryResultMessage-1", srm));
mbus::Routable::UP routable = deserialize("QueryResultMessage-1", DocumentProtocol::MESSAGE_QUERYRESULT, LANG_CPP);
- if (!EXPECT_TRUE(routable)) {
- return false;
- }
- QueryResultMessage * dm = static_cast<QueryResultMessage *>(routable.get());
+ ASSERT_TRUE(routable);
+ auto* dm = dynamic_cast<QueryResultMessage*>(routable.get());
+ ASSERT_TRUE(dm);
vdslib::SearchResult * dr(&dm->getSearchResult());
- EXPECT_EQUAL(dm->getSequenceId(), size_t(0));
- EXPECT_EQUAL(dr->getHitCount(), size_t(0));
+ EXPECT_EQ(dm->getSequenceId(), size_t(0));
+ EXPECT_EQ(dr->getHitCount(), size_t(0));
sr.addHit(0, "doc1", 89);
sr.addHit(1, "doc17", 109);
- EXPECT_EQUAL(MESSAGE_BASE_LENGTH + 63u, serialize("QueryResultMessage-2", srm));
+ EXPECT_EQ(MESSAGE_BASE_LENGTH + 63u, serialize("QueryResultMessage-2", srm));
routable = deserialize("QueryResultMessage-2", DocumentProtocol::MESSAGE_QUERYRESULT, LANG_CPP);
- if (!EXPECT_TRUE(routable)) {
- return false;
- }
- dm = static_cast<QueryResultMessage *>(routable.get());
+ ASSERT_TRUE(routable);
+ dm = dynamic_cast<QueryResultMessage*>(routable.get());
+ ASSERT_TRUE(dm);
dr = &dm->getSearchResult();
- EXPECT_EQUAL(dr->getHitCount(), size_t(2));
+ EXPECT_EQ(dr->getHitCount(), size_t(2));
const char *docId;
vdslib::SearchResult::RankType rank;
dr->getHit(0, docId, rank);
- EXPECT_EQUAL(rank, vdslib::SearchResult::RankType(89));
- EXPECT_EQUAL(strcmp("doc1", docId), 0);
+ EXPECT_EQ(rank, vdslib::SearchResult::RankType(89));
+ EXPECT_EQ(strcmp("doc1", docId), 0);
dr->getHit(1, docId, rank);
- EXPECT_EQUAL(rank, vdslib::SearchResult::RankType(109));
- EXPECT_EQUAL(strcmp("doc17", docId), 0);
+ EXPECT_EQ(rank, vdslib::SearchResult::RankType(109));
+ EXPECT_EQ(strcmp("doc17", docId), 0);
sr.sort();
- EXPECT_EQUAL(MESSAGE_BASE_LENGTH + 63u, serialize("QueryResultMessage-3", srm));
+ EXPECT_EQ(MESSAGE_BASE_LENGTH + 63u, serialize("QueryResultMessage-3", srm));
routable = deserialize("QueryResultMessage-3", DocumentProtocol::MESSAGE_QUERYRESULT, LANG_CPP);
- if (!EXPECT_TRUE(routable)) {
- return false;
- }
- dm = static_cast<QueryResultMessage *>(routable.get());
+ ASSERT_TRUE(routable);
+ dm = dynamic_cast<QueryResultMessage*>(routable.get());
+ ASSERT_TRUE(dm);
dr = &dm->getSearchResult();
- EXPECT_EQUAL(dr->getHitCount(), size_t(2));
+ EXPECT_EQ(dr->getHitCount(), size_t(2));
dr->getHit(0, docId, rank);
- EXPECT_EQUAL(rank, vdslib::SearchResult::RankType(109));
- EXPECT_EQUAL(strcmp("doc17", docId), 0);
+ EXPECT_EQ(rank, vdslib::SearchResult::RankType(109));
+ EXPECT_EQ(strcmp("doc17", docId), 0);
dr->getHit(1, docId, rank);
- EXPECT_EQUAL(rank, vdslib::SearchResult::RankType(89));
- EXPECT_EQUAL(strcmp("doc1", docId), 0);
+ EXPECT_EQ(rank, vdslib::SearchResult::RankType(89));
+ EXPECT_EQ(strcmp("doc1", docId), 0);
QueryResultMessage srm2;
vdslib::SearchResult & sr2(srm2.getSearchResult());
@@ -605,72 +481,70 @@ Messages60Test::testQueryResultMessage()
sr2.addHit(1, "doc17", 109, "sortdata1", 9);
sr2.addHit(2, "doc18", 90, "sortdata3", 9);
- EXPECT_EQUAL(MESSAGE_BASE_LENGTH + 116u, serialize("QueryResultMessage-4", srm2));
+ EXPECT_EQ(MESSAGE_BASE_LENGTH + 116u, serialize("QueryResultMessage-4", srm2));
routable = deserialize("QueryResultMessage-4", DocumentProtocol::MESSAGE_QUERYRESULT, LANG_CPP);
- if (!EXPECT_TRUE(routable)) {
- return false;
- }
- dm = static_cast<QueryResultMessage *>(routable.get());
+ ASSERT_TRUE(routable);
+ dm = dynamic_cast<QueryResultMessage*>(routable.get());
+ ASSERT_TRUE(dm);
dr = &dm->getSearchResult();
- EXPECT_EQUAL(dr->getHitCount(), size_t(3));
+ EXPECT_EQ(dr->getHitCount(), size_t(3));
dr->getHit(0, docId, rank);
- EXPECT_EQUAL(rank, vdslib::SearchResult::RankType(89));
- EXPECT_EQUAL(strcmp("doc1", docId), 0);
+ EXPECT_EQ(rank, vdslib::SearchResult::RankType(89));
+ EXPECT_EQ(strcmp("doc1", docId), 0);
dr->getHit(1, docId, rank);
- EXPECT_EQUAL(rank, vdslib::SearchResult::RankType(109));
- EXPECT_EQUAL(strcmp("doc17", docId), 0);
+ EXPECT_EQ(rank, vdslib::SearchResult::RankType(109));
+ EXPECT_EQ(strcmp("doc17", docId), 0);
dr->getHit(2, docId, rank);
- EXPECT_EQUAL(rank, vdslib::SearchResult::RankType(90));
- EXPECT_EQUAL(strcmp("doc18", docId), 0);
+ EXPECT_EQ(rank, vdslib::SearchResult::RankType(90));
+ EXPECT_EQ(strcmp("doc18", docId), 0);
sr2.sort();
const void *buf;
size_t sz;
sr2.getHit(0, docId, rank);
sr2.getSortBlob(0, buf, sz);
- EXPECT_EQUAL(sz, 9u);
- EXPECT_EQUAL(memcmp("sortdata1", buf, sz), 0);
- EXPECT_EQUAL(rank, vdslib::SearchResult::RankType(109));
- EXPECT_EQUAL(strcmp("doc17", docId), 0);
+ EXPECT_EQ(sz, 9u);
+ EXPECT_EQ(memcmp("sortdata1", buf, sz), 0);
+ EXPECT_EQ(rank, vdslib::SearchResult::RankType(109));
+ EXPECT_EQ(strcmp("doc17", docId), 0);
sr2.getHit(1, docId, rank);
sr2.getSortBlob(1, buf, sz);
- EXPECT_EQUAL(sz, 9u);
- EXPECT_EQUAL(memcmp("sortdata2", buf, sz), 0);
- EXPECT_EQUAL(rank, vdslib::SearchResult::RankType(89));
- EXPECT_EQUAL(strcmp("doc1", docId), 0);
+ EXPECT_EQ(sz, 9u);
+ EXPECT_EQ(memcmp("sortdata2", buf, sz), 0);
+ EXPECT_EQ(rank, vdslib::SearchResult::RankType(89));
+ EXPECT_EQ(strcmp("doc1", docId), 0);
sr2.getHit(2, docId, rank);
sr2.getSortBlob(2, buf, sz);
- EXPECT_EQUAL(sz, 9u);
- EXPECT_EQUAL(memcmp("sortdata3", buf, sz), 0);
- EXPECT_EQUAL(rank, vdslib::SearchResult::RankType(90));
- EXPECT_EQUAL(strcmp("doc18", docId), 0);
+ EXPECT_EQ(sz, 9u);
+ EXPECT_EQ(memcmp("sortdata3", buf, sz), 0);
+ EXPECT_EQ(rank, vdslib::SearchResult::RankType(90));
+ EXPECT_EQ(strcmp("doc18", docId), 0);
- EXPECT_EQUAL(MESSAGE_BASE_LENGTH + 116u, serialize("QueryResultMessage-5", srm2));
+ EXPECT_EQ(MESSAGE_BASE_LENGTH + 116u, serialize("QueryResultMessage-5", srm2));
routable = deserialize("QueryResultMessage-5", DocumentProtocol::MESSAGE_QUERYRESULT, LANG_CPP);
- if (!EXPECT_TRUE(routable)) {
- return false;
- }
- dm = static_cast<QueryResultMessage *>(routable.get());
+ ASSERT_TRUE(routable);
+ dm = dynamic_cast<QueryResultMessage*>(routable.get());
+ ASSERT_TRUE(dm);
dr = &dm->getSearchResult();
- EXPECT_EQUAL(dr->getHitCount(), size_t(3));
+ EXPECT_EQ(dr->getHitCount(), size_t(3));
dr->getHit(0, docId, rank);
dr->getSortBlob(0, buf, sz);
- EXPECT_EQUAL(sz, 9u);
- EXPECT_EQUAL(memcmp("sortdata1", buf, sz), 0);
- EXPECT_EQUAL(rank, vdslib::SearchResult::RankType(109));
- EXPECT_EQUAL(strcmp("doc17", docId), 0);
+ EXPECT_EQ(sz, 9u);
+ EXPECT_EQ(memcmp("sortdata1", buf, sz), 0);
+ EXPECT_EQ(rank, vdslib::SearchResult::RankType(109));
+ EXPECT_EQ(strcmp("doc17", docId), 0);
dr->getHit(1, docId, rank);
dr->getSortBlob(1, buf, sz);
- EXPECT_EQUAL(sz, 9u);
- EXPECT_EQUAL(memcmp("sortdata2", buf, sz), 0);
- EXPECT_EQUAL(rank, vdslib::SearchResult::RankType(89));
- EXPECT_EQUAL(strcmp("doc1", docId), 0);
+ EXPECT_EQ(sz, 9u);
+ EXPECT_EQ(memcmp("sortdata2", buf, sz), 0);
+ EXPECT_EQ(rank, vdslib::SearchResult::RankType(89));
+ EXPECT_EQ(strcmp("doc1", docId), 0);
dr->getHit(2, docId, rank);
dr->getSortBlob(2, buf, sz);
- EXPECT_EQUAL(sz, 9u);
- EXPECT_EQUAL(memcmp("sortdata3", buf, sz), 0);
- EXPECT_EQUAL(rank, vdslib::SearchResult::RankType(90));
- EXPECT_EQUAL(strcmp("doc18", docId), 0);
+ EXPECT_EQ(sz, 9u);
+ EXPECT_EQ(memcmp("sortdata3", buf, sz), 0);
+ EXPECT_EQ(rank, vdslib::SearchResult::RankType(90));
+ EXPECT_EQ(strcmp("doc18", docId), 0);
QueryResultMessage qrm3;
auto& sr3(qrm3.getSearchResult());
@@ -687,44 +561,38 @@ Messages60Test::testQueryResultMessage()
sr3.set_match_features(FeatureValues(mf));
sr3.sort();
- EXPECT_EQUAL(MESSAGE_BASE_LENGTH + 125u, serialize("QueryResultMessage-6", qrm3));
+ EXPECT_EQ(MESSAGE_BASE_LENGTH + 125u, serialize("QueryResultMessage-6", qrm3));
routable = deserialize("QueryResultMessage-6", DocumentProtocol::MESSAGE_QUERYRESULT, LANG_CPP);
- if (!EXPECT_TRUE(routable)) {
- return false;
- }
- dm = static_cast<QueryResultMessage *>(routable.get());
+ ASSERT_TRUE(routable);
+ dm = dynamic_cast<QueryResultMessage *>(routable.get());
+ ASSERT_TRUE(dm);
dr = &dm->getSearchResult();
- EXPECT_EQUAL(size_t(2), dr->getHitCount());
+ EXPECT_EQ(size_t(2), dr->getHitCount());
dr->getHit(0, docId, rank);
- EXPECT_EQUAL(vdslib::SearchResult::RankType(7), rank);
- EXPECT_EQUAL(strcmp("doc2", docId), 0);
+ EXPECT_EQ(vdslib::SearchResult::RankType(7), rank);
+ EXPECT_EQ(strcmp("doc2", docId), 0);
dr->getHit(1, docId, rank);
- EXPECT_EQUAL(vdslib::SearchResult::RankType(5), rank);
- EXPECT_EQUAL(strcmp("doc1", docId), 0);
+ EXPECT_EQ(vdslib::SearchResult::RankType(5), rank);
+ EXPECT_EQ(strcmp("doc1", docId), 0);
auto mfv = dr->get_match_feature_values(0);
- EXPECT_EQUAL(2u, mfv.size());
- EXPECT_EQUAL(12.0, mfv[0].as_double());
- EXPECT_EQUAL("There", mfv[1].as_data().make_string());
+ EXPECT_EQ(2u, mfv.size());
+ EXPECT_EQ(12.0, mfv[0].as_double());
+ EXPECT_EQ("There", mfv[1].as_data().make_string());
mfv = dr->get_match_feature_values(1);
- EXPECT_EQUAL(2u, mfv.size());
- EXPECT_EQUAL(1.0, mfv[0].as_double());
- EXPECT_EQUAL("Hi", mfv[1].as_data().make_string());
+ EXPECT_EQ(2u, mfv.size());
+ EXPECT_EQ(1.0, mfv[0].as_double());
+ EXPECT_EQ("Hi", mfv[1].as_data().make_string());
const auto& mf_names = dr->get_match_features().names;
- EXPECT_EQUAL(2u, mf_names.size());
- EXPECT_EQUAL("foo", mf_names[0]);
- EXPECT_EQUAL("bar", mf_names[1]);
- return true;
+ EXPECT_EQ(2u, mf_names.size());
+ EXPECT_EQ("foo", mf_names[0]);
+ EXPECT_EQ("bar", mf_names[1]);
}
-bool
-Messages60Test::testQueryResultReply()
-{
- return tryVisitorReply("QueryResultReply", DocumentProtocol::REPLY_QUERYRESULT);
+TEST_F(Messages60Test, testQueryResultReply) {
+ ASSERT_NO_FATAL_FAILURE(tryVisitorReply("QueryResultReply", DocumentProtocol::REPLY_QUERYRESULT));
}
-bool
-Messages60Test::testVisitorInfoMessage()
-{
+TEST_F(Messages60Test, testVisitorInfoMessage) {
VisitorInfoMessage tmp;
tmp.getFinishedBuckets().push_back(document::BucketId(16, 1));
@@ -733,30 +601,24 @@ Messages60Test::testVisitorInfoMessage()
string utf8 = "error message: \u00e6\u00c6\u00f8\u00d8\u00e5\u00c5\u00f6\u00d6";
tmp.setErrorMessage(utf8);
- EXPECT_EQUAL(MESSAGE_BASE_LENGTH + 67u, serialize("VisitorInfoMessage", tmp));
+ EXPECT_EQ(MESSAGE_BASE_LENGTH + 67u, serialize("VisitorInfoMessage", tmp));
for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
mbus::Routable::UP obj = deserialize("VisitorInfoMessage", DocumentProtocol::MESSAGE_VISITORINFO, lang);
- if (EXPECT_TRUE(obj)) {
- VisitorInfoMessage &ref = static_cast<VisitorInfoMessage&>(*obj);
- EXPECT_EQUAL(document::BucketId(16, 1), ref.getFinishedBuckets()[0]);
- EXPECT_EQUAL(document::BucketId(16, 2), ref.getFinishedBuckets()[1]);
- EXPECT_EQUAL(document::BucketId(16, 4), ref.getFinishedBuckets()[2]);
- EXPECT_EQUAL(utf8, ref.getErrorMessage());
- }
+ ASSERT_TRUE(obj);
+ auto& ref = dynamic_cast<VisitorInfoMessage&>(*obj);
+ EXPECT_EQ(document::BucketId(16, 1), ref.getFinishedBuckets()[0]);
+ EXPECT_EQ(document::BucketId(16, 2), ref.getFinishedBuckets()[1]);
+ EXPECT_EQ(document::BucketId(16, 4), ref.getFinishedBuckets()[2]);
+ EXPECT_EQ(utf8, ref.getErrorMessage());
}
- return true;
}
-bool
-Messages60Test::testDestroyVisitorReply()
-{
- return tryVisitorReply("DestroyVisitorReply", DocumentProtocol::REPLY_DESTROYVISITOR);
+TEST_F(Messages60Test, testDestroyVisitorReply) {
+ ASSERT_NO_FATAL_FAILURE(tryVisitorReply("DestroyVisitorReply", DocumentProtocol::REPLY_DESTROYVISITOR));
}
-bool
-Messages60Test::testDocumentIgnoredReply()
-{
+TEST_F(Messages60Test, testDocumentIgnoredReply) {
DocumentIgnoredReply tmp;
serialize("DocumentIgnoredReply", tmp);
for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
@@ -765,152 +627,120 @@ Messages60Test::testDocumentIgnoredReply()
DocumentProtocol::REPLY_DOCUMENTIGNORED, lang));
EXPECT_TRUE(obj);
}
- return true;
}
-bool
-Messages60Test::testDocumentListReply()
-{
- return tryVisitorReply("DocumentListReply", DocumentProtocol::REPLY_DOCUMENTLIST);
+TEST_F(Messages60Test, testDocumentListReply) {
+ ASSERT_NO_FATAL_FAILURE(tryVisitorReply("DocumentListReply", DocumentProtocol::REPLY_DOCUMENTLIST));
}
-bool
-Messages60Test::testGetDocumentReply()
-{
+TEST_F(Messages60Test, testGetDocumentReply) {
document::Document::SP doc =
- createDoc(getTypeRepo(), "testdoc", "id:ns:testdoc::");
+ createDoc(type_repo(), "testdoc", "id:ns:testdoc::");
GetDocumentReply tmp(doc);
- EXPECT_EQUAL(128u, sizeof(GetDocumentReply));
- EXPECT_EQUAL((size_t)47, serialize("GetDocumentReply", tmp));
+ EXPECT_EQ(128u, sizeof(GetDocumentReply));
+ EXPECT_EQ((size_t)47, serialize("GetDocumentReply", tmp));
for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
mbus::Routable::UP obj = deserialize("GetDocumentReply", DocumentProtocol::REPLY_GETDOCUMENT, lang);
- if (EXPECT_TRUE(obj)) {
- GetDocumentReply &ref = static_cast<GetDocumentReply&>(*obj);
+ ASSERT_TRUE(obj);
+ auto& ref = dynamic_cast<GetDocumentReply&>(*obj);
- EXPECT_EQUAL(string("testdoc"), ref.getDocument().getType().getName());
- EXPECT_EQUAL(string("id:ns:testdoc::"), ref.getDocument().getId().toString());
- }
+ EXPECT_EQ(string("testdoc"), ref.getDocument().getType().getName());
+ EXPECT_EQ(string("id:ns:testdoc::"), ref.getDocument().getId().toString());
}
- return true;
}
-bool
-Messages60Test::testMapVisitorReply()
-{
- return tryVisitorReply("MapVisitorReply", DocumentProtocol::REPLY_MAPVISITOR);
+TEST_F(Messages60Test, testMapVisitorReply) {
+ ASSERT_NO_FATAL_FAILURE(tryVisitorReply("MapVisitorReply", DocumentProtocol::REPLY_MAPVISITOR));
}
-bool
-Messages60Test::testStatBucketReply()
-{
+TEST_F(Messages60Test, testStatBucketReply) {
StatBucketReply msg;
msg.setResults("These are the votes of the Norwegian jury");
- EXPECT_EQUAL(50u, serialize("StatBucketReply", msg));
+ EXPECT_EQ(50u, serialize("StatBucketReply", msg));
for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
mbus::Routable::UP obj = deserialize("StatBucketReply", DocumentProtocol::REPLY_STATBUCKET, lang);
- if (EXPECT_TRUE(obj)) {
- StatBucketReply &ref = static_cast<StatBucketReply&>(*obj);
- EXPECT_EQUAL("These are the votes of the Norwegian jury", ref.getResults());
- }
+ ASSERT_TRUE(obj);
+ auto& ref = dynamic_cast<StatBucketReply&>(*obj);
+ EXPECT_EQ("These are the votes of the Norwegian jury", ref.getResults());
}
- return true;
}
-bool
-Messages60Test::testVisitorInfoReply()
-{
- return tryVisitorReply("VisitorInfoReply", DocumentProtocol::REPLY_VISITORINFO);
+TEST_F(Messages60Test, testVisitorInfoReply) {
+ ASSERT_NO_FATAL_FAILURE(tryVisitorReply("VisitorInfoReply", DocumentProtocol::REPLY_VISITORINFO));
}
-bool
-Messages60Test::testWrongDistributionReply()
-{
+TEST_F(Messages60Test, testWrongDistributionReply) {
WrongDistributionReply tmp("distributor:3 storage:2");
serialize("WrongDistributionReply", tmp);
for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
mbus::Routable::UP obj = deserialize("WrongDistributionReply", DocumentProtocol::REPLY_WRONGDISTRIBUTION, lang);
- if (EXPECT_TRUE(obj)) {
- WrongDistributionReply &ref = static_cast<WrongDistributionReply&>(*obj);
- EXPECT_EQUAL(string("distributor:3 storage:2"), ref.getSystemState());
- }
+ ASSERT_TRUE(obj);
+ auto& ref = dynamic_cast<WrongDistributionReply&>(*obj);
+ EXPECT_EQ(string("distributor:3 storage:2"), ref.getSystemState());
}
- return true;
}
-bool
-Messages60Test::testGetBucketListReply()
-{
+TEST_F(Messages60Test, testGetBucketListReply) {
GetBucketListReply reply;
reply.getBuckets().push_back(GetBucketListReply::BucketInfo(document::BucketId(16, 123), "foo"));
reply.getBuckets().push_back(GetBucketListReply::BucketInfo(document::BucketId(17, 1123), "bar"));
reply.getBuckets().push_back(GetBucketListReply::BucketInfo(document::BucketId(18, 11123), "zoink"));
- EXPECT_EQUAL(56u, serialize("GetBucketListReply", reply));
+ EXPECT_EQ(56u, serialize("GetBucketListReply", reply));
for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
mbus::Routable::UP obj = deserialize("GetBucketListReply", DocumentProtocol::REPLY_GETBUCKETLIST, lang);
- if (EXPECT_TRUE(obj)) {
- GetBucketListReply &ref = static_cast<GetBucketListReply&>(*obj);
+ ASSERT_TRUE(obj);
+ auto& ref = dynamic_cast<GetBucketListReply&>(*obj);
- EXPECT_EQUAL(ref.getBuckets()[0], GetBucketListReply::BucketInfo(document::BucketId(16, 123), "foo"));
- EXPECT_EQUAL(ref.getBuckets()[1], GetBucketListReply::BucketInfo(document::BucketId(17, 1123), "bar"));
- EXPECT_EQUAL(ref.getBuckets()[2], GetBucketListReply::BucketInfo(document::BucketId(18, 11123), "zoink"));
- }
+ EXPECT_EQ(ref.getBuckets()[0], GetBucketListReply::BucketInfo(document::BucketId(16, 123), "foo"));
+ EXPECT_EQ(ref.getBuckets()[1], GetBucketListReply::BucketInfo(document::BucketId(17, 1123), "bar"));
+ EXPECT_EQ(ref.getBuckets()[2], GetBucketListReply::BucketInfo(document::BucketId(18, 11123), "zoink"));
}
- return true;
}
-bool
-Messages60Test::testGetBucketStateReply()
-{
+TEST_F(Messages60Test, testGetBucketStateReply) {
document::GlobalId foo = document::DocumentId("id:ns:testdoc::foo").getGlobalId();
document::GlobalId bar = document::DocumentId("id:ns:testdoc::bar").getGlobalId();
GetBucketStateReply reply;
reply.getBucketState().push_back(DocumentState(foo, 777, false));
reply.getBucketState().push_back(DocumentState(bar, 888, true));
- EXPECT_EQUAL(53u, serialize("GetBucketStateReply", reply));
+ EXPECT_EQ(53u, serialize("GetBucketStateReply", reply));
for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
mbus::Routable::UP obj = deserialize("GetBucketStateReply", DocumentProtocol::REPLY_GETBUCKETSTATE, lang);
- if (EXPECT_TRUE(obj)) {
- GetBucketStateReply &ref = static_cast<GetBucketStateReply&>(*obj);
-
- EXPECT_EQUAL(777u, ref.getBucketState()[0].getTimestamp());
- EXPECT_EQUAL(foo, ref.getBucketState()[0].getGlobalId());
- EXPECT_EQUAL(false, ref.getBucketState()[0].isRemoveEntry());
- EXPECT_EQUAL(888u, ref.getBucketState()[1].getTimestamp());
- EXPECT_EQUAL(bar, ref.getBucketState()[1].getGlobalId());
- EXPECT_EQUAL(true, ref.getBucketState()[1].isRemoveEntry());
- }
+ ASSERT_TRUE(obj);
+ auto& ref = dynamic_cast<GetBucketStateReply&>(*obj);
+
+ EXPECT_EQ(777u, ref.getBucketState()[0].getTimestamp());
+ EXPECT_EQ(foo, ref.getBucketState()[0].getGlobalId());
+ EXPECT_EQ(false, ref.getBucketState()[0].isRemoveEntry());
+ EXPECT_EQ(888u, ref.getBucketState()[1].getTimestamp());
+ EXPECT_EQ(bar, ref.getBucketState()[1].getGlobalId());
+ EXPECT_EQ(true, ref.getBucketState()[1].isRemoveEntry());
}
- return true;
}
-bool
-Messages60Test::testEmptyBucketsReply()
-{
- return tryVisitorReply("EmptyBucketsReply", DocumentProtocol::REPLY_EMPTYBUCKETS);
+TEST_F(Messages60Test, testEmptyBucketsReply) {
+ ASSERT_NO_FATAL_FAILURE(tryVisitorReply("EmptyBucketsReply", DocumentProtocol::REPLY_EMPTYBUCKETS));
}
-bool
-Messages60Test::testRemoveLocationReply()
-{
+TEST_F(Messages60Test, testRemoveLocationReply) {
DocumentReply tmp(DocumentProtocol::REPLY_REMOVELOCATION);
- EXPECT_EQUAL((uint32_t)5, serialize("RemoveLocationReply", tmp));
+ EXPECT_EQ((uint32_t)5, serialize("RemoveLocationReply", tmp));
for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
mbus::Routable::UP obj = deserialize("RemoveLocationReply", DocumentProtocol::REPLY_REMOVELOCATION, lang);
EXPECT_TRUE(obj);
}
- return true;
}
@@ -921,19 +751,18 @@ Messages60Test::testRemoveLocationReply()
//
////////////////////////////////////////////////////////////////////////////////
-bool
-Messages60Test::tryVisitorReply(const string &filename, uint32_t type)
+void
+Messages60Test::tryVisitorReply(const string& filename, uint32_t type)
{
VisitorReply tmp(type);
-
- EXPECT_EQUAL((uint32_t)5, serialize(filename, tmp));
+ EXPECT_EQ((uint32_t)5, serialize(filename, tmp));
for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
mbus::Routable::UP obj = deserialize(filename, type, lang);
- if (EXPECT_TRUE(obj)) {
- VisitorReply *ref = dynamic_cast<VisitorReply*>(obj.get());
- EXPECT_TRUE(ref != NULL);
- }
+ ASSERT_TRUE(obj);
+ auto* ref = dynamic_cast<VisitorReply*>(obj.get());
+ EXPECT_TRUE(ref);
}
- return true;
}
+
+} // documentapi
diff --git a/documentapi/src/tests/messages/messages60test.h b/documentapi/src/tests/messages/messages60test.h
deleted file mode 100644
index d1060a83962..00000000000
--- a/documentapi/src/tests/messages/messages60test.h
+++ /dev/null
@@ -1,52 +0,0 @@
-// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-// @author Vegard Sjonfjell
-#pragma once
-
-#include "testbase.h"
-
-class Messages60Test : public TestBase {
-protected:
- vespalib::Version getVersion() const override { return vespalib::Version(6, 221); }
- bool shouldTestCoverage() const override { return true; }
-
- bool tryVisitorReply(const string &filename, uint32_t type);
-
- static size_t serializedLength(const string & str) { return sizeof(int32_t) + str.size(); }
-
-public:
- Messages60Test();
-
- bool testCreateVisitorMessage();
- bool testCreateVisitorReply();
- bool testDestroyVisitorMessage();
- bool testDestroyVisitorReply();
- bool testDocumentIgnoredReply();
- bool testDocumentListMessage();
- bool testDocumentListReply();
- bool testEmptyBucketsMessage();
- bool testEmptyBucketsReply();
- bool testGetBucketListMessage();
- bool testGetBucketListReply();
- bool testGetBucketStateMessage();
- bool testGetBucketStateReply();
- bool testGetDocumentMessage();
- bool testGetDocumentReply();
- bool testMapVisitorMessage();
- bool testMapVisitorReply();
- bool testPutDocumentMessage();
- bool testPutDocumentReply();
- bool testQueryResultMessage();
- bool testQueryResultReply();
- bool testRemoveDocumentMessage();
- bool testRemoveDocumentReply();
- bool testRemoveLocationMessage();
- bool testRemoveLocationReply();
- bool testStatBucketMessage();
- bool testStatBucketReply();
- bool testUpdateDocumentMessage();
- bool testUpdateDocumentReply();
- bool testVisitorInfoMessage();
- bool testVisitorInfoReply();
- bool testWrongDistributionReply();
-};
-
diff --git a/documentapi/src/tests/messages/messages80test.cpp b/documentapi/src/tests/messages/messages80test.cpp
index 0812aceb4a3..c61b1575dac 100644
--- a/documentapi/src/tests/messages/messages80test.cpp
+++ b/documentapi/src/tests/messages/messages80test.cpp
@@ -1,5 +1,5 @@
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#include "testbase.h"
+#include "message_fixture.h"
#include <vespa/document/bucket/bucketidfactory.h>
#include <vespa/document/datatype/documenttype.h>
#include <vespa/document/fieldvalue/document.h>
@@ -16,61 +16,32 @@ using document::DataType;
using document::DocumentTypeRepo;
using vespalib::FeatureValues;
-// TODO rewrite to GTest!
-class Messages80Test : public TestBase {
-protected:
- vespalib::Version getVersion() const override {
+namespace documentapi {
+
+// This is not version-dependent
+TEST(MessagesTest, concrete_types_have_expected_sizes) {
+ EXPECT_EQ(sizeof(GetDocumentMessage), 280u);
+ EXPECT_EQ(sizeof(GetDocumentReply), 128u);
+ EXPECT_EQ(sizeof(vespalib::string), 64u);
+ EXPECT_EQ(sizeof(TestAndSetCondition), sizeof(vespalib::string));
+ EXPECT_EQ(sizeof(DocumentMessage), 112u);
+ EXPECT_EQ(sizeof(TestAndSetMessage), sizeof(TestAndSetCondition) + sizeof(DocumentMessage));
+ EXPECT_EQ(sizeof(PutDocumentMessage), sizeof(TestAndSetMessage) + 32);
+ EXPECT_EQ(sizeof(WriteDocumentReply), 112u);
+ EXPECT_EQ(sizeof(UpdateDocumentReply), 120u);
+ EXPECT_EQ(sizeof(UpdateDocumentMessage), sizeof(TestAndSetMessage) + 32);
+ EXPECT_EQ(sizeof(RemoveDocumentMessage), sizeof(TestAndSetMessage) + 104);
+ EXPECT_EQ(sizeof(RemoveDocumentReply), 120u);
+}
+
+struct Messages80Test : MessageFixture {
+ [[nodiscard]] vespalib::Version tested_protocol_version() const override {
// Must be as high--or higher--than the v8 protocol version specified in documentprocotol.cpp
// (and equal to its corresponding value in the Java implementation).
return {8, 310};
}
- bool shouldTestCoverage() const override { return true; }
-
- bool try_visitor_reply(const string& filename, uint32_t type);
-
- static constexpr std::array<uint32_t, 2> languages() noexcept {
- return {TestBase::LANG_CPP, TestBase::LANG_JAVA};
- }
-
-public:
- Messages80Test();
- ~Messages80Test() override = default;
-
- bool test_create_visitor_message();
- bool test_create_visitor_reply();
- bool test_destroy_visitor_message();
- bool test_destroy_visitor_reply();
- bool test_document_ignored_reply();
- bool test_document_list_message();
- bool test_document_list_reply();
- bool test_empty_buckets_message();
- bool test_empty_buckets_reply();
- bool test_get_bucket_list_message();
- bool test_get_bucket_list_reply();
- bool test_get_bucket_state_message();
- bool test_get_bucket_state_reply();
- bool test_get_document_message();
- bool test_get_document_reply();
- bool test_map_visitor_message();
- bool test_map_visitor_reply();
- bool test_put_document_message();
- bool test_put_document_reply();
- bool test_query_result_message();
- bool test_query_result_reply();
- bool test_remove_document_message();
- bool test_remove_document_reply();
- bool test_remove_location_message();
- bool test_remove_location_reply();
- bool test_stat_bucket_message();
- bool test_stat_bucket_reply();
- bool test_update_document_message();
- bool test_update_document_reply();
- bool test_visitor_info_message();
- bool test_visitor_info_reply();
- bool test_wrong_distribution_reply();
-
- void do_test_get_reply_with_doc();
- void do_test_empty_get_reply();
+
+ void try_visitor_reply(const std::string& filename, uint32_t type);
};
namespace {
@@ -80,42 +51,6 @@ std::vector<char> doc2_mf_data{'T', 'h', 'e', 'r', 'e'};
}
-Messages80Test::Messages80Test() {
- putTest(DocumentProtocol::MESSAGE_CREATEVISITOR, TEST_METHOD(Messages80Test::test_create_visitor_message));
- putTest(DocumentProtocol::MESSAGE_DESTROYVISITOR, TEST_METHOD(Messages80Test::test_destroy_visitor_message));
- putTest(DocumentProtocol::MESSAGE_DOCUMENTLIST, TEST_METHOD(Messages80Test::test_document_list_message));
- putTest(DocumentProtocol::MESSAGE_EMPTYBUCKETS, TEST_METHOD(Messages80Test::test_empty_buckets_message));
- putTest(DocumentProtocol::MESSAGE_GETBUCKETLIST, TEST_METHOD(Messages80Test::test_get_bucket_list_message));
- putTest(DocumentProtocol::MESSAGE_GETBUCKETSTATE, TEST_METHOD(Messages80Test::test_get_bucket_state_message));
- putTest(DocumentProtocol::MESSAGE_GETDOCUMENT, TEST_METHOD(Messages80Test::test_get_document_message));
- putTest(DocumentProtocol::MESSAGE_MAPVISITOR, TEST_METHOD(Messages80Test::test_map_visitor_message));
- putTest(DocumentProtocol::MESSAGE_PUTDOCUMENT, TEST_METHOD(Messages80Test::test_put_document_message));
- putTest(DocumentProtocol::MESSAGE_QUERYRESULT, TEST_METHOD(Messages80Test::test_query_result_message));
- putTest(DocumentProtocol::MESSAGE_REMOVEDOCUMENT, TEST_METHOD(Messages80Test::test_remove_document_message));
- putTest(DocumentProtocol::MESSAGE_REMOVELOCATION, TEST_METHOD(Messages80Test::test_remove_location_message));
- putTest(DocumentProtocol::MESSAGE_STATBUCKET, TEST_METHOD(Messages80Test::test_stat_bucket_message));
- putTest(DocumentProtocol::MESSAGE_UPDATEDOCUMENT, TEST_METHOD(Messages80Test::test_update_document_message));
- putTest(DocumentProtocol::MESSAGE_VISITORINFO, TEST_METHOD(Messages80Test::test_visitor_info_message));
-
- putTest(DocumentProtocol::REPLY_CREATEVISITOR, TEST_METHOD(Messages80Test::test_create_visitor_reply));
- putTest(DocumentProtocol::REPLY_DESTROYVISITOR, TEST_METHOD(Messages80Test::test_destroy_visitor_reply));
- putTest(DocumentProtocol::REPLY_DOCUMENTIGNORED, TEST_METHOD(Messages80Test::test_document_ignored_reply));
- putTest(DocumentProtocol::REPLY_DOCUMENTLIST, TEST_METHOD(Messages80Test::test_document_list_reply));
- putTest(DocumentProtocol::REPLY_EMPTYBUCKETS, TEST_METHOD(Messages80Test::test_empty_buckets_reply));
- putTest(DocumentProtocol::REPLY_GETBUCKETLIST, TEST_METHOD(Messages80Test::test_get_bucket_list_reply));
- putTest(DocumentProtocol::REPLY_GETBUCKETSTATE, TEST_METHOD(Messages80Test::test_get_bucket_state_reply));
- putTest(DocumentProtocol::REPLY_GETDOCUMENT, TEST_METHOD(Messages80Test::test_get_document_reply));
- putTest(DocumentProtocol::REPLY_MAPVISITOR, TEST_METHOD(Messages80Test::test_map_visitor_reply));
- putTest(DocumentProtocol::REPLY_PUTDOCUMENT, TEST_METHOD(Messages80Test::test_put_document_reply));
- putTest(DocumentProtocol::REPLY_QUERYRESULT, TEST_METHOD(Messages80Test::test_query_result_reply));
- putTest(DocumentProtocol::REPLY_REMOVEDOCUMENT, TEST_METHOD(Messages80Test::test_remove_document_reply));
- putTest(DocumentProtocol::REPLY_REMOVELOCATION, TEST_METHOD(Messages80Test::test_remove_location_reply));
- putTest(DocumentProtocol::REPLY_STATBUCKET, TEST_METHOD(Messages80Test::test_stat_bucket_reply));
- putTest(DocumentProtocol::REPLY_UPDATEDOCUMENT, TEST_METHOD(Messages80Test::test_update_document_reply));
- putTest(DocumentProtocol::REPLY_VISITORINFO, TEST_METHOD(Messages80Test::test_visitor_info_reply));
- putTest(DocumentProtocol::REPLY_WRONGDISTRIBUTION, TEST_METHOD(Messages80Test::test_wrong_distribution_reply));
-}
-
namespace {
document::Document::SP
@@ -125,128 +60,102 @@ createDoc(const DocumentTypeRepo& repo, const string& type_name, const string& i
}
-bool Messages80Test::test_get_document_message() {
+TEST_F(Messages80Test, get_document_message) {
GetDocumentMessage tmp(document::DocumentId("id:ns:testdoc::"), "foo bar");
- EXPECT_EQUAL(280u, sizeof(GetDocumentMessage)); // FIXME doesn't belong here
serialize("GetDocumentMessage", tmp);
for (auto lang : languages()) {
auto obj = deserialize("GetDocumentMessage", DocumentProtocol::MESSAGE_GETDOCUMENT, lang);
- if (EXPECT_TRUE(obj)) {
- auto& ref = dynamic_cast<GetDocumentMessage&>(*obj);
- EXPECT_EQUAL(ref.getDocumentId().toString(), "id:ns:testdoc::");
- EXPECT_EQUAL(ref.getFieldSet(), "foo bar");
- }
+ ASSERT_TRUE(obj);
+ auto& ref = dynamic_cast<GetDocumentMessage&>(*obj);
+ EXPECT_EQ(ref.getDocumentId().toString(), "id:ns:testdoc::");
+ EXPECT_EQ(ref.getFieldSet(), "foo bar");
}
- return true;
}
-void Messages80Test::do_test_get_reply_with_doc() {
- auto doc = createDoc(getTypeRepo(), "testdoc", "id:ns:testdoc::");
+TEST_F(Messages80Test, get_reply_with_doc) {
+ auto doc = createDoc(type_repo(), "testdoc", "id:ns:testdoc::");
GetDocumentReply tmp(doc);
tmp.setLastModified(1234567);
- EXPECT_EQUAL(128u, sizeof(GetDocumentReply)); // FIXME doesn't belong here!
serialize("GetDocumentReply", tmp);
for (auto lang : languages()) {
auto obj = deserialize("GetDocumentReply", DocumentProtocol::REPLY_GETDOCUMENT, lang);
- if (EXPECT_TRUE(obj)) {
- auto& ref = dynamic_cast<GetDocumentReply&>(*obj);
- EXPECT_EQUAL(ref.getLastModified(), 1234567ULL); // FIXME signed vs. unsigned... -_-
- ASSERT_TRUE(ref.hasDocument());
- auto& doc2 = ref.getDocument();
- EXPECT_EQUAL(doc2.getType().getName(), "testdoc");
- EXPECT_EQUAL(doc2.getId().toString(), "id:ns:testdoc::");
- EXPECT_EQUAL(doc2.getLastModified(), 1234567LL); // FIXME signed vs. unsigned... -_-
- }
+ ASSERT_TRUE(obj);
+ auto& ref = dynamic_cast<GetDocumentReply&>(*obj);
+ EXPECT_EQ(ref.getLastModified(), 1234567ULL); // FIXME signed vs. unsigned... -_-
+ ASSERT_TRUE(ref.hasDocument());
+ auto& doc2 = ref.getDocument();
+ EXPECT_EQ(doc2.getType().getName(), "testdoc");
+ EXPECT_EQ(doc2.getId().toString(), "id:ns:testdoc::");
+ EXPECT_EQ(doc2.getLastModified(), 1234567LL); // FIXME signed vs. unsigned... -_-
}
}
-void Messages80Test::do_test_empty_get_reply() {
+TEST_F(Messages80Test, empty_get_reply) {
GetDocumentReply tmp;
serialize("GetDocumentReply-empty", tmp);
for (auto lang : languages()) {
auto obj = deserialize("GetDocumentReply-empty", DocumentProtocol::REPLY_GETDOCUMENT, lang);
- if (EXPECT_TRUE(obj)) {
- auto& ref = dynamic_cast<GetDocumentReply&>(*obj);
- EXPECT_EQUAL(ref.getLastModified(), 0ULL);
- EXPECT_FALSE(ref.hasDocument());
- }
+ ASSERT_TRUE(obj);
+ auto& ref = dynamic_cast<GetDocumentReply&>(*obj);
+ EXPECT_EQ(ref.getLastModified(), 0ULL);
+ EXPECT_FALSE(ref.hasDocument());
}
}
-bool Messages80Test::test_get_document_reply() {
- TEST_DO(do_test_get_reply_with_doc());
- TEST_DO(do_test_empty_get_reply());
- return true;
-}
-
-bool Messages80Test::test_put_document_message() {
- auto doc = createDoc(getTypeRepo(), "testdoc", "id:ns:testdoc::");
+TEST_F(Messages80Test, put_document_message) {
+ auto doc = createDoc(type_repo(), "testdoc", "id:ns:testdoc::");
PutDocumentMessage msg(doc);
msg.setTimestamp(666);
msg.setCondition(TestAndSetCondition("There's just one condition"));
- // FIXME these don't belong here!
- EXPECT_EQUAL(64u, sizeof(vespalib::string));
- EXPECT_EQUAL(sizeof(vespalib::string), sizeof(TestAndSetCondition));
- EXPECT_EQUAL(112u, sizeof(DocumentMessage));
- EXPECT_EQUAL(sizeof(TestAndSetCondition) + sizeof(DocumentMessage), sizeof(TestAndSetMessage));
- EXPECT_EQUAL(sizeof(TestAndSetMessage) + 32, sizeof(PutDocumentMessage));
-
serialize("PutDocumentMessage", msg);
for (auto lang : languages()) {
auto routableUp = deserialize("PutDocumentMessage", DocumentProtocol::MESSAGE_PUTDOCUMENT, lang);
- if (EXPECT_TRUE(routableUp)) {
- auto& deserializedMsg = dynamic_cast<PutDocumentMessage &>(*routableUp);
-
- EXPECT_EQUAL(deserializedMsg.getDocument().getType().getName(), msg.getDocument().getType().getName());
- EXPECT_EQUAL(deserializedMsg.getDocument().getId().toString(), msg.getDocument().getId().toString());
- EXPECT_EQUAL(deserializedMsg.getTimestamp(), msg.getTimestamp());
- EXPECT_GREATER(deserializedMsg.getApproxSize(), 0u);
- EXPECT_EQUAL(deserializedMsg.getCondition().getSelection(), msg.getCondition().getSelection());
- EXPECT_FALSE(deserializedMsg.get_create_if_non_existent());
- }
+ ASSERT_TRUE(routableUp);
+ auto& deserializedMsg = dynamic_cast<PutDocumentMessage &>(*routableUp);
+ EXPECT_EQ(deserializedMsg.getDocument().getType().getName(), msg.getDocument().getType().getName());
+ EXPECT_EQ(deserializedMsg.getDocument().getId().toString(), msg.getDocument().getId().toString());
+ EXPECT_EQ(deserializedMsg.getTimestamp(), msg.getTimestamp());
+ EXPECT_GT(deserializedMsg.getApproxSize(), 0u);
+ EXPECT_EQ(deserializedMsg.getCondition().getSelection(), msg.getCondition().getSelection());
+ EXPECT_FALSE(deserializedMsg.get_create_if_non_existent());
}
//-------------------------------------------------------------------------
- PutDocumentMessage msg2(createDoc(getTypeRepo(), "testdoc", "id:ns:testdoc::"));
+ PutDocumentMessage msg2(createDoc(type_repo(), "testdoc", "id:ns:testdoc::"));
msg2.set_create_if_non_existent(true);
serialize("PutDocumentMessage-create", msg2);
for (auto lang : languages()) {
auto obj = deserialize("PutDocumentMessage-create", DocumentProtocol::MESSAGE_PUTDOCUMENT, lang);
- if (EXPECT_TRUE(obj)) {
- auto& decoded = dynamic_cast<PutDocumentMessage&>(*obj);
- EXPECT_TRUE(decoded.get_create_if_non_existent());
- }
+ ASSERT_TRUE(obj);
+ auto& decoded = dynamic_cast<PutDocumentMessage&>(*obj);
+ EXPECT_TRUE(decoded.get_create_if_non_existent());
}
- return true;
}
-bool Messages80Test::test_put_document_reply() {
+TEST_F(Messages80Test, put_document_reply) {
WriteDocumentReply reply(DocumentProtocol::REPLY_PUTDOCUMENT);
reply.setHighestModificationTimestamp(30);
serialize("PutDocumentReply", reply);
- EXPECT_EQUAL(sizeof(WriteDocumentReply), 112u); // FIXME doesn't belong here!
for (auto lang : languages()) {
auto obj = deserialize("PutDocumentReply", DocumentProtocol::REPLY_PUTDOCUMENT, lang);
- if (EXPECT_TRUE(obj)) {
- auto& ref = dynamic_cast<WriteDocumentReply&>(*obj);
- EXPECT_EQUAL(ref.getHighestModificationTimestamp(), 30u);
- }
+ ASSERT_TRUE(obj);
+ auto& ref = dynamic_cast<WriteDocumentReply&>(*obj);
+ EXPECT_EQ(ref.getHighestModificationTimestamp(), 30u);
}
- return true;
}
-bool Messages80Test::test_update_document_message() {
- const DocumentTypeRepo& repo = getTypeRepo();
+TEST_F(Messages80Test, update_document_message) {
+ const DocumentTypeRepo& repo = type_repo();
const document::DocumentType& docType = *repo.getDocumentType("testdoc");
auto doc_update = std::make_shared<document::DocumentUpdate>(repo, docType, document::DocumentId("id:ns:testdoc::"));
@@ -257,99 +166,84 @@ bool Messages80Test::test_update_document_message() {
msg.setNewTimestamp(777u);
msg.setCondition(TestAndSetCondition("There's just one condition"));
- EXPECT_EQUAL(sizeof(TestAndSetMessage) + 32, sizeof(UpdateDocumentMessage)); // FIXME doesn't belong here!
serialize("UpdateDocumentMessage", msg);
for (auto lang : languages()) {
auto obj = deserialize("UpdateDocumentMessage", DocumentProtocol::MESSAGE_UPDATEDOCUMENT, lang);
- if (EXPECT_TRUE(obj)) {
- auto& decoded = dynamic_cast<UpdateDocumentMessage&>(*obj);
- EXPECT_EQUAL(decoded.getDocumentUpdate(), msg.getDocumentUpdate());
- EXPECT_EQUAL(decoded.getOldTimestamp(), msg.getOldTimestamp());
- EXPECT_EQUAL(decoded.getNewTimestamp(), msg.getNewTimestamp());
- EXPECT_GREATER(decoded.getApproxSize(), 0u); // Actual value depends on protobuf size
- EXPECT_EQUAL(decoded.getCondition().getSelection(), msg.getCondition().getSelection());
- }
+ ASSERT_TRUE(obj);
+ auto& decoded = dynamic_cast<UpdateDocumentMessage&>(*obj);
+ EXPECT_EQ(decoded.getDocumentUpdate(), msg.getDocumentUpdate());
+ EXPECT_EQ(decoded.getOldTimestamp(), msg.getOldTimestamp());
+ EXPECT_EQ(decoded.getNewTimestamp(), msg.getNewTimestamp());
+ EXPECT_GT(decoded.getApproxSize(), 0u); // Actual value depends on protobuf size
+ EXPECT_EQ(decoded.getCondition().getSelection(), msg.getCondition().getSelection());
}
- return true;
}
-bool Messages80Test::test_update_document_reply() {
+TEST_F(Messages80Test, update_document_reply) {
UpdateDocumentReply reply;
reply.setWasFound(true);
reply.setHighestModificationTimestamp(30);
serialize("UpdateDocumentReply", reply);
- EXPECT_EQUAL(120u, sizeof(UpdateDocumentReply)); // FIXME doesn't belong here!
for (auto lang : languages()) {
auto obj = deserialize("UpdateDocumentReply", DocumentProtocol::REPLY_UPDATEDOCUMENT, lang);
- if (EXPECT_TRUE(obj)) {
- auto& ref = dynamic_cast<UpdateDocumentReply&>(*obj);
- EXPECT_EQUAL(ref.getHighestModificationTimestamp(), 30u);
- EXPECT_TRUE(ref.wasFound());
- }
+ ASSERT_TRUE(obj);
+ auto& ref = dynamic_cast<UpdateDocumentReply&>(*obj);
+ EXPECT_EQ(ref.getHighestModificationTimestamp(), 30u);
+ EXPECT_TRUE(ref.wasFound());
}
- return true;
}
-bool Messages80Test::test_remove_document_message() {
+TEST_F(Messages80Test, remove_document_message) {
RemoveDocumentMessage msg(document::DocumentId("id:ns:testdoc::"));
msg.setCondition(TestAndSetCondition("There's just one condition"));
- EXPECT_EQUAL(sizeof(TestAndSetMessage) + 104, sizeof(RemoveDocumentMessage)); // FIXME doesn't belong here!
serialize("RemoveDocumentMessage", msg);
for (auto lang : languages()) {
auto obj = deserialize("RemoveDocumentMessage", DocumentProtocol::MESSAGE_REMOVEDOCUMENT, lang);
- if (EXPECT_TRUE(obj)) {
- auto& ref = dynamic_cast<RemoveDocumentMessage &>(*obj);
- EXPECT_EQUAL(ref.getDocumentId().toString(), "id:ns:testdoc::");
- EXPECT_EQUAL(ref.getCondition().getSelection(), msg.getCondition().getSelection());
- }
+ ASSERT_TRUE(obj);
+ auto& ref = dynamic_cast<RemoveDocumentMessage &>(*obj);
+ EXPECT_EQ(ref.getDocumentId().toString(), "id:ns:testdoc::");
+ EXPECT_EQ(ref.getCondition().getSelection(), msg.getCondition().getSelection());
}
- return true;
}
-bool Messages80Test::test_remove_document_reply() {
+TEST_F(Messages80Test, remove_document_reply) {
RemoveDocumentReply reply;
- std::vector<uint64_t> ts;
reply.setWasFound(true);
reply.setHighestModificationTimestamp(30);
- EXPECT_EQUAL(120u, sizeof(RemoveDocumentReply)); // FIXME doesn't belong here!
serialize("RemoveDocumentReply", reply);
for (auto lang : languages()) {
auto obj = deserialize("RemoveDocumentReply", DocumentProtocol::REPLY_REMOVEDOCUMENT, lang);
- if (EXPECT_TRUE(obj)) {
- auto& ref = dynamic_cast<RemoveDocumentReply&>(*obj);
- EXPECT_EQUAL(ref.getHighestModificationTimestamp(), 30u);
- EXPECT_TRUE(ref.wasFound());
- }
+ ASSERT_TRUE(obj);
+ auto& ref = dynamic_cast<RemoveDocumentReply&>(*obj);
+ EXPECT_EQ(ref.getHighestModificationTimestamp(), 30u);
+ EXPECT_TRUE(ref.wasFound());
}
- return true;
}
-bool Messages80Test::test_remove_location_message() {
+TEST_F(Messages80Test, remove_location_message) {
document::BucketIdFactory factory;
- document::select::Parser parser(getTypeRepo(), factory);
+ document::select::Parser parser(type_repo(), factory);
RemoveLocationMessage msg(factory, parser, "id.group == \"mygroup\"");
msg.setBucketSpace("bjarne");
serialize("RemoveLocationMessage", msg);
for (auto lang : languages()) {
auto obj = deserialize("RemoveLocationMessage", DocumentProtocol::MESSAGE_REMOVELOCATION, lang);
- if (EXPECT_TRUE(obj)) {
- auto& ref = dynamic_cast<RemoveLocationMessage&>(*obj);
- EXPECT_EQUAL(ref.getDocumentSelection(), "id.group == \"mygroup\"");
- EXPECT_EQUAL(ref.getBucketSpace(), "bjarne");
- }
+ ASSERT_TRUE(obj);
+ auto& ref = dynamic_cast<RemoveLocationMessage&>(*obj);
+ EXPECT_EQ(ref.getDocumentSelection(), "id.group == \"mygroup\"");
+ EXPECT_EQ(ref.getBucketSpace(), "bjarne");
}
- return true;
}
-bool Messages80Test::test_remove_location_reply() {
+TEST_F(Messages80Test, remove_location_reply) {
DocumentReply tmp(DocumentProtocol::REPLY_REMOVELOCATION);
serialize("RemoveLocationReply", tmp);
@@ -357,10 +251,9 @@ bool Messages80Test::test_remove_location_reply() {
auto obj = deserialize("RemoveLocationReply", DocumentProtocol::REPLY_REMOVELOCATION, lang);
EXPECT_TRUE(obj);
}
- return true;
}
-bool Messages80Test::test_create_visitor_message() {
+TEST_F(Messages80Test, create_visitor_message) {
CreateVisitorMessage tmp("SomeLibrary", "myvisitor", "newyork", "london");
tmp.setDocumentSelection("true and false or true");
tmp.getParameters().set("myvar", "somevalue");
@@ -377,30 +270,28 @@ bool Messages80Test::test_create_visitor_message() {
for (auto lang : languages()) {
auto obj = deserialize("CreateVisitorMessage", DocumentProtocol::MESSAGE_CREATEVISITOR, lang);
- if (EXPECT_TRUE(obj)) {
- auto& ref = dynamic_cast<CreateVisitorMessage&>(*obj);
-
- EXPECT_EQUAL(ref.getLibraryName(), "SomeLibrary");
- EXPECT_EQUAL(ref.getInstanceId(), "myvisitor");
- EXPECT_EQUAL(ref.getControlDestination(), "newyork");
- EXPECT_EQUAL(ref.getDataDestination(), "london");
- EXPECT_EQUAL(ref.getDocumentSelection(), "true and false or true");
- EXPECT_EQUAL(ref.getFieldSet(), "foo bar");
- EXPECT_EQUAL(ref.getMaximumPendingReplyCount(), uint32_t(12));
- EXPECT_TRUE(ref.visitRemoves());
- EXPECT_TRUE(ref.visitInconsistentBuckets());
- ASSERT_EQUAL(ref.getBuckets().size(), size_t(1));
- EXPECT_EQUAL(ref.getBuckets()[0], document::BucketId(16, 1234));
- EXPECT_EQUAL(ref.getParameters().get("myvar"), "somevalue");
- EXPECT_EQUAL(ref.getParameters().get("anothervar", uint64_t(1)), uint64_t(34));
- EXPECT_EQUAL(ref.getMaxBucketsPerVisitor(), uint32_t(2));
- EXPECT_EQUAL(ref.getBucketSpace(), "bjarne");
- }
- }
- return true;
-}
-
-bool Messages80Test::test_create_visitor_reply() {
+ ASSERT_TRUE(obj);
+ auto& ref = dynamic_cast<CreateVisitorMessage&>(*obj);
+
+ EXPECT_EQ(ref.getLibraryName(), "SomeLibrary");
+ EXPECT_EQ(ref.getInstanceId(), "myvisitor");
+ EXPECT_EQ(ref.getControlDestination(), "newyork");
+ EXPECT_EQ(ref.getDataDestination(), "london");
+ EXPECT_EQ(ref.getDocumentSelection(), "true and false or true");
+ EXPECT_EQ(ref.getFieldSet(), "foo bar");
+ EXPECT_EQ(ref.getMaximumPendingReplyCount(), uint32_t(12));
+ EXPECT_TRUE(ref.visitRemoves());
+ EXPECT_TRUE(ref.visitInconsistentBuckets());
+ ASSERT_EQ(ref.getBuckets().size(), size_t(1));
+ EXPECT_EQ(ref.getBuckets()[0], document::BucketId(16, 1234));
+ EXPECT_EQ(ref.getParameters().get("myvar"), "somevalue");
+ EXPECT_EQ(ref.getParameters().get("anothervar", uint64_t(1)), uint64_t(34));
+ EXPECT_EQ(ref.getMaxBucketsPerVisitor(), uint32_t(2));
+ EXPECT_EQ(ref.getBucketSpace(), "bjarne");
+ }
+}
+
+TEST_F(Messages80Test, create_visitor_reply) {
CreateVisitorReply reply(DocumentProtocol::REPLY_CREATEVISITOR);
reply.setLastBucket(document::BucketId(16, 123));
vdslib::VisitorStatistics vs;
@@ -415,38 +306,34 @@ bool Messages80Test::test_create_visitor_reply() {
for (auto lang : languages()) {
auto obj = deserialize("CreateVisitorReply", DocumentProtocol::REPLY_CREATEVISITOR, lang);
- if (EXPECT_TRUE(obj)) {
- auto& ref = dynamic_cast<CreateVisitorReply&>(*obj);
- EXPECT_EQUAL(ref.getLastBucket(), document::BucketId(16, 123));
- EXPECT_EQUAL(ref.getVisitorStatistics().getBucketsVisited(), (uint32_t)3);
- EXPECT_EQUAL(ref.getVisitorStatistics().getDocumentsVisited(), (uint64_t)1000);
- EXPECT_EQUAL(ref.getVisitorStatistics().getBytesVisited(), (uint64_t)1024000);
- EXPECT_EQUAL(ref.getVisitorStatistics().getDocumentsReturned(), (uint64_t)123);
- EXPECT_EQUAL(ref.getVisitorStatistics().getBytesReturned(), (uint64_t)512000);
- }
+ ASSERT_TRUE(obj);
+ auto& ref = dynamic_cast<CreateVisitorReply&>(*obj);
+ EXPECT_EQ(ref.getLastBucket(), document::BucketId(16, 123));
+ EXPECT_EQ(ref.getVisitorStatistics().getBucketsVisited(), (uint32_t)3);
+ EXPECT_EQ(ref.getVisitorStatistics().getDocumentsVisited(), (uint64_t)1000);
+ EXPECT_EQ(ref.getVisitorStatistics().getBytesVisited(), (uint64_t)1024000);
+ EXPECT_EQ(ref.getVisitorStatistics().getDocumentsReturned(), (uint64_t)123);
+ EXPECT_EQ(ref.getVisitorStatistics().getBytesReturned(), (uint64_t)512000);
}
- return true;
}
-bool Messages80Test::test_destroy_visitor_message() {
+TEST_F(Messages80Test, destroy_visitor_message) {
DestroyVisitorMessage tmp("myvisitor");
serialize("DestroyVisitorMessage", tmp);
for (auto lang : languages()) {
auto obj = deserialize("DestroyVisitorMessage", DocumentProtocol::MESSAGE_DESTROYVISITOR, lang);
- if (EXPECT_TRUE(obj)) {
- auto& ref = dynamic_cast<DestroyVisitorMessage&>(*obj);
- EXPECT_EQUAL(ref.getInstanceId(), "myvisitor");
- }
+ ASSERT_TRUE(obj);
+ auto& ref = dynamic_cast<DestroyVisitorMessage&>(*obj);
+ EXPECT_EQ(ref.getInstanceId(), "myvisitor");
}
- return true;
}
-bool Messages80Test::test_destroy_visitor_reply() {
- return try_visitor_reply("DestroyVisitorReply", DocumentProtocol::REPLY_DESTROYVISITOR);
+TEST_F(Messages80Test, destroy_visitor_reply) {
+ ASSERT_NO_FATAL_FAILURE(try_visitor_reply("DestroyVisitorReply", DocumentProtocol::REPLY_DESTROYVISITOR));
}
-bool Messages80Test::test_map_visitor_message() {
+TEST_F(Messages80Test, map_visitor_message) {
MapVisitorMessage tmp;
tmp.getData().set("foo", 3);
tmp.getData().set("bar", 5);
@@ -455,41 +342,37 @@ bool Messages80Test::test_map_visitor_message() {
for (auto lang : languages()) {
auto obj = deserialize("MapVisitorMessage", DocumentProtocol::MESSAGE_MAPVISITOR, lang);
- if (EXPECT_TRUE(obj)) {
- auto& ref = dynamic_cast<MapVisitorMessage&>(*obj);
- EXPECT_EQUAL(ref.getData().size(), 2u);
- EXPECT_EQUAL(ref.getData().get("foo", 0), 3);
- EXPECT_EQUAL(ref.getData().get("bar", 0), 5);
- }
+ ASSERT_TRUE(obj);
+ auto& ref = dynamic_cast<MapVisitorMessage&>(*obj);
+ EXPECT_EQ(ref.getData().size(), 2u);
+ EXPECT_EQ(ref.getData().get("foo", 0), 3);
+ EXPECT_EQ(ref.getData().get("bar", 0), 5);
}
- return true;
}
-bool Messages80Test::test_map_visitor_reply() {
- return try_visitor_reply("MapVisitorReply", DocumentProtocol::REPLY_MAPVISITOR);
+TEST_F(Messages80Test, map_visitor_reply) {
+ ASSERT_NO_FATAL_FAILURE(try_visitor_reply("MapVisitorReply", DocumentProtocol::REPLY_MAPVISITOR));
}
-bool Messages80Test::test_query_result_message() {
+TEST_F(Messages80Test, query_result_message) {
QueryResultMessage srm;
vdslib::SearchResult& sr(srm.getSearchResult());
- EXPECT_EQUAL(srm.getSequenceId(), 0u);
- EXPECT_EQUAL(sr.getHitCount(), 0u);
- EXPECT_EQUAL(sr.getAggregatorList().getSerializedSize(), 4u);
- EXPECT_EQUAL(sr.getSerializedSize(), 20u);
- EXPECT_EQUAL(srm.getApproxSize(), 28u);
+ EXPECT_EQ(srm.getSequenceId(), 0u);
+ EXPECT_EQ(sr.getHitCount(), 0u);
+ EXPECT_EQ(sr.getAggregatorList().getSerializedSize(), 4u);
+ EXPECT_EQ(sr.getSerializedSize(), 20u);
+ EXPECT_EQ(srm.getApproxSize(), 28u);
serialize("QueryResultMessage-1", srm);
// Serialization is only implemented in C++
{
auto routable = deserialize("QueryResultMessage-1", DocumentProtocol::MESSAGE_QUERYRESULT, LANG_CPP);
- if (!EXPECT_TRUE(routable)) {
- return false;
- }
+ ASSERT_TRUE(routable);
auto& dm = dynamic_cast<QueryResultMessage&>(*routable);
vdslib::SearchResult& dr = dm.getSearchResult();
- EXPECT_EQUAL(dm.getSequenceId(), size_t(0));
- EXPECT_EQUAL(dr.getHitCount(), size_t(0));
+ EXPECT_EQ(dm.getSequenceId(), size_t(0));
+ EXPECT_EQ(dr.getHitCount(), size_t(0));
}
sr.addHit(0, "doc1", 89);
@@ -501,18 +384,16 @@ bool Messages80Test::test_query_result_message() {
{
auto routable = deserialize("QueryResultMessage-2", DocumentProtocol::MESSAGE_QUERYRESULT, LANG_CPP);
- if (!EXPECT_TRUE(routable)) {
- return false;
- }
+ ASSERT_TRUE(routable);
auto& dm = dynamic_cast<QueryResultMessage&>(*routable);
auto& dr = dm.getSearchResult();
- EXPECT_EQUAL(dr.getHitCount(), size_t(2));
+ EXPECT_EQ(dr.getHitCount(), size_t(2));
dr.getHit(0, doc_id, rank);
- EXPECT_EQUAL(rank, vdslib::SearchResult::RankType(89));
- EXPECT_EQUAL(strcmp("doc1", doc_id), 0);
+ EXPECT_EQ(rank, vdslib::SearchResult::RankType(89));
+ EXPECT_EQ(strcmp("doc1", doc_id), 0);
dr.getHit(1, doc_id, rank);
- EXPECT_EQUAL(rank, vdslib::SearchResult::RankType(109));
- EXPECT_EQUAL(strcmp("doc17", doc_id), 0);
+ EXPECT_EQ(rank, vdslib::SearchResult::RankType(109));
+ EXPECT_EQ(strcmp("doc17", doc_id), 0);
}
sr.sort();
@@ -520,18 +401,16 @@ bool Messages80Test::test_query_result_message() {
{
auto routable = deserialize("QueryResultMessage-3", DocumentProtocol::MESSAGE_QUERYRESULT, LANG_CPP);
- if (!EXPECT_TRUE(routable)) {
- return false;
- }
+ ASSERT_TRUE(routable);
auto& dm = dynamic_cast<QueryResultMessage&>(*routable);
auto& dr = dm.getSearchResult();
- EXPECT_EQUAL(dr.getHitCount(), size_t(2));
+ EXPECT_EQ(dr.getHitCount(), size_t(2));
dr.getHit(0, doc_id, rank);
- EXPECT_EQUAL(rank, vdslib::SearchResult::RankType(109));
- EXPECT_EQUAL(strcmp("doc17", doc_id), 0);
+ EXPECT_EQ(rank, vdslib::SearchResult::RankType(109));
+ EXPECT_EQ(strcmp("doc17", doc_id), 0);
dr.getHit(1, doc_id, rank);
- EXPECT_EQUAL(rank, vdslib::SearchResult::RankType(89));
- EXPECT_EQUAL(strcmp("doc1", doc_id), 0);
+ EXPECT_EQ(rank, vdslib::SearchResult::RankType(89));
+ EXPECT_EQ(strcmp("doc1", doc_id), 0);
}
QueryResultMessage srm2;
@@ -543,21 +422,19 @@ bool Messages80Test::test_query_result_message() {
{
auto routable = deserialize("QueryResultMessage-4", DocumentProtocol::MESSAGE_QUERYRESULT, LANG_CPP);
- if (!EXPECT_TRUE(routable)) {
- return false;
- }
+ ASSERT_TRUE(routable);
auto& dm = dynamic_cast<QueryResultMessage&>(*routable);
auto& dr = dm.getSearchResult();
- EXPECT_EQUAL(dr.getHitCount(), size_t(3));
+ EXPECT_EQ(dr.getHitCount(), size_t(3));
dr.getHit(0, doc_id, rank);
- EXPECT_EQUAL(rank, vdslib::SearchResult::RankType(89));
- EXPECT_EQUAL(strcmp("doc1", doc_id), 0);
+ EXPECT_EQ(rank, vdslib::SearchResult::RankType(89));
+ EXPECT_EQ(strcmp("doc1", doc_id), 0);
dr.getHit(1, doc_id, rank);
- EXPECT_EQUAL(rank, vdslib::SearchResult::RankType(109));
- EXPECT_EQUAL(strcmp("doc17", doc_id), 0);
+ EXPECT_EQ(rank, vdslib::SearchResult::RankType(109));
+ EXPECT_EQ(strcmp("doc17", doc_id), 0);
dr.getHit(2, doc_id, rank);
- EXPECT_EQUAL(rank, vdslib::SearchResult::RankType(90));
- EXPECT_EQUAL(strcmp("doc18", doc_id), 0);
+ EXPECT_EQ(rank, vdslib::SearchResult::RankType(90));
+ EXPECT_EQ(strcmp("doc18", doc_id), 0);
}
sr2.sort();
@@ -565,50 +442,48 @@ bool Messages80Test::test_query_result_message() {
size_t sz;
sr2.getHit(0, doc_id, rank);
sr2.getSortBlob(0, buf, sz);
- EXPECT_EQUAL(sz, 9u);
- EXPECT_EQUAL(memcmp("sortdata1", buf, sz), 0);
- EXPECT_EQUAL(rank, vdslib::SearchResult::RankType(109));
- EXPECT_EQUAL(strcmp("doc17", doc_id), 0);
+ EXPECT_EQ(sz, 9u);
+ EXPECT_EQ(memcmp("sortdata1", buf, sz), 0);
+ EXPECT_EQ(rank, vdslib::SearchResult::RankType(109));
+ EXPECT_EQ(strcmp("doc17", doc_id), 0);
sr2.getHit(1, doc_id, rank);
sr2.getSortBlob(1, buf, sz);
- EXPECT_EQUAL(sz, 9u);
- EXPECT_EQUAL(memcmp("sortdata2", buf, sz), 0);
- EXPECT_EQUAL(rank, vdslib::SearchResult::RankType(89));
- EXPECT_EQUAL(strcmp("doc1", doc_id), 0);
+ EXPECT_EQ(sz, 9u);
+ EXPECT_EQ(memcmp("sortdata2", buf, sz), 0);
+ EXPECT_EQ(rank, vdslib::SearchResult::RankType(89));
+ EXPECT_EQ(strcmp("doc1", doc_id), 0);
sr2.getHit(2, doc_id, rank);
sr2.getSortBlob(2, buf, sz);
- EXPECT_EQUAL(sz, 9u);
- EXPECT_EQUAL(memcmp("sortdata3", buf, sz), 0);
- EXPECT_EQUAL(rank, vdslib::SearchResult::RankType(90));
- EXPECT_EQUAL(strcmp("doc18", doc_id), 0);
+ EXPECT_EQ(sz, 9u);
+ EXPECT_EQ(memcmp("sortdata3", buf, sz), 0);
+ EXPECT_EQ(rank, vdslib::SearchResult::RankType(90));
+ EXPECT_EQ(strcmp("doc18", doc_id), 0);
serialize("QueryResultMessage-5", srm2);
{
auto routable = deserialize("QueryResultMessage-5", DocumentProtocol::MESSAGE_QUERYRESULT, LANG_CPP);
- if (!EXPECT_TRUE(routable)) {
- return false;
- }
+ ASSERT_TRUE(routable);
auto& dm = dynamic_cast<QueryResultMessage&>(*routable);
auto& dr = dm.getSearchResult();
- EXPECT_EQUAL(dr.getHitCount(), size_t(3));
+ EXPECT_EQ(dr.getHitCount(), size_t(3));
dr.getHit(0, doc_id, rank);
dr.getSortBlob(0, buf, sz);
- EXPECT_EQUAL(sz, 9u);
- EXPECT_EQUAL(memcmp("sortdata1", buf, sz), 0);
- EXPECT_EQUAL(rank, vdslib::SearchResult::RankType(109));
- EXPECT_EQUAL(strcmp("doc17", doc_id), 0);
+ EXPECT_EQ(sz, 9u);
+ EXPECT_EQ(memcmp("sortdata1", buf, sz), 0);
+ EXPECT_EQ(rank, vdslib::SearchResult::RankType(109));
+ EXPECT_EQ(strcmp("doc17", doc_id), 0);
dr.getHit(1, doc_id, rank);
dr.getSortBlob(1, buf, sz);
- EXPECT_EQUAL(sz, 9u);
- EXPECT_EQUAL(memcmp("sortdata2", buf, sz), 0);
- EXPECT_EQUAL(rank, vdslib::SearchResult::RankType(89));
- EXPECT_EQUAL(strcmp("doc1", doc_id), 0);
+ EXPECT_EQ(sz, 9u);
+ EXPECT_EQ(memcmp("sortdata2", buf, sz), 0);
+ EXPECT_EQ(rank, vdslib::SearchResult::RankType(89));
+ EXPECT_EQ(strcmp("doc1", doc_id), 0);
dr.getHit(2, doc_id, rank);
dr.getSortBlob(2, buf, sz);
- EXPECT_EQUAL(sz, 9u);
- EXPECT_EQUAL(memcmp("sortdata3", buf, sz), 0);
- EXPECT_EQUAL(rank, vdslib::SearchResult::RankType(90));
- EXPECT_EQUAL(strcmp("doc18", doc_id), 0);
+ EXPECT_EQ(sz, 9u);
+ EXPECT_EQ(memcmp("sortdata3", buf, sz), 0);
+ EXPECT_EQ(rank, vdslib::SearchResult::RankType(90));
+ EXPECT_EQ(strcmp("doc18", doc_id), 0);
}
QueryResultMessage qrm3;
@@ -629,39 +504,36 @@ bool Messages80Test::test_query_result_message() {
serialize("QueryResultMessage-6", qrm3);
{
auto routable = deserialize("QueryResultMessage-6", DocumentProtocol::MESSAGE_QUERYRESULT, LANG_CPP);
- if (!EXPECT_TRUE(routable)) {
- return false;
- }
+ ASSERT_TRUE(routable);
auto& dm = dynamic_cast<QueryResultMessage&>(*routable);
auto& dr = dm.getSearchResult();
- EXPECT_EQUAL(dr.getHitCount(), size_t(2));
+ EXPECT_EQ(dr.getHitCount(), size_t(2));
dr.getHit(0, doc_id, rank);
- EXPECT_EQUAL(vdslib::SearchResult::RankType(7), rank);
- EXPECT_EQUAL(strcmp("doc2", doc_id), 0);
+ EXPECT_EQ(vdslib::SearchResult::RankType(7), rank);
+ EXPECT_EQ(strcmp("doc2", doc_id), 0);
dr.getHit(1, doc_id, rank);
- EXPECT_EQUAL(vdslib::SearchResult::RankType(5), rank);
- EXPECT_EQUAL(strcmp("doc1", doc_id), 0);
+ EXPECT_EQ(vdslib::SearchResult::RankType(5), rank);
+ EXPECT_EQ(strcmp("doc1", doc_id), 0);
auto mfv = dr.get_match_feature_values(0);
- EXPECT_EQUAL(mfv.size(), 2u);
- EXPECT_EQUAL(mfv[0].as_double(), 12.0);
- EXPECT_EQUAL(mfv[1].as_data().make_string(), "There");
+ EXPECT_EQ(mfv.size(), 2u);
+ EXPECT_EQ(mfv[0].as_double(), 12.0);
+ EXPECT_EQ(mfv[1].as_data().make_string(), "There");
mfv = dr.get_match_feature_values(1);
- EXPECT_EQUAL(mfv.size(), 2u);
- EXPECT_EQUAL(mfv[0].as_double(), 1.0);
- EXPECT_EQUAL(mfv[1].as_data().make_string(), "Hi");
+ EXPECT_EQ(mfv.size(), 2u);
+ EXPECT_EQ(mfv[0].as_double(), 1.0);
+ EXPECT_EQ(mfv[1].as_data().make_string(), "Hi");
const auto& mf_names = dr.get_match_features().names;
- EXPECT_EQUAL(mf_names.size(), 2u);
- EXPECT_EQUAL(mf_names[0], "foo");
- EXPECT_EQUAL(mf_names[1], "bar");
+ EXPECT_EQ(mf_names.size(), 2u);
+ EXPECT_EQ(mf_names[0], "foo");
+ EXPECT_EQ(mf_names[1], "bar");
}
- return true;
}
-bool Messages80Test::test_query_result_reply() {
- return try_visitor_reply("QueryResultReply", DocumentProtocol::REPLY_QUERYRESULT);
+TEST_F(Messages80Test, query_result_reply) {
+ ASSERT_NO_FATAL_FAILURE(try_visitor_reply("QueryResultReply", DocumentProtocol::REPLY_QUERYRESULT));
}
-bool Messages80Test::test_visitor_info_message() {
+TEST_F(Messages80Test, test_visitor_info_message) {
VisitorInfoMessage tmp;
tmp.getFinishedBuckets().emplace_back(16, 1);
tmp.getFinishedBuckets().emplace_back(16, 2);
@@ -673,24 +545,22 @@ bool Messages80Test::test_visitor_info_message() {
for (auto lang : languages()) {
auto obj = deserialize("VisitorInfoMessage", DocumentProtocol::MESSAGE_VISITORINFO, lang);
- if (EXPECT_TRUE(obj)) {
- auto& ref = dynamic_cast<VisitorInfoMessage&>(*obj);
- ASSERT_EQUAL(ref.getFinishedBuckets().size(), 3u);
- EXPECT_EQUAL(ref.getFinishedBuckets()[0], document::BucketId(16, 1));
- EXPECT_EQUAL(ref.getFinishedBuckets()[1], document::BucketId(16, 2));
- EXPECT_EQUAL(ref.getFinishedBuckets()[2], document::BucketId(16, 4));
- EXPECT_EQUAL(ref.getErrorMessage(), utf8);
- }
+ ASSERT_TRUE(obj);
+ auto& ref = dynamic_cast<VisitorInfoMessage&>(*obj);
+ ASSERT_EQ(ref.getFinishedBuckets().size(), 3u);
+ EXPECT_EQ(ref.getFinishedBuckets()[0], document::BucketId(16, 1));
+ EXPECT_EQ(ref.getFinishedBuckets()[1], document::BucketId(16, 2));
+ EXPECT_EQ(ref.getFinishedBuckets()[2], document::BucketId(16, 4));
+ EXPECT_EQ(ref.getErrorMessage(), utf8);
}
- return true;
}
-bool Messages80Test::test_visitor_info_reply() {
- return try_visitor_reply("VisitorInfoReply", DocumentProtocol::REPLY_VISITORINFO);
+TEST_F(Messages80Test, visitor_info_reply) {
+ ASSERT_NO_FATAL_FAILURE(try_visitor_reply("VisitorInfoReply", DocumentProtocol::REPLY_VISITORINFO));
}
-bool Messages80Test::test_document_list_message() {
- auto doc = createDoc(getTypeRepo(), "testdoc", "id:scheme:testdoc:n=1234:1");
+TEST_F(Messages80Test, document_list_message) {
+ auto doc = createDoc(type_repo(), "testdoc", "id:scheme:testdoc:n=1234:1");
DocumentListMessage::Entry entry(1234, std::move(doc), true);
DocumentListMessage tmp(document::BucketId(17, 1234));
tmp.getDocuments().push_back(std::move(entry));
@@ -699,22 +569,20 @@ bool Messages80Test::test_document_list_message() {
for (auto lang : languages()) {
auto obj = deserialize("DocumentListMessage", DocumentProtocol::MESSAGE_DOCUMENTLIST, lang);
- if (EXPECT_TRUE(obj)) {
- auto& ref = dynamic_cast<DocumentListMessage&>(*obj);
- ASSERT_EQUAL(ref.getDocuments().size(), 1u);
- EXPECT_EQUAL(ref.getDocuments()[0].getDocument()->getId().toString(), "id:scheme:testdoc:n=1234:1");
- EXPECT_EQUAL(ref.getDocuments()[0].getTimestamp(), 1234);
- EXPECT_TRUE(ref.getDocuments()[0].isRemoveEntry());
- }
+ ASSERT_TRUE(obj);
+ auto& ref = dynamic_cast<DocumentListMessage&>(*obj);
+ ASSERT_EQ(ref.getDocuments().size(), 1u);
+ EXPECT_EQ(ref.getDocuments()[0].getDocument()->getId().toString(), "id:scheme:testdoc:n=1234:1");
+ EXPECT_EQ(ref.getDocuments()[0].getTimestamp(), 1234);
+ EXPECT_TRUE(ref.getDocuments()[0].isRemoveEntry());
}
- return true;
}
-bool Messages80Test::test_document_list_reply() {
- return try_visitor_reply("DocumentListReply", DocumentProtocol::REPLY_DOCUMENTLIST);
+TEST_F(Messages80Test, document_list_reply) {
+ ASSERT_NO_FATAL_FAILURE(try_visitor_reply("DocumentListReply", DocumentProtocol::REPLY_DOCUMENTLIST));
}
-bool Messages80Test::test_empty_buckets_message() {
+TEST_F(Messages80Test, empty_buckets_message) {
std::vector<document::BucketId> bids;
for (size_t i=0; i < 13; ++i) {
bids.emplace_back(16, i);
@@ -725,22 +593,20 @@ bool Messages80Test::test_empty_buckets_message() {
for (auto lang : languages()) {
auto obj = deserialize("EmptyBucketsMessage", DocumentProtocol::MESSAGE_EMPTYBUCKETS, lang);
- if (EXPECT_TRUE(obj)) {
- auto& ref = dynamic_cast<EmptyBucketsMessage&>(*obj);
- ASSERT_EQUAL(ref.getBucketIds().size(), 13u);
- for (size_t i = 0; i < 13; ++i) {
- EXPECT_EQUAL(ref.getBucketIds()[i], document::BucketId(16, i));
- }
+ ASSERT_TRUE(obj);
+ auto& ref = dynamic_cast<EmptyBucketsMessage&>(*obj);
+ ASSERT_EQ(ref.getBucketIds().size(), 13u);
+ for (size_t i = 0; i < 13; ++i) {
+ EXPECT_EQ(ref.getBucketIds()[i], document::BucketId(16, i));
}
}
- return true;
}
-bool Messages80Test::test_empty_buckets_reply() {
- return try_visitor_reply("EmptyBucketsReply", DocumentProtocol::REPLY_EMPTYBUCKETS);
+TEST_F(Messages80Test, empty_buckets_reply) {
+ ASSERT_NO_FATAL_FAILURE(try_visitor_reply("EmptyBucketsReply", DocumentProtocol::REPLY_EMPTYBUCKETS));
}
-bool Messages80Test::test_get_bucket_list_message() {
+TEST_F(Messages80Test, get_bucket_list_message) {
GetBucketListMessage msg(document::BucketId(16, 123));
msg.setBucketSpace("beartato");
@@ -748,16 +614,14 @@ bool Messages80Test::test_get_bucket_list_message() {
for (auto lang : languages()) {
auto obj = deserialize("GetBucketListMessage", DocumentProtocol::MESSAGE_GETBUCKETLIST, lang);
- if (EXPECT_TRUE(obj)) {
- auto& ref = dynamic_cast<GetBucketListMessage&>(*obj);
- EXPECT_EQUAL(ref.getBucketId(), document::BucketId(16, 123));
- EXPECT_EQUAL(ref.getBucketSpace(), "beartato");
- }
+ ASSERT_TRUE(obj);
+ auto& ref = dynamic_cast<GetBucketListMessage&>(*obj);
+ EXPECT_EQ(ref.getBucketId(), document::BucketId(16, 123));
+ EXPECT_EQ(ref.getBucketSpace(), "beartato");
}
- return true;
}
-bool Messages80Test::test_get_bucket_list_reply() {
+TEST_F(Messages80Test, get_bucket_list_reply) {
GetBucketListReply reply;
reply.getBuckets().emplace_back(document::BucketId(16, 123), "foo");
reply.getBuckets().emplace_back(document::BucketId(17, 1123), "bar");
@@ -767,18 +631,16 @@ bool Messages80Test::test_get_bucket_list_reply() {
for (auto lang : languages()) {
auto obj = deserialize("GetBucketListReply", DocumentProtocol::REPLY_GETBUCKETLIST, lang);
- if (EXPECT_TRUE(obj)) {
- auto& ref = dynamic_cast<GetBucketListReply&>(*obj);
- ASSERT_EQUAL(ref.getBuckets().size(), 3u);
- EXPECT_EQUAL(ref.getBuckets()[0], GetBucketListReply::BucketInfo(document::BucketId(16, 123), "foo"));
- EXPECT_EQUAL(ref.getBuckets()[1], GetBucketListReply::BucketInfo(document::BucketId(17, 1123), "bar"));
- EXPECT_EQUAL(ref.getBuckets()[2], GetBucketListReply::BucketInfo(document::BucketId(18, 11123), "zoink"));
- }
+ ASSERT_TRUE(obj);
+ auto& ref = dynamic_cast<GetBucketListReply&>(*obj);
+ ASSERT_EQ(ref.getBuckets().size(), 3u);
+ EXPECT_EQ(ref.getBuckets()[0], GetBucketListReply::BucketInfo(document::BucketId(16, 123), "foo"));
+ EXPECT_EQ(ref.getBuckets()[1], GetBucketListReply::BucketInfo(document::BucketId(17, 1123), "bar"));
+ EXPECT_EQ(ref.getBuckets()[2], GetBucketListReply::BucketInfo(document::BucketId(18, 11123), "zoink"));
}
- return true;
}
-bool Messages80Test::test_get_bucket_state_message() {
+TEST_F(Messages80Test, get_bucket_state_message) {
GetBucketStateMessage tmp;
tmp.setBucketId(document::BucketId(16, 666));
@@ -786,16 +648,14 @@ bool Messages80Test::test_get_bucket_state_message() {
for (auto lang : languages()) {
auto obj = deserialize("GetBucketStateMessage", DocumentProtocol::MESSAGE_GETBUCKETSTATE, lang);
- if (EXPECT_TRUE(obj)) {
- auto& ref = dynamic_cast<GetBucketStateMessage&>(*obj);
- EXPECT_EQUAL(ref.getBucketId().getUsedBits(), 16u);
- EXPECT_EQUAL(ref.getBucketId().getId(), 4611686018427388570ULL);
- }
+ ASSERT_TRUE(obj);
+ auto& ref = dynamic_cast<GetBucketStateMessage&>(*obj);
+ EXPECT_EQ(ref.getBucketId().getUsedBits(), 16u);
+ EXPECT_EQ(ref.getBucketId().getId(), 4611686018427388570ULL);
}
- return true;
}
-bool Messages80Test::test_get_bucket_state_reply() {
+TEST_F(Messages80Test, get_bucket_state_reply) {
auto foo = document::DocumentId("id:ns:testdoc::foo").getGlobalId();
auto bar = document::DocumentId("id:ns:testdoc::bar").getGlobalId();
auto baz = document::DocumentId("id:ns:testdoc::baz");
@@ -808,30 +668,28 @@ bool Messages80Test::test_get_bucket_state_reply() {
for (auto lang : languages()) {
auto obj = deserialize("GetBucketStateReply", DocumentProtocol::REPLY_GETBUCKETSTATE, lang);
- if (EXPECT_TRUE(obj)) {
- auto& ref = dynamic_cast<GetBucketStateReply&>(*obj);
- ASSERT_EQUAL(ref.getBucketState().size(), 3u);
- EXPECT_EQUAL(ref.getBucketState()[0].getTimestamp(), 777u);
- EXPECT_FALSE(ref.getBucketState()[0].getDocumentId());
- EXPECT_EQUAL(ref.getBucketState()[0].getGlobalId(), foo);
- EXPECT_FALSE(ref.getBucketState()[0].isRemoveEntry());
-
- EXPECT_EQUAL(ref.getBucketState()[1].getTimestamp(), 888u);
- EXPECT_FALSE(ref.getBucketState()[1].getDocumentId());
- EXPECT_EQUAL(ref.getBucketState()[1].getGlobalId(), bar);
- EXPECT_TRUE(ref.getBucketState()[1].isRemoveEntry());
-
- EXPECT_EQUAL(ref.getBucketState()[2].getTimestamp(), 999u);
- EXPECT_EQUAL(ref.getBucketState()[2].getGlobalId(), baz.getGlobalId());
- EXPECT_FALSE(ref.getBucketState()[2].isRemoveEntry());
- ASSERT_TRUE(ref.getBucketState()[2].getDocumentId());
- EXPECT_EQUAL(*ref.getBucketState()[2].getDocumentId(), baz);
- }
+ ASSERT_TRUE(obj);
+ auto& ref = dynamic_cast<GetBucketStateReply&>(*obj);
+ ASSERT_EQ(ref.getBucketState().size(), 3u);
+ EXPECT_EQ(ref.getBucketState()[0].getTimestamp(), 777u);
+ EXPECT_FALSE(ref.getBucketState()[0].getDocumentId());
+ EXPECT_EQ(ref.getBucketState()[0].getGlobalId(), foo);
+ EXPECT_FALSE(ref.getBucketState()[0].isRemoveEntry());
+
+ EXPECT_EQ(ref.getBucketState()[1].getTimestamp(), 888u);
+ EXPECT_FALSE(ref.getBucketState()[1].getDocumentId());
+ EXPECT_EQ(ref.getBucketState()[1].getGlobalId(), bar);
+ EXPECT_TRUE(ref.getBucketState()[1].isRemoveEntry());
+
+ EXPECT_EQ(ref.getBucketState()[2].getTimestamp(), 999u);
+ EXPECT_EQ(ref.getBucketState()[2].getGlobalId(), baz.getGlobalId());
+ EXPECT_FALSE(ref.getBucketState()[2].isRemoveEntry());
+ ASSERT_TRUE(ref.getBucketState()[2].getDocumentId());
+ EXPECT_EQ(*ref.getBucketState()[2].getDocumentId(), baz);
}
- return true;
}
-bool Messages80Test::test_stat_bucket_message() {
+TEST_F(Messages80Test, stat_bucket_message) {
StatBucketMessage msg(document::BucketId(16, 123), "id.user=123");
msg.setBucketSpace("andrei");
@@ -839,17 +697,15 @@ bool Messages80Test::test_stat_bucket_message() {
for (auto lang : languages()) {
auto obj = deserialize("StatBucketMessage", DocumentProtocol::MESSAGE_STATBUCKET, lang);
- if (EXPECT_TRUE(obj)) {
- auto& ref = dynamic_cast<StatBucketMessage&>(*obj);
- EXPECT_EQUAL(ref.getBucketId(), document::BucketId(16, 123));
- EXPECT_EQUAL(ref.getDocumentSelection(), "id.user=123");
- EXPECT_EQUAL(ref.getBucketSpace(), "andrei");
- }
+ ASSERT_TRUE(obj);
+ auto& ref = dynamic_cast<StatBucketMessage&>(*obj);
+ EXPECT_EQ(ref.getBucketId(), document::BucketId(16, 123));
+ EXPECT_EQ(ref.getDocumentSelection(), "id.user=123");
+ EXPECT_EQ(ref.getBucketSpace(), "andrei");
}
- return true;
}
-bool Messages80Test::test_stat_bucket_reply() {
+TEST_F(Messages80Test, stat_bucket_reply) {
StatBucketReply msg;
msg.setResults("These are the votes of the Norwegian jury");
@@ -857,52 +713,44 @@ bool Messages80Test::test_stat_bucket_reply() {
for (auto lang : languages()) {
auto obj = deserialize("StatBucketReply", DocumentProtocol::REPLY_STATBUCKET, lang);
- if (EXPECT_TRUE(obj)) {
- auto& ref = dynamic_cast<StatBucketReply&>(*obj);
- EXPECT_EQUAL(ref.getResults(), "These are the votes of the Norwegian jury");
- }
+ ASSERT_TRUE(obj);
+ auto& ref = dynamic_cast<StatBucketReply&>(*obj);
+ EXPECT_EQ(ref.getResults(), "These are the votes of the Norwegian jury");
}
- return true;
}
-bool Messages80Test::test_wrong_distribution_reply() {
+TEST_F(Messages80Test, wrong_distribution_reply) {
WrongDistributionReply tmp("distributor:3 storage:2");
serialize("WrongDistributionReply", tmp);
for (auto lang : languages()) {
auto obj = deserialize("WrongDistributionReply", DocumentProtocol::REPLY_WRONGDISTRIBUTION, lang);
- if (EXPECT_TRUE(obj)) {
- auto& ref = dynamic_cast<WrongDistributionReply&>(*obj);
- EXPECT_EQUAL(ref.getSystemState(), "distributor:3 storage:2");
- }
+ ASSERT_TRUE(obj);
+ auto& ref = dynamic_cast<WrongDistributionReply&>(*obj);
+ EXPECT_EQ(ref.getSystemState(), "distributor:3 storage:2");
}
- return true;
}
-bool Messages80Test::test_document_ignored_reply() {
+TEST_F(Messages80Test, document_ignored_reply) {
DocumentIgnoredReply tmp;
serialize("DocumentIgnoredReply", tmp);
for (auto lang : languages()) {
auto obj = deserialize("DocumentIgnoredReply", DocumentProtocol::REPLY_DOCUMENTIGNORED, lang);
EXPECT_TRUE(obj);
}
- return true;
}
-bool Messages80Test::try_visitor_reply(const string& filename, uint32_t type) {
+void Messages80Test::try_visitor_reply(const std::string& filename, uint32_t type) {
VisitorReply tmp(type);
serialize(filename, tmp);
for (auto lang : languages()) {
auto obj = deserialize(filename, type, lang);
- if (EXPECT_TRUE(obj)) {
- auto* ptr = dynamic_cast<VisitorReply*>(obj.get());
- EXPECT_TRUE(ptr);
- }
+ ASSERT_TRUE(obj);
+ auto* ptr = dynamic_cast<VisitorReply*>(obj.get());
+ EXPECT_TRUE(ptr);
}
- return true;
}
-// TODO rewrite to Gtest
-TEST_APPHOOK(Messages80Test);
+} // documentapi
diff --git a/documentapi/src/tests/messages/messages_app.cpp b/documentapi/src/tests/messages/messages_app.cpp
new file mode 100644
index 00000000000..ffb88a2fc33
--- /dev/null
+++ b/documentapi/src/tests/messages/messages_app.cpp
@@ -0,0 +1,8 @@
+// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#include <vespa/vespalib/gtest/gtest.h>
+
+#include <vespa/log/log.h>
+LOG_SETUP("messages_test");
+
+GTEST_MAIN_RUN_ALL_TESTS()
diff --git a/documentapi/src/tests/messages/testbase.cpp b/documentapi/src/tests/messages/testbase.cpp
deleted file mode 100644
index e5647ceaef8..00000000000
--- a/documentapi/src/tests/messages/testbase.cpp
+++ /dev/null
@@ -1,228 +0,0 @@
-// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-#include "testbase.h"
-#include <vespa/document/repo/documenttyperepo.h>
-#include <vespa/document/base/testdocrepo.h>
-#include <vespa/document/config/documenttypes_config_fwd.h>
-#include <vespa/vespalib/util/exception.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <algorithm>
-#include <filesystem>
-
-#include <vespa/log/log.h>
-LOG_SETUP(".testbase");
-
-using document::DocumentTypeRepo;
-using document::readDocumenttypesConfig;
-
-TestBase::TestBase() :
- _repo(new DocumentTypeRepo(readDocumenttypesConfig(
- TEST_PATH("../../../test/cfg/testdoctypes.cfg")))),
- _dataPath(TEST_PATH("../../../test/crosslanguagefiles")),
- _protocol(_repo),
- _tests()
-{
-}
-
-TestBase::~TestBase() = default;
-
-int
-TestBase::Main()
-{
- TEST_INIT("messages_test");
-
- // Retrieve version number to test for.
- LOG(info, "Running tests for version %s.", getVersion().toString().c_str());
-
- // Run registered tests.
- for (const auto& test : _tests) {
- LOG(info, "Running test for routable type %d.", test.first);
- EXPECT_TRUE( (this->*(test.second))() );
- TEST_FLUSH();
- }
-
- // Test routable type coverage.
- std::vector<uint32_t> expected;
- std::vector<uint32_t> actual;
- EXPECT_TRUE(testCoverage(expected, actual));
- expected.push_back(0);
- EXPECT_TRUE(!testCoverage(expected, actual));
- actual.push_back(1);
- EXPECT_TRUE(!testCoverage(expected, actual));
- actual.push_back(0);
- EXPECT_TRUE(!testCoverage(expected, actual));
- expected.push_back(1);
- EXPECT_TRUE(testCoverage(expected, actual));
-
- expected.clear();
- _protocol.getRoutableTypes(getVersion(), expected);
-
- actual.clear();
- for (const auto& test : _tests) {
- actual.push_back(test.first);
- }
- if (shouldTestCoverage()) {
- EXPECT_TRUE(testCoverage(expected, actual, true));
- }
- TEST_DONE();
-}
-
-TestBase &
-TestBase::putTest(uint32_t type, TEST_METHOD_PT test)
-{
- _tests[type] = test;
- return *this;
-}
-
-mbus::Blob
-TestBase::truncate(mbus::Blob data, size_t bytes)
-{
- ASSERT_GREATER(data.size(), bytes);
- mbus::Blob res(data.size() - bytes);
- memcpy(res.data(), data.data(), res.size());
- return res;
-}
-
-mbus::Blob
-TestBase::pad(mbus::Blob data, size_t bytes)
-{
- mbus::Blob res(data.size() + bytes);
- memset(res.data(), 0, res.size());
- memcpy(res.data(), data.data(), data.size());
- return res;
-}
-
-bool
-TestBase::testCoverage(const std::vector<uint32_t> &expected, const std::vector<uint32_t> &actual, bool report) const
-{
- bool ret = true;
-
- std::vector<uint32_t> lst(actual);
- for (uint32_t wanted : expected) {
- auto occ = std::find(lst.begin(), lst.end(), wanted);
- if (occ == lst.end()) {
- if (report) {
- LOG(error, "Routable type %d is registered in DocumentProtocol but not tested.", wanted);
- }
- ret = false;
- } else {
- lst.erase(occ);
- }
- }
- if (!lst.empty()) {
- if (report) {
- for (uint32_t missing : lst) {
- LOG(error, "Routable type %d is tested but not registered in DocumentProtocol.", missing);
- }
- }
- ret = false;
- }
-
- return ret;
-}
-
-bool TestBase::file_content_is_unchanged(const string& filename, const mbus::Blob& data_to_write) const {
- if (!std::filesystem::exists(std::filesystem::path(filename))) {
- return false;
- }
- mbus::Blob existing = readFile(filename);
- return ((existing.size() == data_to_write.size())
- && (memcmp(existing.data(), data_to_write.data(), data_to_write.size()) == 0));
-}
-
-uint32_t
-TestBase::serialize(const string &filename, const mbus::Routable &routable, Tamper tamper)
-{
- const vespalib::Version version = getVersion();
- string path = getPath(version.toString() + "-cpp-" + filename + ".dat");
- LOG(info, "Serializing to '%s'..", path.c_str());
-
- mbus::Blob blob = tamper(_protocol.encode(version, routable));
- if (file_content_is_unchanged(path, blob)) {
- LOG(info, "Serialization for '%s' is unchanged; not overwriting it", path.c_str());
- } else if (!EXPECT_TRUE(writeFile(path, blob))) {
- LOG(error, "Could not open file '%s' for writing.", path.c_str());
- return 0;
- }
- mbus::Routable::UP obj = _protocol.decode(version, blob);
- if (!EXPECT_TRUE(obj.get() != nullptr)) {
- LOG(error, "Protocol failed to decode serialized data.");
- return 0;
- }
- if (!EXPECT_TRUE(routable.getType() == obj->getType())) {
- LOG(error, "Expected class %d, got %d.", routable.getType(), obj->getType());
- return 0;
- }
- return blob.size();
-}
-
-mbus::Routable::UP
-TestBase::deserialize(const string &filename, uint32_t classId, uint32_t lang)
-{
- const vespalib::Version version = getVersion();
- string path = getPath(version.toString() + (lang == LANG_JAVA ? "-java" : "-cpp") + "-" + filename + ".dat");
- LOG(info, "Deserializing from '%s'..", path.c_str());
-
- mbus::Blob blob = readFile(path);
- if (!EXPECT_TRUE(blob.size() != 0)) {
- LOG(error, "Could not open file '%s' for reading.", path.c_str());
- return {};
- }
- mbus::Routable::UP ret = _protocol.decode(version, blob);
-
- if (!EXPECT_TRUE(ret.get())) {
- LOG(error, "Unable to decode class %d", classId);
- } else if (!EXPECT_TRUE(classId == ret->getType())) {
- LOG(error, "Expected class %d, got %d.", classId, ret->getType());
- return {};
- }
- return ret;
-}
-
-void
-TestBase::dump(const mbus::Blob& blob) const
-{
- fprintf(stderr, "[%ld]: ", blob.size());
- for(size_t i = 0; i < blob.size(); i++) {
- if (blob.data()[i] > 32 && blob.data()[i] < 126) {
- fprintf(stderr, "%c ", blob.data()[i]);
- }
- else {
- fprintf(stderr, "%d ", blob.data()[i]);
- }
- }
- fprintf(stderr, "\n");
-}
-
-
-bool
-TestBase::writeFile(const string &filename, const mbus::Blob& blob) const
-{
- int file = open(filename.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0644);
- if (file == -1) {
- return false;
- }
- if (write(file, blob.data(), blob.size()) != (ssize_t)blob.size()) {
- throw vespalib::Exception("write failed");
- }
- close(file);
- return true;
-}
-
-mbus::Blob
-TestBase::readFile(const string &filename) const
-{
- int file = open(filename.c_str(), O_RDONLY);
- int len = (file == -1) ? 0 : lseek(file, 0, SEEK_END);
- mbus::Blob blob(len);
- if (file != -1) {
- lseek(file, 0, SEEK_SET);
- if (read(file, blob.data(), len) != len) {
- throw vespalib::Exception("read failed");
- }
- close(file);
- }
-
- return blob;
-}
diff --git a/documentapi/src/tests/messages/testbase.h b/documentapi/src/tests/messages/testbase.h
deleted file mode 100644
index ad371bcc3bc..00000000000
--- a/documentapi/src/tests/messages/testbase.h
+++ /dev/null
@@ -1,69 +0,0 @@
-// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#pragma once
-
-#include <vespa/documentapi/messagebus/documentprotocol.h>
-#include <vespa/messagebus/routable.h>
-#include <vespa/vespalib/component/version.h>
-#include <vespa/vespalib/testkit/testapp.h>
-#include <map>
-
-using namespace documentapi;
-
-/**
- * Declare the signature of the test method.
- */
-class TestBase;
-typedef bool (TestBase::*TEST_METHOD_PT)();
-#define TEST_METHOD(pt) ((TEST_METHOD_PT)&pt)
-
-/**
- * This is the test base itself. It offers a set of utility functions that reflect on the version returned by
- * the pure virtual getVersion() function. You need to inherit this and assign a version and a set of message
- * tests to it.
- */
-class TestBase : public vespalib::TestApp {
- std::shared_ptr<const document::DocumentTypeRepo> _repo;
-protected:
- const string _dataPath;
- DocumentProtocol _protocol;
- std::map<uint32_t, TEST_METHOD_PT> _tests;
-
- // Declares what languages share serialization.
- enum {
- LANG_CPP = 0,
- LANG_JAVA,
- NUM_LANGUAGES
- };
-
- TestBase();
- ~TestBase() override;
- virtual vespalib::Version getVersion() const = 0;
- virtual bool shouldTestCoverage() const = 0;
- TestBase &putTest(uint32_t type, TEST_METHOD_PT test);
- int Main() override;
-
-public:
- using Tamper = std::function<mbus::Blob(mbus::Blob)>;
- static mbus::Blob truncate(mbus::Blob data, size_t bytes);
- static mbus::Blob pad(mbus::Blob data, size_t bytes);
-
- const document::DocumentTypeRepo &getTypeRepo() { return *_repo; }
- std::shared_ptr<const document::DocumentTypeRepo> &getTypeRepoSp() { return _repo; }
-
- bool testCoverage(const std::vector<uint32_t> &expected, const std::vector<uint32_t> &actual, bool report = false) const;
- bool writeFile(const string &filename, const mbus::Blob& blob) const;
- mbus::Blob readFile(const string &filename) const;
- uint32_t serialize(const string &filename, const mbus::Routable &routable, Tamper tamper);
- uint32_t serialize(const string &filename, const mbus::Routable &routable) {
- return serialize(filename, routable, [](auto x)noexcept{ return x; });
- }
- mbus::Routable::UP deserialize(const string &filename, uint32_t classId, uint32_t lang);
- void dump(const mbus::Blob &blob) const;
-
- string getPath(const string &filename) const { return _dataPath + "/" + filename; }
- mbus::Blob encode(const mbus::Routable &obj) const { return _protocol.encode(getVersion(), obj); }
- mbus::Routable::UP decode(mbus::BlobRef data) const { return _protocol.decode(getVersion(), data); }
-private:
- bool file_content_is_unchanged(const string& filename, const mbus::Blob& data_to_write) const;
-};
-