blob: 6c3675bd5f9c3ee5d62ba8772084de6a2e813ef3 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
#include <vespa/document/repo/documenttyperepo.h>
#include <vespa/documentapi/messagebus/documentprotocol.h>
#include <vespa/documentapi/loadtypes/loadtypeset.h>
#include <vespa/messagebus/routable.h>
#include <vespa/vespalib/component/version.h>
#include <vespa/vespalib/testkit/testapp.h>
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 {
const document::DocumentTypeRepo::SP _repo;
protected:
const string _dataPath;
LoadTypeSet _loadTypes;
DocumentProtocol _protocol;
std::map<uint32_t, TEST_METHOD_PT> _tests;
// Declares what languages share serialization.
enum {
LANG_CPP = 0,
LANG_JAVA,
NUM_LANGUAGES
};
TestBase();
virtual ~TestBase() { /* empty */ }
virtual const vespalib::Version getVersion() const = 0;
virtual bool shouldTestCoverage() const = 0;
TestBase &putTest(uint32_t type, TEST_METHOD_PT test);
int Main() override;
public:
const document::DocumentTypeRepo &getTypeRepo() { return *_repo; }
const document::DocumentTypeRepo::SP &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);
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); }
};
|