-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataBlock.cpp
132 lines (96 loc) · 2.48 KB
/
DataBlock.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
#include "DataBlock.hpp"
#define _UNIT_TEST false
#if _UNIT_TEST
#include "gmock/gmock.h"
#include "gtest/gtest.h"
using namespace lio;
TEST(DataBlockTest, InitTest) {
try {
DataBlock<int> a;
ASSERT_THAT(false, true);
} catch (std::exception& ex) {
}
try {
// Should this be allowed??
DataBlock<intptr_t> a;
ASSERT_THAT(false, true);
} catch (std::exception& ex) {
}
try {
DataBlock<void*> dv;
DataBlock<string*> ds;
DataBlock<char*> dc;
} catch (std::exception& ex){
ASSERT_THAT(false,true);
}
}
TEST(DataBlockTest, EqEqCompareTest) {
DataBlock<> a, b;
b.index = 10;
EXPECT_EQ(a == b, false);
}
TEST(DataBlockTest, GetStringValue) {
DataBlock<string*> a;
string fullString("This is String that is full!");
size_t index = 3;
size_t length = 3;
a.SetObject(&fullString);
a.SetIndex(index);
a.SetLength(length);
EXPECT_EQ(a.GetValue() == fullString.substr(index, length), true);
}
TEST(virtualTest, VirtualTest) {
string t = "Hello";
DataBlock<string*> s (&t,1,1);
s._PrintInfo();
}
TEST(CharPtrCompare, Fail) {
char c[20] = "HelloWorld";
DataBlock<char*> dc(c, 2, 3);
DataBlock<char*> dca(c, 3, 3);
EXPECT_EQ(dc == dca, false);
dca.SetIndex(2);
dca.SetLength(3);
EXPECT_EQ(dc == dca, true);
}
TEST(StringPtrCompare, Fail) {
string s("HelloWorld");
DataBlock<string*> dc(&s, 2, 3);
DataBlock<string*> dca(&s, 3, 3);
EXPECT_EQ(dc == dca, false);
dca.SetIndex(2);
dca.SetLength(3);
EXPECT_EQ(dc == dca, true);
}
int main (int argc, char** argv) {
::testing::InitGoogleMock(&argc, argv);
return RUN_ALL_TESTS();
}
/*
#include <string>
using namespace lio;
using std::string;
int main() {
DEBUG_cout << "DataBlock UnitTest" << endl;
DataBlock<> defDb;
DataBlock<> cmpDb;
defDb.index = 10;
defDb._PrintInfo();
UnitTest::Test<DataBlock<>>(defDb, cmpDb, "Compare DataBlock", UnitTest::MEANT_TO_BE_FAILED);
cmpDb.index = 10;
UnitTest::Test<DataBlock<>>(defDb, cmpDb, "Compare DataBlock");
DEBUG_cout << "String* DataBlock" << endl;
string fullString = "This is Test string. Hello world!";
DataBlock<string*> partialString;
partialString.object = &fullString;
partialString.index = 3;
partialString.length = 5;
string retPartString = partialString.GetValue();
DEBUG_cout << "partString: " << retPartString << endl;
UnitTest::Test<string>(retPartString, "s is ", "Compare Partial String");
UnitTest::ReportTestResult();
return 0;
}
*/
#endif
#undef _UNIT_TEST