xref: /aoo42x/main/sal/qa/osl/process/osl_Thread.cxx (revision 44e8df1f)
187d2adbcSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
387d2adbcSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
487d2adbcSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
587d2adbcSAndrew Rist  * distributed with this work for additional information
687d2adbcSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
787d2adbcSAndrew Rist  * to you under the Apache License, Version 2.0 (the
887d2adbcSAndrew Rist  * "License"); you may not use this file except in compliance
987d2adbcSAndrew Rist  * with the License.  You may obtain a copy of the License at
1087d2adbcSAndrew Rist  *
1187d2adbcSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
1287d2adbcSAndrew Rist  *
1387d2adbcSAndrew Rist  * Unless required by applicable law or agreed to in writing,
1487d2adbcSAndrew Rist  * software distributed under the License is distributed on an
1587d2adbcSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1687d2adbcSAndrew Rist  * KIND, either express or implied.  See the License for the
1787d2adbcSAndrew Rist  * specific language governing permissions and limitations
1887d2adbcSAndrew Rist  * under the License.
1987d2adbcSAndrew Rist  *
2087d2adbcSAndrew Rist  *************************************************************/
2187d2adbcSAndrew Rist 
2287d2adbcSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sal.hxx"
26cdf0e10cSrcweir //------------------------------------------------------------------------
27cdf0e10cSrcweir // include files
28cdf0e10cSrcweir //------------------------------------------------------------------------
29cdf0e10cSrcweir #include <sal/types.h>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #ifndef _RTL_USTRING_HXX_
32cdf0e10cSrcweir #include <rtl/string.hxx>
33cdf0e10cSrcweir #endif
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #ifndef _RTL_USTRING_HXX_
36cdf0e10cSrcweir #include <rtl/strbuf.hxx>
37cdf0e10cSrcweir #endif
38cdf0e10cSrcweir 
39cdf0e10cSrcweir #ifndef _OSL_THREAD_HXX
40cdf0e10cSrcweir #include <osl/thread.hxx>
41cdf0e10cSrcweir #endif
42cdf0e10cSrcweir 
43cdf0e10cSrcweir #ifndef _OSL_MUTEX_HXX
44cdf0e10cSrcweir #include <osl/mutex.hxx>
45cdf0e10cSrcweir #endif
46cdf0e10cSrcweir #include <osl/time.h>
47cdf0e10cSrcweir 
48*44e8df1fSDamjan Jovanovic #include "gtest/gtest.h"
49cdf0e10cSrcweir 
50cdf0e10cSrcweir using namespace osl;
51cdf0e10cSrcweir using namespace rtl;
52cdf0e10cSrcweir 
53cdf0e10cSrcweir #ifdef UNX
54cdf0e10cSrcweir #include <unistd.h>
55cdf0e10cSrcweir #include <time.h>
56cdf0e10cSrcweir #endif
57cdf0e10cSrcweir // -----------------------------------------------------------------------------
58cdf0e10cSrcweir // Kleine Stopuhr
59cdf0e10cSrcweir class StopWatch {
60cdf0e10cSrcweir     TimeValue t1,t2;                                // Start und Stopzeit
61cdf0e10cSrcweir 
62cdf0e10cSrcweir protected:
63cdf0e10cSrcweir     sal_Int32 m_nNanoSec;
64cdf0e10cSrcweir     sal_Int32 m_nSeconds;
65cdf0e10cSrcweir 
66cdf0e10cSrcweir     bool m_bIsValid;                                   // TRUE, wenn gestartet und gestoppt
67cdf0e10cSrcweir     bool m_bIsRunning;                                 // TRUE, wenn gestartet.
68cdf0e10cSrcweir 
69cdf0e10cSrcweir public:
70cdf0e10cSrcweir     StopWatch();
71cdf0e10cSrcweir     ~StopWatch() {}
72cdf0e10cSrcweir 
73cdf0e10cSrcweir     void start();                                 // Startet Timer
74cdf0e10cSrcweir     void stop();                                  // Stoppt Timer
75cdf0e10cSrcweir 
76cdf0e10cSrcweir     double getSeconds() const;
77cdf0e10cSrcweir     double getTenthSec() const;
78cdf0e10cSrcweir };
79cdf0e10cSrcweir 
80cdf0e10cSrcweir // ================================= Stop Watch =================================
81cdf0e10cSrcweir 
82cdf0e10cSrcweir // Eine kleine Stop-Uhr fuer den internen Gebrauch.
83cdf0e10cSrcweir // (c) Lars Langhans 29.12.1996 22:10
84cdf0e10cSrcweir 
85cdf0e10cSrcweir StopWatch::StopWatch():m_bIsValid(false),m_bIsRunning(false) {}
86cdf0e10cSrcweir 
87cdf0e10cSrcweir void StopWatch::start()
88cdf0e10cSrcweir {
89cdf0e10cSrcweir // pre: %
90cdf0e10cSrcweir // post: Start Timer
91cdf0e10cSrcweir 
92cdf0e10cSrcweir     m_bIsValid = false;
93cdf0e10cSrcweir     m_bIsRunning = true;
94cdf0e10cSrcweir     osl_getSystemTime( &t1 );
95*44e8df1fSDamjan Jovanovic     printf("# %d %d nsecs\n", t1.Seconds, t1.Nanosec);
96cdf0e10cSrcweir     // gettimeofday(&t1, 0);
97cdf0e10cSrcweir }
98cdf0e10cSrcweir 
99cdf0e10cSrcweir void StopWatch::stop()
100cdf0e10cSrcweir {
101cdf0e10cSrcweir // pre: Timer should be started
102cdf0e10cSrcweir // post: Timer will stopped
103cdf0e10cSrcweir 
104cdf0e10cSrcweir     // gettimeofday(&t2, 0);                         // Timer ausfragen
105cdf0e10cSrcweir     osl_getSystemTime( &t2 );
106*44e8df1fSDamjan Jovanovic     printf("# %d %d nsecs\n", t2.Seconds, t2.Nanosec);
107cdf0e10cSrcweir 
108cdf0e10cSrcweir     if (m_bIsRunning)
109cdf0e10cSrcweir     {                                // check ob gestartet.
110cdf0e10cSrcweir // LLA: old         m_nNanoSec = static_cast<sal_Int32>(t2.Nanosec) - static_cast<sal_Int32>(t1.Nanosec);
111cdf0e10cSrcweir // LLA: old         m_nSeconds = static_cast<sal_Int32>(t2.Seconds) - static_cast<sal_Int32>(t1.Seconds);
112cdf0e10cSrcweir // LLA: old         if (m_nNanoSec < 0)
113cdf0e10cSrcweir // LLA: old         {
114cdf0e10cSrcweir // LLA: old             m_nNanoSec += 1000000000;
115cdf0e10cSrcweir // LLA: old             m_nSeconds -= 1;
116cdf0e10cSrcweir // LLA: old         }
117cdf0e10cSrcweir         //m_nNanoSec = t2.Nanosec - t1.Nanosec;
118cdf0e10cSrcweir         m_nSeconds = static_cast<sal_Int32>(t2.Seconds) - static_cast<sal_Int32>(t1.Seconds);
119cdf0e10cSrcweir         if ( t2.Nanosec > t1.Nanosec )
120cdf0e10cSrcweir        		m_nNanoSec = static_cast<sal_Int32>(t2.Nanosec) - static_cast<sal_Int32>(t1.Nanosec);
121cdf0e10cSrcweir        	else
122cdf0e10cSrcweir        	{
123cdf0e10cSrcweir 		m_nNanoSec = 1000000000 + static_cast<sal_Int32>(t2.Nanosec) - static_cast<sal_Int32>(t1.Nanosec);
124cdf0e10cSrcweir             	m_nSeconds -= 1;
125cdf0e10cSrcweir 	}
126*44e8df1fSDamjan Jovanovic 	printf("# %d %d nsecs\n", m_nSeconds, m_nNanoSec );
127cdf0e10cSrcweir         //if (m_nNanoSec < 0)
128cdf0e10cSrcweir         //{
129cdf0e10cSrcweir             //m_nNanoSec += 1000000000;
130cdf0e10cSrcweir             //m_nSeconds -= 1;
131cdf0e10cSrcweir         //}
132cdf0e10cSrcweir         m_bIsValid = true;
133cdf0e10cSrcweir         m_bIsRunning = false;
134cdf0e10cSrcweir     }
135cdf0e10cSrcweir }
136cdf0e10cSrcweir 
137cdf0e10cSrcweir double StopWatch::getSeconds() const
138cdf0e10cSrcweir {
139cdf0e10cSrcweir // pre: gueltig = TRUE
140cdf0e10cSrcweir // BACK: Zeit in Sekunden.
141cdf0e10cSrcweir 
142cdf0e10cSrcweir     double nValue = 0.0;
143cdf0e10cSrcweir     if (m_bIsValid)
144cdf0e10cSrcweir     {
145cdf0e10cSrcweir         nValue = double(m_nNanoSec) / 1000000000.0 + m_nSeconds; // milli micro nano
146cdf0e10cSrcweir     }
147cdf0e10cSrcweir     return nValue;
148cdf0e10cSrcweir }
149cdf0e10cSrcweir 
150cdf0e10cSrcweir double StopWatch::getTenthSec() const
151cdf0e10cSrcweir {
152cdf0e10cSrcweir     double nValue = 0.0;
153cdf0e10cSrcweir     if (m_bIsValid)
154cdf0e10cSrcweir     {
155cdf0e10cSrcweir         nValue = double(m_nNanoSec) / 100000000.0 + m_nSeconds * 10;
156cdf0e10cSrcweir     }
157cdf0e10cSrcweir     return nValue ;
158cdf0e10cSrcweir }
159cdf0e10cSrcweir 
160cdf0e10cSrcweir // -----------------------------------------------------------------------------
161cdf0e10cSrcweir template <class T>
162cdf0e10cSrcweir class ThreadSafeValue
163cdf0e10cSrcweir {
164cdf0e10cSrcweir     T   m_nFlag;
165cdf0e10cSrcweir     Mutex   m_aMutex;
166cdf0e10cSrcweir public:
167cdf0e10cSrcweir     ThreadSafeValue(T n = 0): m_nFlag(n) {}
168cdf0e10cSrcweir     T getValue()
169cdf0e10cSrcweir         {
170cdf0e10cSrcweir             //block if already acquired by another thread.
171cdf0e10cSrcweir             osl::MutexGuard g(m_aMutex);
172cdf0e10cSrcweir             return m_nFlag;
173cdf0e10cSrcweir         }
174cdf0e10cSrcweir     void addValue(T n)
175cdf0e10cSrcweir         {
176cdf0e10cSrcweir             //only one thread operate on the flag.
177cdf0e10cSrcweir             osl::MutexGuard g(m_aMutex);
178cdf0e10cSrcweir             m_nFlag += n;
179cdf0e10cSrcweir         }
180cdf0e10cSrcweir     void acquire() {m_aMutex.acquire();}
181cdf0e10cSrcweir     void release() {m_aMutex.release();}
182cdf0e10cSrcweir };
183cdf0e10cSrcweir 
184cdf0e10cSrcweir // -----------------------------------------------------------------------------
185cdf0e10cSrcweir namespace ThreadHelper
186cdf0e10cSrcweir {
187cdf0e10cSrcweir     // typedef enum {
188cdf0e10cSrcweir     //     QUIET=1,
189cdf0e10cSrcweir     //     VERBOSE
190cdf0e10cSrcweir     // } eSleepVerboseMode;
191cdf0e10cSrcweir 
192cdf0e10cSrcweir     void thread_sleep_tenth_sec(sal_Int32 _nTenthSec/*, eSleepVerboseMode nVerbose = VERBOSE*/)
193cdf0e10cSrcweir     {
194cdf0e10cSrcweir         // if (nVerbose == VERBOSE)
195cdf0e10cSrcweir         // {
196*44e8df1fSDamjan Jovanovic         //     printf("wait %d tenth seconds. ", _nTenthSec );
197cdf0e10cSrcweir         //     fflush(stdout);
198cdf0e10cSrcweir         // }
199cdf0e10cSrcweir #ifdef WNT      //Windows
200cdf0e10cSrcweir         Sleep(_nTenthSec * 100 );
201cdf0e10cSrcweir #endif
202cdf0e10cSrcweir #if ( defined UNX ) || ( defined OS2 )  //Unix
203cdf0e10cSrcweir         TimeValue nTV;
204cdf0e10cSrcweir         nTV.Seconds = static_cast<sal_uInt32>( _nTenthSec/10 );
205cdf0e10cSrcweir         nTV.Nanosec = ( (_nTenthSec%10 ) * 100000000 );
206cdf0e10cSrcweir         osl_waitThread(&nTV);
207cdf0e10cSrcweir #endif
208cdf0e10cSrcweir         // if (nVerbose == VERBOSE)
209cdf0e10cSrcweir         // {
210*44e8df1fSDamjan Jovanovic         //     printf("done\n");
211cdf0e10cSrcweir         // }
212cdf0e10cSrcweir     }
213cdf0e10cSrcweir 
214cdf0e10cSrcweir     void outputPriority(oslThreadPriority const& _aPriority)
215cdf0e10cSrcweir     {
216cdf0e10cSrcweir         // LLA: output the priority
217cdf0e10cSrcweir         if (_aPriority == osl_Thread_PriorityHighest)
218cdf0e10cSrcweir         {
219*44e8df1fSDamjan Jovanovic             printf("Prio is High\n");
220cdf0e10cSrcweir         }
221cdf0e10cSrcweir         else if (_aPriority == osl_Thread_PriorityAboveNormal)
222cdf0e10cSrcweir         {
223*44e8df1fSDamjan Jovanovic             printf("Prio is above normal\n");
224cdf0e10cSrcweir         }
225cdf0e10cSrcweir         else if (_aPriority == osl_Thread_PriorityNormal)
226cdf0e10cSrcweir         {
227*44e8df1fSDamjan Jovanovic             printf("Prio is normal\n");
228cdf0e10cSrcweir         }
229cdf0e10cSrcweir         else if (_aPriority == osl_Thread_PriorityBelowNormal)
230cdf0e10cSrcweir         {
231*44e8df1fSDamjan Jovanovic             printf("Prio is below normal\n");
232cdf0e10cSrcweir         }
233cdf0e10cSrcweir         else if (_aPriority == osl_Thread_PriorityLowest)
234cdf0e10cSrcweir         {
235*44e8df1fSDamjan Jovanovic             printf("Prio is lowest\n");
236cdf0e10cSrcweir         }
237cdf0e10cSrcweir         else
238cdf0e10cSrcweir         {
239*44e8df1fSDamjan Jovanovic             printf("Prio is unknown\n");
240cdf0e10cSrcweir         }
241cdf0e10cSrcweir     }
242cdf0e10cSrcweir }
243cdf0e10cSrcweir 
244cdf0e10cSrcweir /** Simple thread for testing Thread-create.
245cdf0e10cSrcweir 
246cdf0e10cSrcweir     Just add 1 of value 0, and after running, result is 1.
247cdf0e10cSrcweir  */
248cdf0e10cSrcweir class myThread : public Thread
249cdf0e10cSrcweir {
250cdf0e10cSrcweir     ThreadSafeValue<sal_Int32> m_aFlag;
251cdf0e10cSrcweir public:
252cdf0e10cSrcweir     sal_Int32 getValue() { return m_aFlag.getValue(); }
253cdf0e10cSrcweir protected:
254cdf0e10cSrcweir     /** guarded value which initialized 0
255cdf0e10cSrcweir 
256cdf0e10cSrcweir         @see ThreadSafeValue
257cdf0e10cSrcweir     */
258cdf0e10cSrcweir     void SAL_CALL run()
259cdf0e10cSrcweir         {
260cdf0e10cSrcweir             while(schedule())
261cdf0e10cSrcweir             {
262cdf0e10cSrcweir                 m_aFlag.addValue(1);
263cdf0e10cSrcweir                 ThreadHelper::thread_sleep_tenth_sec(1);
264cdf0e10cSrcweir             }
265cdf0e10cSrcweir         }
266cdf0e10cSrcweir 
267cdf0e10cSrcweir public:
268cdf0e10cSrcweir 
269cdf0e10cSrcweir     virtual void SAL_CALL suspend()
270cdf0e10cSrcweir         {
271cdf0e10cSrcweir             m_aFlag.acquire();
272cdf0e10cSrcweir             ::osl::Thread::suspend();
273cdf0e10cSrcweir             m_aFlag.release();
274cdf0e10cSrcweir         }
275cdf0e10cSrcweir 
276cdf0e10cSrcweir     ~myThread()
277cdf0e10cSrcweir         {
278cdf0e10cSrcweir             if (isRunning())
279cdf0e10cSrcweir             {
280*44e8df1fSDamjan Jovanovic                 printf("error: not terminated.\n");
281cdf0e10cSrcweir             }
282cdf0e10cSrcweir         }
283cdf0e10cSrcweir 
284cdf0e10cSrcweir };
285cdf0e10cSrcweir 
286cdf0e10cSrcweir // -----------------------------------------------------------------------------
287cdf0e10cSrcweir /** Thread which has a flag add 1 every second until 20
288cdf0e10cSrcweir  */
289cdf0e10cSrcweir class OCountThread : public Thread
290cdf0e10cSrcweir {
291cdf0e10cSrcweir     ThreadSafeValue<sal_Int32> m_aFlag;
292cdf0e10cSrcweir public:
293cdf0e10cSrcweir     OCountThread()
294cdf0e10cSrcweir         {
295cdf0e10cSrcweir             m_nWaitSec = 0;
296*44e8df1fSDamjan Jovanovic             printf("new OCountThread thread %d!\n", getIdentifier());
297cdf0e10cSrcweir         }
298cdf0e10cSrcweir     sal_Int32 getValue() { return m_aFlag.getValue(); }
299cdf0e10cSrcweir 
300cdf0e10cSrcweir     void setWait(sal_Int32 nSec)
301cdf0e10cSrcweir         {
302cdf0e10cSrcweir             m_nWaitSec = nSec;
303cdf0e10cSrcweir             //m_bWait = sal_True;
304cdf0e10cSrcweir         }
305cdf0e10cSrcweir 
306cdf0e10cSrcweir     virtual void SAL_CALL suspend()
307cdf0e10cSrcweir         {
308cdf0e10cSrcweir             m_aFlag.acquire();
309cdf0e10cSrcweir             ::osl::Thread::suspend();
310cdf0e10cSrcweir             m_aFlag.release();
311cdf0e10cSrcweir         }
312cdf0e10cSrcweir 
313cdf0e10cSrcweir protected:
314cdf0e10cSrcweir     //sal_Bool m_bWait;
315cdf0e10cSrcweir     sal_Int32 m_nWaitSec;
316cdf0e10cSrcweir 
317cdf0e10cSrcweir     void SAL_CALL run()
318cdf0e10cSrcweir         {
319cdf0e10cSrcweir             /// if the thread should terminate, schedule return false
320cdf0e10cSrcweir             while (m_aFlag.getValue() < 20 && schedule() == sal_True)
321cdf0e10cSrcweir             {
322cdf0e10cSrcweir                 m_aFlag.addValue(1);
323cdf0e10cSrcweir                 ThreadHelper::thread_sleep_tenth_sec(1);
324cdf0e10cSrcweir                 // TimeValue nTV;
325cdf0e10cSrcweir                 // nTV.Seconds = 1;
326cdf0e10cSrcweir                 // nTV.Nanosec = 0;
327cdf0e10cSrcweir                 // wait(nTV);
328cdf0e10cSrcweir 
329cdf0e10cSrcweir                 if (m_nWaitSec != 0)
330cdf0e10cSrcweir                 {
331cdf0e10cSrcweir                     //ThreadHelper::thread_sleep_tenth_sec(m_nWaitSec * 10);
332cdf0e10cSrcweir                     TimeValue nTV;
333cdf0e10cSrcweir                     nTV.Seconds = m_nWaitSec / 10 ;
334cdf0e10cSrcweir                     nTV.Nanosec = ( m_nWaitSec%10 ) * 100000000 ;
335cdf0e10cSrcweir                     wait( nTV );
336cdf0e10cSrcweir                     m_nWaitSec = 0;
337cdf0e10cSrcweir                 }
338cdf0e10cSrcweir             }
339cdf0e10cSrcweir         }
340cdf0e10cSrcweir     void SAL_CALL onTerminated()
341cdf0e10cSrcweir         {
342*44e8df1fSDamjan Jovanovic             printf("normally terminate this thread %d!\n", getIdentifier());
343cdf0e10cSrcweir         }
344cdf0e10cSrcweir public:
345cdf0e10cSrcweir 
346cdf0e10cSrcweir     ~OCountThread()
347cdf0e10cSrcweir         {
348cdf0e10cSrcweir             if (isRunning())
349cdf0e10cSrcweir             {
350*44e8df1fSDamjan Jovanovic                 printf("error: not terminated.\n");
351cdf0e10cSrcweir             }
352cdf0e10cSrcweir         }
353cdf0e10cSrcweir 
354cdf0e10cSrcweir };
355cdf0e10cSrcweir 
356cdf0e10cSrcweir /** call suspend in the run method
357cdf0e10cSrcweir */
358cdf0e10cSrcweir class OSuspendThread : public Thread
359cdf0e10cSrcweir {
360cdf0e10cSrcweir     ThreadSafeValue<sal_Int32> m_aFlag;
361cdf0e10cSrcweir public:
362cdf0e10cSrcweir     OSuspendThread(){ m_bSuspend = sal_False; }
363cdf0e10cSrcweir     sal_Int32 getValue() { return m_aFlag.getValue(); }
364cdf0e10cSrcweir     void setSuspend()
365cdf0e10cSrcweir         {
366cdf0e10cSrcweir             m_bSuspend = sal_True;
367cdf0e10cSrcweir         }
368cdf0e10cSrcweir     virtual void SAL_CALL suspend()
369cdf0e10cSrcweir         {
370cdf0e10cSrcweir             m_aFlag.acquire();
371cdf0e10cSrcweir             ::osl::Thread::suspend();
372cdf0e10cSrcweir             m_aFlag.release();
373cdf0e10cSrcweir         }
374cdf0e10cSrcweir protected:
375cdf0e10cSrcweir     sal_Bool m_bSuspend;
376cdf0e10cSrcweir     void SAL_CALL run()
377cdf0e10cSrcweir         {
378cdf0e10cSrcweir             //if the thread should terminate, schedule return false
379cdf0e10cSrcweir             while (schedule() == sal_True)
380cdf0e10cSrcweir             {
381cdf0e10cSrcweir                 m_aFlag.addValue(1);
382cdf0e10cSrcweir 
383cdf0e10cSrcweir                 ThreadHelper::thread_sleep_tenth_sec(1);
384cdf0e10cSrcweir                 // m_bWait =    sal_False;
385cdf0e10cSrcweir                 // TimeValue nTV;
386cdf0e10cSrcweir                 // nTV.Seconds = 1;
387cdf0e10cSrcweir                 // nTV.Nanosec = 0;
388cdf0e10cSrcweir                 // wait(nTV);
389cdf0e10cSrcweir                 if (m_bSuspend == sal_True)
390cdf0e10cSrcweir                 {
391cdf0e10cSrcweir                     suspend();
392cdf0e10cSrcweir                     m_bSuspend  = sal_False;
393cdf0e10cSrcweir                 }
394cdf0e10cSrcweir             }
395cdf0e10cSrcweir         }
396cdf0e10cSrcweir public:
397cdf0e10cSrcweir 
398cdf0e10cSrcweir     ~OSuspendThread()
399cdf0e10cSrcweir         {
400cdf0e10cSrcweir             if (isRunning())
401cdf0e10cSrcweir             {
402*44e8df1fSDamjan Jovanovic                 printf("error: not terminated.\n");
403cdf0e10cSrcweir             }
404cdf0e10cSrcweir         }
405cdf0e10cSrcweir 
406cdf0e10cSrcweir };
407cdf0e10cSrcweir 
408cdf0e10cSrcweir /** no call schedule in the run method
409cdf0e10cSrcweir */
410cdf0e10cSrcweir class ONoScheduleThread : public Thread
411cdf0e10cSrcweir {
412cdf0e10cSrcweir     ThreadSafeValue<sal_Int32> m_aFlag;
413cdf0e10cSrcweir public:
414cdf0e10cSrcweir     sal_Int32 getValue() { return m_aFlag.getValue(); }
415cdf0e10cSrcweir 
416cdf0e10cSrcweir     virtual void SAL_CALL suspend()
417cdf0e10cSrcweir         {
418cdf0e10cSrcweir             m_aFlag.acquire();
419cdf0e10cSrcweir             ::osl::Thread::suspend();
420cdf0e10cSrcweir             m_aFlag.release();
421cdf0e10cSrcweir         }
422cdf0e10cSrcweir protected:
423cdf0e10cSrcweir     void SAL_CALL run()
424cdf0e10cSrcweir         {
425cdf0e10cSrcweir             while (m_aFlag.getValue() < 10)
426cdf0e10cSrcweir             {
427cdf0e10cSrcweir                 m_aFlag.addValue(1);
428cdf0e10cSrcweir                 ThreadHelper::thread_sleep_tenth_sec(1);
429cdf0e10cSrcweir                 // TimeValue nTV;
430cdf0e10cSrcweir                 // nTV.Seconds = 1;
431cdf0e10cSrcweir                 // nTV.Nanosec = 0;
432cdf0e10cSrcweir                 // wait(nTV);
433cdf0e10cSrcweir             }
434cdf0e10cSrcweir         }
435cdf0e10cSrcweir     void SAL_CALL onTerminated()
436cdf0e10cSrcweir         {
437*44e8df1fSDamjan Jovanovic             printf("normally terminate this thread %d!\n", getIdentifier());
438cdf0e10cSrcweir         }
439cdf0e10cSrcweir public:
440cdf0e10cSrcweir     ONoScheduleThread()
441cdf0e10cSrcweir         {
442*44e8df1fSDamjan Jovanovic                 printf("new thread id %d!\n", getIdentifier());
443cdf0e10cSrcweir         }
444cdf0e10cSrcweir     ~ONoScheduleThread()
445cdf0e10cSrcweir         {
446cdf0e10cSrcweir             if (isRunning())
447cdf0e10cSrcweir             {
448*44e8df1fSDamjan Jovanovic                 printf("error: not terminated.\n");
449cdf0e10cSrcweir             }
450cdf0e10cSrcweir         }
451cdf0e10cSrcweir 
452cdf0e10cSrcweir };
453cdf0e10cSrcweir 
454cdf0e10cSrcweir /**
455cdf0e10cSrcweir */
456cdf0e10cSrcweir class OAddThread : public Thread
457cdf0e10cSrcweir {
458cdf0e10cSrcweir     ThreadSafeValue<sal_Int32> m_aFlag;
459cdf0e10cSrcweir public:
460cdf0e10cSrcweir     //oslThreadIdentifier m_id, m_CurId;
461cdf0e10cSrcweir     OAddThread(){}
462cdf0e10cSrcweir     sal_Int32 getValue() { return m_aFlag.getValue(); }
463cdf0e10cSrcweir 
464cdf0e10cSrcweir     virtual void SAL_CALL suspend()
465cdf0e10cSrcweir         {
466cdf0e10cSrcweir             m_aFlag.acquire();
467cdf0e10cSrcweir             ::osl::Thread::suspend();
468cdf0e10cSrcweir             m_aFlag.release();
469cdf0e10cSrcweir         }
470cdf0e10cSrcweir protected:
471cdf0e10cSrcweir     void SAL_CALL run()
472cdf0e10cSrcweir         {
473cdf0e10cSrcweir             //if the thread should terminate, schedule return false
474cdf0e10cSrcweir             while (schedule() == sal_True)
475cdf0e10cSrcweir             {
476cdf0e10cSrcweir                 m_aFlag.addValue(1);
477cdf0e10cSrcweir             }
478cdf0e10cSrcweir         }
479cdf0e10cSrcweir     void SAL_CALL onTerminated()
480cdf0e10cSrcweir         {
481*44e8df1fSDamjan Jovanovic             // printf("normally terminate this thread %d!\n", getIdentifier());
482cdf0e10cSrcweir         }
483cdf0e10cSrcweir public:
484cdf0e10cSrcweir 
485cdf0e10cSrcweir     ~OAddThread()
486cdf0e10cSrcweir         {
487cdf0e10cSrcweir             if (isRunning())
488cdf0e10cSrcweir             {
489*44e8df1fSDamjan Jovanovic                 // printf("error: not terminated.\n");
490cdf0e10cSrcweir             }
491cdf0e10cSrcweir         }
492cdf0e10cSrcweir 
493cdf0e10cSrcweir };
494cdf0e10cSrcweir 
495cdf0e10cSrcweir namespace osl_Thread
496cdf0e10cSrcweir {
497cdf0e10cSrcweir 
498cdf0e10cSrcweir     void resumeAndWaitThread(Thread* _pThread)
499cdf0e10cSrcweir     {
500cdf0e10cSrcweir         // This functions starts a thread, wait a second and suspends the thread
501cdf0e10cSrcweir         // Due to the fact, that a suspend and never run thread never really exists.
502cdf0e10cSrcweir 
503cdf0e10cSrcweir         // Note: on UNX, after createSuspended, and then terminate the thread, it performs well;
504cdf0e10cSrcweir         // while on Windows, after createSuspended, the thread can not terminate, wait endlessly,
505cdf0e10cSrcweir         // so here call resume at first, then call terminate.
506cdf0e10cSrcweir #ifdef WNT
507*44e8df1fSDamjan Jovanovic         printf("resumeAndWaitThread\n");
508cdf0e10cSrcweir         _pThread->resume();
509cdf0e10cSrcweir         ThreadHelper::thread_sleep_tenth_sec(1);
510cdf0e10cSrcweir #else
511cdf0e10cSrcweir         _pThread->resume();
512cdf0e10cSrcweir #endif
513cdf0e10cSrcweir         // ThreadHelper::thread_sleep_tenth_sec(1);
514cdf0e10cSrcweir         // _pThread->suspend();
515cdf0e10cSrcweir         // ThreadHelper::thread_sleep_tenth_sec(1);
516cdf0e10cSrcweir     }
517cdf0e10cSrcweir 
518cdf0e10cSrcweir     // kill a running thread and join it, if it has terminated, do nothing
519cdf0e10cSrcweir     void termAndJoinThread(Thread* _pThread)
520cdf0e10cSrcweir     {
521cdf0e10cSrcweir         _pThread->terminate();
522cdf0e10cSrcweir 
523cdf0e10cSrcweir // LLA: Windows feature???, a suspended thread can not terminated, so we have to weak it up
524cdf0e10cSrcweir #ifdef WNT
525cdf0e10cSrcweir         _pThread->resume();
526cdf0e10cSrcweir         ThreadHelper::thread_sleep_tenth_sec(1);
527cdf0e10cSrcweir #endif
528*44e8df1fSDamjan Jovanovic         printf("#wait for join.\n");
529cdf0e10cSrcweir         _pThread->join();
530cdf0e10cSrcweir     }
531cdf0e10cSrcweir /** Test of the osl::Thread::create method
532cdf0e10cSrcweir  */
533cdf0e10cSrcweir 
534*44e8df1fSDamjan Jovanovic     class create : public ::testing::Test
535cdf0e10cSrcweir     {
536cdf0e10cSrcweir     public:
537cdf0e10cSrcweir 
538cdf0e10cSrcweir         // initialise your test code values here.
539*44e8df1fSDamjan Jovanovic         void SetUp()
540cdf0e10cSrcweir             {
541cdf0e10cSrcweir             }
542cdf0e10cSrcweir 
543*44e8df1fSDamjan Jovanovic         void TearDown()
544cdf0e10cSrcweir             {
545cdf0e10cSrcweir             }
546*44e8df1fSDamjan Jovanovic     }; // class create
547cdf0e10cSrcweir 
548cdf0e10cSrcweir 
549*44e8df1fSDamjan Jovanovic     /** Simple create a thread.
550cdf0e10cSrcweir 
551*44e8df1fSDamjan Jovanovic         Create a simple thread, it just does add 1 to value(which initialized 0),
552*44e8df1fSDamjan Jovanovic         if the thread run, the value should be 1.
553*44e8df1fSDamjan Jovanovic     */
554*44e8df1fSDamjan Jovanovic     TEST_F(create, create_001)
555*44e8df1fSDamjan Jovanovic         {
556*44e8df1fSDamjan Jovanovic             myThread* newthread = new myThread();
557*44e8df1fSDamjan Jovanovic             sal_Bool bRes = newthread->create();
558*44e8df1fSDamjan Jovanovic             ASSERT_TRUE(bRes == sal_True) << "Can not creates a new thread!\n";
559cdf0e10cSrcweir 
560*44e8df1fSDamjan Jovanovic             ThreadHelper::thread_sleep_tenth_sec(1);        // wait short
561*44e8df1fSDamjan Jovanovic             sal_Bool isRunning = newthread->isRunning();    // check if thread is running
562*44e8df1fSDamjan Jovanovic             /// wait for the new thread to assure it has run
563*44e8df1fSDamjan Jovanovic             ThreadHelper::thread_sleep_tenth_sec(3);
564*44e8df1fSDamjan Jovanovic             sal_Int32 nValue = newthread->getValue();
565*44e8df1fSDamjan Jovanovic             /// to assure the new thread has terminated
566*44e8df1fSDamjan Jovanovic             termAndJoinThread(newthread);
567*44e8df1fSDamjan Jovanovic             delete newthread;
568cdf0e10cSrcweir 
569*44e8df1fSDamjan Jovanovic             printf("   nValue = %d\n", nValue);
570*44e8df1fSDamjan Jovanovic             printf("isRunning = %d\n", isRunning);
571cdf0e10cSrcweir 
572*44e8df1fSDamjan Jovanovic             ASSERT_TRUE(nValue >= 1 && isRunning == sal_True) << "Creates a new thread";
573cdf0e10cSrcweir 
574*44e8df1fSDamjan Jovanovic         }
575*44e8df1fSDamjan Jovanovic 
576*44e8df1fSDamjan Jovanovic     /** only one running thread per instance, return false if create secondly
577*44e8df1fSDamjan Jovanovic      */
578*44e8df1fSDamjan Jovanovic     TEST_F(create, create_002)
579*44e8df1fSDamjan Jovanovic         {
580*44e8df1fSDamjan Jovanovic             myThread* newthread = new myThread();
581*44e8df1fSDamjan Jovanovic             sal_Bool res1 = newthread->create();
582*44e8df1fSDamjan Jovanovic             sal_Bool res2 = newthread->create();
583*44e8df1fSDamjan Jovanovic             printf("In non pro, an assertion should occured. This behaviour is right.\n");
584*44e8df1fSDamjan Jovanovic             termAndJoinThread(newthread);
585*44e8df1fSDamjan Jovanovic             delete newthread;
586*44e8df1fSDamjan Jovanovic 
587*44e8df1fSDamjan Jovanovic             ASSERT_TRUE(res1 && !res2) << "Creates a new thread: can not create two threads per instance";
588*44e8df1fSDamjan Jovanovic 
589*44e8df1fSDamjan Jovanovic         }
590cdf0e10cSrcweir 
591cdf0e10cSrcweir 
592cdf0e10cSrcweir     /** Test of the osl::Thread::createSuspended method
593cdf0e10cSrcweir     */
594*44e8df1fSDamjan Jovanovic     class createSuspended : public ::testing::Test
595cdf0e10cSrcweir     {
596cdf0e10cSrcweir     public:
597cdf0e10cSrcweir         // initialise your test code values here.
598*44e8df1fSDamjan Jovanovic         void SetUp()
599cdf0e10cSrcweir             {
600cdf0e10cSrcweir             }
601cdf0e10cSrcweir 
602*44e8df1fSDamjan Jovanovic         void TearDown()
603cdf0e10cSrcweir             {
604cdf0e10cSrcweir             }
605*44e8df1fSDamjan Jovanovic     }; // class createSuspended
606cdf0e10cSrcweir 
607*44e8df1fSDamjan Jovanovic     /** Create a suspended thread, use the same class as create_001
608cdf0e10cSrcweir 
609*44e8df1fSDamjan Jovanovic         after create, wait enough time, check the value, if it's still the initial value, pass
610*44e8df1fSDamjan Jovanovic     */
611*44e8df1fSDamjan Jovanovic     TEST_F(createSuspended, createSuspended_001)
612*44e8df1fSDamjan Jovanovic         {
613*44e8df1fSDamjan Jovanovic             myThread* newthread = new myThread();
614*44e8df1fSDamjan Jovanovic             sal_Bool bRes = newthread->createSuspended();
615*44e8df1fSDamjan Jovanovic             ASSERT_TRUE(bRes == sal_True) << "Can not creates a new thread!";
616cdf0e10cSrcweir 
617*44e8df1fSDamjan Jovanovic             ThreadHelper::thread_sleep_tenth_sec(1);
618*44e8df1fSDamjan Jovanovic             sal_Bool isRunning = newthread->isRunning();
619*44e8df1fSDamjan Jovanovic             ThreadHelper::thread_sleep_tenth_sec(3);
620*44e8df1fSDamjan Jovanovic             sal_Int32 nValue = newthread->getValue();
621cdf0e10cSrcweir 
622*44e8df1fSDamjan Jovanovic             resumeAndWaitThread(newthread);
623cdf0e10cSrcweir 
624*44e8df1fSDamjan Jovanovic             termAndJoinThread(newthread);
625*44e8df1fSDamjan Jovanovic             delete newthread;
626cdf0e10cSrcweir 
627*44e8df1fSDamjan Jovanovic             ASSERT_TRUE(nValue == 0 && isRunning) << "Creates a new suspended thread";
628*44e8df1fSDamjan Jovanovic         }
629*44e8df1fSDamjan Jovanovic     // LLA: Deadlocked!!!
630*44e8df1fSDamjan Jovanovic     TEST_F(createSuspended, createSuspended_002)
631*44e8df1fSDamjan Jovanovic         {
632*44e8df1fSDamjan Jovanovic             myThread* newthread = new myThread();
633*44e8df1fSDamjan Jovanovic             sal_Bool res1 = newthread->createSuspended();
634*44e8df1fSDamjan Jovanovic             sal_Bool res2 = newthread->createSuspended();
635cdf0e10cSrcweir 
636*44e8df1fSDamjan Jovanovic             resumeAndWaitThread(newthread);
637cdf0e10cSrcweir 
638*44e8df1fSDamjan Jovanovic             termAndJoinThread(newthread);
639cdf0e10cSrcweir 
640*44e8df1fSDamjan Jovanovic             delete newthread;
641cdf0e10cSrcweir 
642*44e8df1fSDamjan Jovanovic             ASSERT_TRUE(res1 && !res2) << "Creates a new thread: can not create two threads per instance";
643*44e8df1fSDamjan Jovanovic         }
644cdf0e10cSrcweir 
645cdf0e10cSrcweir 
646cdf0e10cSrcweir     /** when the count value equal to or more than 3, suspend the thread.
647cdf0e10cSrcweir     */
648cdf0e10cSrcweir     void suspendCountThread(OCountThread* _pCountThread)
649cdf0e10cSrcweir     {
650cdf0e10cSrcweir         sal_Int32 nValue = 0;
651cdf0e10cSrcweir         while (1)
652cdf0e10cSrcweir         {
653cdf0e10cSrcweir             nValue = _pCountThread->getValue();
654cdf0e10cSrcweir             if (nValue >= 3)
655cdf0e10cSrcweir             {
656cdf0e10cSrcweir                 _pCountThread->suspend();
657cdf0e10cSrcweir                 break;
658cdf0e10cSrcweir             }
659cdf0e10cSrcweir         }
660cdf0e10cSrcweir     }
661cdf0e10cSrcweir 
662cdf0e10cSrcweir     /** Test of the osl::Thread::suspend method
663cdf0e10cSrcweir     */
664*44e8df1fSDamjan Jovanovic     class suspend : public ::testing::Test
665cdf0e10cSrcweir     {
666cdf0e10cSrcweir     public:
667cdf0e10cSrcweir         // initialise your test code values here.
668*44e8df1fSDamjan Jovanovic         void SetUp()
669cdf0e10cSrcweir             {
670cdf0e10cSrcweir             }
671cdf0e10cSrcweir 
672*44e8df1fSDamjan Jovanovic         void TearDown()
673cdf0e10cSrcweir             {
674cdf0e10cSrcweir             }
675*44e8df1fSDamjan Jovanovic     }; // class suspend
676cdf0e10cSrcweir 
677*44e8df1fSDamjan Jovanovic     /** Use a thread which has a flag added 1 every second
678cdf0e10cSrcweir 
679*44e8df1fSDamjan Jovanovic         ALGORITHM:
680*44e8df1fSDamjan Jovanovic         create the thread, after running special time, record value of flag, then suspend it,
681*44e8df1fSDamjan Jovanovic         wait a long time, check the flag, if it remains unchanged during suspending
682*44e8df1fSDamjan Jovanovic     */
683*44e8df1fSDamjan Jovanovic     TEST_F(suspend, suspend_001)
684*44e8df1fSDamjan Jovanovic         {
685*44e8df1fSDamjan Jovanovic             OCountThread* aCountThread = new OCountThread();
686*44e8df1fSDamjan Jovanovic             sal_Bool bRes = aCountThread->create();
687*44e8df1fSDamjan Jovanovic             ASSERT_TRUE(bRes == sal_True) << "Can't start thread!";
688*44e8df1fSDamjan Jovanovic             // the thread run for some seconds, but not terminate
689*44e8df1fSDamjan Jovanovic             suspendCountThread( aCountThread );
690cdf0e10cSrcweir 
691*44e8df1fSDamjan Jovanovic             // the value just after calling suspend
692*44e8df1fSDamjan Jovanovic             sal_Int32 nValue = aCountThread->getValue();       // (2)
693cdf0e10cSrcweir 
694*44e8df1fSDamjan Jovanovic             ThreadHelper::thread_sleep_tenth_sec(3);
695cdf0e10cSrcweir 
696*44e8df1fSDamjan Jovanovic             // the value after waiting 3 seconds
697*44e8df1fSDamjan Jovanovic             sal_Int32 nLaterValue = aCountThread->getValue();    // (3)
698cdf0e10cSrcweir 
699*44e8df1fSDamjan Jovanovic             resumeAndWaitThread(aCountThread);
700*44e8df1fSDamjan Jovanovic             termAndJoinThread(aCountThread);
701*44e8df1fSDamjan Jovanovic             delete aCountThread;
702cdf0e10cSrcweir 
703*44e8df1fSDamjan Jovanovic             ASSERT_TRUE(bRes == sal_True && nValue == nLaterValue) << "Suspend the thread";
704cdf0e10cSrcweir 
705*44e8df1fSDamjan Jovanovic         }
706*44e8df1fSDamjan Jovanovic     /** suspend a thread in it's worker-function, the ALGORITHM is same as suspend_001
707*44e8df1fSDamjan Jovanovic          reason of deadlocked I think: no schedule can schedule other threads to go on excuting
708*44e8df1fSDamjan Jovanovic      */
709*44e8df1fSDamjan Jovanovic     TEST_F(suspend, suspend_002)
710*44e8df1fSDamjan Jovanovic         {
711*44e8df1fSDamjan Jovanovic #if 0
712*44e8df1fSDamjan Jovanovic             OSuspendThread* aThread = new OSuspendThread();
713*44e8df1fSDamjan Jovanovic             sal_Bool bRes = aThread->create();
714*44e8df1fSDamjan Jovanovic             ASSERT_TRUE(bRes == sal_True) << "Can't start thread!";
715*44e8df1fSDamjan Jovanovic             // first the thread run for some seconds, but not terminate
716*44e8df1fSDamjan Jovanovic             sal_Int32 nValue = 0;
717*44e8df1fSDamjan Jovanovic             //while (1)
718*44e8df1fSDamjan Jovanovic             //{
719*44e8df1fSDamjan Jovanovic             ThreadHelper::thread_sleep_tenth_sec(3);
720*44e8df1fSDamjan Jovanovic             nValue = aThread->getValue();    // (1)
721*44e8df1fSDamjan Jovanovic             printf(" getValue is %d !", nValue );
722*44e8df1fSDamjan Jovanovic             if (nValue >= 2)
723cdf0e10cSrcweir             {
724*44e8df1fSDamjan Jovanovic                     aThread->setSuspend();
725*44e8df1fSDamjan Jovanovic                     //break;
726cdf0e10cSrcweir             }
727*44e8df1fSDamjan Jovanovic             //}
728*44e8df1fSDamjan Jovanovic             printf(" after while!");
729*44e8df1fSDamjan Jovanovic             // the value just after calling suspend
730*44e8df1fSDamjan Jovanovic             nValue = aThread->getValue();       // (2)
731*44e8df1fSDamjan Jovanovic 
732*44e8df1fSDamjan Jovanovic             ThreadHelper::thread_sleep_tenth_sec(3);
733*44e8df1fSDamjan Jovanovic             printf(" after sleep!");
734*44e8df1fSDamjan Jovanovic             // the value after waiting 3 seconds
735*44e8df1fSDamjan Jovanovic             sal_Int32 nLaterValue = aThread->getValue();        // (3)
736*44e8df1fSDamjan Jovanovic 
737*44e8df1fSDamjan Jovanovic             //resumeAndWaitThread(aThread);
738*44e8df1fSDamjan Jovanovic             aThread->resume();
739*44e8df1fSDamjan Jovanovic             termAndJoinThread(aThread);
740*44e8df1fSDamjan Jovanovic             delete aThread;
741*44e8df1fSDamjan Jovanovic 
742*44e8df1fSDamjan Jovanovic             ASSERT_TRUE(bRes == sal_True && nValue == nLaterValue) << "Suspend the thread";
743*44e8df1fSDamjan Jovanovic #endif
744*44e8df1fSDamjan Jovanovic         }
745cdf0e10cSrcweir 
746cdf0e10cSrcweir 
747cdf0e10cSrcweir     /** Test of the osl::Thread::resume method
748cdf0e10cSrcweir     */
749*44e8df1fSDamjan Jovanovic     class resume : public ::testing::Test
750cdf0e10cSrcweir     {
751cdf0e10cSrcweir     public:
752cdf0e10cSrcweir         // initialise your test code values here.
753*44e8df1fSDamjan Jovanovic         void SetUp()
754cdf0e10cSrcweir             {
755cdf0e10cSrcweir             }
756cdf0e10cSrcweir 
757*44e8df1fSDamjan Jovanovic         void TearDown()
758cdf0e10cSrcweir             {
759cdf0e10cSrcweir             }
760*44e8df1fSDamjan Jovanovic     }; // class resume
761cdf0e10cSrcweir 
762*44e8df1fSDamjan Jovanovic     /** check if the thread run samely as usual after suspend and resume
763cdf0e10cSrcweir 
764*44e8df1fSDamjan Jovanovic         ALGORITHM:
765*44e8df1fSDamjan Jovanovic         compare the values before and after suspend, they should be same,
766*44e8df1fSDamjan Jovanovic         then compare values before and after resume, the difference should be same as the sleep seconds number
767*44e8df1fSDamjan Jovanovic     */
768*44e8df1fSDamjan Jovanovic     TEST_F(resume, resume_001)
769*44e8df1fSDamjan Jovanovic         {
770*44e8df1fSDamjan Jovanovic             OCountThread* pCountThread = new OCountThread();
771*44e8df1fSDamjan Jovanovic             sal_Bool bRes = pCountThread->create();
772*44e8df1fSDamjan Jovanovic             ASSERT_TRUE(bRes == sal_True) << "Can't start thread!";
773cdf0e10cSrcweir 
774*44e8df1fSDamjan Jovanovic             suspendCountThread(pCountThread);
775cdf0e10cSrcweir 
776*44e8df1fSDamjan Jovanovic             sal_Int32 nSuspendValue = pCountThread->getValue();  // (2)
777*44e8df1fSDamjan Jovanovic             // suspend for 3 seconds
778*44e8df1fSDamjan Jovanovic             ThreadHelper::thread_sleep_tenth_sec(3);
779*44e8df1fSDamjan Jovanovic             pCountThread->resume();
780cdf0e10cSrcweir 
781*44e8df1fSDamjan Jovanovic             ThreadHelper::thread_sleep_tenth_sec(3);
782*44e8df1fSDamjan Jovanovic             sal_Int32 nResumeValue = pCountThread->getValue();
783cdf0e10cSrcweir 
784*44e8df1fSDamjan Jovanovic             ThreadHelper::thread_sleep_tenth_sec(3);
785*44e8df1fSDamjan Jovanovic             sal_Int32 nLaterValue = pCountThread->getValue();
786cdf0e10cSrcweir 
787*44e8df1fSDamjan Jovanovic             termAndJoinThread(pCountThread);
788*44e8df1fSDamjan Jovanovic             delete pCountThread;
789cdf0e10cSrcweir 
790*44e8df1fSDamjan Jovanovic             printf("SuspendValue: %d\n", nSuspendValue);
791*44e8df1fSDamjan Jovanovic             printf("ResumeValue:  %d\n", nResumeValue);
792*44e8df1fSDamjan Jovanovic             printf("LaterValue:   %d\n", nLaterValue);
793cdf0e10cSrcweir 
794*44e8df1fSDamjan Jovanovic             /* LLA: this assumption is no longer relevant: nResumeValue ==  nSuspendValue && */
795*44e8df1fSDamjan Jovanovic             ASSERT_TRUE(nLaterValue >= 9 &&
796*44e8df1fSDamjan Jovanovic                 nResumeValue > nSuspendValue &&
797*44e8df1fSDamjan Jovanovic                 nLaterValue > nResumeValue) << "Suspend then resume the thread";
798cdf0e10cSrcweir 
799*44e8df1fSDamjan Jovanovic         }
800cdf0e10cSrcweir 
801*44e8df1fSDamjan Jovanovic     /** Create a suspended thread then resume, check if the thread has run
802*44e8df1fSDamjan Jovanovic      */
803*44e8df1fSDamjan Jovanovic     TEST_F(resume, resume_002)
804*44e8df1fSDamjan Jovanovic         {
805*44e8df1fSDamjan Jovanovic             myThread* newthread = new myThread();
806*44e8df1fSDamjan Jovanovic             sal_Bool bRes = newthread->createSuspended();
807*44e8df1fSDamjan Jovanovic             ASSERT_TRUE(bRes == sal_True) << "Can't create thread!";
808cdf0e10cSrcweir 
809*44e8df1fSDamjan Jovanovic             newthread->resume();
810*44e8df1fSDamjan Jovanovic             ThreadHelper::thread_sleep_tenth_sec(2);
811*44e8df1fSDamjan Jovanovic             sal_Int32 nValue = newthread->getValue();
812cdf0e10cSrcweir 
813*44e8df1fSDamjan Jovanovic             termAndJoinThread(newthread);
814*44e8df1fSDamjan Jovanovic             delete newthread;
815cdf0e10cSrcweir 
816*44e8df1fSDamjan Jovanovic             printf("   nValue = %d\n", nValue);
817cdf0e10cSrcweir 
818*44e8df1fSDamjan Jovanovic             ASSERT_TRUE(nValue >= 1) << "Creates a suspended thread, then resume";
819*44e8df1fSDamjan Jovanovic         }
820cdf0e10cSrcweir 
821cdf0e10cSrcweir     /** Test of the osl::Thread::terminate method
822cdf0e10cSrcweir     */
823*44e8df1fSDamjan Jovanovic     class terminate : public ::testing::Test
824cdf0e10cSrcweir     {
825cdf0e10cSrcweir     public:
826cdf0e10cSrcweir         // initialise your test code values here.
827*44e8df1fSDamjan Jovanovic         void SetUp()
828cdf0e10cSrcweir             {
829cdf0e10cSrcweir             }
830cdf0e10cSrcweir 
831*44e8df1fSDamjan Jovanovic         void TearDown()
832cdf0e10cSrcweir             {
833cdf0e10cSrcweir             }
834*44e8df1fSDamjan Jovanovic     }; // class terminate
835cdf0e10cSrcweir 
836*44e8df1fSDamjan Jovanovic     /** Check after call terminate if the running thread running go on executing
837cdf0e10cSrcweir 
838*44e8df1fSDamjan Jovanovic         ALGORITHM:
839*44e8df1fSDamjan Jovanovic         before and after call terminate, the values should be the same
840*44e8df1fSDamjan Jovanovic     */
841*44e8df1fSDamjan Jovanovic     TEST_F(terminate, terminate_001)
842*44e8df1fSDamjan Jovanovic         {
843*44e8df1fSDamjan Jovanovic             OCountThread* aCountThread = new OCountThread();
844*44e8df1fSDamjan Jovanovic             sal_Bool bRes = aCountThread->create();
845*44e8df1fSDamjan Jovanovic             ASSERT_TRUE(bRes == sal_True) << "Can't start thread!";
846cdf0e10cSrcweir 
847*44e8df1fSDamjan Jovanovic             ThreadHelper::thread_sleep_tenth_sec(2);
848*44e8df1fSDamjan Jovanovic             sal_Int32 nValue = aCountThread->getValue();
849*44e8df1fSDamjan Jovanovic             aCountThread->terminate();
850*44e8df1fSDamjan Jovanovic             ThreadHelper::thread_sleep_tenth_sec(2);
851*44e8df1fSDamjan Jovanovic             sal_Int32 nLaterValue = aCountThread->getValue();
852*44e8df1fSDamjan Jovanovic 
853*44e8df1fSDamjan Jovanovic             // isRunning should be false after terminate
854*44e8df1fSDamjan Jovanovic             sal_Bool isRunning = aCountThread->isRunning();
855*44e8df1fSDamjan Jovanovic             aCountThread->join();
856*44e8df1fSDamjan Jovanovic             delete aCountThread;
857cdf0e10cSrcweir 
858*44e8df1fSDamjan Jovanovic             printf("     nValue = %d\n", nValue);
859*44e8df1fSDamjan Jovanovic             printf("nLaterValue = %d\n", nLaterValue);
860cdf0e10cSrcweir 
861*44e8df1fSDamjan Jovanovic             ASSERT_TRUE(isRunning == sal_False && nLaterValue >= nValue) << "Terminate the thread";
862*44e8df1fSDamjan Jovanovic         }
863*44e8df1fSDamjan Jovanovic     /** Check if a suspended thread will terminate after call terminate, different on w32 and on UNX
864*44e8df1fSDamjan Jovanovic      */
865*44e8df1fSDamjan Jovanovic     TEST_F(terminate, terminate_002)
866*44e8df1fSDamjan Jovanovic         {
867*44e8df1fSDamjan Jovanovic             OCountThread* aCountThread = new OCountThread();
868*44e8df1fSDamjan Jovanovic             sal_Bool bRes = aCountThread->create();
869*44e8df1fSDamjan Jovanovic             ASSERT_TRUE(bRes == sal_True) << "Can't start thread!";
870cdf0e10cSrcweir 
871*44e8df1fSDamjan Jovanovic             ThreadHelper::thread_sleep_tenth_sec(1);
872*44e8df1fSDamjan Jovanovic             suspendCountThread(aCountThread);
873*44e8df1fSDamjan Jovanovic             sal_Int32 nValue = aCountThread->getValue();
874cdf0e10cSrcweir 
875*44e8df1fSDamjan Jovanovic             // seems a suspended thread can not be terminated on W32, while on Solaris can
876*44e8df1fSDamjan Jovanovic             resumeAndWaitThread(aCountThread);
877cdf0e10cSrcweir 
878*44e8df1fSDamjan Jovanovic             ThreadHelper::thread_sleep_tenth_sec(2);
879*44e8df1fSDamjan Jovanovic 
880*44e8df1fSDamjan Jovanovic             termAndJoinThread(aCountThread);
881*44e8df1fSDamjan Jovanovic             sal_Int32 nLaterValue = aCountThread->getValue();
882*44e8df1fSDamjan Jovanovic             delete aCountThread;
883*44e8df1fSDamjan Jovanovic 
884*44e8df1fSDamjan Jovanovic             printf("     nValue = %d\n", nValue);
885*44e8df1fSDamjan Jovanovic             printf("nLaterValue = %d\n", nLaterValue);
886*44e8df1fSDamjan Jovanovic 
887*44e8df1fSDamjan Jovanovic             ASSERT_TRUE(nLaterValue > nValue) << "Suspend then resume the thread";
888*44e8df1fSDamjan Jovanovic         }
889cdf0e10cSrcweir 
890cdf0e10cSrcweir 
891cdf0e10cSrcweir     /** Test of the osl::Thread::join method
892cdf0e10cSrcweir     */
893*44e8df1fSDamjan Jovanovic     class join : public ::testing::Test
894cdf0e10cSrcweir     {
895cdf0e10cSrcweir     public:
896cdf0e10cSrcweir         // initialise your test code values here.
897*44e8df1fSDamjan Jovanovic         void SetUp()
898cdf0e10cSrcweir             {
899cdf0e10cSrcweir             }
900cdf0e10cSrcweir 
901*44e8df1fSDamjan Jovanovic         void TearDown()
902cdf0e10cSrcweir             {
903cdf0e10cSrcweir             }
904*44e8df1fSDamjan Jovanovic     }; // class join
905cdf0e10cSrcweir 
906*44e8df1fSDamjan Jovanovic     /** Check after call terminate if the thread running function will not go on executing
907cdf0e10cSrcweir 
908*44e8df1fSDamjan Jovanovic         the next statement after join will not exec before the thread terminate
909*44e8df1fSDamjan Jovanovic         ALGORITHM:
910*44e8df1fSDamjan Jovanovic         recode system time at the beginning of the thread run, call join, then record system time again,
911*44e8df1fSDamjan Jovanovic         the difference of the two time should be equal or more than 20 seconds, the CountThead normally terminate
912*44e8df1fSDamjan Jovanovic     */
913*44e8df1fSDamjan Jovanovic     TEST_F(join, join_001)
914*44e8df1fSDamjan Jovanovic         {
915*44e8df1fSDamjan Jovanovic             OCountThread *aCountThread = new OCountThread();
916*44e8df1fSDamjan Jovanovic             sal_Bool bRes = aCountThread->create();
917*44e8df1fSDamjan Jovanovic             ASSERT_TRUE(bRes == sal_True) << "Can't start thread!";
918cdf0e10cSrcweir 
919*44e8df1fSDamjan Jovanovic             StopWatch aStopWatch;
920*44e8df1fSDamjan Jovanovic             aStopWatch.start();
921*44e8df1fSDamjan Jovanovic             // TimeValue aTimeVal_befor;
922*44e8df1fSDamjan Jovanovic             // osl_getSystemTime( &aTimeVal_befor );
923*44e8df1fSDamjan Jovanovic             //printf("#join:the system time is %d,%d\n", pTimeVal_befor->Seconds,pTimeVal_befor->Nanosec);
924cdf0e10cSrcweir 
925*44e8df1fSDamjan Jovanovic             aCountThread->join();
926cdf0e10cSrcweir 
927*44e8df1fSDamjan Jovanovic             //the below line will be executed after aCountThread terminate
928*44e8df1fSDamjan Jovanovic             // TimeValue aTimeVal_after;
929*44e8df1fSDamjan Jovanovic             // osl_getSystemTime( &aTimeVal_after );
930*44e8df1fSDamjan Jovanovic             aStopWatch.stop();
931*44e8df1fSDamjan Jovanovic             // sal_uInt32 nSec  = aTimeVal_after.Seconds - aTimeVal_befor.Seconds;
932*44e8df1fSDamjan Jovanovic             double nSec = aStopWatch.getSeconds();
933*44e8df1fSDamjan Jovanovic             printf("join_001 nSec=%f\n", nSec);
934*44e8df1fSDamjan Jovanovic             delete aCountThread;
935*44e8df1fSDamjan Jovanovic 
936*44e8df1fSDamjan Jovanovic             ASSERT_TRUE(nSec >= 2) << "Join the thread: after the thread terminate";
937*44e8df1fSDamjan Jovanovic 
938*44e8df1fSDamjan Jovanovic         }
939*44e8df1fSDamjan Jovanovic     /** after terminated by another thread, join exited immediately
940*44e8df1fSDamjan Jovanovic 
941*44e8df1fSDamjan Jovanovic         ALGORITHM:
942*44e8df1fSDamjan Jovanovic         terminate the thread when value>=3, call join, check the beginning time and time after join,
943*44e8df1fSDamjan Jovanovic         the difference should be 3 seconds, join costs little time
944*44e8df1fSDamjan Jovanovic     */
945*44e8df1fSDamjan Jovanovic     TEST_F(join, join_002)
946*44e8df1fSDamjan Jovanovic         {
947*44e8df1fSDamjan Jovanovic             OCountThread *aCountThread = new OCountThread();
948*44e8df1fSDamjan Jovanovic             sal_Bool bRes = aCountThread->create();
949*44e8df1fSDamjan Jovanovic             ASSERT_TRUE(bRes == sal_True) << "Can't start thread!";
950*44e8df1fSDamjan Jovanovic 
951*44e8df1fSDamjan Jovanovic             //record the time when the running begin
952*44e8df1fSDamjan Jovanovic             // TimeValue aTimeVal_befor;
953*44e8df1fSDamjan Jovanovic             // osl_getSystemTime( &aTimeVal_befor );
954*44e8df1fSDamjan Jovanovic             StopWatch aStopWatch;
955*44e8df1fSDamjan Jovanovic             aStopWatch.start();
956*44e8df1fSDamjan Jovanovic 
957*44e8df1fSDamjan Jovanovic             ThreadHelper::thread_sleep_tenth_sec(10);
958*44e8df1fSDamjan Jovanovic             termAndJoinThread(aCountThread);
959*44e8df1fSDamjan Jovanovic 
960*44e8df1fSDamjan Jovanovic             //the below line will be executed after aCountThread terminate
961*44e8df1fSDamjan Jovanovic             // TimeValue aTimeVal_after;
962*44e8df1fSDamjan Jovanovic             // osl_getSystemTime( &aTimeVal_after );
963*44e8df1fSDamjan Jovanovic             // sal_uInt32 nSec  = aTimeVal_after.Seconds - aTimeVal_befor.Seconds;
964*44e8df1fSDamjan Jovanovic             aStopWatch.stop();
965*44e8df1fSDamjan Jovanovic             double nSec = aStopWatch.getSeconds();
966*44e8df1fSDamjan Jovanovic             printf("join_002 nSec=%f\n", nSec);
967*44e8df1fSDamjan Jovanovic 
968*44e8df1fSDamjan Jovanovic             delete aCountThread;
969*44e8df1fSDamjan Jovanovic             ASSERT_TRUE(nSec >= 1) << "Join the thread: after thread terminate by another thread";
970*44e8df1fSDamjan Jovanovic         }
971cdf0e10cSrcweir 
972cdf0e10cSrcweir     /** Test of the osl::Thread::isRunning method
973cdf0e10cSrcweir     */
974*44e8df1fSDamjan Jovanovic     class isRunning : public ::testing::Test
975cdf0e10cSrcweir     {
976cdf0e10cSrcweir     public:
977cdf0e10cSrcweir         // initialise your test code values here.
978*44e8df1fSDamjan Jovanovic         void SetUp()
979cdf0e10cSrcweir             {
980cdf0e10cSrcweir             }
981cdf0e10cSrcweir 
982*44e8df1fSDamjan Jovanovic         void TearDown()
983cdf0e10cSrcweir             {
984cdf0e10cSrcweir             }
985*44e8df1fSDamjan Jovanovic     }; // class isRunning
986cdf0e10cSrcweir 
987*44e8df1fSDamjan Jovanovic     /**
988*44e8df1fSDamjan Jovanovic      */
989*44e8df1fSDamjan Jovanovic     TEST_F(isRunning, isRunning_001)
990*44e8df1fSDamjan Jovanovic         {
991*44e8df1fSDamjan Jovanovic             OCountThread *aCountThread = new OCountThread();
992*44e8df1fSDamjan Jovanovic             sal_Bool bRes = aCountThread->create();
993*44e8df1fSDamjan Jovanovic             ASSERT_TRUE(bRes == sal_True) << "Can't start thread!";
994cdf0e10cSrcweir 
995*44e8df1fSDamjan Jovanovic             sal_Bool bRun = aCountThread->isRunning();
996cdf0e10cSrcweir 
997*44e8df1fSDamjan Jovanovic             ThreadHelper::thread_sleep_tenth_sec(2);
998*44e8df1fSDamjan Jovanovic             termAndJoinThread(aCountThread);
999*44e8df1fSDamjan Jovanovic             sal_Bool bTer = aCountThread->isRunning();
1000*44e8df1fSDamjan Jovanovic             delete aCountThread;
1001cdf0e10cSrcweir 
1002*44e8df1fSDamjan Jovanovic             ASSERT_TRUE(bRun == sal_True && bTer == sal_False) << "Test isRunning";
1003*44e8df1fSDamjan Jovanovic         }
1004*44e8df1fSDamjan Jovanovic     /** check the value of isRunning when suspending and after resume
1005*44e8df1fSDamjan Jovanovic      */
1006*44e8df1fSDamjan Jovanovic     TEST_F(isRunning, isRunning_002)
1007*44e8df1fSDamjan Jovanovic         {
1008*44e8df1fSDamjan Jovanovic             OCountThread *aCountThread = new OCountThread();
1009*44e8df1fSDamjan Jovanovic             sal_Bool bRes = aCountThread->create();
1010*44e8df1fSDamjan Jovanovic             ASSERT_TRUE(bRes == sal_True) << "Can't start thread!";
1011*44e8df1fSDamjan Jovanovic 
1012*44e8df1fSDamjan Jovanovic             // sal_Bool bRunning = aCountThread->isRunning();
1013*44e8df1fSDamjan Jovanovic             // sal_Int32 nValue = 0;
1014*44e8df1fSDamjan Jovanovic             suspendCountThread(aCountThread);
1015*44e8df1fSDamjan Jovanovic 
1016*44e8df1fSDamjan Jovanovic             sal_Bool bRunning_sup = aCountThread->isRunning();
1017*44e8df1fSDamjan Jovanovic             ThreadHelper::thread_sleep_tenth_sec(2);
1018*44e8df1fSDamjan Jovanovic             aCountThread->resume();
1019*44e8df1fSDamjan Jovanovic             ThreadHelper::thread_sleep_tenth_sec(2);
1020*44e8df1fSDamjan Jovanovic             sal_Bool bRunning_res = aCountThread->isRunning();
1021*44e8df1fSDamjan Jovanovic             termAndJoinThread(aCountThread);
1022*44e8df1fSDamjan Jovanovic             sal_Bool bRunning_ter = aCountThread->isRunning();
1023*44e8df1fSDamjan Jovanovic             delete aCountThread;
1024*44e8df1fSDamjan Jovanovic 
1025*44e8df1fSDamjan Jovanovic             ASSERT_TRUE(bRes == sal_True &&
1026*44e8df1fSDamjan Jovanovic                 bRunning_sup == sal_True &&
1027*44e8df1fSDamjan Jovanovic                 bRunning_res == sal_True &&
1028*44e8df1fSDamjan Jovanovic                 bRunning_ter == sal_False) << "Test isRunning";
1029cdf0e10cSrcweir 
1030*44e8df1fSDamjan Jovanovic         }
1031cdf0e10cSrcweir 
1032cdf0e10cSrcweir     /// check osl::Thread::setPriority
1033*44e8df1fSDamjan Jovanovic     class setPriority : public ::testing::Test
1034cdf0e10cSrcweir     {
1035cdf0e10cSrcweir     public:
1036cdf0e10cSrcweir         // initialise your test code values here.
1037*44e8df1fSDamjan Jovanovic         void SetUp()
1038cdf0e10cSrcweir             {
1039cdf0e10cSrcweir             }
1040cdf0e10cSrcweir 
1041*44e8df1fSDamjan Jovanovic         void TearDown()
1042cdf0e10cSrcweir             {
1043cdf0e10cSrcweir             }
1044cdf0e10cSrcweir 
1045cdf0e10cSrcweir         // insert your test code here.
1046cdf0e10cSrcweir         rtl::OString getPrioName(oslThreadPriority _aPriority)
1047cdf0e10cSrcweir             {
1048cdf0e10cSrcweir                 rtl::OString sPrioStr;
1049cdf0e10cSrcweir                 switch (_aPriority)
1050cdf0e10cSrcweir                 {
1051cdf0e10cSrcweir                 case osl_Thread_PriorityHighest:
1052cdf0e10cSrcweir                     sPrioStr = "Highest";
1053cdf0e10cSrcweir                     break;
1054cdf0e10cSrcweir 
1055cdf0e10cSrcweir                 case osl_Thread_PriorityAboveNormal:
1056cdf0e10cSrcweir                     sPrioStr = "AboveNormal";
1057cdf0e10cSrcweir 
1058cdf0e10cSrcweir                 case osl_Thread_PriorityNormal:
1059cdf0e10cSrcweir                     sPrioStr = "Normal";
1060cdf0e10cSrcweir 
1061cdf0e10cSrcweir                 case osl_Thread_PriorityBelowNormal:
1062cdf0e10cSrcweir                     sPrioStr = "BelowNormal";
1063cdf0e10cSrcweir                     break;
1064cdf0e10cSrcweir 
1065cdf0e10cSrcweir                 case osl_Thread_PriorityLowest:
1066cdf0e10cSrcweir                     sPrioStr = "Lowest";
1067cdf0e10cSrcweir                     break;
1068cdf0e10cSrcweir                 default:
1069cdf0e10cSrcweir                     sPrioStr = "unknown";
1070cdf0e10cSrcweir                 }
1071cdf0e10cSrcweir                 return sPrioStr;
1072cdf0e10cSrcweir             }
1073cdf0e10cSrcweir 
1074cdf0e10cSrcweir 
1075cdf0e10cSrcweir         /** check 2 threads.
1076cdf0e10cSrcweir 
1077cdf0e10cSrcweir             ALGORITHM:
1078cdf0e10cSrcweir             Here the function should show, that 2 different threads,
1079cdf0e10cSrcweir             which only increase a value, should run at the same time with same prio.
1080cdf0e10cSrcweir             The test fails, if the difference between the two values is more than 5%
1081cdf0e10cSrcweir             but IMHO this isn't a failure, it's only a feature of the OS.
1082cdf0e10cSrcweir         */
1083cdf0e10cSrcweir 
1084cdf0e10cSrcweir         void check2Threads(oslThreadPriority _aPriority)
1085cdf0e10cSrcweir             {
1086cdf0e10cSrcweir                 // initial 5 threads with different priorities
1087cdf0e10cSrcweir                 OAddThread* pThread = new OAddThread();
1088cdf0e10cSrcweir                 OAddThread* p2Thread = new OAddThread();
1089cdf0e10cSrcweir 
1090cdf0e10cSrcweir                 //Create them and start running at the same time
1091cdf0e10cSrcweir                 pThread->create();
1092cdf0e10cSrcweir                 pThread->setPriority(_aPriority);
1093cdf0e10cSrcweir                 p2Thread->create();
1094cdf0e10cSrcweir                 p2Thread->setPriority(_aPriority);
1095cdf0e10cSrcweir 
1096cdf0e10cSrcweir                 ThreadHelper::thread_sleep_tenth_sec(5);
1097cdf0e10cSrcweir 
1098cdf0e10cSrcweir                 pThread->terminate();
1099cdf0e10cSrcweir                 p2Thread->terminate();
1100cdf0e10cSrcweir 
1101cdf0e10cSrcweir                 sal_Int32 nValueNormal = 0;
1102cdf0e10cSrcweir                 nValueNormal = pThread->getValue();
1103cdf0e10cSrcweir 
1104cdf0e10cSrcweir                 sal_Int32 nValueNormal2 = 0;
1105cdf0e10cSrcweir                 nValueNormal2 = p2Thread->getValue();
1106cdf0e10cSrcweir 
1107cdf0e10cSrcweir                 rtl::OString sPrio = getPrioName(_aPriority);
1108*44e8df1fSDamjan Jovanovic                 printf("After 10 tenth seconds\n");
1109cdf0e10cSrcweir 
1110*44e8df1fSDamjan Jovanovic                 printf("nValue in %s Prio Thread is  %d\n",sPrio.getStr(), nValueNormal);
1111*44e8df1fSDamjan Jovanovic                 printf("nValue in %s Prio Thread is %d\n", sPrio.getStr(), nValueNormal2);
1112cdf0e10cSrcweir 
1113cdf0e10cSrcweir                 // ThreadHelper::thread_sleep_tenth_sec(1);
1114cdf0e10cSrcweir                 pThread->join();
1115cdf0e10cSrcweir                 p2Thread->join();
1116cdf0e10cSrcweir 
1117cdf0e10cSrcweir                 delete pThread;
1118cdf0e10cSrcweir                 delete p2Thread;
1119cdf0e10cSrcweir 
1120cdf0e10cSrcweir                 sal_Int32 nDelta = abs(nValueNormal - nValueNormal2);
1121cdf0e10cSrcweir                 double nQuotient = std::max(nValueNormal, nValueNormal2);
1122*44e8df1fSDamjan Jovanovic                 ASSERT_TRUE(nQuotient != 0) << "Quotient is zero, which means, there exist no right values.";
1123cdf0e10cSrcweir                 double nDeltaPercent = nDelta / nQuotient * 100;
1124cdf0e10cSrcweir 
1125*44e8df1fSDamjan Jovanovic                 printf("Delta value %d, percent %f\n",nDelta, nDeltaPercent);
1126cdf0e10cSrcweir 
1127cdf0e10cSrcweir                 // LLA: it's not a bug if the current OS is not able to handle thread scheduling right and good.
1128cdf0e10cSrcweir                 // like Windows XP
1129*44e8df1fSDamjan Jovanovic                 // LLA: ASSERT_TRUE(// LLA:     nDeltaPercent <= 5
1130*44e8df1fSDamjan Jovanovic                 // LLA:) << // LLA:     "Run 2 normal threads, the count diff more than 5 percent.";
1131cdf0e10cSrcweir             }
1132*44e8df1fSDamjan Jovanovic     }; // class setPriority
1133cdf0e10cSrcweir 
1134*44e8df1fSDamjan Jovanovic     TEST_F(setPriority, setPriority_001_1)
1135*44e8df1fSDamjan Jovanovic         {
1136*44e8df1fSDamjan Jovanovic             check2Threads(osl_Thread_PriorityHighest);
1137*44e8df1fSDamjan Jovanovic         }
1138*44e8df1fSDamjan Jovanovic     TEST_F(setPriority, setPriority_001_2)
1139*44e8df1fSDamjan Jovanovic         {
1140*44e8df1fSDamjan Jovanovic             check2Threads(osl_Thread_PriorityAboveNormal);
1141*44e8df1fSDamjan Jovanovic         }
1142*44e8df1fSDamjan Jovanovic     TEST_F(setPriority, setPriority_001_3)
1143*44e8df1fSDamjan Jovanovic         {
1144*44e8df1fSDamjan Jovanovic             check2Threads(osl_Thread_PriorityNormal);
1145*44e8df1fSDamjan Jovanovic         }
1146*44e8df1fSDamjan Jovanovic     TEST_F(setPriority, setPriority_001_4)
1147*44e8df1fSDamjan Jovanovic         {
1148*44e8df1fSDamjan Jovanovic             check2Threads(osl_Thread_PriorityBelowNormal);
1149*44e8df1fSDamjan Jovanovic         }
1150*44e8df1fSDamjan Jovanovic     TEST_F(setPriority, setPriority_001_5)
1151*44e8df1fSDamjan Jovanovic         {
1152*44e8df1fSDamjan Jovanovic             check2Threads(osl_Thread_PriorityLowest);
1153*44e8df1fSDamjan Jovanovic         }
1154cdf0e10cSrcweir 
1155*44e8df1fSDamjan Jovanovic #ifndef SOLARIS
1156*44e8df1fSDamjan Jovanovic     TEST_F(setPriority, setPriority_002)
1157*44e8df1fSDamjan Jovanovic         {
1158*44e8df1fSDamjan Jovanovic             // initial 5 threads with different priorities
1159*44e8df1fSDamjan Jovanovic 
1160*44e8df1fSDamjan Jovanovic             OAddThread aHighestThread;
1161*44e8df1fSDamjan Jovanovic             OAddThread aAboveNormalThread;
1162*44e8df1fSDamjan Jovanovic             OAddThread aNormalThread;
1163*44e8df1fSDamjan Jovanovic             //OAddThread *aBelowNormalThread = new OAddThread();
1164*44e8df1fSDamjan Jovanovic             //OAddThread *aLowestThread = new OAddThread();
1165*44e8df1fSDamjan Jovanovic 
1166*44e8df1fSDamjan Jovanovic             //Create them and start running at the same time
1167*44e8df1fSDamjan Jovanovic             aHighestThread.createSuspended();
1168*44e8df1fSDamjan Jovanovic             aHighestThread.setPriority(osl_Thread_PriorityHighest);
1169*44e8df1fSDamjan Jovanovic 
1170*44e8df1fSDamjan Jovanovic             aAboveNormalThread.createSuspended();
1171*44e8df1fSDamjan Jovanovic             aAboveNormalThread.setPriority(osl_Thread_PriorityAboveNormal);
1172*44e8df1fSDamjan Jovanovic 
1173*44e8df1fSDamjan Jovanovic             aNormalThread.createSuspended();
1174*44e8df1fSDamjan Jovanovic             aNormalThread.setPriority(osl_Thread_PriorityNormal);
1175*44e8df1fSDamjan Jovanovic             /*aBelowNormalThread->create();
1176*44e8df1fSDamjan Jovanovic               aBelowNormalThread->setPriority(osl_Thread_PriorityBelowNormal);
1177*44e8df1fSDamjan Jovanovic               aLowestThread->create();
1178*44e8df1fSDamjan Jovanovic               aLowestThread->setPriority(osl_Thread_PriorityLowest);
1179*44e8df1fSDamjan Jovanovic             */
1180*44e8df1fSDamjan Jovanovic 
1181*44e8df1fSDamjan Jovanovic             aHighestThread.resume();
1182*44e8df1fSDamjan Jovanovic             aAboveNormalThread.resume();
1183*44e8df1fSDamjan Jovanovic             aNormalThread.resume();
1184*44e8df1fSDamjan Jovanovic 
1185*44e8df1fSDamjan Jovanovic             ThreadHelper::thread_sleep_tenth_sec(5);
1186*44e8df1fSDamjan Jovanovic 
1187*44e8df1fSDamjan Jovanovic             aHighestThread.suspend();
1188*44e8df1fSDamjan Jovanovic             aAboveNormalThread.suspend();
1189*44e8df1fSDamjan Jovanovic             aNormalThread.suspend();
1190*44e8df1fSDamjan Jovanovic 
1191*44e8df1fSDamjan Jovanovic             termAndJoinThread(&aNormalThread);
1192*44e8df1fSDamjan Jovanovic             termAndJoinThread(&aAboveNormalThread);
1193*44e8df1fSDamjan Jovanovic             termAndJoinThread(&aHighestThread);
1194*44e8df1fSDamjan Jovanovic             //aBelowNormalThread->terminate();
1195*44e8df1fSDamjan Jovanovic             //aLowestThread->terminate();
1196*44e8df1fSDamjan Jovanovic 
1197*44e8df1fSDamjan Jovanovic             sal_Int32 nValueHighest = 0;
1198*44e8df1fSDamjan Jovanovic             nValueHighest = aHighestThread.getValue();
1199*44e8df1fSDamjan Jovanovic 
1200*44e8df1fSDamjan Jovanovic             sal_Int32 nValueAboveNormal = 0;
1201*44e8df1fSDamjan Jovanovic             nValueAboveNormal = aAboveNormalThread.getValue();
1202*44e8df1fSDamjan Jovanovic 
1203*44e8df1fSDamjan Jovanovic             sal_Int32 nValueNormal = 0;
1204*44e8df1fSDamjan Jovanovic             nValueNormal = aNormalThread.getValue();
1205*44e8df1fSDamjan Jovanovic 
1206*44e8df1fSDamjan Jovanovic             // sal_Int32 nValueBelowNormal = 0;
1207*44e8df1fSDamjan Jovanovic             //nValueBelowNormal = aBelowNormalThread->getValue();
1208*44e8df1fSDamjan Jovanovic             // sal_Int32 nValueLowest = 0;
1209*44e8df1fSDamjan Jovanovic             //nValueLowest = aLowestThread->getValue();
1210*44e8df1fSDamjan Jovanovic             printf("After 10 tenth seconds\n");
1211*44e8df1fSDamjan Jovanovic             printf("nValue in Highest Prio Thread is %d\n",nValueHighest);
1212*44e8df1fSDamjan Jovanovic             printf("nValue in AboveNormal Prio Thread is %d\n",nValueAboveNormal);
1213*44e8df1fSDamjan Jovanovic             printf("nValue in Normal Prio Thread is %d\n",nValueNormal);
1214*44e8df1fSDamjan Jovanovic 
1215*44e8df1fSDamjan Jovanovic             // LLA: this is not a save test, so we only check if all values not zero
1216*44e8df1fSDamjan Jovanovic             // LLA: ASSERT_TRUE(// LLA:     nValueHighest >= nValueAboveNormal &&
1217*44e8df1fSDamjan Jovanovic             // LLA:     nValueAboveNormal >= nValueNormal &&
1218*44e8df1fSDamjan Jovanovic             // LLA:     nValueNormal > 0
1219*44e8df1fSDamjan Jovanovic             // LLA:) << // LLA:     "SetPriority";
1220cdf0e10cSrcweir 
1221cdf0e10cSrcweir // LLA: windows let starve threads with lower priority
1222cdf0e10cSrcweir #ifndef WNT
1223*44e8df1fSDamjan Jovanovic             ASSERT_TRUE(nValueHighest     > 0 &&
1224*44e8df1fSDamjan Jovanovic                 nValueAboveNormal > 0 &&
1225*44e8df1fSDamjan Jovanovic                 nValueNormal > 0) << "SetPriority";
1226cdf0e10cSrcweir #endif
1227*44e8df1fSDamjan Jovanovic         }
1228cdf0e10cSrcweir 
1229*44e8df1fSDamjan Jovanovic     TEST_F(setPriority, setPriority_003)
1230*44e8df1fSDamjan Jovanovic         {
1231*44e8df1fSDamjan Jovanovic             // initial 5 threads with different priorities
1232*44e8df1fSDamjan Jovanovic             OAddThread *pHighestThread = new OAddThread();
1233*44e8df1fSDamjan Jovanovic             OAddThread *pAboveNormalThread = new OAddThread();
1234*44e8df1fSDamjan Jovanovic             OAddThread *pNormalThread = new OAddThread();
1235*44e8df1fSDamjan Jovanovic             OAddThread *pBelowNormalThread = new OAddThread();
1236*44e8df1fSDamjan Jovanovic             OAddThread *pLowestThread = new OAddThread();
1237*44e8df1fSDamjan Jovanovic 
1238*44e8df1fSDamjan Jovanovic             //Create them and start running at the same time
1239*44e8df1fSDamjan Jovanovic             pHighestThread->createSuspended();
1240*44e8df1fSDamjan Jovanovic             pHighestThread->setPriority(osl_Thread_PriorityHighest);
1241*44e8df1fSDamjan Jovanovic 
1242*44e8df1fSDamjan Jovanovic             pAboveNormalThread->createSuspended();
1243*44e8df1fSDamjan Jovanovic             pAboveNormalThread->setPriority(osl_Thread_PriorityAboveNormal);
1244*44e8df1fSDamjan Jovanovic 
1245*44e8df1fSDamjan Jovanovic             pNormalThread->createSuspended();
1246*44e8df1fSDamjan Jovanovic             pNormalThread->setPriority(osl_Thread_PriorityNormal);
1247*44e8df1fSDamjan Jovanovic 
1248*44e8df1fSDamjan Jovanovic             pBelowNormalThread->createSuspended();
1249*44e8df1fSDamjan Jovanovic             pBelowNormalThread->setPriority(osl_Thread_PriorityBelowNormal);
1250*44e8df1fSDamjan Jovanovic 
1251*44e8df1fSDamjan Jovanovic             pLowestThread->createSuspended();
1252*44e8df1fSDamjan Jovanovic             pLowestThread->setPriority(osl_Thread_PriorityLowest);
1253*44e8df1fSDamjan Jovanovic 
1254*44e8df1fSDamjan Jovanovic             pHighestThread->resume();
1255*44e8df1fSDamjan Jovanovic             pAboveNormalThread->resume();
1256*44e8df1fSDamjan Jovanovic             pNormalThread->resume();
1257*44e8df1fSDamjan Jovanovic             pBelowNormalThread->resume();
1258*44e8df1fSDamjan Jovanovic             pLowestThread->resume();
1259*44e8df1fSDamjan Jovanovic 
1260*44e8df1fSDamjan Jovanovic             ThreadHelper::thread_sleep_tenth_sec(5);
1261*44e8df1fSDamjan Jovanovic 
1262*44e8df1fSDamjan Jovanovic             pHighestThread->suspend();
1263*44e8df1fSDamjan Jovanovic             pAboveNormalThread->suspend();
1264*44e8df1fSDamjan Jovanovic             pNormalThread->suspend();
1265*44e8df1fSDamjan Jovanovic             pBelowNormalThread->suspend();
1266*44e8df1fSDamjan Jovanovic             pLowestThread->suspend();
1267*44e8df1fSDamjan Jovanovic 
1268*44e8df1fSDamjan Jovanovic             termAndJoinThread(pHighestThread);
1269*44e8df1fSDamjan Jovanovic             termAndJoinThread(pAboveNormalThread);
1270*44e8df1fSDamjan Jovanovic             termAndJoinThread(pNormalThread);
1271*44e8df1fSDamjan Jovanovic             termAndJoinThread(pBelowNormalThread);
1272*44e8df1fSDamjan Jovanovic             termAndJoinThread(pLowestThread);
1273*44e8df1fSDamjan Jovanovic 
1274*44e8df1fSDamjan Jovanovic             sal_Int32 nValueHighest = 0;
1275*44e8df1fSDamjan Jovanovic             nValueHighest = pHighestThread->getValue();
1276*44e8df1fSDamjan Jovanovic 
1277*44e8df1fSDamjan Jovanovic             sal_Int32 nValueAboveNormal = 0;
1278*44e8df1fSDamjan Jovanovic             nValueAboveNormal = pAboveNormalThread->getValue();
1279*44e8df1fSDamjan Jovanovic 
1280*44e8df1fSDamjan Jovanovic             sal_Int32 nValueNormal = 0;
1281*44e8df1fSDamjan Jovanovic             nValueNormal = pNormalThread->getValue();
1282*44e8df1fSDamjan Jovanovic 
1283*44e8df1fSDamjan Jovanovic             sal_Int32 nValueBelowNormal = 0;
1284*44e8df1fSDamjan Jovanovic             nValueBelowNormal = pBelowNormalThread->getValue();
1285*44e8df1fSDamjan Jovanovic 
1286*44e8df1fSDamjan Jovanovic             sal_Int32 nValueLowest = 0;
1287*44e8df1fSDamjan Jovanovic             nValueLowest = pLowestThread->getValue();
1288*44e8df1fSDamjan Jovanovic 
1289*44e8df1fSDamjan Jovanovic             printf("After 10 tenth seconds\n");
1290*44e8df1fSDamjan Jovanovic             printf("nValue in Highest Prio Thread is     %d\n",nValueHighest);
1291*44e8df1fSDamjan Jovanovic             printf("nValue in AboveNormal Prio Thread is %d\n",nValueAboveNormal);
1292*44e8df1fSDamjan Jovanovic             printf("nValue in Normal Prio Thread is      %d\n",nValueNormal);
1293*44e8df1fSDamjan Jovanovic             printf("nValue in BelowNormal Prio Thread is %d\n",nValueBelowNormal);
1294*44e8df1fSDamjan Jovanovic             printf("nValue in Lowest Prio Thread is      %d\n",nValueLowest);
1295*44e8df1fSDamjan Jovanovic 
1296*44e8df1fSDamjan Jovanovic             delete pHighestThread;
1297*44e8df1fSDamjan Jovanovic             delete pAboveNormalThread;
1298*44e8df1fSDamjan Jovanovic             delete pNormalThread;
1299*44e8df1fSDamjan Jovanovic             delete pBelowNormalThread;
1300*44e8df1fSDamjan Jovanovic             delete pLowestThread;
1301*44e8df1fSDamjan Jovanovic 
1302*44e8df1fSDamjan Jovanovic             // LLA: this is not a save test, so we only check if all values not zero
1303*44e8df1fSDamjan Jovanovic             // LLA: ASSERT_TRUE(// LLA:     nValueHighest > nValueAboveNormal &&
1304*44e8df1fSDamjan Jovanovic             // LLA:     nValueAboveNormal > nValueNormal &&
1305*44e8df1fSDamjan Jovanovic             // LLA:     nValueNormal > nValueBelowNormal &&
1306*44e8df1fSDamjan Jovanovic             // LLA:     nValueBelowNormal > nValueLowest &&
1307*44e8df1fSDamjan Jovanovic             // LLA:     nValueLowest > 0
1308*44e8df1fSDamjan Jovanovic             // LLA:) << // LLA:     "SetPriority";
1309cdf0e10cSrcweir 
1310cdf0e10cSrcweir // LLA: windows let starve threads with lower priority
1311cdf0e10cSrcweir #ifndef WNT
1312*44e8df1fSDamjan Jovanovic             ASSERT_TRUE(nValueHighest     > 0 &&
1313*44e8df1fSDamjan Jovanovic                 nValueAboveNormal > 0 &&
1314*44e8df1fSDamjan Jovanovic                 nValueNormal      > 0 &&
1315*44e8df1fSDamjan Jovanovic                 nValueBelowNormal > 0 &&
1316*44e8df1fSDamjan Jovanovic                 nValueLowest      > 0) << "SetPriority";
1317cdf0e10cSrcweir #endif
1318*44e8df1fSDamjan Jovanovic         }
1319cdf0e10cSrcweir 
1320*44e8df1fSDamjan Jovanovic     TEST_F(setPriority, setPriority_004)
1321*44e8df1fSDamjan Jovanovic         {
1322*44e8df1fSDamjan Jovanovic             // initial 5 threads with different priorities
1323*44e8df1fSDamjan Jovanovic             // OAddThread *pHighestThread = new OAddThread();
1324*44e8df1fSDamjan Jovanovic             OAddThread *pAboveNormalThread = new OAddThread();
1325*44e8df1fSDamjan Jovanovic             OAddThread *pNormalThread = new OAddThread();
1326*44e8df1fSDamjan Jovanovic             OAddThread *pBelowNormalThread = new OAddThread();
1327*44e8df1fSDamjan Jovanovic             OAddThread *pLowestThread = new OAddThread();
1328*44e8df1fSDamjan Jovanovic 
1329*44e8df1fSDamjan Jovanovic             //Create them and start running at the same time
1330*44e8df1fSDamjan Jovanovic             // pHighestThread->createSuspended();
1331*44e8df1fSDamjan Jovanovic             // pHighestThread->setPriority(osl_Thread_PriorityHighest);
1332*44e8df1fSDamjan Jovanovic 
1333*44e8df1fSDamjan Jovanovic             pAboveNormalThread->createSuspended();
1334*44e8df1fSDamjan Jovanovic             pAboveNormalThread->setPriority(osl_Thread_PriorityAboveNormal);
1335*44e8df1fSDamjan Jovanovic 
1336*44e8df1fSDamjan Jovanovic             pNormalThread->createSuspended();
1337*44e8df1fSDamjan Jovanovic             pNormalThread->setPriority(osl_Thread_PriorityNormal);
1338*44e8df1fSDamjan Jovanovic 
1339*44e8df1fSDamjan Jovanovic             pBelowNormalThread->createSuspended();
1340*44e8df1fSDamjan Jovanovic             pBelowNormalThread->setPriority(osl_Thread_PriorityBelowNormal);
1341*44e8df1fSDamjan Jovanovic 
1342*44e8df1fSDamjan Jovanovic             pLowestThread->createSuspended();
1343*44e8df1fSDamjan Jovanovic             pLowestThread->setPriority(osl_Thread_PriorityLowest);
1344*44e8df1fSDamjan Jovanovic 
1345*44e8df1fSDamjan Jovanovic             // pHighestThread->resume();
1346*44e8df1fSDamjan Jovanovic             pAboveNormalThread->resume();
1347*44e8df1fSDamjan Jovanovic             pNormalThread->resume();
1348*44e8df1fSDamjan Jovanovic             pBelowNormalThread->resume();
1349*44e8df1fSDamjan Jovanovic             pLowestThread->resume();
1350*44e8df1fSDamjan Jovanovic 
1351*44e8df1fSDamjan Jovanovic             ThreadHelper::thread_sleep_tenth_sec(5);
1352*44e8df1fSDamjan Jovanovic 
1353*44e8df1fSDamjan Jovanovic             // pHighestThread->suspend();
1354*44e8df1fSDamjan Jovanovic             pAboveNormalThread->suspend();
1355*44e8df1fSDamjan Jovanovic             pNormalThread->suspend();
1356*44e8df1fSDamjan Jovanovic             pBelowNormalThread->suspend();
1357*44e8df1fSDamjan Jovanovic             pLowestThread->suspend();
1358*44e8df1fSDamjan Jovanovic 
1359*44e8df1fSDamjan Jovanovic             // termAndJoinThread(pHighestThread);
1360*44e8df1fSDamjan Jovanovic             termAndJoinThread(pAboveNormalThread);
1361*44e8df1fSDamjan Jovanovic             termAndJoinThread(pNormalThread);
1362*44e8df1fSDamjan Jovanovic             termAndJoinThread(pBelowNormalThread);
1363*44e8df1fSDamjan Jovanovic             termAndJoinThread(pLowestThread);
1364*44e8df1fSDamjan Jovanovic 
1365*44e8df1fSDamjan Jovanovic             // sal_Int32 nValueHighest  = 0;
1366*44e8df1fSDamjan Jovanovic             // nValueHighest =  pHighestThread->getValue();
1367*44e8df1fSDamjan Jovanovic 
1368*44e8df1fSDamjan Jovanovic             sal_Int32 nValueAboveNormal = 0;
1369*44e8df1fSDamjan Jovanovic             nValueAboveNormal = pAboveNormalThread->getValue();
1370*44e8df1fSDamjan Jovanovic 
1371*44e8df1fSDamjan Jovanovic             sal_Int32 nValueNormal = 0;
1372*44e8df1fSDamjan Jovanovic             nValueNormal = pNormalThread->getValue();
1373*44e8df1fSDamjan Jovanovic 
1374*44e8df1fSDamjan Jovanovic             sal_Int32 nValueBelowNormal = 0;
1375*44e8df1fSDamjan Jovanovic             nValueBelowNormal = pBelowNormalThread->getValue();
1376*44e8df1fSDamjan Jovanovic 
1377*44e8df1fSDamjan Jovanovic             sal_Int32 nValueLowest = 0;
1378*44e8df1fSDamjan Jovanovic             nValueLowest = pLowestThread->getValue();
1379*44e8df1fSDamjan Jovanovic 
1380*44e8df1fSDamjan Jovanovic             printf("After 5 tenth seconds\n");
1381*44e8df1fSDamjan Jovanovic             // printf("nValue in Highest Prio Thread  is     %d\n",nValueHighest);
1382*44e8df1fSDamjan Jovanovic             printf("nValue in AboveNormal Prio Thread is %d\n",nValueAboveNormal);
1383*44e8df1fSDamjan Jovanovic             printf("nValue in Normal Prio Thread is      %d\n",nValueNormal);
1384*44e8df1fSDamjan Jovanovic             printf("nValue in BelowNormal Prio Thread is %d\n",nValueBelowNormal);
1385*44e8df1fSDamjan Jovanovic             printf("nValue in Lowest Prio Thread is      %d\n",nValueLowest);
1386*44e8df1fSDamjan Jovanovic 
1387*44e8df1fSDamjan Jovanovic             // delete pHighestThread;
1388*44e8df1fSDamjan Jovanovic             delete pAboveNormalThread;
1389*44e8df1fSDamjan Jovanovic             delete pNormalThread;
1390*44e8df1fSDamjan Jovanovic             delete pBelowNormalThread;
1391*44e8df1fSDamjan Jovanovic             delete pLowestThread;
1392*44e8df1fSDamjan Jovanovic 
1393*44e8df1fSDamjan Jovanovic             // LLA: this is not a save test, so we only check if all values not zero
1394*44e8df1fSDamjan Jovanovic             // LLA: ASSERT_TRUE(// LLA:     nValueHighest > nValueAboveNormal &&
1395*44e8df1fSDamjan Jovanovic             // LLA:     nValueAboveNormal > nValueNormal &&
1396*44e8df1fSDamjan Jovanovic             // LLA:     nValueNormal > nValueBelowNormal &&
1397*44e8df1fSDamjan Jovanovic             // LLA:     nValueBelowNormal > nValueLowest &&
1398*44e8df1fSDamjan Jovanovic             // LLA:     nValueLowest > 0
1399*44e8df1fSDamjan Jovanovic             // LLA:) << // LLA:     "SetPriority";
1400cdf0e10cSrcweir 
1401cdf0e10cSrcweir // LLA: windows let starve threads with lower priority
1402cdf0e10cSrcweir #ifndef WNT
1403*44e8df1fSDamjan Jovanovic             ASSERT_TRUE(/* nValueHighest     > 0 &&  */
1404*44e8df1fSDamjan Jovanovic                 nValueAboveNormal > 0 &&
1405*44e8df1fSDamjan Jovanovic                 nValueNormal      > 0 &&
1406*44e8df1fSDamjan Jovanovic                 nValueBelowNormal > 0 &&
1407*44e8df1fSDamjan Jovanovic                 nValueLowest      > 0) << "SetPriority";
1408cdf0e10cSrcweir #endif
1409*44e8df1fSDamjan Jovanovic         }
1410*44e8df1fSDamjan Jovanovic     TEST_F(setPriority, setPriority_005)
1411*44e8df1fSDamjan Jovanovic         {
1412*44e8df1fSDamjan Jovanovic             // initial 5 threads with different priorities
1413*44e8df1fSDamjan Jovanovic             // OAddThread *pHighestThread = new OAddThread();
1414*44e8df1fSDamjan Jovanovic             // OAddThread *pAboveNormalThread = new OAddThread();
1415*44e8df1fSDamjan Jovanovic             OAddThread *pNormalThread = new OAddThread();
1416*44e8df1fSDamjan Jovanovic             OAddThread *pBelowNormalThread = new OAddThread();
1417*44e8df1fSDamjan Jovanovic             OAddThread *pLowestThread = new OAddThread();
1418*44e8df1fSDamjan Jovanovic 
1419*44e8df1fSDamjan Jovanovic             //Create them and start running at the same time
1420*44e8df1fSDamjan Jovanovic             // pHighestThread->createSuspended();
1421*44e8df1fSDamjan Jovanovic             // pHighestThread->setPriority(osl_Thread_PriorityHighest);
1422*44e8df1fSDamjan Jovanovic 
1423*44e8df1fSDamjan Jovanovic             // pAboveNormalThread->createSuspended();
1424*44e8df1fSDamjan Jovanovic             // pAboveNormalThread->setPriority(osl_Thread_PriorityAboveNormal);
1425*44e8df1fSDamjan Jovanovic 
1426*44e8df1fSDamjan Jovanovic             pNormalThread->createSuspended();
1427*44e8df1fSDamjan Jovanovic             pNormalThread->setPriority(osl_Thread_PriorityNormal);
1428*44e8df1fSDamjan Jovanovic 
1429*44e8df1fSDamjan Jovanovic             pBelowNormalThread->createSuspended();
1430*44e8df1fSDamjan Jovanovic             pBelowNormalThread->setPriority(osl_Thread_PriorityBelowNormal);
1431*44e8df1fSDamjan Jovanovic 
1432*44e8df1fSDamjan Jovanovic             pLowestThread->createSuspended();
1433*44e8df1fSDamjan Jovanovic             pLowestThread->setPriority(osl_Thread_PriorityLowest);
1434*44e8df1fSDamjan Jovanovic 
1435*44e8df1fSDamjan Jovanovic             // pHighestThread->resume();
1436*44e8df1fSDamjan Jovanovic             // pAboveNormalThread->resume();
1437*44e8df1fSDamjan Jovanovic             pNormalThread->resume();
1438*44e8df1fSDamjan Jovanovic             pBelowNormalThread->resume();
1439*44e8df1fSDamjan Jovanovic             pLowestThread->resume();
1440*44e8df1fSDamjan Jovanovic 
1441*44e8df1fSDamjan Jovanovic             ThreadHelper::thread_sleep_tenth_sec(5);
1442*44e8df1fSDamjan Jovanovic 
1443*44e8df1fSDamjan Jovanovic             // pHighestThread->suspend();
1444*44e8df1fSDamjan Jovanovic             // pAboveNormalThread->suspend();
1445*44e8df1fSDamjan Jovanovic             pNormalThread->suspend();
1446*44e8df1fSDamjan Jovanovic             pBelowNormalThread->suspend();
1447*44e8df1fSDamjan Jovanovic             pLowestThread->suspend();
1448*44e8df1fSDamjan Jovanovic 
1449*44e8df1fSDamjan Jovanovic             // termAndJoinThread(pHighestThread);
1450*44e8df1fSDamjan Jovanovic             // termAndJoinThread(pAboveNormalThread);
1451*44e8df1fSDamjan Jovanovic             termAndJoinThread(pNormalThread);
1452*44e8df1fSDamjan Jovanovic             termAndJoinThread(pBelowNormalThread);
1453*44e8df1fSDamjan Jovanovic             termAndJoinThread(pLowestThread);
1454*44e8df1fSDamjan Jovanovic 
1455*44e8df1fSDamjan Jovanovic             // sal_Int32 nValueHighest  = 0;
1456*44e8df1fSDamjan Jovanovic             // nValueHighest =  pHighestThread->getValue();
1457*44e8df1fSDamjan Jovanovic 
1458*44e8df1fSDamjan Jovanovic             // sal_Int32 nValueAboveNormal = 0;
1459*44e8df1fSDamjan Jovanovic             // nValueAboveNormal = pAboveNormalThread->getValue();
1460*44e8df1fSDamjan Jovanovic 
1461*44e8df1fSDamjan Jovanovic             sal_Int32 nValueNormal = 0;
1462*44e8df1fSDamjan Jovanovic             nValueNormal = pNormalThread->getValue();
1463*44e8df1fSDamjan Jovanovic 
1464*44e8df1fSDamjan Jovanovic             sal_Int32 nValueBelowNormal = 0;
1465*44e8df1fSDamjan Jovanovic             nValueBelowNormal = pBelowNormalThread->getValue();
1466*44e8df1fSDamjan Jovanovic 
1467*44e8df1fSDamjan Jovanovic             sal_Int32 nValueLowest = 0;
1468*44e8df1fSDamjan Jovanovic             nValueLowest = pLowestThread->getValue();
1469*44e8df1fSDamjan Jovanovic 
1470*44e8df1fSDamjan Jovanovic             printf("After 5 tenth seconds\n");
1471*44e8df1fSDamjan Jovanovic             // printf("nValue in Highest Prio Thread  is     %d\n",nValueHighest);
1472*44e8df1fSDamjan Jovanovic             // printf("nValue in AboveNormal  Prio Thread is %d\n",nValueAboveNormal);
1473*44e8df1fSDamjan Jovanovic             printf("nValue in Normal Prio Thread is      %d\n",nValueNormal);
1474*44e8df1fSDamjan Jovanovic             printf("nValue in BelowNormal Prio Thread is %d\n",nValueBelowNormal);
1475*44e8df1fSDamjan Jovanovic             printf("nValue in Lowest Prio Thread is      %d\n",nValueLowest);
1476*44e8df1fSDamjan Jovanovic 
1477*44e8df1fSDamjan Jovanovic             // delete pHighestThread;
1478*44e8df1fSDamjan Jovanovic             // delete pAboveNormalThread;
1479*44e8df1fSDamjan Jovanovic             delete pNormalThread;
1480*44e8df1fSDamjan Jovanovic             delete pBelowNormalThread;
1481*44e8df1fSDamjan Jovanovic             delete pLowestThread;
1482*44e8df1fSDamjan Jovanovic 
1483*44e8df1fSDamjan Jovanovic             // LLA: this is not a save test, so we only check if all values not zero
1484*44e8df1fSDamjan Jovanovic             // LLA: ASSERT_TRUE(// LLA:     nValueHighest > nValueAboveNormal &&
1485*44e8df1fSDamjan Jovanovic             // LLA:     nValueAboveNormal > nValueNormal &&
1486*44e8df1fSDamjan Jovanovic             // LLA:     nValueNormal > nValueBelowNormal &&
1487*44e8df1fSDamjan Jovanovic             // LLA:     nValueBelowNormal > nValueLowest &&
1488*44e8df1fSDamjan Jovanovic             // LLA:     nValueLowest > 0
1489*44e8df1fSDamjan Jovanovic             // LLA:) << // LLA:     "SetPriority";
1490cdf0e10cSrcweir 
1491cdf0e10cSrcweir // LLA: windows let starve threads with lower priority
1492cdf0e10cSrcweir #ifndef WNT
1493*44e8df1fSDamjan Jovanovic             ASSERT_TRUE(/* nValueHighest     > 0 &&  */
1494*44e8df1fSDamjan Jovanovic                 /* nValueAboveNormal > 0 &&  */
1495*44e8df1fSDamjan Jovanovic                 nValueNormal      > 0 &&
1496*44e8df1fSDamjan Jovanovic                 nValueBelowNormal > 0 &&
1497*44e8df1fSDamjan Jovanovic                 nValueLowest      > 0) << "SetPriority";
1498cdf0e10cSrcweir #endif
1499*44e8df1fSDamjan Jovanovic         }
1500*44e8df1fSDamjan Jovanovic #endif // SOLARIS
1501cdf0e10cSrcweir 
1502cdf0e10cSrcweir 
1503cdf0e10cSrcweir     /** Test of the osl::Thread::getPriority method
1504cdf0e10cSrcweir     */
1505*44e8df1fSDamjan Jovanovic     class getPriority : public ::testing::Test
1506cdf0e10cSrcweir     {
1507cdf0e10cSrcweir     public:
1508cdf0e10cSrcweir         // initialise your test code values here.
1509*44e8df1fSDamjan Jovanovic         void SetUp()
1510cdf0e10cSrcweir             {
1511cdf0e10cSrcweir             }
1512cdf0e10cSrcweir 
1513*44e8df1fSDamjan Jovanovic         void TearDown()
1514cdf0e10cSrcweir             {
1515cdf0e10cSrcweir             }
1516*44e8df1fSDamjan Jovanovic     }; // class getPriority
1517cdf0e10cSrcweir 
1518*44e8df1fSDamjan Jovanovic     TEST_F(getPriority, getPriority_001)
1519*44e8df1fSDamjan Jovanovic         {
1520*44e8df1fSDamjan Jovanovic             OAddThread *pHighestThread = new OAddThread();
1521cdf0e10cSrcweir 
1522*44e8df1fSDamjan Jovanovic             //Create them and start running at the same time
1523*44e8df1fSDamjan Jovanovic             pHighestThread->create();
1524*44e8df1fSDamjan Jovanovic             pHighestThread->setPriority(osl_Thread_PriorityHighest);
1525cdf0e10cSrcweir 
1526*44e8df1fSDamjan Jovanovic             oslThreadPriority aPriority = pHighestThread->getPriority();
1527*44e8df1fSDamjan Jovanovic             termAndJoinThread(pHighestThread);
1528*44e8df1fSDamjan Jovanovic             delete pHighestThread;
1529cdf0e10cSrcweir 
1530*44e8df1fSDamjan Jovanovic             ThreadHelper::outputPriority(aPriority);
1531cdf0e10cSrcweir 
1532cdf0e10cSrcweir // LLA: Priority settings may not work within some OS versions.
1533cdf0e10cSrcweir #if ( defined WNT ) || ( defined SOLARIS )
1534*44e8df1fSDamjan Jovanovic             ASSERT_TRUE(aPriority == osl_Thread_PriorityHighest) << "getPriority";
1535cdf0e10cSrcweir #else
1536cdf0e10cSrcweir // LLA: Linux
1537cdf0e10cSrcweir // NO_PTHREAD_PRIORITY ???
1538*44e8df1fSDamjan Jovanovic             ASSERT_TRUE(aPriority == osl_Thread_PriorityNormal) << "getPriority";
1539cdf0e10cSrcweir #endif
1540*44e8df1fSDamjan Jovanovic         }
1541cdf0e10cSrcweir 
1542*44e8df1fSDamjan Jovanovic     TEST_F(getPriority, getPriority_002)
1543*44e8df1fSDamjan Jovanovic         {
1544cdf0e10cSrcweir 
1545*44e8df1fSDamjan Jovanovic         }
1546cdf0e10cSrcweir 
1547cdf0e10cSrcweir 
1548*44e8df1fSDamjan Jovanovic     class getIdentifier : public ::testing::Test
1549cdf0e10cSrcweir     {
1550cdf0e10cSrcweir     public:
1551cdf0e10cSrcweir         // initialise your test code values here.
1552*44e8df1fSDamjan Jovanovic         void SetUp()
1553cdf0e10cSrcweir             {
1554cdf0e10cSrcweir             }
1555cdf0e10cSrcweir 
1556*44e8df1fSDamjan Jovanovic         void TearDown()
1557cdf0e10cSrcweir             {
1558cdf0e10cSrcweir             }
1559*44e8df1fSDamjan Jovanovic     }; // class getIdentifier
1560cdf0e10cSrcweir 
1561*44e8df1fSDamjan Jovanovic     // insert your test code here.
1562*44e8df1fSDamjan Jovanovic     TEST_F(getIdentifier, getIdentifier_001)
1563*44e8df1fSDamjan Jovanovic         {
1564cdf0e10cSrcweir 
1565*44e8df1fSDamjan Jovanovic         }
1566cdf0e10cSrcweir 
1567*44e8df1fSDamjan Jovanovic     TEST_F(getIdentifier, getIdentifier_002)
1568*44e8df1fSDamjan Jovanovic         {
1569cdf0e10cSrcweir 
1570*44e8df1fSDamjan Jovanovic         }
1571cdf0e10cSrcweir 
1572cdf0e10cSrcweir     /** Test of the osl::Thread::getCurrentIdentifier method
1573cdf0e10cSrcweir     */
1574*44e8df1fSDamjan Jovanovic     class getCurrentIdentifier : public ::testing::Test
1575cdf0e10cSrcweir     {
1576cdf0e10cSrcweir     public:
1577cdf0e10cSrcweir         // initialise your test code values here.
1578*44e8df1fSDamjan Jovanovic         void SetUp()
1579cdf0e10cSrcweir             {
1580cdf0e10cSrcweir             }
1581cdf0e10cSrcweir 
1582*44e8df1fSDamjan Jovanovic         void TearDown()
1583cdf0e10cSrcweir             {
1584cdf0e10cSrcweir             }
1585*44e8df1fSDamjan Jovanovic     }; // class getCurrentIdentifier
1586cdf0e10cSrcweir 
1587*44e8df1fSDamjan Jovanovic     // insert your test code here.
1588*44e8df1fSDamjan Jovanovic     TEST_F(getCurrentIdentifier, getCurrentIdentifier_001)
1589*44e8df1fSDamjan Jovanovic         {
1590*44e8df1fSDamjan Jovanovic             oslThreadIdentifier oId;
1591*44e8df1fSDamjan Jovanovic             OCountThread* pCountThread = new OCountThread;
1592*44e8df1fSDamjan Jovanovic             //OCountThread* pCountThread2 = new OCountThread;
1593*44e8df1fSDamjan Jovanovic             pCountThread->create();
1594*44e8df1fSDamjan Jovanovic             //pCountThread2->create();
1595*44e8df1fSDamjan Jovanovic             pCountThread->setWait(3);
1596*44e8df1fSDamjan Jovanovic             oId = Thread::getCurrentIdentifier();
1597*44e8df1fSDamjan Jovanovic             oslThreadIdentifier oIdChild = pCountThread->getIdentifier();
1598*44e8df1fSDamjan Jovanovic             //printf("CurrentId is %ld, Child1 id is %ld, Child2 id is %ld\n",oId, oIdChild,pCountThread2->m_id );
1599*44e8df1fSDamjan Jovanovic             termAndJoinThread(pCountThread);
1600*44e8df1fSDamjan Jovanovic             delete pCountThread;
1601*44e8df1fSDamjan Jovanovic             //termAndJoinThread(pCountThread2);
1602*44e8df1fSDamjan Jovanovic             //delete pCountThread2;
1603*44e8df1fSDamjan Jovanovic 
1604*44e8df1fSDamjan Jovanovic             ASSERT_TRUE(oId != oIdChild) << "Get the identifier for the current active thread.";
1605cdf0e10cSrcweir 
1606*44e8df1fSDamjan Jovanovic         }
1607cdf0e10cSrcweir 
1608*44e8df1fSDamjan Jovanovic     TEST_F(getCurrentIdentifier, getCurrentIdentifier_002)
1609*44e8df1fSDamjan Jovanovic         {
1610*44e8df1fSDamjan Jovanovic         }
1611cdf0e10cSrcweir 
1612cdf0e10cSrcweir 
1613cdf0e10cSrcweir     /** Test of the osl::Thread::wait method
1614cdf0e10cSrcweir     */
1615*44e8df1fSDamjan Jovanovic     class wait : public ::testing::Test
1616cdf0e10cSrcweir     {
1617cdf0e10cSrcweir     public:
1618cdf0e10cSrcweir         // initialise your test code values here.
1619*44e8df1fSDamjan Jovanovic         void SetUp()
1620cdf0e10cSrcweir             {
1621cdf0e10cSrcweir             }
1622cdf0e10cSrcweir 
1623*44e8df1fSDamjan Jovanovic         void TearDown()
1624cdf0e10cSrcweir             {
1625cdf0e10cSrcweir             }
1626*44e8df1fSDamjan Jovanovic     }; // class wait
1627cdf0e10cSrcweir 
1628cdf0e10cSrcweir 
1629*44e8df1fSDamjan Jovanovic     /** call wait in the run method
1630cdf0e10cSrcweir 
1631*44e8df1fSDamjan Jovanovic         ALGORITHM:
1632*44e8df1fSDamjan Jovanovic         tested thread wait nWaitSec seconds, main thread sleep (2) seconds,
1633*44e8df1fSDamjan Jovanovic         then terminate the tested thread, due to the fact that the thread do a sleep(1) + wait(5)
1634*44e8df1fSDamjan Jovanovic         it's finish after 6 seconds.
1635*44e8df1fSDamjan Jovanovic     */
1636*44e8df1fSDamjan Jovanovic     TEST_F(wait, wait_001)
1637*44e8df1fSDamjan Jovanovic         {
1638*44e8df1fSDamjan Jovanovic             OCountThread *aCountThread = new OCountThread();
1639*44e8df1fSDamjan Jovanovic             sal_Int32 nWaitSec = 5;
1640*44e8df1fSDamjan Jovanovic             aCountThread->setWait(nWaitSec);
1641*44e8df1fSDamjan Jovanovic             // thread runs at least 5 seconds.
1642*44e8df1fSDamjan Jovanovic             sal_Bool bRes = aCountThread->create();
1643*44e8df1fSDamjan Jovanovic             ASSERT_TRUE(bRes == sal_True) << "Can't start thread!";
1644*44e8df1fSDamjan Jovanovic 
1645*44e8df1fSDamjan Jovanovic             //record the time when the running begin
1646*44e8df1fSDamjan Jovanovic             StopWatch aStopWatch;
1647*44e8df1fSDamjan Jovanovic             aStopWatch.start();
1648*44e8df1fSDamjan Jovanovic 
1649*44e8df1fSDamjan Jovanovic             // wait a little bit, to let the thread the time, to start
1650*44e8df1fSDamjan Jovanovic             ThreadHelper::thread_sleep_tenth_sec( 4 );
1651*44e8df1fSDamjan Jovanovic 
1652*44e8df1fSDamjan Jovanovic             // if wait works,
1653*44e8df1fSDamjan Jovanovic             // this function returns, after 4 sec. later
1654*44e8df1fSDamjan Jovanovic             termAndJoinThread(aCountThread);
1655*44e8df1fSDamjan Jovanovic 
1656*44e8df1fSDamjan Jovanovic             // value should be one.
1657*44e8df1fSDamjan Jovanovic             sal_Int32 nValue = aCountThread->getValue();
1658*44e8df1fSDamjan Jovanovic 
1659*44e8df1fSDamjan Jovanovic             aStopWatch.stop();
1660*44e8df1fSDamjan Jovanovic 
1661*44e8df1fSDamjan Jovanovic             // sal_uInt32 nSec  = aTimeVal_after.Seconds - aTimeVal_befor.Seconds;
1662*44e8df1fSDamjan Jovanovic             double nTenthSec = aStopWatch.getTenthSec();
1663*44e8df1fSDamjan Jovanovic             double nSec = aStopWatch.getSeconds();
1664*44e8df1fSDamjan Jovanovic             delete aCountThread;
1665*44e8df1fSDamjan Jovanovic             printf("nTenthSec = %f \n", nTenthSec);
1666*44e8df1fSDamjan Jovanovic             printf("nSec = %f \n", nSec);
1667*44e8df1fSDamjan Jovanovic             printf("nValue = %d \n", nValue);
1668*44e8df1fSDamjan Jovanovic 
1669*44e8df1fSDamjan Jovanovic             ASSERT_TRUE(nTenthSec >= 5 && nValue == 1) << "Wait: Blocks the calling thread for the given number of time.";
1670*44e8df1fSDamjan Jovanovic 
1671*44e8df1fSDamjan Jovanovic         }
1672cdf0e10cSrcweir // LLA: wait_001 does the same.
1673cdf0e10cSrcweir // LLA:         /** wait then terminate the thread
1674cdf0e10cSrcweir // LLA:
1675cdf0e10cSrcweir // LLA:         ALGORITHM:
1676cdf0e10cSrcweir // LLA:         wait nWaitSec seconds, and terminate when the wait does not finish
1677cdf0e10cSrcweir // LLA:         Windows & UNX: thread terminates immediatlly
1678cdf0e10cSrcweir // LLA:     */
1679*44e8df1fSDamjan Jovanovic // LLA:     TEST_F(wait, wait_002)
1680cdf0e10cSrcweir // LLA:     {
1681cdf0e10cSrcweir // LLA:         OCountThread aThread;
1682cdf0e10cSrcweir // LLA:
1683cdf0e10cSrcweir // LLA:         sal_Int32 nWaitSec = 3;
1684cdf0e10cSrcweir // LLA:         aThread.setWait(nWaitSec);
1685cdf0e10cSrcweir // LLA:
1686cdf0e10cSrcweir // LLA:         sal_Bool bRes = aThread.create();
1687*44e8df1fSDamjan Jovanovic // LLA:         ASSERT_TRUE(bRes == sal_True) << "Can't start thread!";
1688cdf0e10cSrcweir // LLA:
1689cdf0e10cSrcweir // LLA:         StopWatch aStopWatch;
1690cdf0e10cSrcweir // LLA:         // TimeValue aTimeVal_befor;
1691cdf0e10cSrcweir // LLA:         // osl_getSystemTime( &aTimeVal_befor );
1692cdf0e10cSrcweir // LLA:         aStopWatch.start();
1693cdf0e10cSrcweir // LLA:
1694cdf0e10cSrcweir // LLA:         termAndJoinThread(&aThread);
1695cdf0e10cSrcweir // LLA:         sal_Int32 nValue = aThread.getValue();
1696cdf0e10cSrcweir // LLA:
1697cdf0e10cSrcweir // LLA:         // TimeValue aTimeVal_after;
1698cdf0e10cSrcweir // LLA:         // osl_getSystemTime( &aTimeVal_after );
1699cdf0e10cSrcweir // LLA:         aStopWatch.stop();
1700cdf0e10cSrcweir // LLA:         // sal_Int32 nSec = aTimeVal_after.Seconds  - aTimeVal_befor.Seconds;
1701cdf0e10cSrcweir // LLA:         double nSec = aStopWatch.getSeconds();
1702*44e8df1fSDamjan Jovanovic // LLA:         printf("sec=%f\n", nSec);
1703*44e8df1fSDamjan Jovanovic // LLA:         printf("nValue = %d\n", nValue);
1704cdf0e10cSrcweir // LLA:
1705*44e8df1fSDamjan Jovanovic // LLA:         ASSERT_TRUE(// LLA:             nSec < 1 && nValue == 0
1706*44e8df1fSDamjan Jovanovic // LLA:) << // LLA:             "Wait: Blocks the calling thread for the given number of time.";
1707cdf0e10cSrcweir // LLA:     }
1708cdf0e10cSrcweir     /** osl::Thread::yield method: can not design good test scenario to test up to now
1709cdf0e10cSrcweir     */
1710*44e8df1fSDamjan Jovanovic     class yield : public ::testing::Test
1711cdf0e10cSrcweir     {
1712cdf0e10cSrcweir     public:
1713*44e8df1fSDamjan Jovanovic         void SetUp()
1714cdf0e10cSrcweir             {
1715cdf0e10cSrcweir             }
1716cdf0e10cSrcweir 
1717*44e8df1fSDamjan Jovanovic         void TearDown()
1718cdf0e10cSrcweir             {
1719cdf0e10cSrcweir             }
1720cdf0e10cSrcweir     }; // class yield
1721cdf0e10cSrcweir 
1722*44e8df1fSDamjan Jovanovic     // insert your test code here.
1723*44e8df1fSDamjan Jovanovic     TEST_F(yield, yield_001)
1724*44e8df1fSDamjan Jovanovic         {
1725*44e8df1fSDamjan Jovanovic         }
1726*44e8df1fSDamjan Jovanovic 
1727cdf0e10cSrcweir     /** Test of the osl::Thread::schedule method
1728cdf0e10cSrcweir     */
1729*44e8df1fSDamjan Jovanovic     class schedule : public ::testing::Test
1730cdf0e10cSrcweir     {
1731cdf0e10cSrcweir     public:
1732cdf0e10cSrcweir         // initialise your test code values here.
1733*44e8df1fSDamjan Jovanovic         void SetUp()
1734cdf0e10cSrcweir             {
1735cdf0e10cSrcweir             }
1736cdf0e10cSrcweir 
1737*44e8df1fSDamjan Jovanovic         void TearDown()
1738cdf0e10cSrcweir             {
1739cdf0e10cSrcweir             }
1740*44e8df1fSDamjan Jovanovic     }; // class schedule
1741cdf0e10cSrcweir 
1742*44e8df1fSDamjan Jovanovic     /** The requested thread will get terminate the next time schedule() is called.
1743cdf0e10cSrcweir 
1744*44e8df1fSDamjan Jovanovic         Note: on UNX, if call suspend thread is not the to be suspended thread, the to be
1745*44e8df1fSDamjan Jovanovic         suspended   thread will get suspended the next time schedule() is called,
1746*44e8df1fSDamjan Jovanovic         while on w32, it's nothing with schedule.
1747cdf0e10cSrcweir 
1748*44e8df1fSDamjan Jovanovic         check if suspend and terminate work well via schedule
1749*44e8df1fSDamjan Jovanovic     */
1750*44e8df1fSDamjan Jovanovic     TEST_F(schedule, schedule_001)
1751*44e8df1fSDamjan Jovanovic         {
1752*44e8df1fSDamjan Jovanovic             OAddThread* aThread = new OAddThread();
1753*44e8df1fSDamjan Jovanovic             sal_Bool bRes = aThread->create();
1754*44e8df1fSDamjan Jovanovic             ASSERT_TRUE(bRes == sal_True) << "Can't start thread!";
1755*44e8df1fSDamjan Jovanovic 
1756*44e8df1fSDamjan Jovanovic             ThreadHelper::thread_sleep_tenth_sec(2);
1757*44e8df1fSDamjan Jovanovic             aThread->suspend();
1758*44e8df1fSDamjan Jovanovic             ThreadHelper::thread_sleep_tenth_sec(1);
1759*44e8df1fSDamjan Jovanovic             sal_Int32 nValue = aThread->getValue();
1760*44e8df1fSDamjan Jovanovic             ThreadHelper::thread_sleep_tenth_sec(3);
1761*44e8df1fSDamjan Jovanovic             sal_Int32 nLaterValue = aThread->getValue();
1762*44e8df1fSDamjan Jovanovic             // resumeAndWaitThread(aThread);
1763*44e8df1fSDamjan Jovanovic             printf("      value = %d\n", nValue);
1764*44e8df1fSDamjan Jovanovic             printf("later value = %d\n", nLaterValue);
1765*44e8df1fSDamjan Jovanovic             // if value and latervalue not equal, than the thread would not suspended
1766cdf0e10cSrcweir 
1767*44e8df1fSDamjan Jovanovic             ASSERT_TRUE(nLaterValue == nValue) << "Schedule: suspend works.";
1768cdf0e10cSrcweir 
1769*44e8df1fSDamjan Jovanovic             aThread->resume();
1770*44e8df1fSDamjan Jovanovic             ThreadHelper::thread_sleep_tenth_sec(2);
1771cdf0e10cSrcweir 
1772*44e8df1fSDamjan Jovanovic             aThread->terminate();
1773*44e8df1fSDamjan Jovanovic             sal_Int32 nValue_term = aThread->getValue();
1774cdf0e10cSrcweir 
1775*44e8df1fSDamjan Jovanovic             aThread->join();
1776*44e8df1fSDamjan Jovanovic             sal_Int32 nValue_join = aThread->getValue();
1777cdf0e10cSrcweir 
1778*44e8df1fSDamjan Jovanovic             printf("value after term = %d\n", nValue_term);
1779*44e8df1fSDamjan Jovanovic             printf("value after join = %d\n", nValue_join);
1780cdf0e10cSrcweir 
1781*44e8df1fSDamjan Jovanovic             // nValue_term and nValue_join should be the same
1782*44e8df1fSDamjan Jovanovic             // but should be differ from nValue
1783cdf0e10cSrcweir 
1784*44e8df1fSDamjan Jovanovic             delete aThread;
1785*44e8df1fSDamjan Jovanovic             //check if thread really terminate after call terminate, if join immediatlly return
1786*44e8df1fSDamjan Jovanovic             ASSERT_TRUE(nValue_join -  nValue_term <= 1 && nValue_join -  nValue_term >= 0) << "Schedule: Returns False if the thread should terminate.";
1787cdf0e10cSrcweir 
1788*44e8df1fSDamjan Jovanovic         }
1789cdf0e10cSrcweir 
1790*44e8df1fSDamjan Jovanovic     /** design a thread that has not call schedule in the workfunction--run method
1791*44e8df1fSDamjan Jovanovic      */
1792*44e8df1fSDamjan Jovanovic     TEST_F(schedule, schedule_002)
1793*44e8df1fSDamjan Jovanovic         {
1794*44e8df1fSDamjan Jovanovic             ONoScheduleThread aThread; // this thread runs 10 sec. (no schedule() used)
1795*44e8df1fSDamjan Jovanovic             sal_Bool bRes = aThread.create();
1796*44e8df1fSDamjan Jovanovic             ASSERT_TRUE(bRes == sal_True) << "Can't start thread!";
1797cdf0e10cSrcweir 
1798*44e8df1fSDamjan Jovanovic             ThreadHelper::thread_sleep_tenth_sec(2);
1799*44e8df1fSDamjan Jovanovic             aThread.suspend();
1800*44e8df1fSDamjan Jovanovic             sal_Int32 nValue = aThread.getValue();
1801cdf0e10cSrcweir 
1802*44e8df1fSDamjan Jovanovic             ThreadHelper::thread_sleep_tenth_sec(3);
1803*44e8df1fSDamjan Jovanovic             sal_Int32 nLaterValue = aThread.getValue();
1804*44e8df1fSDamjan Jovanovic             ThreadHelper::thread_sleep_tenth_sec(5);
1805cdf0e10cSrcweir 
1806*44e8df1fSDamjan Jovanovic             resumeAndWaitThread(&aThread);
1807cdf0e10cSrcweir 
1808*44e8df1fSDamjan Jovanovic             printf("      value = %d\n", nValue);
1809*44e8df1fSDamjan Jovanovic             printf("later value = %d\n", nLaterValue);
1810cdf0e10cSrcweir 
1811*44e8df1fSDamjan Jovanovic             //On windows, suspend works, so the values are same
1812cdf0e10cSrcweir #ifdef WNT
1813*44e8df1fSDamjan Jovanovic             ASSERT_TRUE(nLaterValue == nValue) << "Schedule: don't schedule in thread run method, suspend works.";
1814cdf0e10cSrcweir #endif
1815cdf0e10cSrcweir 
1816*44e8df1fSDamjan Jovanovic             //On UNX, suspend does not work, so the difference of the values equals to sleep seconds number
1817cdf0e10cSrcweir #ifdef UNX
1818*44e8df1fSDamjan Jovanovic             aThread.resume();
1819*44e8df1fSDamjan Jovanovic             ASSERT_TRUE(nLaterValue > nValue) << "Schedule: don't schedule in thread run method, suspend does not work too.";
1820cdf0e10cSrcweir #endif
1821cdf0e10cSrcweir 
1822*44e8df1fSDamjan Jovanovic             // terminate will not work if no schedule in thread's work function
1823*44e8df1fSDamjan Jovanovic             termAndJoinThread(&aThread);
1824*44e8df1fSDamjan Jovanovic             sal_Int32 nValue_term = aThread.getValue();
1825cdf0e10cSrcweir 
1826*44e8df1fSDamjan Jovanovic             printf(" value term = %d\n", nValue_term);
1827cdf0e10cSrcweir 
1828*44e8df1fSDamjan Jovanovic             ASSERT_TRUE(nValue_term == 10) << "Schedule: don't schedule in thread run method, terminate failed.";
1829*44e8df1fSDamjan Jovanovic         }
1830cdf0e10cSrcweir 
1831cdf0e10cSrcweir } // namespace osl_Thread
1832cdf0e10cSrcweir 
1833cdf0e10cSrcweir 
1834cdf0e10cSrcweir // -----------------------------------------------------------------------------
1835cdf0e10cSrcweir // destroy function when the binding thread terminate
1836cdf0e10cSrcweir void SAL_CALL destroyCallback(void * data)
1837cdf0e10cSrcweir {
1838*44e8df1fSDamjan Jovanovic     printf("destroying local data %s\n", (char *) data);
1839cdf0e10cSrcweir     delete[] (char *) data;
1840cdf0e10cSrcweir }
1841cdf0e10cSrcweir 
1842cdf0e10cSrcweir static ThreadData myThreadData(destroyCallback);
1843cdf0e10cSrcweir 
1844cdf0e10cSrcweir /**
1845cdf0e10cSrcweir */
1846cdf0e10cSrcweir class myKeyThread : public Thread
1847cdf0e10cSrcweir {
1848cdf0e10cSrcweir public:
1849cdf0e10cSrcweir     // a public char member for test result checking
1850cdf0e10cSrcweir     char m_Char_Test;
1851cdf0e10cSrcweir     // for pass thread-special data to thread
1852cdf0e10cSrcweir     myKeyThread(const char cData)
1853cdf0e10cSrcweir         {
1854cdf0e10cSrcweir             m_nData = cData;
1855cdf0e10cSrcweir         }
1856cdf0e10cSrcweir private:
1857cdf0e10cSrcweir     char m_nData;
1858cdf0e10cSrcweir 
1859cdf0e10cSrcweir     void SAL_CALL run()
1860cdf0e10cSrcweir         {
1861cdf0e10cSrcweir             char * pc = new char[2];
1862cdf0e10cSrcweir //      strcpy(pc, &m_nData);
1863cdf0e10cSrcweir             memcpy(pc, &m_nData, 1);
1864cdf0e10cSrcweir             pc[1] = '\0';
1865cdf0e10cSrcweir 
1866cdf0e10cSrcweir             myThreadData.setData(pc);
1867cdf0e10cSrcweir             char* pData = (char*)myThreadData.getData();
1868cdf0e10cSrcweir             m_Char_Test = *pData;
1869cdf0e10cSrcweir             // wait for long time to check the data value in main thread
1870cdf0e10cSrcweir             ThreadHelper::thread_sleep_tenth_sec(3);
1871cdf0e10cSrcweir         }
1872cdf0e10cSrcweir public:
1873cdf0e10cSrcweir     ~myKeyThread()
1874cdf0e10cSrcweir         {
1875cdf0e10cSrcweir             if (isRunning())
1876cdf0e10cSrcweir             {
1877*44e8df1fSDamjan Jovanovic                 printf("error: not terminated.\n");
1878cdf0e10cSrcweir             }
1879cdf0e10cSrcweir         }
1880cdf0e10cSrcweir };
1881cdf0e10cSrcweir 
1882cdf0e10cSrcweir static ThreadData idData;
1883cdf0e10cSrcweir 
1884cdf0e10cSrcweir class idThread: public Thread
1885cdf0e10cSrcweir {
1886cdf0e10cSrcweir public:
1887cdf0e10cSrcweir     oslThreadIdentifier m_Id;
1888cdf0e10cSrcweir private:
1889cdf0e10cSrcweir     void SAL_CALL run()
1890cdf0e10cSrcweir         {
1891cdf0e10cSrcweir             oslThreadIdentifier* pId = new oslThreadIdentifier;
1892cdf0e10cSrcweir             *pId = getIdentifier();
1893cdf0e10cSrcweir             idData.setData(pId);
1894cdf0e10cSrcweir             oslThreadIdentifier* pIdData = (oslThreadIdentifier*)idData.getData();
1895*44e8df1fSDamjan Jovanovic             //printf("Thread %d has Data %d\n", getIdentifier(), *pIdData);
1896cdf0e10cSrcweir             m_Id = *pIdData;
1897cdf0e10cSrcweir             delete pId;
1898cdf0e10cSrcweir         }
1899cdf0e10cSrcweir 
1900cdf0e10cSrcweir public:
1901cdf0e10cSrcweir     ~idThread()
1902cdf0e10cSrcweir         {
1903cdf0e10cSrcweir             if (isRunning())
1904cdf0e10cSrcweir             {
1905*44e8df1fSDamjan Jovanovic                 printf("error: not terminated.\n");
1906cdf0e10cSrcweir             }
1907cdf0e10cSrcweir         }
1908cdf0e10cSrcweir };
1909cdf0e10cSrcweir 
1910cdf0e10cSrcweir namespace osl_ThreadData
1911cdf0e10cSrcweir {
1912cdf0e10cSrcweir 
1913*44e8df1fSDamjan Jovanovic     class ctors : public ::testing::Test
1914cdf0e10cSrcweir     {
1915cdf0e10cSrcweir     public:
1916cdf0e10cSrcweir         // initialise your test code values here.
1917*44e8df1fSDamjan Jovanovic         void SetUp()
1918cdf0e10cSrcweir             {
1919cdf0e10cSrcweir             }
1920cdf0e10cSrcweir 
1921*44e8df1fSDamjan Jovanovic         void TearDown()
1922cdf0e10cSrcweir             {
1923cdf0e10cSrcweir             }
1924*44e8df1fSDamjan Jovanovic     }; // class ctors
1925cdf0e10cSrcweir 
1926cdf0e10cSrcweir 
1927*44e8df1fSDamjan Jovanovic     // insert your test code here.
1928*44e8df1fSDamjan Jovanovic     TEST_F(ctors, ctor_001)
1929*44e8df1fSDamjan Jovanovic         {
1930cdf0e10cSrcweir 
1931*44e8df1fSDamjan Jovanovic         }
1932cdf0e10cSrcweir 
1933*44e8df1fSDamjan Jovanovic     class setData : public ::testing::Test
1934cdf0e10cSrcweir     {
1935cdf0e10cSrcweir     public:
1936cdf0e10cSrcweir         // initialise your test code values here.
1937*44e8df1fSDamjan Jovanovic         void SetUp()
1938cdf0e10cSrcweir             {
1939cdf0e10cSrcweir             }
1940cdf0e10cSrcweir 
1941*44e8df1fSDamjan Jovanovic         void TearDown()
1942cdf0e10cSrcweir             {
1943cdf0e10cSrcweir             }
1944*44e8df1fSDamjan Jovanovic     }; // class setData
1945cdf0e10cSrcweir 
1946*44e8df1fSDamjan Jovanovic     /** the same instance of the class can have different values in different threads
1947*44e8df1fSDamjan Jovanovic      */
1948*44e8df1fSDamjan Jovanovic     TEST_F(setData, setData_001)
1949*44e8df1fSDamjan Jovanovic         {
1950*44e8df1fSDamjan Jovanovic             idThread aThread1;
1951*44e8df1fSDamjan Jovanovic             aThread1.create();
1952*44e8df1fSDamjan Jovanovic             idThread aThread2;
1953*44e8df1fSDamjan Jovanovic             aThread2.create();
1954cdf0e10cSrcweir 
1955*44e8df1fSDamjan Jovanovic             aThread1.join();
1956*44e8df1fSDamjan Jovanovic             aThread2.join();
1957cdf0e10cSrcweir 
1958*44e8df1fSDamjan Jovanovic             oslThreadIdentifier aThreadId1 = aThread1.getIdentifier();
1959*44e8df1fSDamjan Jovanovic             oslThreadIdentifier aThreadId2 = aThread2.getIdentifier();
1960cdf0e10cSrcweir 
1961*44e8df1fSDamjan Jovanovic             ASSERT_TRUE(aThread1.m_Id == aThreadId1 && aThread2.m_Id == aThreadId2) << "ThreadData setData: ";
1962cdf0e10cSrcweir 
1963*44e8df1fSDamjan Jovanovic         }
1964cdf0e10cSrcweir 
1965*44e8df1fSDamjan Jovanovic     TEST_F(setData, setData_002)
1966*44e8df1fSDamjan Jovanovic         {
1967*44e8df1fSDamjan Jovanovic             // at first, set the data a value
1968*44e8df1fSDamjan Jovanovic             char* pc = new char[2];
1969*44e8df1fSDamjan Jovanovic             char m_nData = 'm';
1970cdf0e10cSrcweir // LLA: this is a copy functions only and really only for \0 terminated strings
1971cdf0e10cSrcweir //      m_nData is not a string, it's a character
1972cdf0e10cSrcweir //          strcpy(pc, &m_nData);
1973*44e8df1fSDamjan Jovanovic             memcpy(pc, &m_nData, 1);
1974*44e8df1fSDamjan Jovanovic             pc[1] = '\0';
1975cdf0e10cSrcweir 
1976*44e8df1fSDamjan Jovanovic             myThreadData.setData(pc);
1977cdf0e10cSrcweir 
1978*44e8df1fSDamjan Jovanovic             myKeyThread aThread1('a');
1979*44e8df1fSDamjan Jovanovic             aThread1.create();
1980*44e8df1fSDamjan Jovanovic             myKeyThread aThread2('b');
1981*44e8df1fSDamjan Jovanovic             aThread2.create();
1982*44e8df1fSDamjan Jovanovic             // aThread1 and aThread2 should have not terminated yet, check current data, not 'a' 'b'
1983*44e8df1fSDamjan Jovanovic             char* pChar = (char*)myThreadData.getData();
1984*44e8df1fSDamjan Jovanovic             char aChar = *pChar;
1985cdf0e10cSrcweir 
1986*44e8df1fSDamjan Jovanovic             aThread1.join();
1987*44e8df1fSDamjan Jovanovic             aThread2.join();
1988cdf0e10cSrcweir 
1989*44e8df1fSDamjan Jovanovic             // the saved thread data of aThread1 & aThread2, different
1990*44e8df1fSDamjan Jovanovic             char cData1 = aThread1.m_Char_Test;
1991*44e8df1fSDamjan Jovanovic             char cData2 = aThread2.m_Char_Test;
1992cdf0e10cSrcweir 
1993*44e8df1fSDamjan Jovanovic             ASSERT_TRUE(cData1 == 'a' && cData2 == 'b' && aChar == 'm') << "ThreadData setData: ";
1994cdf0e10cSrcweir 
1995*44e8df1fSDamjan Jovanovic         }
1996*44e8df1fSDamjan Jovanovic     /** setData the second time, and then getData
1997*44e8df1fSDamjan Jovanovic      */
1998*44e8df1fSDamjan Jovanovic     TEST_F(setData, setData_003)
1999*44e8df1fSDamjan Jovanovic         {
2000*44e8df1fSDamjan Jovanovic             // at first, set the data a value
2001*44e8df1fSDamjan Jovanovic             char* pc = new char[2];
2002*44e8df1fSDamjan Jovanovic             char m_nData = 'm';
2003cdf0e10cSrcweir //          strcpy(pc, &m_nData);
2004*44e8df1fSDamjan Jovanovic             memcpy(pc, &m_nData, 1);
2005*44e8df1fSDamjan Jovanovic             pc[1] = '\0';
2006*44e8df1fSDamjan Jovanovic             myThreadData.setData(pc);
2007cdf0e10cSrcweir 
2008*44e8df1fSDamjan Jovanovic             myKeyThread aThread1('a');
2009*44e8df1fSDamjan Jovanovic             aThread1.create();
2010*44e8df1fSDamjan Jovanovic             myKeyThread aThread2('b');
2011*44e8df1fSDamjan Jovanovic             aThread2.create();
2012*44e8df1fSDamjan Jovanovic             // aThread1 and aThread2 should have not terminated yet
2013*44e8df1fSDamjan Jovanovic             // setData the second time
2014*44e8df1fSDamjan Jovanovic             char* pc2 = new char[2];
2015*44e8df1fSDamjan Jovanovic             m_nData = 'o';
2016*44e8df1fSDamjan Jovanovic //          strcpy(pc2, &m_nData);
2017*44e8df1fSDamjan Jovanovic             memcpy(pc2, &m_nData, 1);
2018*44e8df1fSDamjan Jovanovic             pc2[1] = '\0';
2019cdf0e10cSrcweir 
2020*44e8df1fSDamjan Jovanovic             myThreadData.setData(pc2);
2021*44e8df1fSDamjan Jovanovic             char* pChar = (char*)myThreadData.getData();
2022*44e8df1fSDamjan Jovanovic             char aChar = *pChar;
2023cdf0e10cSrcweir 
2024*44e8df1fSDamjan Jovanovic             aThread1.join();
2025*44e8df1fSDamjan Jovanovic             aThread2.join();
2026cdf0e10cSrcweir 
2027*44e8df1fSDamjan Jovanovic             // the saved thread data of aThread1 & aThread2, different
2028*44e8df1fSDamjan Jovanovic             char cData1 = aThread1.m_Char_Test;
2029*44e8df1fSDamjan Jovanovic             char cData2 = aThread2.m_Char_Test;
2030cdf0e10cSrcweir 
2031*44e8df1fSDamjan Jovanovic             ASSERT_TRUE(cData1 == 'a' && cData2 == 'b' && aChar == 'o') << "ThreadData setData: ";
2032cdf0e10cSrcweir 
2033*44e8df1fSDamjan Jovanovic         }
2034cdf0e10cSrcweir 
2035cdf0e10cSrcweir     //sal_Bool buildTwoThreads(char)
2036cdf0e10cSrcweir 
2037*44e8df1fSDamjan Jovanovic     class getData : public ::testing::Test
2038cdf0e10cSrcweir     {
2039cdf0e10cSrcweir     public:
2040cdf0e10cSrcweir         // initialise your test code values here.
2041*44e8df1fSDamjan Jovanovic         void SetUp()
2042cdf0e10cSrcweir             {
2043cdf0e10cSrcweir             }
2044cdf0e10cSrcweir 
2045*44e8df1fSDamjan Jovanovic         void TearDown()
2046cdf0e10cSrcweir             {
2047cdf0e10cSrcweir             }
2048*44e8df1fSDamjan Jovanovic     }; // class getData
2049cdf0e10cSrcweir 
2050*44e8df1fSDamjan Jovanovic     // After setData in child threads, get Data in the main thread, should be independent
2051*44e8df1fSDamjan Jovanovic     TEST_F(getData, getData_001)
2052*44e8df1fSDamjan Jovanovic         {
2053*44e8df1fSDamjan Jovanovic             char* pc = new char[2];
2054*44e8df1fSDamjan Jovanovic             char m_nData[] = "i";
2055*44e8df1fSDamjan Jovanovic             strcpy(pc, m_nData);
2056*44e8df1fSDamjan Jovanovic             printf("pc %s\n", pc);
2057*44e8df1fSDamjan Jovanovic             myThreadData.setData(pc);
2058cdf0e10cSrcweir 
2059*44e8df1fSDamjan Jovanovic             myKeyThread aThread1('c');
2060*44e8df1fSDamjan Jovanovic             aThread1.create();
2061*44e8df1fSDamjan Jovanovic             myKeyThread aThread2('d');
2062*44e8df1fSDamjan Jovanovic             aThread2.create();
2063cdf0e10cSrcweir 
2064*44e8df1fSDamjan Jovanovic             aThread1.join();
2065*44e8df1fSDamjan Jovanovic             aThread2.join();
2066cdf0e10cSrcweir 
2067*44e8df1fSDamjan Jovanovic             char cData1 = aThread1.m_Char_Test;
2068*44e8df1fSDamjan Jovanovic             char cData2 = aThread2.m_Char_Test;
2069cdf0e10cSrcweir 
2070*44e8df1fSDamjan Jovanovic             char* pChar = (char*)myThreadData.getData();
2071*44e8df1fSDamjan Jovanovic             char aChar = *pChar;
2072cdf0e10cSrcweir 
2073*44e8df1fSDamjan Jovanovic             ASSERT_TRUE(cData1 == 'c' && cData2 == 'd' && aChar == 'i') << "ThreadData setData: ";
2074cdf0e10cSrcweir 
2075*44e8df1fSDamjan Jovanovic         }
2076cdf0e10cSrcweir 
2077*44e8df1fSDamjan Jovanovic     // setData then change the value in the address data pointer points,
2078*44e8df1fSDamjan Jovanovic     // and then getData, should get the new value
2079*44e8df1fSDamjan Jovanovic     TEST_F(getData, getData_002)
2080*44e8df1fSDamjan Jovanovic         {
2081*44e8df1fSDamjan Jovanovic             char* pc = new char[2];
2082*44e8df1fSDamjan Jovanovic             char m_nData = 'i';
2083cdf0e10cSrcweir //          strcpy(pc, &m_nData);
2084*44e8df1fSDamjan Jovanovic             memcpy(pc, &m_nData, 1);
2085*44e8df1fSDamjan Jovanovic             pc[1] = '\0';
2086cdf0e10cSrcweir //          strncpy(pc, &m_nData, sizeof(char);
2087cdf0e10cSrcweir 
2088*44e8df1fSDamjan Jovanovic             printf("pc %s\n", pc);
2089*44e8df1fSDamjan Jovanovic             myThreadData.setData(pc);
2090cdf0e10cSrcweir 
2091*44e8df1fSDamjan Jovanovic             myKeyThread aThread1('a');
2092*44e8df1fSDamjan Jovanovic             aThread1.create();
2093*44e8df1fSDamjan Jovanovic             myKeyThread aThread2('b');
2094*44e8df1fSDamjan Jovanovic             aThread2.create();
2095cdf0e10cSrcweir 
2096*44e8df1fSDamjan Jovanovic             // change the value which pc points
2097*44e8df1fSDamjan Jovanovic             char m_nData2 = 'j';
2098*44e8df1fSDamjan Jovanovic             // strcpy(pc, &m_nData2);
2099*44e8df1fSDamjan Jovanovic             memcpy(pc, &m_nData2, 1);
2100*44e8df1fSDamjan Jovanovic             pc[1] = '\0';
2101cdf0e10cSrcweir 
2102*44e8df1fSDamjan Jovanovic             //printf("pc %s\n", pc);
2103*44e8df1fSDamjan Jovanovic             void* pChar = myThreadData.getData();
2104*44e8df1fSDamjan Jovanovic             char aChar = *(char*)pChar;
2105cdf0e10cSrcweir 
2106*44e8df1fSDamjan Jovanovic             aThread1.join();
2107*44e8df1fSDamjan Jovanovic             aThread2.join();
2108cdf0e10cSrcweir 
2109*44e8df1fSDamjan Jovanovic             char cData1 = aThread1.m_Char_Test;
2110*44e8df1fSDamjan Jovanovic             char cData2 = aThread2.m_Char_Test;
2111cdf0e10cSrcweir 
2112*44e8df1fSDamjan Jovanovic             ASSERT_TRUE(cData1 == 'a' && cData2 == 'b' && aChar == 'j') << "ThreadData setData: ";
2113cdf0e10cSrcweir 
2114*44e8df1fSDamjan Jovanovic         }
2115cdf0e10cSrcweir 
2116cdf0e10cSrcweir 
2117cdf0e10cSrcweir } // namespace osl_ThreadData
2118cdf0e10cSrcweir 
2119*44e8df1fSDamjan Jovanovic int main(int argc, char **argv)
2120*44e8df1fSDamjan Jovanovic {
2121*44e8df1fSDamjan Jovanovic     ::testing::InitGoogleTest(&argc, argv);
2122*44e8df1fSDamjan Jovanovic     return RUN_ALL_TESTS();
2123*44e8df1fSDamjan Jovanovic }
2124