2 #include <gtest/gtest.h> 10 TEST(DDValueTest, intTest) {
13 ASSERT_EQ(0,v.
toInt());
16 ASSERT_EQ(-1,v.toInt());
17 ASSERT_EQ(v.getType(),
"int");
19 ASSERT_EQ(INT32_MAX,v.toInt());
20 ASSERT_EQ(v.getType(),
"int");
22 ASSERT_EQ(INT32_MIN,v.toInt());
23 ASSERT_EQ(v.getType(),
"int");
27 ASSERT_EQ(i,v.toInt());
28 ASSERT_EQ(v.getType(),
"double");
30 ASSERT_EQ(i,v.toInt());
31 ASSERT_EQ(v.getType(),
"bool");
32 stringstream str; str << i;
34 ASSERT_EQ(i,v.toInt());
35 ASSERT_EQ(v.getType(),
"string");
41 TEST(DDValueTest, doubleTest) {
45 ASSERT_EQ(v.
getType(),
"double");
47 ASSERT_EQ(-1.0,v.toDouble());
48 ASSERT_EQ(v.getType(),
"double");
49 v =
Value((
double)INT32_MAX);
50 ASSERT_EQ((
double)INT32_MAX,v.toDouble());
51 ASSERT_EQ(v.getType(),
"double");
52 v =
Value((
double)INT32_MIN);
53 ASSERT_EQ((
double)INT32_MIN,v.toDouble());
54 ASSERT_EQ(v.getType(),
"double");
56 ASSERT_EQ(DBL_MAX,v.toDouble());
57 ASSERT_EQ(v.getType(),
"double");
59 ASSERT_EQ(DBL_MIN,v.toDouble());
60 ASSERT_EQ(v.getType(),
"double");
62 ASSERT_EQ(-DBL_MAX,v.toDouble());
63 ASSERT_EQ(v.getType(),
"double");
67 ASSERT_EQ(f,v.toDouble());
68 ASSERT_EQ(v.getType(),
"int");
69 v =
Value((
int)(f + 0.1));
70 ASSERT_NE(f + 0.1,v.toDouble());
71 ASSERT_EQ(v.getType(),
"int");
73 ASSERT_EQ(f,v.toDouble());
74 ASSERT_EQ(v.getType(),
"bool");
75 stringstream str; str << f;
77 ASSERT_EQ(f,v.toDouble());
78 ASSERT_EQ(v.getType(),
"string");
81 ASSERT_EQ(f,v.toDouble());
82 ASSERT_EQ(v.getType(),
"string");
88 TEST(DDValueTest, boolTest) {
91 ASSERT_EQ(
false,v.
toBool());
94 ASSERT_EQ(
true,v.toBool());
95 ASSERT_EQ(v.getType(),
"bool");
98 ASSERT_EQ(
true,v.toBool());
99 ASSERT_EQ(v.getType(),
"int");
101 ASSERT_EQ(
false,v.toBool());
102 ASSERT_EQ(v.getType(),
"int");
104 ASSERT_EQ(
true,v.toBool());
105 ASSERT_EQ(v.getType(),
"int");
107 ASSERT_EQ(
false,v.toBool());
108 ASSERT_EQ(v.getType(),
"int");
110 ASSERT_EQ(
true,v.toBool());
111 ASSERT_EQ(v.getType(),
"double");
113 ASSERT_EQ(
false,v.toBool());
114 ASSERT_EQ(v.getType(),
"double");
116 ASSERT_EQ(
true,v.toBool());
117 ASSERT_EQ(v.getType(),
"double");
119 ASSERT_EQ(
false,v.toBool());
120 ASSERT_EQ(v.getType(),
"double");
122 ASSERT_EQ(
true,v.toBool());
123 ASSERT_EQ(v.getType(),
"string");
125 ASSERT_EQ(
false,v.toBool());
126 ASSERT_EQ(v.getType(),
"string");
127 v =
Value(
"not a bool");
128 ASSERT_EQ(
false,v.toBool());
129 ASSERT_EQ(v.getType(),
"string");
131 ASSERT_EQ(
false,v.toBool());
132 ASSERT_EQ(v.getType(),
"string");
138 TEST(DDValueTest, stringTest) {
142 ASSERT_EQ(v.
getType(),
"string");
144 ASSERT_EQ(
"\000",v.toString());
145 ASSERT_EQ(v.getType(),
"string");
147 ASSERT_EQ(
"",v.toString());
148 ASSERT_EQ(v.getType(),
"string");
149 string s(
"How long can I make this string go on for? Well, You would be surprised! I can make it really long, but I won't.");
151 ASSERT_EQ(s,v.toString());
152 ASSERT_EQ(v.getType(),
"string");
155 ASSERT_EQ(
"1",v.toString());
156 ASSERT_EQ(v.getType(),
"int");
158 ASSERT_EQ(
"-1",v.toString());
159 ASSERT_EQ(v.getType(),
"int");
161 ASSERT_EQ(
"1",v.toString());
162 ASSERT_EQ(v.getType(),
"double");
164 ASSERT_EQ(
"-1",v.toString());
165 ASSERT_EQ(v.getType(),
"double");
167 ASSERT_EQ(
"1.1",v.toString());
168 ASSERT_EQ(v.getType(),
"double");
170 ASSERT_EQ(
"-1.1",v.toString());
171 ASSERT_EQ(v.getType(),
"double");
173 ASSERT_EQ(
"true",v.toString());
174 ASSERT_EQ(v.getType(),
"bool");
176 ASSERT_EQ(
"false",v.toString());
177 ASSERT_EQ(v.getType(),
"bool");
182 int main(
int argc,
char** argv) {
183 testing::InitGoogleTest(&argc, argv);
185 srand((
unsigned int)random());
187 return RUN_ALL_TESTS();
int main(int argc, char **argv)