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