Sync tests for sync
[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 TestGraphicsSyncImplementation::TestGraphicsSyncImplementation()
42 {
43   Initialize();
44 }
45
46 /**
47  * Destructor
48  */
49 TestGraphicsSyncImplementation::~TestGraphicsSyncImplementation()
50 {
51   for(SyncIter iter = mSyncObjects.begin(), end = mSyncObjects.end(); iter != end; ++iter)
52   {
53     delete *iter;
54   }
55 }
56
57 /**
58  * Initialize the sync objects
59  */
60 void TestGraphicsSyncImplementation::Initialize()
61 {
62   mSyncObjects.clear();
63 }
64
65 Integration::GraphicsSyncAbstraction::SyncObject* TestGraphicsSyncImplementation::CreateSyncObject()
66 {
67   mTrace.PushCall("CreateSyncObject", ""); // Trace the method
68
69   TestSyncObject* syncObject = new TestSyncObject(mTrace);
70   mSyncObjects.push_back(syncObject);
71   return syncObject;
72 }
73
74 /**
75  * Destroy a sync object
76  * @param[in] syncObject The object to destroy
77  */
78 void TestGraphicsSyncImplementation::DestroySyncObject(Integration::GraphicsSyncAbstraction::SyncObject* syncObject)
79 {
80   std::stringstream out;
81   out << syncObject;
82   mTrace.PushCall("DestroySyncObject", out.str()); // Trace the method
83
84   for(SyncIter iter = mSyncObjects.begin(), end = mSyncObjects.end(); iter != end; ++iter)
85   {
86     if(*iter == syncObject)
87     {
88       delete *iter;
89       mSyncObjects.erase(iter);
90       break;
91     }
92   }
93 }
94
95 Integration::GraphicsSyncAbstraction::SyncObject* TestGraphicsSyncImplementation::GetLastSyncObject()
96 {
97   if(!mSyncObjects.empty())
98   {
99     return mSyncObjects.back();
100   }
101   return NULL;
102 }
103
104 /**
105  * Test method to trigger the object sync behaviour.
106  * @param[in]
107  * @param[in] sync The sync value to set
108  */
109 void TestGraphicsSyncImplementation::SetObjectSynced(Integration::GraphicsSyncAbstraction::SyncObject* syncObject, bool sync)
110 {
111   TestSyncObject* testSyncObject = static_cast<TestSyncObject*>(syncObject);
112   testSyncObject->synced         = sync;
113 }
114
115 /**
116  * Turn trace on
117  */
118 void TestGraphicsSyncImplementation::EnableTrace(bool enable)
119 {
120   mTrace.Enable(enable);
121 }
122
123 /**
124  * Reset the trace callstack
125  */
126 void TestGraphicsSyncImplementation::ResetTrace()
127 {
128   mTrace.Reset();
129 }
130
131 /**
132  * Get the trace object (allows test case to find methods on it)
133  */
134 TraceCallStack& TestGraphicsSyncImplementation::GetTrace()
135 {
136   return mTrace;
137 }
138
139 int32_t TestGraphicsSyncImplementation::GetNumberOfSyncObjects()
140 {
141   return static_cast<int32_t>(mSyncObjects.size());
142 }
143
144 } // namespace Dali