Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <test/bootstrapfixture.hxx>
21 :
22 : #include <connectivity/FValue.hxx>
23 : #include <com/sun/star/sdbc/DataType.hpp>
24 : using namespace ::com::sun::star::sdbc;
25 : using namespace ::com::sun::star::uno;
26 :
27 : namespace connectivity { namespace commontools {
28 :
29 56 : class FValueTest: public test::BootstrapFixture
30 : {
31 : public:
32 28 : FValueTest() : test::BootstrapFixture(false, false) {};
33 :
34 : void test_Bool();
35 :
36 : void test_Int8();
37 : void test_uInt8();
38 :
39 : void test_Int16();
40 : void test_uInt16();
41 :
42 : void test_Int32();
43 : void test_uInt32();
44 :
45 : void test_Int64();
46 : void test_uInt64();
47 :
48 : void test_float();
49 : void test_double();
50 :
51 : void test_bool_getString();
52 : void test_bit_getString();
53 :
54 : void test_bool_creation();
55 :
56 4 : CPPUNIT_TEST_SUITE(FValueTest);
57 :
58 2 : CPPUNIT_TEST(test_Bool);
59 :
60 2 : CPPUNIT_TEST(test_Int8);
61 2 : CPPUNIT_TEST(test_uInt8);
62 :
63 2 : CPPUNIT_TEST(test_Int16);
64 2 : CPPUNIT_TEST(test_uInt16);
65 :
66 2 : CPPUNIT_TEST(test_Int32);
67 2 : CPPUNIT_TEST(test_uInt32);
68 :
69 2 : CPPUNIT_TEST(test_Int64);
70 2 : CPPUNIT_TEST(test_uInt64);
71 :
72 2 : CPPUNIT_TEST(test_float);
73 2 : CPPUNIT_TEST(test_double);
74 :
75 2 : CPPUNIT_TEST(test_bool_getString);
76 2 : CPPUNIT_TEST(test_bit_getString);
77 2 : CPPUNIT_TEST(test_bool_creation);
78 4 : CPPUNIT_TEST_SUITE_END();
79 : };
80 :
81 2 : void FValueTest::test_Bool()
82 : {
83 2 : bool src_Bool = true;
84 2 : ORowSetValue v(src_Bool);
85 2 : bool trg_Bool = v.getBool();
86 :
87 2 : std::cerr << "src_Bool: " << src_Bool << std::endl;
88 2 : std::cerr << "trg_Bool: " << trg_Bool << std::endl;
89 :
90 2 : CPPUNIT_ASSERT_MESSAGE("bool conversion to ORowSetValue didn't work", src_Bool == trg_Bool);
91 :
92 4 : Any any_Bool = v.makeAny();
93 4 : ORowSetValue t;
94 2 : t.fill(any_Bool);
95 2 : trg_Bool = t.getBool();
96 :
97 2 : std::cerr << "trg_Bool: " << trg_Bool << std::endl;
98 :
99 4 : CPPUNIT_ASSERT_MESSAGE("bool conversion from Any didn't work", src_Bool == trg_Bool);
100 2 : }
101 :
102 2 : void FValueTest::test_Int8()
103 : {
104 2 : sal_Int8 src_salInt8 = 127;
105 2 : ORowSetValue v(src_salInt8);
106 2 : sal_Int8 trg_salInt8 = v.getInt8();
107 :
108 2 : std::cerr << "src_salInt8: " << static_cast<short>(src_salInt8) << std::endl;
109 2 : std::cerr << "trg_salInt8: " << static_cast<short>(trg_salInt8) << std::endl;
110 :
111 2 : CPPUNIT_ASSERT_MESSAGE("sal_Int8 conversion to ORowSetValue didn't work", src_salInt8 == trg_salInt8);
112 :
113 4 : Any any_Int8 = v.makeAny();
114 4 : ORowSetValue t;
115 2 : t.fill(any_Int8);
116 2 : trg_salInt8 = t.getInt8();
117 :
118 2 : std::cerr << "trg_salInt8: " << static_cast<short>(trg_salInt8) << std::endl;
119 :
120 4 : CPPUNIT_ASSERT_MESSAGE("sal_Int8 conversion from Any didn't work", src_salInt8 == trg_salInt8);
121 2 : }
122 :
123 2 : void FValueTest::test_uInt8()
124 : {
125 2 : sal_uInt8 src_saluInt8 = 255;
126 2 : ORowSetValue v(src_saluInt8);
127 2 : sal_uInt8 trg_saluInt8 = v.getUInt8();
128 :
129 2 : std::cerr << "src_saluInt8: " << static_cast<short>(src_saluInt8) << std::endl;
130 2 : std::cerr << "trg_saluInt8: " << static_cast<short>(trg_saluInt8) << std::endl;
131 :
132 2 : CPPUNIT_ASSERT_MESSAGE("sal_uInt8 conversion to ORowSetValue didn't work", src_saluInt8 == trg_saluInt8);
133 :
134 4 : Any any_uInt8 = v.makeAny();
135 4 : ORowSetValue t;
136 2 : t.fill(any_uInt8);
137 2 : trg_saluInt8 = t.getUInt8();
138 :
139 2 : std::cerr << "trg_saluInt8: " << static_cast<short>(trg_saluInt8) << std::endl;
140 :
141 4 : CPPUNIT_ASSERT_MESSAGE("sal_uInt8 conversion from Any didn't work", src_saluInt8 == trg_saluInt8);
142 2 : }
143 :
144 2 : void FValueTest::test_Int16()
145 : {
146 2 : sal_Int16 src_salInt16 = -10001;
147 2 : ORowSetValue v(src_salInt16);
148 2 : sal_Int16 trg_salInt16 = v.getInt16();
149 :
150 2 : std::cerr << "src_salInt16: " << src_salInt16 << std::endl;
151 2 : std::cerr << "trg_salInt16: " << trg_salInt16 << std::endl;
152 :
153 2 : CPPUNIT_ASSERT_MESSAGE("sal_Int16 conversion to ORowSetValue didn't work", src_salInt16 == trg_salInt16);
154 :
155 4 : Any any_Int16 = v.makeAny();
156 4 : ORowSetValue t;
157 2 : t.fill(any_Int16);
158 2 : trg_salInt16 = t.getInt16();
159 :
160 4 : CPPUNIT_ASSERT_MESSAGE("sal_Int16 conversion from Any didn't work", src_salInt16 == trg_salInt16);
161 2 : }
162 :
163 2 : void FValueTest::test_uInt16()
164 : {
165 2 : sal_uInt16 src_saluInt16 = 10001;
166 2 : ORowSetValue v(src_saluInt16);
167 2 : sal_uInt16 trg_saluInt16 = v.getUInt16();
168 :
169 2 : std::cerr << "src_saluInt16: " << src_saluInt16 << std::endl;
170 2 : std::cerr << "trg_saluInt16: " << trg_saluInt16 << std::endl;
171 :
172 2 : CPPUNIT_ASSERT_MESSAGE("sal_uInt16 conversion to ORowSetValue didn't work", src_saluInt16 == trg_saluInt16);
173 :
174 4 : Any any_uInt16 = v.makeAny();
175 4 : ORowSetValue t;
176 2 : t.fill(any_uInt16);
177 2 : trg_saluInt16 = t.getUInt16();
178 :
179 4 : CPPUNIT_ASSERT_MESSAGE("sal_uInt16 conversion from Any didn't work", src_saluInt16 == trg_saluInt16);
180 2 : }
181 :
182 2 : void FValueTest::test_Int32()
183 : {
184 2 : sal_Int32 src_salInt32 = -10000001;
185 2 : ORowSetValue v(src_salInt32);
186 2 : sal_Int32 trg_salInt32 = v.getInt32();
187 :
188 2 : std::cerr << "src_salInt32: " << src_salInt32 << std::endl;
189 2 : std::cerr << "trg_salInt32: " << trg_salInt32 << std::endl;
190 :
191 2 : CPPUNIT_ASSERT_MESSAGE("sal_Int32 conversion to ORowSetValue didn't work", src_salInt32 == trg_salInt32);
192 :
193 4 : Any any_Int32 = v.makeAny();
194 4 : ORowSetValue t;
195 2 : t.fill(any_Int32);
196 2 : trg_salInt32 = t.getInt32();
197 :
198 4 : CPPUNIT_ASSERT_MESSAGE("sal_Int32 conversion from Any didn't work", src_salInt32 == trg_salInt32);
199 2 : }
200 :
201 2 : void FValueTest::test_uInt32()
202 : {
203 2 : sal_uInt32 src_saluInt32 = 100000001;
204 2 : ORowSetValue v(src_saluInt32);
205 2 : sal_uInt32 trg_saluInt32 = v.getUInt32();
206 :
207 2 : std::cerr << "src_saluInt32: " << src_saluInt32 << std::endl;
208 2 : std::cerr << "trg_saluInt32: " << trg_saluInt32 << std::endl;
209 :
210 2 : CPPUNIT_ASSERT_MESSAGE("sal_uInt32 conversion to ORowSetValue didn't work", src_saluInt32 == trg_saluInt32);
211 :
212 4 : Any any_uInt32 = v.makeAny();
213 4 : ORowSetValue t;
214 2 : t.fill(any_uInt32);
215 2 : trg_saluInt32 = t.getUInt32();
216 :
217 4 : CPPUNIT_ASSERT_MESSAGE("sal_uInt32 conversion from Any didn't work", src_saluInt32 == trg_saluInt32);
218 2 : }
219 :
220 2 : void FValueTest::test_Int64()
221 : {
222 2 : sal_Int64 src_salInt64 = -1000000000000000001LL;
223 2 : ORowSetValue v(src_salInt64);
224 2 : sal_Int64 trg_salInt64 = v.getLong();
225 :
226 2 : std::cerr << "src_salInt64: " << src_salInt64 << std::endl;
227 2 : std::cerr << "trg_salInt64: " << trg_salInt64 << std::endl;
228 :
229 2 : CPPUNIT_ASSERT_MESSAGE("sal_Int64 conversion to ORowSetValue didn't work", src_salInt64 == trg_salInt64);
230 :
231 4 : Any any_Int64 = v.makeAny();
232 4 : ORowSetValue t;
233 2 : t.fill(any_Int64);
234 2 : trg_salInt64 = t.getLong();
235 :
236 4 : CPPUNIT_ASSERT_MESSAGE("sal_Int64 conversion from Any didn't work", src_salInt64 == trg_salInt64);
237 2 : }
238 :
239 2 : void FValueTest::test_uInt64()
240 : {
241 2 : sal_uInt64 src_saluInt64 = 10000000000000000001ULL;
242 2 : ORowSetValue v(src_saluInt64);
243 2 : sal_uInt64 trg_saluInt64 = v.getULong();
244 :
245 2 : std::cerr << "src_saluInt64: " << src_saluInt64 << std::endl;
246 2 : std::cerr << "trg_saluInt64: " << trg_saluInt64 << std::endl;
247 :
248 2 : CPPUNIT_ASSERT_MESSAGE("sal_uInt64 conversion to ORowSetValue didn't work", src_saluInt64 == trg_saluInt64);
249 :
250 4 : Any any_uInt64 = v.makeAny();
251 4 : ORowSetValue t;
252 2 : t.fill(any_uInt64);
253 2 : trg_saluInt64 = t.getULong();
254 :
255 4 : CPPUNIT_ASSERT_MESSAGE("sal_uInt64 conversion from Any didn't work", src_saluInt64 == trg_saluInt64);
256 2 : }
257 :
258 2 : void FValueTest::test_float()
259 : {
260 2 : float src_float = 1.234f;
261 2 : ORowSetValue v(src_float);
262 2 : float trg_float = v.getFloat();
263 :
264 2 : std::cerr << "src_float: " << src_float << std::endl;
265 2 : std::cerr << "trg_float: " << trg_float << std::endl;
266 :
267 2 : CPPUNIT_ASSERT_MESSAGE("float conversion to ORowSetValue didn't work", src_float == trg_float);
268 :
269 4 : Any any_float = v.makeAny();
270 4 : ORowSetValue t;
271 2 : t.fill(any_float);
272 2 : trg_float = t.getFloat();
273 :
274 4 : CPPUNIT_ASSERT_MESSAGE("float conversion from Any didn't work", src_float == trg_float);
275 2 : }
276 :
277 2 : void FValueTest::test_double()
278 : {
279 2 : double src_double = 1.23456789;
280 2 : ORowSetValue v(src_double);
281 2 : double trg_double = v.getDouble();
282 :
283 2 : std::cerr << "src_double: " << src_double << std::endl;
284 2 : std::cerr << "trg_double: " << trg_double << std::endl;
285 :
286 2 : CPPUNIT_ASSERT_MESSAGE("double conversion to ORowSetValue didn't work", src_double == trg_double);
287 :
288 4 : Any any_double = v.makeAny();
289 4 : ORowSetValue t;
290 2 : t.fill(any_double);
291 2 : trg_double = t.getDouble();
292 :
293 4 : CPPUNIT_ASSERT_MESSAGE("double conversion from Any didn't work", src_double == trg_double);
294 2 : }
295 :
296 2 : void FValueTest::test_bool_getString()
297 : {
298 2 : bool src_bool_1 = true;
299 2 : ORowSetValue v_1(src_bool_1);
300 4 : OUString trg_bool_1 = v_1.getString();
301 :
302 2 : std::cerr << "src_bool_1: " << src_bool_1 << std::endl;
303 2 : std::cerr << "trg_bool_1: " << trg_bool_1 << std::endl;
304 :
305 2 : CPPUNIT_ASSERT_MESSAGE("ORowSetValue bool to string conversion didn't work", trg_bool_1 == "true");
306 :
307 2 : bool src_bool_0 = false;
308 4 : ORowSetValue v_0(src_bool_0);
309 4 : OUString trg_bool_0 = v_0.getString();
310 :
311 2 : std::cerr << "src_bool_0: " << src_bool_0 << std::endl;
312 2 : std::cerr << "trg_bool_0: " << trg_bool_0 << std::endl;
313 :
314 4 : CPPUNIT_ASSERT_MESSAGE("ORowSetValue bool to string conversion didn't work", trg_bool_0 == "false");
315 2 : }
316 :
317 2 : void FValueTest::test_bit_getString()
318 : {
319 2 : bool src_bool_1 = true;
320 2 : ORowSetValue v_1(src_bool_1);
321 2 : v_1.setTypeKind(DataType::BIT);
322 4 : OUString trg_bool_1 = v_1.getString();
323 :
324 2 : std::cerr << "src_bit_1: " << src_bool_1 << std::endl;
325 2 : std::cerr << "trg_bit_1: " << trg_bool_1 << std::endl;
326 :
327 2 : CPPUNIT_ASSERT_MESSAGE("ORowSetValue bit to string conversion didn't work", trg_bool_1 == "1");
328 :
329 2 : bool src_bool_0 = false;
330 4 : ORowSetValue v_0(src_bool_0);
331 2 : v_0.setTypeKind(DataType::BIT);
332 4 : OUString trg_bool_0 = v_0.getString();
333 :
334 2 : std::cerr << "src_bit_0: " << src_bool_0 << std::endl;
335 2 : std::cerr << "trg_bit_0: " << trg_bool_0 << std::endl;
336 :
337 4 : CPPUNIT_ASSERT_MESSAGE("ORowSetValue bit to string conversion didn't work", trg_bool_0 == "0");
338 2 : }
339 :
340 2 : void FValueTest::test_bool_creation()
341 : {
342 2 : OUString s1("1");
343 4 : OUString s0("0");
344 4 : OUString sTrue("true");
345 4 : OUString sTrUe("tRuE");
346 4 : OUString sFalse("false");
347 4 : ORowSetValue vTrue(true);
348 4 : ORowSetValue vFalse(false);
349 :
350 : {
351 2 : ORowSetValue v(s1);
352 2 : v.setTypeKind(DataType::BOOLEAN);
353 2 : CPPUNIT_ASSERT_MESSAGE("ORowSetValue bool creation from string didn't work", v == vTrue);
354 : }
355 :
356 : {
357 2 : ORowSetValue v(s0);
358 2 : v.setTypeKind(DataType::BOOLEAN);
359 2 : CPPUNIT_ASSERT_MESSAGE("ORowSetValue bool creation from string didn't work", v == vFalse);
360 : }
361 :
362 : {
363 2 : ORowSetValue v(sTrue);
364 2 : v.setTypeKind(DataType::BOOLEAN);
365 2 : CPPUNIT_ASSERT_MESSAGE("ORowSetValue bool creation from string didn't work", v == vTrue);
366 : }
367 :
368 : {
369 2 : ORowSetValue v(sTrUe);
370 2 : v.setTypeKind(DataType::BOOLEAN);
371 2 : CPPUNIT_ASSERT_MESSAGE("ORowSetValue bool creation from string didn't work", v == vTrue);
372 : }
373 :
374 : {
375 2 : ORowSetValue v(sFalse);
376 2 : v.setTypeKind(DataType::BOOLEAN);
377 2 : CPPUNIT_ASSERT_MESSAGE("ORowSetValue bool creation from string didn't work", v == vFalse);
378 : }
379 :
380 : {
381 2 : ORowSetValue v(s0);
382 2 : v.setTypeKind(DataType::BOOLEAN);
383 2 : CPPUNIT_ASSERT_MESSAGE("ORowSetValue bool creation from string didn't work", v == vFalse);
384 2 : }
385 :
386 2 : }
387 :
388 2 : CPPUNIT_TEST_SUITE_REGISTRATION(FValueTest);
389 :
390 : }}
391 :
392 8 : CPPUNIT_PLUGIN_IMPLEMENT();
393 :
394 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|