-
Notifications
You must be signed in to change notification settings - Fork 49
/
BondSplicerTests.cpp
145 lines (120 loc) · 3.96 KB
/
BondSplicerTests.cpp
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
//
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
//
#include "common/Common.hpp"
#include "Enums.hpp"
#include "packager/BondSplicer.hpp"
#include "bond/All.hpp"
#include "bond/generated/CsProtocol_writers.hpp"
#include "bond/FullDumpBinaryBlob.hpp"
using namespace testing;
using namespace MAT;
class ShadowBondSplicer : protected MAT::BondSplicer
{
public:
using MAT::BondSplicer::addTenantToken;
void addCsRecord(size_t dataPackageIndex, ::CsProtocol::Record& record)
{
std::vector<uint8_t> recordBlob;
{
bond_lite::CompactBinaryProtocolWriter writer(recordBlob);
bond_lite::Serialize(writer, record);
}
MAT::BondSplicer::addRecord(dataPackageIndex, recordBlob);
}
std::vector<uint8_t> splice() const override
{
FullDumpBinaryBlob output;
static_cast<std::vector<uint8_t>&>(output) = MAT::BondSplicer::splice();
return output;
}
};
//---
class BondSplicerTests : public Test
{
protected:
ShadowBondSplicer bs;
};
TEST_F(BondSplicerTests, addTenantToken_EmptyString_Returns0)
{
EXPECT_EQ(bs.addTenantToken(std::string { }), size_t { 0 });
}
TEST_F(BondSplicerTests, addTenantToken_TestString_Returns0)
{
EXPECT_EQ(bs.addTenantToken(std::string { "Test" }), size_t { 0 });
}
TEST_F(BondSplicerTests, addTenantToken_TwoDifferentStrings_Returns0And1)
{
EXPECT_EQ(bs.addTenantToken(std::string { "Test" }), size_t { 0 });
EXPECT_EQ(bs.addTenantToken(std::string { "Test2" }), size_t { 1 });
}
TEST_F(BondSplicerTests, addTenantToken_TwoSameStrings_Returns0And1)
{
EXPECT_EQ(bs.addTenantToken(std::string { "Test" }), size_t { 0 });
EXPECT_EQ(bs.addTenantToken(std::string { "Test" }), size_t { 1 });
}
TEST_F(BondSplicerTests, splice_Empty_SizeZero)
{
EXPECT_EQ(bs.splice().size(), size_t { 0 });
}
TEST_F(BondSplicerTests, splice_OneEmptyTenantToken_SizeZero)
{
bs.addTenantToken("tenant1");
EXPECT_EQ(bs.splice().size(), size_t { 0 });
}
TEST_F(BondSplicerTests, splice_OnePackageWithOneEmptyRecord_SizeOne)
{
::CsProtocol::Record r;
bs.addCsRecord(bs.addTenantToken("tenant1"), r);
EXPECT_THAT(bs.splice().size(), size_t { 1 });
}
TEST_F(BondSplicerTests, splice_OnePackageWithOneNonEmptyRecord_SizeNine)
{
::CsProtocol::Record r;
r.name = std::string { "Record" };
bs.addCsRecord(bs.addTenantToken("tenant1"), r);
EXPECT_THAT(bs.splice().size(), size_t { 9 });
}
TEST_F(BondSplicerTests, splice_OneDataPackageWithTwoEmptyRecords_SizeTwo)
{
::CsProtocol::Record r;
::CsProtocol::Record r2;
auto tokenIndex = bs.addTenantToken("tenant1");
bs.addCsRecord(tokenIndex, r);
bs.addCsRecord(tokenIndex, r2);
EXPECT_THAT(bs.splice().size(), size_t { 2 });
}
TEST_F(BondSplicerTests, splice_OneDataPackageWithTwoNonEmptyRecords_SizeTwenty)
{
::CsProtocol::Record r;
r.name = std::string { "Record1" };
::CsProtocol::Record r2;
r2.name = std::string { "Record2" };
auto tokenIndex = bs.addTenantToken("tenant1");
bs.addCsRecord(tokenIndex, r);
bs.addCsRecord(tokenIndex, r2);
EXPECT_THAT(bs.splice().size(), size_t { 20 });
}
TEST_F(BondSplicerTests, splice_TwoDataPackagesWithOneEmptyRecordEach_SizeTwo)
{
::CsProtocol::Record r;
::CsProtocol::Record r2;
auto firstTokenIndex = bs.addTenantToken("tenant1");
auto secondTokenIndex = bs.addTenantToken("tenant2");
bs.addCsRecord(firstTokenIndex, r);
bs.addCsRecord(secondTokenIndex, r2);
EXPECT_THAT(bs.splice().size(), size_t { 2 });
}
TEST_F(BondSplicerTests, splice_TwoDataPackagesWithOneNonEmptyRecordEach_SizeTwenty)
{
::CsProtocol::Record r;
r.name = std::string { "Record1" };
::CsProtocol::Record r2;
r2.name = std::string { "Record2" };
auto firstTokenIndex = bs.addTenantToken("tenant1");
auto secondTokenIndex = bs.addTenantToken("tenant2");
bs.addCsRecord(firstTokenIndex, r);
bs.addCsRecord(secondTokenIndex, r2);
EXPECT_THAT(bs.splice().size(), size_t { 20 });
}