Adding new test harness
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / test-gl-sync-abstraction.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 #include "test-gl-sync-abstraction.h"
18
19 namespace Dali
20 {
21
22 TestSyncObject::TestSyncObject(TraceCallStack& trace)
23 : synced(false),
24   mTrace(trace)
25 {
26 }
27
28 TestSyncObject::~TestSyncObject()
29 {
30 }
31
32 bool TestSyncObject::IsSynced()
33 {
34   mTrace.PushCall("SyncObject::IsSynced", ""); // Trace the method
35   return synced;
36 }
37
38
39
40 TestGlSyncAbstraction::TestGlSyncAbstraction()
41 {
42   Initialize();
43 }
44
45 /**
46  * Destructor
47  */
48 TestGlSyncAbstraction::~TestGlSyncAbstraction()
49 {
50   for( SyncIter iter=mSyncObjects.begin(), end=mSyncObjects.end(); iter != end; ++iter )
51   {
52     delete *iter;
53   }
54 }
55
56 /**
57  * Initialize the sync objects - clear down the map
58  */
59 void TestGlSyncAbstraction::Initialize()
60 {
61   mSyncObjects.clear();
62 }
63
64 /**
65  * Create a sync object
66  * @return the sync object
67  */
68 Integration::GlSyncAbstraction::SyncObject* TestGlSyncAbstraction::CreateSyncObject( )
69 {
70   mTrace.PushCall("CreateSyncObject", ""); // Trace the method
71
72   TestSyncObject* syncObject = new TestSyncObject(mTrace);
73   mSyncObjects.push_back( syncObject );
74   return syncObject;
75 }
76
77 /**
78  * Destroy a sync object
79  * @param[in] syncObject The object to destroy
80  */
81 void TestGlSyncAbstraction::DestroySyncObject( Integration::GlSyncAbstraction::SyncObject* syncObject )
82 {
83   std::stringstream out;
84   out << syncObject;
85   mTrace.PushCall("DestroySyncObject", out.str()); // Trace the method
86
87   for( SyncIter iter=mSyncObjects.begin(), end=mSyncObjects.end(); iter != end; ++iter )
88   {
89     if( *iter == syncObject )
90     {
91       delete *iter;
92       mSyncObjects.erase(iter);
93       break;
94     }
95   }
96 }
97
98
99 Integration::GlSyncAbstraction::SyncObject* TestGlSyncAbstraction::GetLastSyncObject( )
100 {
101   if( !mSyncObjects.empty() )
102   {
103     return mSyncObjects.back();
104   }
105   return NULL;
106 }
107
108 /**
109  * Test method to trigger the object sync behaviour.
110  * @param[in]
111  * @param[in] sync The sync value to set
112  */
113 void TestGlSyncAbstraction::SetObjectSynced( Integration::GlSyncAbstraction::SyncObject* syncObject, bool sync )
114 {
115   TestSyncObject* testSyncObject = static_cast<TestSyncObject*>(syncObject);
116   testSyncObject->synced = sync;
117 }
118
119 /**
120  * Turn trace on
121  */
122 void TestGlSyncAbstraction::EnableTrace(bool enable) { mTrace.Enable(enable); }
123
124 /**
125  * Reset the trace callstack
126  */
127 void TestGlSyncAbstraction::ResetTrace() { mTrace.Reset(); }
128
129 /**
130  * Get the trace object (allows test case to find methods on it)
131  */
132 TraceCallStack& TestGlSyncAbstraction::GetTrace() { return mTrace; }
133
134
135 } // Dali