Merge branch 'devel/graphics' into devel/master
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-ConditionalWait.cpp
index 88a3902..71fe305 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  *
  */
 
-#include <iostream>
-#include <stdlib.h>
-#include <unistd.h>
 #include <dali-test-suite-utils.h>
 #include <dali/devel-api/threading/conditional-wait.h>
 #include <dali/devel-api/threading/thread.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <iostream>
+#include <type_traits>
 
 using Dali::ConditionalWait;
 using Dali::Thread;
 
 namespace // for local variables to avoid name clashes
 {
-volatile int gGlobalValue = 0;
+volatile int  gGlobalValue      = 0;
 volatile bool gWorkerThreadWait = true;
-enum ThreadState { INIT, RUN, TERMINATE } volatile gWorkerThreadState = INIT;
+enum ThreadState
+{
+  INIT,
+  RUN,
+  TERMINATE
+} volatile gWorkerThreadState = INIT;
 ConditionalWait* volatile gConditionalWait; // volatile pointer to a ConditionalWait object
 
 class WorkerThreadNotify : public Thread
@@ -37,12 +44,12 @@ class WorkerThreadNotify : public Thread
   virtual void Run()
   {
     gGlobalValue = -1;
-    while( gWorkerThreadWait ) // wait till we can exit
+    while(gWorkerThreadWait) // wait till we can exit
     {
       gWorkerThreadState = RUN;
-      usleep( 1 ); // 1 microseconds
+      usleep(1); // 1 microseconds
     }
-    usleep( 200 ); // give other thread time to get to Wait
+    usleep(200); // give other thread time to get to Wait
     gGlobalValue = 1;
     gConditionalWait->Notify();
     gWorkerThreadState = TERMINATE;
@@ -54,10 +61,10 @@ class WorkerThreadNotifyN : public Thread
 {
   virtual void Run()
   {
-    while( gNotifyCount > 0 )
+    while(gNotifyCount > 0)
     {
       gConditionalWait->Notify();
-      usleep( 10 ); // 10 microseconds between each notify
+      usleep(10); // 10 microseconds between each notify
     }
   }
 };
@@ -70,7 +77,7 @@ class WorkerThreadWaitN : public Thread
   }
 };
 
-}
+} // namespace
 
 int UtcConditionalWait1P(void)
 {
@@ -78,27 +85,27 @@ int UtcConditionalWait1P(void)
 
   WorkerThreadNotify thread1;
   // initialize values
-  gConditionalWait = new ConditionalWait();
+  gConditionalWait  = new ConditionalWait();
   gWorkerThreadWait = true;
-  DALI_TEST_EQUALS( INIT, gWorkerThreadState, TEST_LOCATION );
-  DALI_TEST_EQUALS( 0, gGlobalValue, TEST_LOCATION );
+  DALI_TEST_EQUALS(INIT, gWorkerThreadState, TEST_LOCATION);
+  DALI_TEST_EQUALS(0, gGlobalValue, TEST_LOCATION);
 
   thread1.Start();
   // wait till the thread is in run state
-  while( RUN != gWorkerThreadState )
+  while(RUN != gWorkerThreadState)
   {
-    usleep( 1 ); // 1 microsecond
+    usleep(1); // 1 microsecond
   }
   // let worker continue and finish
   gWorkerThreadWait = false;
   gConditionalWait->Wait();
-  DALI_TEST_EQUALS( 1, gGlobalValue, TEST_LOCATION );
-  DALI_TEST_EQUALS( 0u, gConditionalWait->GetWaitCount(), TEST_LOCATION );
+  DALI_TEST_EQUALS(1, gGlobalValue, TEST_LOCATION);
+  DALI_TEST_EQUALS(0u, gConditionalWait->GetWaitCount(), TEST_LOCATION);
 
   // wait till the thread is terminated state
-  while( TERMINATE != gWorkerThreadState )
+  while(TERMINATE != gWorkerThreadState)
   {
-    usleep( 1 ); // 1 microsecond
+    usleep(1); // 1 microsecond
   }
 
   thread1.Join();
@@ -112,33 +119,32 @@ int UtcConditionalWait2P(void)
   tet_infoline("Testing ConditionalWait - scenario: notify without wait");
 
   ConditionalWait wait;
-  DALI_TEST_EQUALS( 0u, wait.GetWaitCount(), TEST_LOCATION );
+  DALI_TEST_EQUALS(0u, wait.GetWaitCount(), TEST_LOCATION);
   wait.Notify();
-  DALI_TEST_EQUALS( 0u, wait.GetWaitCount(), TEST_LOCATION );
+  DALI_TEST_EQUALS(0u, wait.GetWaitCount(), TEST_LOCATION);
 
   END_TEST;
 }
 
-
 int UtcConditionalWait3P(void)
 {
   tet_infoline("Testing ConditionalWait - scenario: wait - notify N times 2 threads");
 
   // initialize values
   gConditionalWait = new ConditionalWait();
-  gNotifyCount = 100;
+  gNotifyCount     = 100;
 
   WorkerThreadNotifyN thread1;
   thread1.Start();
 
-  while( gNotifyCount > 0 )
+  while(gNotifyCount > 0)
   {
     gConditionalWait->Wait();
     --gNotifyCount;
-    DALI_TEST_EQUALS( 0u, gConditionalWait->GetWaitCount(), TEST_LOCATION );
-    usleep( 10 ); // 10 microseconds between each notify
+    DALI_TEST_EQUALS(0u, gConditionalWait->GetWaitCount(), TEST_LOCATION);
+    usleep(10); // 10 microseconds between each notify
   }
-  DALI_TEST_EQUALS( 0u, gConditionalWait->GetWaitCount(), TEST_LOCATION );
+  DALI_TEST_EQUALS(0u, gConditionalWait->GetWaitCount(), TEST_LOCATION);
 
   thread1.Join();
 
@@ -152,7 +158,7 @@ int UtcConditionalWait4P(void)
 
   // initialize values
   gConditionalWait = new ConditionalWait();
-  gNotifyCount = 100;
+  gNotifyCount     = 100;
 
   WorkerThreadNotifyN thread1;
   thread1.Start();
@@ -161,12 +167,12 @@ int UtcConditionalWait4P(void)
   WorkerThreadNotifyN thread3;
   thread3.Start();
 
-  while( gNotifyCount > 0 )
+  while(gNotifyCount > 0)
   {
     gConditionalWait->Wait();
     --gNotifyCount;
-    DALI_TEST_EQUALS( 0u, gConditionalWait->GetWaitCount(), TEST_LOCATION );
-    usleep( 10 ); // 10 microseconds between each notify
+    DALI_TEST_EQUALS(0u, gConditionalWait->GetWaitCount(), TEST_LOCATION);
+    usleep(10); // 10 microseconds between each notify
   }
 
   thread1.Join();
@@ -193,8 +199,9 @@ int UtcConditionalWait5P(void)
   WorkerThreadWaitN thread4;
   thread4.Start();
   // wait till all child threads are waiting
-  while( gConditionalWait->GetWaitCount() < 4 )
-  { }
+  while(gConditionalWait->GetWaitCount() < 4)
+  {
+  }
 
   // notify once, it will resume all threads
   gConditionalWait->Notify();
@@ -204,7 +211,7 @@ int UtcConditionalWait5P(void)
   thread3.Join();
   thread4.Join();
 
-  DALI_TEST_EQUALS( 0u, gConditionalWait->GetWaitCount(), TEST_LOCATION );
+  DALI_TEST_EQUALS(0u, gConditionalWait->GetWaitCount(), TEST_LOCATION);
 
   delete gConditionalWait;
   END_TEST;
@@ -226,13 +233,14 @@ int UtcConditionalWait6P(void)
   WorkerThreadWaitN thread4;
   thread4.Start();
   // wait till all child threads are waiting
-  while( gConditionalWait->GetWaitCount() < 4 )
-  { }
+  while(gConditionalWait->GetWaitCount() < 4)
+  {
+  }
 
   // notify once but with a scoped lock, it will resume all threads
   {
-    ConditionalWait::ScopedLock lock( *gConditionalWait );
-    gConditionalWait->Notify( lock );
+    ConditionalWait::ScopedLock lock(*gConditionalWait);
+    gConditionalWait->Notify(lock);
   }
 
   thread1.Join();
@@ -240,7 +248,7 @@ int UtcConditionalWait6P(void)
   thread3.Join();
   thread4.Join();
 
-  DALI_TEST_EQUALS( 0u, gConditionalWait->GetWaitCount(), TEST_LOCATION );
+  DALI_TEST_EQUALS(0u, gConditionalWait->GetWaitCount(), TEST_LOCATION);
 
   delete gConditionalWait;
   END_TEST;
@@ -250,10 +258,8 @@ int UtcConditionalWaitNonCopyable(void)
 {
   // we want to make sure that ConditionalWait is not copyable (its copy constructor is not defined)
   // this test will stop compiling if ConditionalWait has compiler generated copy constructor
-  DALI_COMPILE_TIME_ASSERT( !__has_trivial_copy( ConditionalWait ) );
+  static_assert(!__has_trivial_copy(ConditionalWait), "ConditionalWait should NOT be copyable");
 
-  DALI_TEST_CHECK( true );
+  DALI_TEST_CHECK(true);
   END_TEST;
 }
-
-