Replace DALI_COMPILE_TIME_ASSERT with C++11 static_assert
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Thread.cpp
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include <iostream>
19 #include <stdlib.h>
20 #include <unistd.h>
21 #include <type_traits>
22 #include <dali-test-suite-utils.h>
23 #include <dali/devel-api/threading/thread.h>
24
25 using Dali::Thread;
26
27 namespace
28 {
29 volatile bool gRunThreadEntryFunc = false;
30
31 class TestThread : public Thread
32 {
33   virtual void Run()
34   {
35     gRunThreadEntryFunc = true;
36   }
37 };
38 }
39
40 int UtcDaliThreadP(void)
41 {
42   tet_infoline("Testing Dali::Thread");
43
44   gRunThreadEntryFunc = false;
45
46   TestThread thread;
47
48   thread.Start();
49   // wait till the thread is terminated
50   while( !gRunThreadEntryFunc )
51   {
52     usleep( 1 ); // 1 microsecond
53   }
54   DALI_TEST_EQUALS( true, gRunThreadEntryFunc, TEST_LOCATION );
55
56   thread.Join();
57
58   // Restart the thread after joined
59   gRunThreadEntryFunc = false;
60   thread.Start();
61   thread.Join();
62   // wait till the thread is terminated
63   while( !gRunThreadEntryFunc )
64   {
65     usleep( 1 ); // 1 microsecond
66   }
67   DALI_TEST_EQUALS( true, gRunThreadEntryFunc, TEST_LOCATION );
68
69   END_TEST;
70 }
71
72 int UtcDaliThreadNonCopyable(void)
73 {
74   // we want to make sure that mutex is not copyable (its copy constructor is not defined)
75   // this test will stop compiling if Mutex has compiler generated copy constructor
76   static_assert( !__has_trivial_copy( Thread ), "Thread should NOT be copyable" );
77
78   DALI_TEST_CHECK( true );
79   END_TEST;
80 }