testHelperFunctions.cxx (87d2adbc) testHelperFunctions.cxx (faf81e80)
1/**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance

--- 17 unchanged lines hidden (view full) ---

26#include "precompiled_sal.hxx"
27// This is a test of helperfunctions
28
29#include <osl/time.h>
30#include <osl/thread.hxx>
31
32#include "stringhelper.hxx"
33
1/**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance

--- 17 unchanged lines hidden (view full) ---

26#include "precompiled_sal.hxx"
27// This is a test of helperfunctions
28
29#include <osl/time.h>
30#include <osl/thread.hxx>
31
32#include "stringhelper.hxx"
33
34#include <testshl/simpleheader.hxx>
34#include "gtest/gtest.h"
35
36// void isJaBloed()
37// {
35
36// void isJaBloed()
37// {
38// t_print("Ist ja echt bloed.\n");
38// printf("Ist ja echt bloed.\n");
39// }
40
41inline sal_Int64 t_abs64(sal_Int64 _nValue)
42{
43 // std::abs() seems to have some ambiguity problems (so-texas)
44 // return abs(_nValue);
39// }
40
41inline sal_Int64 t_abs64(sal_Int64 _nValue)
42{
43 // std::abs() seems to have some ambiguity problems (so-texas)
44 // return abs(_nValue);
45 t_print("t_abs64(%ld)\n", _nValue);
46 // CPPUNIT_ASSERT(_nValue < 2147483647);
45 printf("t_abs64(%ld)\n", _nValue);
46 // ASSERT_TRUE(_nValue < 2147483647);
47
48 if (_nValue < 0)
49 {
50 _nValue = -_nValue;
51 }
52 return _nValue;
53}
54
47
48 if (_nValue < 0)
49 {
50 _nValue = -_nValue;
51 }
52 return _nValue;
53}
54
55void t_print64(sal_Int64 n)
55void printf64(sal_Int64 n)
56{
57 if (n < 0)
58 {
59 // negativ
60 printf("-");
61 n = -n;
62 }
63 if (n > 2147483647)

--- 10 unchanged lines hidden (view full) ---

74 printf("0x%.8x (32bit) ", n32);
75 }
76 printf("\n");
77}
78
79// -----------------------------------------------------------------------------
80namespace testOfHelperFunctions
81{
56{
57 if (n < 0)
58 {
59 // negativ
60 printf("-");
61 n = -n;
62 }
63 if (n > 2147483647)

--- 10 unchanged lines hidden (view full) ---

74 printf("0x%.8x (32bit) ", n32);
75 }
76 printf("\n");
77}
78
79// -----------------------------------------------------------------------------
80namespace testOfHelperFunctions
81{
82 class test_t_abs64 : public CppUnit::TestFixture
82 class test_t_abs64 : public ::testing::Test
83 {
83 {
84 public:
85 void test0();
86 void test1_0();
87 void test1();
88 void test1_1();
89 void test2();
90 void test3();
91 void test4();
92
93 CPPUNIT_TEST_SUITE( test_t_abs64 );
94 CPPUNIT_TEST( test0 );
95 CPPUNIT_TEST( test1_0 );
96 CPPUNIT_TEST( test1 );
97 CPPUNIT_TEST( test1_1 );
98 CPPUNIT_TEST( test2 );
99 CPPUNIT_TEST( test3 );
100 CPPUNIT_TEST( test4 );
101 CPPUNIT_TEST_SUITE_END( );
102 };
103
84 };
85
104 void test_t_abs64::test0()
86 TEST_F(test_t_abs64, test0)
105 {
106 // this values has an overrun!
107 sal_Int32 n32 = 2147483648;
87 {
88 // this values has an overrun!
89 sal_Int32 n32 = 2147483648;
108 t_print("n32 should be -2^31 is: %d\n", n32);
109 CPPUNIT_ASSERT_MESSAGE("n32!=2147483648", n32 == -2147483648 );
90 printf("n32 should be -2^31 is: %d\n", n32);
91 ASSERT_TRUE(n32 == -2147483648 ) << "n32!=2147483648";
110 }
111
112
92 }
93
94
113 void test_t_abs64::test1_0()
95 TEST_F(test_t_abs64,test1_0)
114 {
115 sal_Int64 n;
116 n = 1073741824;
117 n <<= 9;
96 {
97 sal_Int64 n;
98 n = 1073741824;
99 n <<= 9;
118 t_print("Value of n is ");
119 t_print64(n);
120 CPPUNIT_ASSERT_MESSAGE("n=2^30 << 9", t_abs64(n) > 0 );
100 printf("Value of n is ");
101 printf64(n);
102 ASSERT_TRUE(t_abs64(n) > 0) << "n=2^30 << 9";
121 }
122
103 }
104
123 void test_t_abs64::test1()
105 TEST_F(test_t_abs64, test1)
124 {
125 sal_Int64 n;
126 n = 2147483648 << 8;
106 {
107 sal_Int64 n;
108 n = 2147483648 << 8;
127 t_print("Value of n is ");
128 t_print64(n);
129 CPPUNIT_ASSERT_MESSAGE("n=2^31 << 8", t_abs64(n) > 0 );
109 printf("Value of n is ");
110 printf64(n);
111 ASSERT_TRUE(t_abs64(n) > 0) << "n=2^31 << 8";
130 }
112 }
131 void test_t_abs64::test1_1()
113 TEST_F(test_t_abs64, test1_1)
132 {
133 sal_Int64 n;
134 n = sal_Int64(2147483648) << 8;
114 {
115 sal_Int64 n;
116 n = sal_Int64(2147483648) << 8;
135 t_print("Value of n is ");
136 t_print64(n);
137 CPPUNIT_ASSERT_MESSAGE("n=2^31 << 8", t_abs64(n) > 0 );
117 printf("Value of n is ");
118 printf64(n);
119 ASSERT_TRUE(t_abs64(n) > 0) << "n=2^31 << 8";
138 }
139
120 }
121
140 void test_t_abs64::test2()
122 TEST_F(test_t_abs64, test2)
141 {
142 sal_Int64 n;
143 n = 2147483648 << 1;
123 {
124 sal_Int64 n;
125 n = 2147483648 << 1;
144 t_print("Value of n is ");
145 t_print64(n);
126 printf("Value of n is ");
127 printf64(n);
146
128
147 CPPUNIT_ASSERT_MESSAGE("(2147483648 << 1) is != 0", n != 0 );
129 ASSERT_TRUE(n != 0) << "(2147483648 << 1) is != 0";
148
149 sal_Int64 n2 = 2147483648 * 2;
130
131 sal_Int64 n2 = 2147483648 * 2;
150 CPPUNIT_ASSERT_MESSAGE("2147483648 * 2 is != 0", n2 != 0 );
132 ASSERT_TRUE(n2 != 0) << "2147483648 * 2 is != 0";
151
152 sal_Int64 n3 = 4294967296LL;
133
134 sal_Int64 n3 = 4294967296LL;
153 CPPUNIT_ASSERT_MESSAGE("4294967296 is != 0", n3 != 0 );
135 ASSERT_TRUE(n3 != 0) << "4294967296 is != 0";
154
136
155 CPPUNIT_ASSERT_MESSAGE("n=2^31 << 1, n2 = 2^31 * 2, n3 = 2^32, all should equal!", n == n2 && n == n3 );
137 ASSERT_TRUE(n == n2 && n == n3) << "n=2^31 << 1, n2 = 2^31 * 2, n3 = 2^32, all should equal!";
156 }
157
158
138 }
139
140
159 void test_t_abs64::test3()
141 TEST_F(test_t_abs64, test3)
160 {
161 sal_Int64 n = 0;
142 {
143 sal_Int64 n = 0;
162 CPPUNIT_ASSERT_MESSAGE("n=0", t_abs64(n) == 0 );
144 ASSERT_TRUE(t_abs64(n) == 0) << "n=0";
163
164 n = 1;
145
146 n = 1;
165 CPPUNIT_ASSERT_MESSAGE("n=1", t_abs64(n) > 0 );
147 ASSERT_TRUE(t_abs64(n) > 0) << "n=1";
166
167 n = 2147483647;
148
149 n = 2147483647;
168 CPPUNIT_ASSERT_MESSAGE("n=2^31 - 1", t_abs64(n) > 0 );
150 ASSERT_TRUE(t_abs64(n) > 0) << "n=2^31 - 1";
169
170 n = 2147483648;
151
152 n = 2147483648;
171 CPPUNIT_ASSERT_MESSAGE("n=2^31", t_abs64(n) > 0 );
153 ASSERT_TRUE(t_abs64(n) > 0) << "n=2^31";
172 }
173
154 }
155
174 void test_t_abs64::test4()
156 TEST_F(test_t_abs64, test4)
175 {
176 sal_Int64 n = 0;
177 n = -1;
157 {
158 sal_Int64 n = 0;
159 n = -1;
178 t_print("Value of n is -1 : ");
179 t_print64(n);
180 CPPUNIT_ASSERT_MESSAGE("n=-1", t_abs64(n) > 0 );
160 printf("Value of n is -1 : ");
161 printf64(n);
162 ASSERT_TRUE(t_abs64(n) > 0) << "n=-1";
181
182 n = -2147483648;
163
164 n = -2147483648;
183 t_print("Value of n is -2^31 : ");
184 t_print64(n);
185 CPPUNIT_ASSERT_MESSAGE("n=-2^31", t_abs64(n) > 0 );
165 printf("Value of n is -2^31 : ");
166 printf64(n);
167 ASSERT_TRUE(t_abs64(n) > 0) << "n=-2^31";
186
187 n = -8589934592LL;
168
169 n = -8589934592LL;
188 t_print("Value of n is -2^33 : ");
189 t_print64(n);
190 CPPUNIT_ASSERT_MESSAGE("n=-2^33", t_abs64(n) > 0 );
170 printf("Value of n is -2^33 : ");
171 printf64(n);
172 ASSERT_TRUE(t_abs64(n) > 0) << "n=-2^33";
191 }
192
193
194// -----------------------------------------------------------------------------
173 }
174
175
176// -----------------------------------------------------------------------------
195 class test_t_print : public CppUnit::TestFixture
177 class test_printf : public ::testing::Test
196 {
178 {
197 public:
198 void t_print_001();
199
200 CPPUNIT_TEST_SUITE( test_t_print );
201 CPPUNIT_TEST( t_print_001 );
202 CPPUNIT_TEST_SUITE_END( );
203 };
204
179 };
180
205 void test_t_print::t_print_001( )
181 TEST_F(test_printf, printf_001)
206 {
182 {
207 t_print("This is only a test of some helper functions\n");
183 printf("This is only a test of some helper functions\n");
208 sal_Int32 nValue = 12345;
184 sal_Int32 nValue = 12345;
209 t_print("a value %d (should be 12345)\n", nValue);
185 printf("a value %d (should be 12345)\n", nValue);
210
211 rtl::OString sValue("foo bar");
186
187 rtl::OString sValue("foo bar");
212 t_print("a String '%s' (should be 'foo bar')\n", sValue.getStr());
188 printf("a String '%s' (should be 'foo bar')\n", sValue.getStr());
213
214 rtl::OUString suValue(rtl::OUString::createFromAscii("a unicode string"));
215 sValue <<= suValue;
189
190 rtl::OUString suValue(rtl::OUString::createFromAscii("a unicode string"));
191 sValue <<= suValue;
216 t_print("a String '%s'\n", sValue.getStr());
192 printf("a String '%s'\n", sValue.getStr());
217 }
218
219
220 class StopWatch
221 {
193 }
194
195
196 class StopWatch
197 {
198 protected:
222 TimeValue m_aStartTime;
223 TimeValue m_aEndTime;
224 bool m_bStarted;
225 public:
226 StopWatch()
227 :m_bStarted(false)
228 {
229 }

--- 130 unchanged lines hidden (view full) ---

360 if (B.Nanosec > A.Nanosec) return true;
361
362 // lower or equal
363 return false;
364}
365 // -----------------------------------------------------------------------------
366
367
199 TimeValue m_aStartTime;
200 TimeValue m_aEndTime;
201 bool m_bStarted;
202 public:
203 StopWatch()
204 :m_bStarted(false)
205 {
206 }

--- 130 unchanged lines hidden (view full) ---

337 if (B.Nanosec > A.Nanosec) return true;
338
339 // lower or equal
340 return false;
341}
342 // -----------------------------------------------------------------------------
343
344
368 class test_TimeValues : public CppUnit::TestFixture
345 class test_TimeValues : public ::testing::Test
369 {
346 {
370 public:
371
372 void t_time1();
373 void t_time2();
374 void t_time3();
375
376 CPPUNIT_TEST_SUITE( test_TimeValues );
377 CPPUNIT_TEST( t_time1 );
378 CPPUNIT_TEST( t_time2 );
379 CPPUNIT_TEST( t_time3 );
380 CPPUNIT_TEST_SUITE_END( );
381 };
382
347 };
348
383void test_TimeValues::t_time1()
349TEST_F(test_TimeValues, t_time1)
384{
385 StopWatch aWatch;
386 aWatch.start();
387 TimeValue aTimeValue={3,0};
388 osl::Thread::wait(aTimeValue);
389 aWatch.stop();
390 aWatch.showTime("Wait for 3 seconds");
391}
392
350{
351 StopWatch aWatch;
352 aWatch.start();
353 TimeValue aTimeValue={3,0};
354 osl::Thread::wait(aTimeValue);
355 aWatch.stop();
356 aWatch.showTime("Wait for 3 seconds");
357}
358
393void test_TimeValues::t_time2()
359TEST_F(test_TimeValues, t_time2)
394{
360{
395 t_print("Wait repeats 20 times.\n");
361 printf("Wait repeats 20 times.\n");
396 int i=0;
397 while(i++<20)
398 {
399 StopWatch aWatch;
400 aWatch.start();
401 TimeValue aTimeValue={0,1000 * 1000 * 500};
402 osl::Thread::wait(aTimeValue);
403 aWatch.stop();
404 aWatch.showTime("wait for 500msec");
405 }
406}
407
362 int i=0;
363 while(i++<20)
364 {
365 StopWatch aWatch;
366 aWatch.start();
367 TimeValue aTimeValue={0,1000 * 1000 * 500};
368 osl::Thread::wait(aTimeValue);
369 aWatch.stop();
370 aWatch.showTime("wait for 500msec");
371 }
372}
373
408void test_TimeValues::t_time3()
374TEST_F(test_TimeValues, t_time3)
409{
375{
410 t_print("Wait repeats 100 times.\n");
376 printf("Wait repeats 100 times.\n");
411 int i=0;
412 while(i++<20)
413 {
414 StopWatch aWatch;
415 aWatch.start();
416 TimeValue aTimeValue={0,1000*1000*100};
417 osl::Thread::wait(aTimeValue);
418 aWatch.stop();

--- 17 unchanged lines hidden (view full) ---

436 // }
437 //
438 // // cout << "Time: " << nSeconds << ". " << nNanoSec << endl;
439 // }
440
441
442} // namespace testOfHelperFunctions
443
377 int i=0;
378 while(i++<20)
379 {
380 StopWatch aWatch;
381 aWatch.start();
382 TimeValue aTimeValue={0,1000*1000*100};
383 osl::Thread::wait(aTimeValue);
384 aWatch.stop();

--- 17 unchanged lines hidden (view full) ---

402 // }
403 //
404 // // cout << "Time: " << nSeconds << ". " << nNanoSec << endl;
405 // }
406
407
408} // namespace testOfHelperFunctions
409
444// -----------------------------------------------------------------------------
445CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( testOfHelperFunctions::test_t_print, "helperFunctions" );
446CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( testOfHelperFunctions::test_t_abs64, "helperFunctions" );
447CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( testOfHelperFunctions::test_TimeValues, "helperFunctions" );
448
449// -----------------------------------------------------------------------------
450NOADDITIONAL;
410int main(int argc, char **argv)
411{
412 ::testing::InitGoogleTest(&argc, argv);
413 return RUN_ALL_TESTS();
414}