[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / test-graphics-sync-impl.cpp
1 /*
2  * Copyright (c) 2014 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 "test-graphics-sync-impl.h"
19
20 namespace Dali
21 {
22 TestSyncObject::TestSyncObject(Dali::TraceCallStack& trace)
23
24 : synced(false),
25   mTrace(trace)
26 {
27   mTrace.PushCall("TestSyncObject cons", ""); // Trace the method
28 }
29
30 TestSyncObject::~TestSyncObject()
31 {
32   mTrace.PushCall("TestSyncObject dstr", ""); // Trace the method
33 }
34
35 bool TestSyncObject::IsSynced()
36 {
37   mTrace.PushCall("SyncObject::IsSynced", ""); // Trace the method
38   return synced;
39 }
40
41 void TestSyncObject::Wait()
42 {
43   mTrace.PushCall("SyncObject::Wait", ""); // Trace the method
44 }
45
46 void TestSyncObject::ClientWait()
47 {
48   mTrace.PushCall("SyncObject::ClientWait", ""); // Trace the method
49 }
50
51 TestGraphicsSyncImplementation::TestGraphicsSyncImplementation()
52 {
53   Initialize();
54 }
55
56 /**
57  * Destructor
58  */
59 TestGraphicsSyncImplementation::~TestGraphicsSyncImplementation()
60 {
61   for(SyncIter iter = mSyncObjects.begin(), end = mSyncObjects.end(); iter != end; ++iter)
62   {
63     delete *iter;
64   }
65 }
66
67 /**
68  * Initialize the sync objects
69  */
70 void TestGraphicsSyncImplementation::Initialize()
71 {
72   mSyncObjects.clear();
73 }
74
75 Integration::GraphicsSyncAbstraction::SyncObject* TestGraphicsSyncImplementation::CreateSyncObject()
76 {
77   mTrace.PushCall("CreateSyncObject", ""); // Trace the method
78
79   TestSyncObject* syncObject = new TestSyncObject(mTrace);
80   mSyncObjects.push_back(syncObject);
81   return syncObject;
82 }
83
84 /**
85  * Destroy a sync object
86  * @param[in] syncObject The object to destroy
87  */
88 void TestGraphicsSyncImplementation::DestroySyncObject(Integration::GraphicsSyncAbstraction::SyncObject* syncObject)
89 {
90   std::stringstream out;
91   out << syncObject;
92   mTrace.PushCall("DestroySyncObject", out.str()); // Trace the method
93
94   for(SyncIter iter = mSyncObjects.begin(), end = mSyncObjects.end(); iter != end; ++iter)
95   {
96     if(*iter == syncObject)
97     {
98       delete *iter;
99       mSyncObjects.erase(iter);
100       break;
101     }
102   }
103 }
104
105 Integration::GraphicsSyncAbstraction::SyncObject* TestGraphicsSyncImplementation::GetLastSyncObject()
106 {
107   if(!mSyncObjects.empty())
108   {
109     return mSyncObjects.back();
110   }
111   return NULL;
112 }
113
114 /**
115  * Test method to trigger the object sync behaviour.
116  * @param[in]
117  * @param[in] sync The sync value to set
118  */
119 void TestGraphicsSyncImplementation::SetObjectSynced(Integration::GraphicsSyncAbstraction::SyncObject* syncObject, bool sync)
120 {
121   TestSyncObject* testSyncObject = static_cast<TestSyncObject*>(syncObject);
122   testSyncObject->synced         = sync;
123 }
124
125 /**
126  * Turn trace on
127  */
128 void TestGraphicsSyncImplementation::EnableTrace(bool enable)
129 {
130   mTrace.Enable(enable);
131 }
132
133 /**
134  * Reset the trace callstack
135  */
136 void TestGraphicsSyncImplementation::ResetTrace()
137 {
138   mTrace.Reset();
139 }
140
141 /**
142  * Get the trace object (allows test case to find methods on it)
143  */
144 TraceCallStack& TestGraphicsSyncImplementation::GetTrace()
145 {
146   return mTrace;
147 }
148
149 int32_t TestGraphicsSyncImplementation::GetNumberOfSyncObjects()
150 {
151   return static_cast<int32_t>(mSyncObjects.size());
152 }
153
154 } // namespace Dali