forked from RaviDesai/mysqlwrap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestAdhocParameter.cpp
126 lines (102 loc) · 2.92 KB
/
TestAdhocParameter.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
#include <iostream>
#include <iomanip>
#include <sstream>
#include "UTFail.h"
#include "TestAdhocParameter.h"
#include "AdhocParameter.h"
using namespace std;
TestAdhocParameter::TestAdhocParameter() {}
void TestAdhocParameter::Test1() {
cout << __PRETTY_FUNCTION__ << endl;
AdhocParameter p;
UTASSERT(p.IsNull());
p.SetData((unsigned char) 220);
UTASSERT(! p.IsNull());
std::string result = p.Get();
UTASSERT(result.size() == 1);
unsigned char res0 = (unsigned char) result[0];
UTASSERT(res0 == (unsigned char) 220);
}
void TestAdhocParameter::Test2() {
cout << __PRETTY_FUNCTION__ << endl;
AdhocParameter p;
UTASSERT(p.IsNull());
p.SetData((char) 'R');
UTASSERT(! p.IsNull());
std::string result = p.Get();
UTASSERT(result.size() == 1);
char res0 = (char) result[0];
UTASSERT(res0 == (char) 'R');
}
void TestAdhocParameter::Test3() {
cout << __PRETTY_FUNCTION__ << endl;
AdhocParameter p;
UTASSERT(p.IsNull());
p.SetData((unsigned short) 16000);
UTASSERT(! p.IsNull());
std::string result = p.Get();
UTASSERT(result.size() == 5);
UTASSERT(strcmp(result.c_str(), "16000") == 0);
}
void TestAdhocParameter::Test4() {
cout << __PRETTY_FUNCTION__ << endl;
AdhocParameter p;
UTASSERT(p.IsNull());
p.SetData((short) 8100);
UTASSERT(! p.IsNull());
std::string result = p.Get();
UTASSERT(result.size() == 4);
UTASSERT(strcmp(result.c_str(), "8100") == 0);
}
void TestAdhocParameter::Test5() {
cout << __PRETTY_FUNCTION__ << endl;
AdhocParameter p;
UTASSERT(p.IsNull());
p.SetData((unsigned int) 3000000000);
UTASSERT(! p.IsNull());
std::string result = p.Get();
UTASSERT(result.size() == 10);
UTASSERT(strcmp(result.c_str(), "3000000000") == 0);
}
void TestAdhocParameter::Test6() {
cout << __PRETTY_FUNCTION__ << endl;
AdhocParameter p;
UTASSERT(p.IsNull());
p.SetData((int) 1000000000);
UTASSERT(! p.IsNull());
std::string result = p.Get();
UTASSERT(result.size() == 10);
UTASSERT(strcmp(result.c_str(), "1000000000") == 0);
}
void TestAdhocParameter::Test7() {
cout << __PRETTY_FUNCTION__ << endl;
AdhocParameter p;
UTASSERT(p.IsNull());
p.SetData((float) 3.14f);
UTASSERT(! p.IsNull());
std::string result = p.Get();
cout << result << endl;
UTASSERT(result.size() == 4);
UTASSERT(strcmp(result.c_str(), "3.14") == 0);
}
int TestAdhocParameter::RunSpecificTest(AdhocParameterMemberPointer test) {
int failures = 0;
try {
(this->*test)();
} catch (UTFail &fail) {
failures++;
cout << fail << endl;
}
return failures;
}
int TestAdhocParameter::RunTests() {
int failures = 0;
failures += RunSpecificTest(&TestAdhocParameter::Test1);
failures += RunSpecificTest(&TestAdhocParameter::Test2);
failures += RunSpecificTest(&TestAdhocParameter::Test3);
failures += RunSpecificTest(&TestAdhocParameter::Test4);
failures += RunSpecificTest(&TestAdhocParameter::Test5);
failures += RunSpecificTest(&TestAdhocParameter::Test6);
failures += RunSpecificTest(&TestAdhocParameter::Test7);
return failures;
}