summaryrefslogtreecommitdiff
path: root/connectivity/qa/connectivity/commontools/FValue_test.cxx
blob: 73b8af5f821f6dcfb27becc0e3bac3cc86a264f1 (plain)
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include <test/bootstrapfixture.hxx>

#include "connectivity/FValue.hxx"
using namespace ::com::sun::star::uno;

namespace connectivity { namespace commontools {

class FValueTest: public test::BootstrapFixture
{
public:
    FValueTest() : test::BootstrapFixture(false, false) {};

    void test_Bool();

    void test_Int8();
    void test_uInt8();

    void test_Int16();
    void test_uInt16();

    void test_Int32();
    void test_uInt32();

    void test_Int64();
    void test_uInt64();

    void test_float();
    void test_double();

    void test_getString();

    CPPUNIT_TEST_SUITE(FValueTest);

    CPPUNIT_TEST(test_Bool);

    CPPUNIT_TEST(test_Int8);
    CPPUNIT_TEST(test_uInt8);

    CPPUNIT_TEST(test_Int16);
    CPPUNIT_TEST(test_uInt16);

    CPPUNIT_TEST(test_Int32);
    CPPUNIT_TEST(test_uInt32);

    CPPUNIT_TEST(test_Int64);
    CPPUNIT_TEST(test_uInt64);

    CPPUNIT_TEST(test_float);
    CPPUNIT_TEST(test_double);

    CPPUNIT_TEST(test_getString);
    CPPUNIT_TEST_SUITE_END();
};

void FValueTest::test_Bool()
{
    bool src_Bool = true;
    ORowSetValue v(src_Bool);
    bool trg_Bool = v.getBool();

    std::cerr << "src_Bool: " << src_Bool << std::endl;
    std::cerr << "trg_Bool: " << trg_Bool << std::endl;

    CPPUNIT_ASSERT_MESSAGE("bool conversion to ORowSetValue didn't work", src_Bool == trg_Bool);

    Any any_Bool = v.makeAny();
    ORowSetValue t;
    t.fill(any_Bool);
    trg_Bool = t.getBool();

    std::cerr << "trg_Bool: " << trg_Bool << std::endl;

    CPPUNIT_ASSERT_MESSAGE("bool conversion from Any didn't work", src_Bool == trg_Bool);
}

void FValueTest::test_Int8()
{
    sal_Int8 src_salInt8 = 127;
    ORowSetValue v(src_salInt8);
    sal_Int8 trg_salInt8 = v.getInt8();

    std::cerr << "src_salInt8: " << static_cast<short>(src_salInt8) << std::endl;
    std::cerr << "trg_salInt8: " << static_cast<short>(trg_salInt8) << std::endl;

    CPPUNIT_ASSERT_MESSAGE("sal_Int8 conversion to ORowSetValue didn't work", src_salInt8 == trg_salInt8);

    Any any_Int8 = v.makeAny();
    ORowSetValue t;
    t.fill(any_Int8);
    trg_salInt8 = t.getInt8();

    std::cerr << "trg_salInt8: " << static_cast<short>(trg_salInt8) << std::endl;

    CPPUNIT_ASSERT_MESSAGE("sal_Int8 conversion from Any didn't work", src_salInt8 == trg_salInt8);
}

void FValueTest::test_uInt8()
{
    sal_uInt8 src_saluInt8 = 255;
    ORowSetValue v(src_saluInt8);
    sal_uInt8 trg_saluInt8 = v.getUInt8();

    std::cerr << "src_saluInt8: " << static_cast<short>(src_saluInt8) << std::endl;
    std::cerr << "trg_saluInt8: " << static_cast<short>(trg_saluInt8) << std::endl;

    CPPUNIT_ASSERT_MESSAGE("sal_uInt8 conversion to ORowSetValue didn't work", src_saluInt8 == trg_saluInt8);

    Any any_uInt8 = v.makeAny();
    ORowSetValue t;
    t.fill(any_uInt8);
    trg_saluInt8 = t.getUInt8();

    std::cerr << "trg_saluInt8: " << static_cast<short>(trg_saluInt8) << std::endl;

    CPPUNIT_ASSERT_MESSAGE("sal_uInt8 conversion from Any didn't work", src_saluInt8 == trg_saluInt8);
}

void FValueTest::test_Int16()
{
    sal_Int16 src_salInt16 = -10001;
    ORowSetValue v(src_salInt16);
    sal_Int16 trg_salInt16 = v.getInt16();

    std::cerr << "src_salInt16: " << src_salInt16 << std::endl;
    std::cerr << "trg_salInt16: " << trg_salInt16 << std::endl;

    CPPUNIT_ASSERT_MESSAGE("sal_Int16 conversion to ORowSetValue didn't work", src_salInt16 == trg_salInt16);

    Any any_Int16 = v.makeAny();
    ORowSetValue t;
    t.fill(any_Int16);
    trg_salInt16 = t.getInt16();

    CPPUNIT_ASSERT_MESSAGE("sal_Int16 conversion from Any didn't work", src_salInt16 == trg_salInt16);
}

void FValueTest::test_uInt16()
{
    sal_uInt16 src_saluInt16 = 10001;
    ORowSetValue v(src_saluInt16);
    sal_uInt16 trg_saluInt16 = v.getUInt16();

    std::cerr << "src_saluInt16: " << src_saluInt16 << std::endl;
    std::cerr << "trg_saluInt16: " << trg_saluInt16 << std::endl;

    CPPUNIT_ASSERT_MESSAGE("sal_uInt16 conversion to ORowSetValue didn't work", src_saluInt16 == trg_saluInt16);

    Any any_uInt16 = v.makeAny();
    ORowSetValue t;
    t.fill(any_uInt16);
    trg_saluInt16 = t.getUInt16();

    CPPUNIT_ASSERT_MESSAGE("sal_uInt16 conversion from Any didn't work", src_saluInt16 == trg_saluInt16);
}

void FValueTest::test_Int32()
{
    sal_Int32 src_salInt32 = -10000001;
    ORowSetValue v(src_salInt32);
    sal_Int32 trg_salInt32 = v.getInt32();

    std::cerr << "src_salInt32: " << src_salInt32 << std::endl;
    std::cerr << "trg_salInt32: " << trg_salInt32 << std::endl;

    CPPUNIT_ASSERT_MESSAGE("sal_Int32 conversion to ORowSetValue didn't work", src_salInt32 == trg_salInt32);

    Any any_Int32 = v.makeAny();
    ORowSetValue t;
    t.fill(any_Int32);
    trg_salInt32 = t.getInt32();

    CPPUNIT_ASSERT_MESSAGE("sal_Int32 conversion from Any didn't work", src_salInt32 == trg_salInt32);
}

void FValueTest::test_uInt32()
{
    sal_uInt32 src_saluInt32 = 100000001;
    ORowSetValue v(src_saluInt32);
    sal_uInt32 trg_saluInt32 = v.getUInt32();

    std::cerr << "src_saluInt32: " << src_saluInt32 << std::endl;
    std::cerr << "trg_saluInt32: " << trg_saluInt32 << std::endl;

    CPPUNIT_ASSERT_MESSAGE("sal_uInt32 conversion to ORowSetValue didn't work", src_saluInt32 == trg_saluInt32);

    Any any_uInt32 = v.makeAny();
    ORowSetValue t;
    t.fill(any_uInt32);
    trg_saluInt32 = t.getUInt32();

    CPPUNIT_ASSERT_MESSAGE("sal_uInt32 conversion from Any didn't work", src_saluInt32 == trg_saluInt32);
}

void FValueTest::test_Int64()
{
    sal_Int64 src_salInt64 = -1000000000000000001LL;
    ORowSetValue v(src_salInt64);
    sal_Int64 trg_salInt64 = v.getLong();

    std::cerr << "src_salInt64: " << src_salInt64 << std::endl;
    std::cerr << "trg_salInt64: " << trg_salInt64 << std::endl;

    CPPUNIT_ASSERT_MESSAGE("sal_Int64 conversion to ORowSetValue didn't work", src_salInt64 == trg_salInt64);

    Any any_Int64 = v.makeAny();
    ORowSetValue t;
    t.fill(any_Int64);
    trg_salInt64 = t.getLong();

    CPPUNIT_ASSERT_MESSAGE("sal_Int64 conversion from Any didn't work", src_salInt64 == trg_salInt64);
}

void FValueTest::test_uInt64()
{
    sal_uInt64 src_saluInt64 = 10000000000000000001ULL;
    ORowSetValue v(src_saluInt64);
    sal_uInt64 trg_saluInt64 = v.getULong();

    std::cerr << "src_saluInt64: " << src_saluInt64 << std::endl;
    std::cerr << "trg_saluInt64: " << trg_saluInt64 << std::endl;

    CPPUNIT_ASSERT_MESSAGE("sal_uInt64 conversion to ORowSetValue didn't work", src_saluInt64 == trg_saluInt64);

    Any any_uInt64 = v.makeAny();
    ORowSetValue t;
    t.fill(any_uInt64);
    trg_saluInt64 = t.getULong();

    CPPUNIT_ASSERT_MESSAGE("sal_uInt64 conversion from Any didn't work", src_saluInt64 == trg_saluInt64);
}

void FValueTest::test_float()
{
    float src_float = 1.234f;
    ORowSetValue v(src_float);
    float trg_float = v.getFloat();

    std::cerr << "src_float: " << src_float << std::endl;
    std::cerr << "trg_float: " << trg_float << std::endl;

    CPPUNIT_ASSERT_MESSAGE("float conversion to ORowSetValue didn't work", src_float == trg_float);

    Any any_float = v.makeAny();
    ORowSetValue t;
    t.fill(any_float);
    trg_float = t.getFloat();

    CPPUNIT_ASSERT_MESSAGE("float conversion from Any didn't work", src_float == trg_float);
}

void FValueTest::test_double()
{
    double src_double = 1.23456789;
    ORowSetValue v(src_double);
    double trg_double = v.getDouble();

    std::cerr << "src_double: " << src_double << std::endl;
    std::cerr << "trg_double: " << trg_double << std::endl;

    CPPUNIT_ASSERT_MESSAGE("double conversion to ORowSetValue didn't work", src_double == trg_double);

    Any any_double = v.makeAny();
    ORowSetValue t;
    t.fill(any_double);
    trg_double = t.getDouble();

    CPPUNIT_ASSERT_MESSAGE("double conversion from Any didn't work", src_double == trg_double);
}

void FValueTest::test_getString()
{
    bool src_bool_1 = true;
    ORowSetValue v_1(src_bool_1);
    OUString trg_bool_1 = v_1.getString();

    std::cerr << "src_bool_1" << src_bool_1 << std::endl;
    std::cerr << "trg_bool_1: " << trg_bool_1 << std::endl;

    CPPUNIT_ASSERT_MESSAGE("bool to string conversion to ORowSetValue didn't work", trg_bool_1 == "1");

    bool src_bool_0 = false;
    ORowSetValue v_0(src_bool_0);
    OUString trg_bool_0 = v_0.getString();

    std::cerr << "src_bool_0" << src_bool_0 << std::endl;
    std::cerr << "trg_bool_0: " << trg_bool_0 << std::endl;

    CPPUNIT_ASSERT_MESSAGE("bool to string conversion to ORowSetValue didn't work", trg_bool_0 == "0");
}

CPPUNIT_TEST_SUITE_REGISTRATION(FValueTest);

}}

CPPUNIT_PLUGIN_IMPLEMENT();

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */