1*87d2adbcSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*87d2adbcSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*87d2adbcSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*87d2adbcSAndrew Rist  * distributed with this work for additional information
6*87d2adbcSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*87d2adbcSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*87d2adbcSAndrew Rist  * "License"); you may not use this file except in compliance
9*87d2adbcSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*87d2adbcSAndrew Rist  *
11*87d2adbcSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*87d2adbcSAndrew Rist  *
13*87d2adbcSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*87d2adbcSAndrew Rist  * software distributed under the License is distributed on an
15*87d2adbcSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*87d2adbcSAndrew Rist  * KIND, either express or implied.  See the License for the
17*87d2adbcSAndrew Rist  * specific language governing permissions and limitations
18*87d2adbcSAndrew Rist  * under the License.
19*87d2adbcSAndrew Rist  *
20*87d2adbcSAndrew Rist  *************************************************************/
21*87d2adbcSAndrew Rist 
22*87d2adbcSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir 
25cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
26cdf0e10cSrcweir #include "precompiled_sal.hxx"
27cdf0e10cSrcweir // This is a test of helperfunctions
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <osl/time.h>
30cdf0e10cSrcweir #include <osl/thread.hxx>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include "stringhelper.hxx"
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include <testshl/simpleheader.hxx>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir // void isJaBloed()
37cdf0e10cSrcweir // {
38cdf0e10cSrcweir //     t_print("Ist ja echt bloed.\n");
39cdf0e10cSrcweir // }
40cdf0e10cSrcweir 
t_abs64(sal_Int64 _nValue)41cdf0e10cSrcweir inline sal_Int64 t_abs64(sal_Int64 _nValue)
42cdf0e10cSrcweir {
43cdf0e10cSrcweir     // std::abs() seems to have some ambiguity problems (so-texas)
44cdf0e10cSrcweir     // return abs(_nValue);
45cdf0e10cSrcweir     t_print("t_abs64(%ld)\n", _nValue);
46cdf0e10cSrcweir     // CPPUNIT_ASSERT(_nValue < 2147483647);
47cdf0e10cSrcweir 
48cdf0e10cSrcweir     if (_nValue < 0)
49cdf0e10cSrcweir     {
50cdf0e10cSrcweir         _nValue = -_nValue;
51cdf0e10cSrcweir     }
52cdf0e10cSrcweir     return _nValue;
53cdf0e10cSrcweir }
54cdf0e10cSrcweir 
t_print64(sal_Int64 n)55cdf0e10cSrcweir void t_print64(sal_Int64 n)
56cdf0e10cSrcweir {
57cdf0e10cSrcweir     if (n < 0)
58cdf0e10cSrcweir     {
59cdf0e10cSrcweir         // negativ
60cdf0e10cSrcweir         printf("-");
61cdf0e10cSrcweir         n = -n;
62cdf0e10cSrcweir     }
63cdf0e10cSrcweir     if (n > 2147483647)
64cdf0e10cSrcweir     {
65cdf0e10cSrcweir         sal_Int64 n64 = n >> 32;
66cdf0e10cSrcweir         sal_uInt32 n32 = n64 & 0xffffffff;
67cdf0e10cSrcweir         printf("0x%.8x ", n32);
68cdf0e10cSrcweir         n32 = n & 0xffffffff;
69cdf0e10cSrcweir         printf("%.8x (64bit)", n32);
70cdf0e10cSrcweir     }
71cdf0e10cSrcweir     else
72cdf0e10cSrcweir     {
73cdf0e10cSrcweir         sal_uInt32 n32 = n & 0xffffffff;
74cdf0e10cSrcweir         printf("0x%.8x (32bit) ", n32);
75cdf0e10cSrcweir     }
76cdf0e10cSrcweir     printf("\n");
77cdf0e10cSrcweir }
78cdf0e10cSrcweir 
79cdf0e10cSrcweir // -----------------------------------------------------------------------------
80cdf0e10cSrcweir namespace testOfHelperFunctions
81cdf0e10cSrcweir {
82cdf0e10cSrcweir     class test_t_abs64 : public CppUnit::TestFixture
83cdf0e10cSrcweir     {
84cdf0e10cSrcweir     public:
85cdf0e10cSrcweir         void test0();
86cdf0e10cSrcweir         void test1_0();
87cdf0e10cSrcweir         void test1();
88cdf0e10cSrcweir         void test1_1();
89cdf0e10cSrcweir         void test2();
90cdf0e10cSrcweir         void test3();
91cdf0e10cSrcweir         void test4();
92cdf0e10cSrcweir 
93cdf0e10cSrcweir         CPPUNIT_TEST_SUITE( test_t_abs64 );
94cdf0e10cSrcweir         CPPUNIT_TEST( test0 );
95cdf0e10cSrcweir         CPPUNIT_TEST( test1_0 );
96cdf0e10cSrcweir         CPPUNIT_TEST( test1 );
97cdf0e10cSrcweir         CPPUNIT_TEST( test1_1 );
98cdf0e10cSrcweir         CPPUNIT_TEST( test2 );
99cdf0e10cSrcweir         CPPUNIT_TEST( test3 );
100cdf0e10cSrcweir         CPPUNIT_TEST( test4 );
101cdf0e10cSrcweir         CPPUNIT_TEST_SUITE_END( );
102cdf0e10cSrcweir     };
103cdf0e10cSrcweir 
test0()104cdf0e10cSrcweir     void test_t_abs64::test0()
105cdf0e10cSrcweir     {
106cdf0e10cSrcweir         // this values has an overrun!
107cdf0e10cSrcweir         sal_Int32 n32 = 2147483648;
108cdf0e10cSrcweir         t_print("n32 should be -2^31 is: %d\n", n32);
109cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("n32!=2147483648", n32 == -2147483648 );
110cdf0e10cSrcweir     }
111cdf0e10cSrcweir 
112cdf0e10cSrcweir 
test1_0()113cdf0e10cSrcweir     void test_t_abs64::test1_0()
114cdf0e10cSrcweir     {
115cdf0e10cSrcweir         sal_Int64 n;
116cdf0e10cSrcweir         n = 1073741824;
117cdf0e10cSrcweir         n <<= 9;
118cdf0e10cSrcweir         t_print("Value of n is ");
119cdf0e10cSrcweir         t_print64(n);
120cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("n=2^30 << 9", t_abs64(n) > 0 );
121cdf0e10cSrcweir     }
122cdf0e10cSrcweir 
test1()123cdf0e10cSrcweir     void test_t_abs64::test1()
124cdf0e10cSrcweir     {
125cdf0e10cSrcweir         sal_Int64 n;
126cdf0e10cSrcweir         n = 2147483648 << 8;
127cdf0e10cSrcweir         t_print("Value of n is ");
128cdf0e10cSrcweir         t_print64(n);
129cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("n=2^31 << 8", t_abs64(n) > 0 );
130cdf0e10cSrcweir     }
test1_1()131cdf0e10cSrcweir     void test_t_abs64::test1_1()
132cdf0e10cSrcweir     {
133cdf0e10cSrcweir         sal_Int64 n;
134cdf0e10cSrcweir         n = sal_Int64(2147483648) << 8;
135cdf0e10cSrcweir         t_print("Value of n is ");
136cdf0e10cSrcweir         t_print64(n);
137cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("n=2^31 << 8", t_abs64(n) > 0 );
138cdf0e10cSrcweir     }
139cdf0e10cSrcweir 
test2()140cdf0e10cSrcweir     void test_t_abs64::test2()
141cdf0e10cSrcweir     {
142cdf0e10cSrcweir         sal_Int64 n;
143cdf0e10cSrcweir         n = 2147483648 << 1;
144cdf0e10cSrcweir         t_print("Value of n is ");
145cdf0e10cSrcweir         t_print64(n);
146cdf0e10cSrcweir 
147cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("(2147483648 << 1) is != 0", n != 0 );
148cdf0e10cSrcweir 
149cdf0e10cSrcweir         sal_Int64 n2 = 2147483648 * 2;
150cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("2147483648 * 2 is != 0", n2 != 0 );
151cdf0e10cSrcweir 
152cdf0e10cSrcweir         sal_Int64 n3 = 4294967296LL;
153cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("4294967296 is != 0", n3 != 0 );
154cdf0e10cSrcweir 
155cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("n=2^31 << 1, n2 = 2^31 * 2, n3 = 2^32, all should equal!", n == n2 && n == n3 );
156cdf0e10cSrcweir     }
157cdf0e10cSrcweir 
158cdf0e10cSrcweir 
test3()159cdf0e10cSrcweir     void test_t_abs64::test3()
160cdf0e10cSrcweir     {
161cdf0e10cSrcweir         sal_Int64 n = 0;
162cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("n=0", t_abs64(n) == 0 );
163cdf0e10cSrcweir 
164cdf0e10cSrcweir         n = 1;
165cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("n=1", t_abs64(n) > 0 );
166cdf0e10cSrcweir 
167cdf0e10cSrcweir         n = 2147483647;
168cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("n=2^31 - 1", t_abs64(n) > 0 );
169cdf0e10cSrcweir 
170cdf0e10cSrcweir         n = 2147483648;
171cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("n=2^31", t_abs64(n) > 0 );
172cdf0e10cSrcweir     }
173cdf0e10cSrcweir 
test4()174cdf0e10cSrcweir     void test_t_abs64::test4()
175cdf0e10cSrcweir     {
176cdf0e10cSrcweir         sal_Int64 n = 0;
177cdf0e10cSrcweir         n = -1;
178cdf0e10cSrcweir         t_print("Value of n is -1 : ");
179cdf0e10cSrcweir         t_print64(n);
180cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("n=-1", t_abs64(n) > 0 );
181cdf0e10cSrcweir 
182cdf0e10cSrcweir         n = -2147483648;
183cdf0e10cSrcweir         t_print("Value of n is -2^31 : ");
184cdf0e10cSrcweir         t_print64(n);
185cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("n=-2^31", t_abs64(n) > 0 );
186cdf0e10cSrcweir 
187cdf0e10cSrcweir         n = -8589934592LL;
188cdf0e10cSrcweir         t_print("Value of n is -2^33 : ");
189cdf0e10cSrcweir         t_print64(n);
190cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("n=-2^33", t_abs64(n) > 0 );
191cdf0e10cSrcweir     }
192cdf0e10cSrcweir 
193cdf0e10cSrcweir 
194cdf0e10cSrcweir // -----------------------------------------------------------------------------
195cdf0e10cSrcweir     class test_t_print : public CppUnit::TestFixture
196cdf0e10cSrcweir     {
197cdf0e10cSrcweir     public:
198cdf0e10cSrcweir         void t_print_001();
199cdf0e10cSrcweir 
200cdf0e10cSrcweir         CPPUNIT_TEST_SUITE( test_t_print );
201cdf0e10cSrcweir         CPPUNIT_TEST( t_print_001 );
202cdf0e10cSrcweir         CPPUNIT_TEST_SUITE_END( );
203cdf0e10cSrcweir     };
204cdf0e10cSrcweir 
t_print_001()205cdf0e10cSrcweir     void test_t_print::t_print_001( )
206cdf0e10cSrcweir     {
207cdf0e10cSrcweir         t_print("This is only a test of some helper functions\n");
208cdf0e10cSrcweir         sal_Int32 nValue = 12345;
209cdf0e10cSrcweir         t_print("a value %d (should be 12345)\n", nValue);
210cdf0e10cSrcweir 
211cdf0e10cSrcweir         rtl::OString sValue("foo bar");
212cdf0e10cSrcweir         t_print("a String '%s' (should be 'foo bar')\n", sValue.getStr());
213cdf0e10cSrcweir 
214cdf0e10cSrcweir         rtl::OUString suValue(rtl::OUString::createFromAscii("a unicode string"));
215cdf0e10cSrcweir         sValue <<= suValue;
216cdf0e10cSrcweir         t_print("a String '%s'\n", sValue.getStr());
217cdf0e10cSrcweir     }
218cdf0e10cSrcweir 
219cdf0e10cSrcweir 
220cdf0e10cSrcweir     class StopWatch
221cdf0e10cSrcweir     {
222cdf0e10cSrcweir         TimeValue m_aStartTime;
223cdf0e10cSrcweir         TimeValue m_aEndTime;
224cdf0e10cSrcweir         bool m_bStarted;
225cdf0e10cSrcweir     public:
StopWatch()226cdf0e10cSrcweir         StopWatch()
227cdf0e10cSrcweir                 :m_bStarted(false)
228cdf0e10cSrcweir             {
229cdf0e10cSrcweir             }
230cdf0e10cSrcweir 
start()231cdf0e10cSrcweir         void start()
232cdf0e10cSrcweir             {
233cdf0e10cSrcweir                 m_bStarted = true;
234cdf0e10cSrcweir                 osl_getSystemTime(&m_aStartTime);
235cdf0e10cSrcweir             }
stop()236cdf0e10cSrcweir         void stop()
237cdf0e10cSrcweir             {
238cdf0e10cSrcweir                 osl_getSystemTime(&m_aEndTime);
239cdf0e10cSrcweir                 OSL_ENSURE(m_bStarted, "Not Started.");
240cdf0e10cSrcweir                 m_bStarted = false;
241cdf0e10cSrcweir             }
makeTwoDigits(rtl::OString const & _sStr)242cdf0e10cSrcweir         rtl::OString makeTwoDigits(rtl::OString const& _sStr)
243cdf0e10cSrcweir             {
244cdf0e10cSrcweir                 rtl::OString sBack;
245cdf0e10cSrcweir                 if (_sStr.getLength() == 0)
246cdf0e10cSrcweir                 {
247cdf0e10cSrcweir                     sBack = "00";
248cdf0e10cSrcweir                 }
249cdf0e10cSrcweir                 else
250cdf0e10cSrcweir                 {
251cdf0e10cSrcweir                     if (_sStr.getLength() == 1)
252cdf0e10cSrcweir                     {
253cdf0e10cSrcweir                         sBack = "0" + _sStr;
254cdf0e10cSrcweir                     }
255cdf0e10cSrcweir                     else
256cdf0e10cSrcweir                     {
257cdf0e10cSrcweir                         sBack = _sStr;
258cdf0e10cSrcweir                     }
259cdf0e10cSrcweir                 }
260cdf0e10cSrcweir                 return sBack;
261cdf0e10cSrcweir             }
makeThreeDigits(rtl::OString const & _sStr)262cdf0e10cSrcweir         rtl::OString makeThreeDigits(rtl::OString const& _sStr)
263cdf0e10cSrcweir             {
264cdf0e10cSrcweir                 rtl::OString sBack;
265cdf0e10cSrcweir                 if (_sStr.getLength() == 0)
266cdf0e10cSrcweir                 {
267cdf0e10cSrcweir                     sBack = "000";
268cdf0e10cSrcweir                 }
269cdf0e10cSrcweir                 else
270cdf0e10cSrcweir                 {
271cdf0e10cSrcweir                     if (_sStr.getLength() == 1)
272cdf0e10cSrcweir                     {
273cdf0e10cSrcweir                         sBack = "00" + _sStr;
274cdf0e10cSrcweir                     }
275cdf0e10cSrcweir                     else
276cdf0e10cSrcweir                     {
277cdf0e10cSrcweir                         if (_sStr.getLength() == 2)
278cdf0e10cSrcweir                         {
279cdf0e10cSrcweir                             sBack = "0" + _sStr;
280cdf0e10cSrcweir                         }
281cdf0e10cSrcweir                         else
282cdf0e10cSrcweir                         {
283cdf0e10cSrcweir                             sBack = _sStr;
284cdf0e10cSrcweir                         }
285cdf0e10cSrcweir                     }
286cdf0e10cSrcweir                 }
287cdf0e10cSrcweir                 return sBack;
288cdf0e10cSrcweir             }
289cdf0e10cSrcweir 
showTime(const rtl::OString & aWhatStr)290cdf0e10cSrcweir         void  showTime(const rtl::OString & aWhatStr)
291cdf0e10cSrcweir             {
292cdf0e10cSrcweir                 OSL_ENSURE(!m_bStarted, "Not Stopped.");
293cdf0e10cSrcweir 
294cdf0e10cSrcweir                 sal_Int32 nSeconds = m_aEndTime.Seconds - m_aStartTime.Seconds;
295cdf0e10cSrcweir                 sal_Int32 nNanoSec = sal_Int32(m_aEndTime.Nanosec) - sal_Int32(m_aStartTime.Nanosec);
296cdf0e10cSrcweir                 // printf("Seconds: %d Nanosec: %d ", nSeconds, nNanoSec);
297cdf0e10cSrcweir                 if (nNanoSec < 0)
298cdf0e10cSrcweir                 {
299cdf0e10cSrcweir                     nNanoSec = 1000000000 + nNanoSec;
300cdf0e10cSrcweir                     nSeconds--;
301cdf0e10cSrcweir                     // printf(" NEW Seconds: %d Nanosec: %d\n", nSeconds, nNanoSec);
302cdf0e10cSrcweir                 }
303cdf0e10cSrcweir 
304cdf0e10cSrcweir                 rtl::OString aStr = "Time for ";
305cdf0e10cSrcweir                 aStr += aWhatStr;
306cdf0e10cSrcweir                 aStr += " ";
307cdf0e10cSrcweir                 aStr += makeTwoDigits(rtl::OString::valueOf(nSeconds / 3600));
308cdf0e10cSrcweir                 aStr += ":";
309cdf0e10cSrcweir                 aStr += makeTwoDigits(rtl::OString::valueOf((nSeconds % 3600) / 60));
310cdf0e10cSrcweir                 aStr += ":";
311cdf0e10cSrcweir                 aStr += makeTwoDigits(rtl::OString::valueOf((nSeconds % 60)));
312cdf0e10cSrcweir                 aStr += ":";
313cdf0e10cSrcweir                 aStr += makeThreeDigits(rtl::OString::valueOf((nNanoSec % 1000000000) / 1000000));
314cdf0e10cSrcweir                 aStr += ":";
315cdf0e10cSrcweir                 aStr += makeThreeDigits(rtl::OString::valueOf((nNanoSec % 1000000) / 1000));
316cdf0e10cSrcweir                 aStr += ":";
317cdf0e10cSrcweir                 aStr += makeThreeDigits(rtl::OString::valueOf((nNanoSec % 1000)));
318cdf0e10cSrcweir 
319cdf0e10cSrcweir                 printf("%s\n", aStr.getStr());
320cdf0e10cSrcweir                 // cout << aStr.getStr() << endl;
321cdf0e10cSrcweir             }
322cdf0e10cSrcweir 
323cdf0e10cSrcweir     };
324cdf0e10cSrcweir 
isEqualTimeValue(const TimeValue * time1,const TimeValue * time2)325cdf0e10cSrcweir static sal_Bool isEqualTimeValue ( const TimeValue* time1,  const TimeValue* time2)
326cdf0e10cSrcweir {
327cdf0e10cSrcweir 	if( time1->Seconds == time2->Seconds &&
328cdf0e10cSrcweir 		time1->Nanosec == time2->Nanosec)
329cdf0e10cSrcweir 		return sal_True;
330cdf0e10cSrcweir 	else
331cdf0e10cSrcweir 		return sal_False;
332cdf0e10cSrcweir }
333cdf0e10cSrcweir 
isGreaterTimeValue(const TimeValue * time1,const TimeValue * time2)334cdf0e10cSrcweir static sal_Bool isGreaterTimeValue(  const TimeValue* time1,  const TimeValue* time2)
335cdf0e10cSrcweir {
336cdf0e10cSrcweir 	sal_Bool retval= sal_False;
337cdf0e10cSrcweir 	if ( time1->Seconds > time2->Seconds)
338cdf0e10cSrcweir 		retval= sal_True;
339cdf0e10cSrcweir 	else if ( time1->Seconds == time2->Seconds)
340cdf0e10cSrcweir 	{
341cdf0e10cSrcweir 		if( time1->Nanosec > time2->Nanosec)
342cdf0e10cSrcweir 			retval= sal_True;
343cdf0e10cSrcweir 	}
344cdf0e10cSrcweir 	return retval;
345cdf0e10cSrcweir }
346cdf0e10cSrcweir 
isGreaterEqualTimeValue(const TimeValue * time1,const TimeValue * time2)347cdf0e10cSrcweir static sal_Bool isGreaterEqualTimeValue( const TimeValue* time1, const TimeValue* time2)
348cdf0e10cSrcweir {
349cdf0e10cSrcweir 	if( isEqualTimeValue( time1, time2) )
350cdf0e10cSrcweir 		return sal_True;
351cdf0e10cSrcweir 	else if( isGreaterTimeValue( time1, time2))
352cdf0e10cSrcweir 		return sal_True;
353cdf0e10cSrcweir 	else
354cdf0e10cSrcweir 		return sal_False;
355cdf0e10cSrcweir }
356cdf0e10cSrcweir 
isBTimeGreaterATime(TimeValue const & A,TimeValue const & B)357cdf0e10cSrcweir bool isBTimeGreaterATime(TimeValue const& A, TimeValue const& B)
358cdf0e10cSrcweir {
359cdf0e10cSrcweir 	if (B.Seconds > A.Seconds) return true;
360cdf0e10cSrcweir 	if (B.Nanosec > A.Nanosec) return true;
361cdf0e10cSrcweir 
362cdf0e10cSrcweir 	// lower or equal
363cdf0e10cSrcweir 	return false;
364cdf0e10cSrcweir }
365cdf0e10cSrcweir     // -----------------------------------------------------------------------------
366cdf0e10cSrcweir 
367cdf0e10cSrcweir 
368cdf0e10cSrcweir     class test_TimeValues : public CppUnit::TestFixture
369cdf0e10cSrcweir     {
370cdf0e10cSrcweir     public:
371cdf0e10cSrcweir 
372cdf0e10cSrcweir         void t_time1();
373cdf0e10cSrcweir         void t_time2();
374cdf0e10cSrcweir         void t_time3();
375cdf0e10cSrcweir 
376cdf0e10cSrcweir         CPPUNIT_TEST_SUITE( test_TimeValues );
377cdf0e10cSrcweir         CPPUNIT_TEST( t_time1 );
378cdf0e10cSrcweir         CPPUNIT_TEST( t_time2 );
379cdf0e10cSrcweir         CPPUNIT_TEST( t_time3 );
380cdf0e10cSrcweir         CPPUNIT_TEST_SUITE_END( );
381cdf0e10cSrcweir     };
382cdf0e10cSrcweir 
t_time1()383cdf0e10cSrcweir void test_TimeValues::t_time1()
384cdf0e10cSrcweir {
385cdf0e10cSrcweir     StopWatch aWatch;
386cdf0e10cSrcweir     aWatch.start();
387cdf0e10cSrcweir     TimeValue aTimeValue={3,0};
388cdf0e10cSrcweir     osl::Thread::wait(aTimeValue);
389cdf0e10cSrcweir     aWatch.stop();
390cdf0e10cSrcweir     aWatch.showTime("Wait for 3 seconds");
391cdf0e10cSrcweir }
392cdf0e10cSrcweir 
t_time2()393cdf0e10cSrcweir void test_TimeValues::t_time2()
394cdf0e10cSrcweir {
395cdf0e10cSrcweir     t_print("Wait repeats 20 times.\n");
396cdf0e10cSrcweir     int i=0;
397cdf0e10cSrcweir     while(i++<20)
398cdf0e10cSrcweir     {
399cdf0e10cSrcweir         StopWatch aWatch;
400cdf0e10cSrcweir         aWatch.start();
401cdf0e10cSrcweir         TimeValue aTimeValue={0,1000 * 1000 * 500};
402cdf0e10cSrcweir         osl::Thread::wait(aTimeValue);
403cdf0e10cSrcweir         aWatch.stop();
404cdf0e10cSrcweir         aWatch.showTime("wait for 500msec");
405cdf0e10cSrcweir     }
406cdf0e10cSrcweir }
407cdf0e10cSrcweir 
t_time3()408cdf0e10cSrcweir void test_TimeValues::t_time3()
409cdf0e10cSrcweir {
410cdf0e10cSrcweir     t_print("Wait repeats 100 times.\n");
411cdf0e10cSrcweir     int i=0;
412cdf0e10cSrcweir     while(i++<20)
413cdf0e10cSrcweir     {
414cdf0e10cSrcweir         StopWatch aWatch;
415cdf0e10cSrcweir         aWatch.start();
416cdf0e10cSrcweir         TimeValue aTimeValue={0,1000*1000*100};
417cdf0e10cSrcweir         osl::Thread::wait(aTimeValue);
418cdf0e10cSrcweir         aWatch.stop();
419cdf0e10cSrcweir         aWatch.showTime("wait for 100msec");
420cdf0e10cSrcweir     }
421cdf0e10cSrcweir }
422cdf0e10cSrcweir 
423cdf0e10cSrcweir     // void demoTimeValue()
424cdf0e10cSrcweir     // {
425cdf0e10cSrcweir     //     TimeValue aStartTime, aEndTime;
426cdf0e10cSrcweir     //     osl_getSystemTime(&aStartTime);
427cdf0e10cSrcweir     //     // testSession(xORB, false);
428cdf0e10cSrcweir     //     osl_getSystemTime(&aEndTime);
429cdf0e10cSrcweir     //
430cdf0e10cSrcweir     //     sal_Int32 nSeconds = aEndTime.Seconds - aStartTime.Seconds;
431cdf0e10cSrcweir     //     sal_Int32 nNanoSec = aEndTime.Nanosec - aStartTime.Nanosec;
432cdf0e10cSrcweir     //     if (nNanoSec < 0)
433cdf0e10cSrcweir     //     {
434cdf0e10cSrcweir     //         nNanoSec = 1000000000 - nNanoSec;
435cdf0e10cSrcweir     //         nSeconds++;
436cdf0e10cSrcweir     //     }
437cdf0e10cSrcweir     //
438cdf0e10cSrcweir     //     // cout << "Time: " << nSeconds << ". " << nNanoSec << endl;
439cdf0e10cSrcweir     // }
440cdf0e10cSrcweir 
441cdf0e10cSrcweir 
442cdf0e10cSrcweir } // namespace testOfHelperFunctions
443cdf0e10cSrcweir 
444cdf0e10cSrcweir // -----------------------------------------------------------------------------
445cdf0e10cSrcweir CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( testOfHelperFunctions::test_t_print, "helperFunctions" );
446cdf0e10cSrcweir CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( testOfHelperFunctions::test_t_abs64, "helperFunctions" );
447cdf0e10cSrcweir CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( testOfHelperFunctions::test_TimeValues, "helperFunctions" );
448cdf0e10cSrcweir 
449cdf0e10cSrcweir // -----------------------------------------------------------------------------
450cdf0e10cSrcweir NOADDITIONAL;
451