Revert "[Tizen] Appendix log for ttrace + Print keycode and timestamp"
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-LocklessBuffer.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 <dali-test-suite-utils.h>
19 #include <dali/integration-api/lockless-buffer.h>
20 #include <dali/public-api/dali-core.h>
21 #include <stdlib.h>
22
23 #include <iostream>
24
25 using namespace Dali;
26
27 namespace
28 {
29 static bool ReadTest(Integration::LocklessBuffer& buf, const unsigned char exp[], size_t size)
30 {
31   const unsigned char* res = buf.Read();
32   for(size_t i = 0; i < size; ++i, ++res)
33   {
34     if(*res != exp[i])
35     {
36       tet_printf("FAIL: expected 0x%X result 0x%X\n", (int)exp[i], (int)*res);
37       return false;
38     }
39   }
40   return true;
41 }
42 } // anonymous namespace
43
44 // Simple write - read test
45 int UtcDaliLocklessBufferWriteRead01(void)
46 {
47   Integration::LocklessBuffer buf(10);
48   unsigned char               data[10];
49
50   for(unsigned char i = 0; i < 10; ++i)
51   {
52     data[i] = i;
53   }
54
55   buf.Write(&data[0], 10);
56
57   if(ReadTest(buf, data, 10))
58   {
59     tet_result(TET_PASS);
60   }
61   else
62   {
63     tet_result(TET_FAIL);
64   }
65   END_TEST;
66 }
67
68 // test multiple writes, one read
69 int UtcDaliLocklessBufferMultipleWrites01(void)
70 {
71   Integration::LocklessBuffer buf(10);
72   unsigned char               data[10];
73
74   for(unsigned char i = 0; i < 10; ++i)
75   {
76     data[i] = i;
77   }
78
79   // Write to a buffer
80   buf.Write(&data[0], 10);
81
82   for(unsigned char i = 0; i < 10; ++i)
83   {
84     data[i] = i + 4;
85   }
86
87   // No reads from buffer, so will overwrite contents of same buffer
88   buf.Write(&data[0], 10);
89
90   if(ReadTest(buf, data, 10))
91   {
92     tet_result(TET_PASS);
93   }
94   else
95   {
96     tet_result(TET_FAIL);
97   }
98   END_TEST;
99 }
100
101 // test one writes, multiple read
102 int UtcDaliLocklessBufferMultipleWrites02(void)
103 {
104   Integration::LocklessBuffer buf(10);
105   unsigned char               data[10];
106
107   for(unsigned char i = 0; i < 10; ++i)
108   {
109     data[i] = i;
110   }
111
112   // Write to a buffer
113   buf.Write(&data[0], 10);
114
115   if(ReadTest(buf, data, 10))
116   {
117     tet_result(TET_PASS);
118   }
119   else
120   {
121     tet_result(TET_FAIL);
122   }
123
124   // ReadTest one more time. for coverity.
125   if(ReadTest(buf, data, 10))
126   {
127     tet_result(TET_PASS);
128   }
129   else
130   {
131     tet_result(TET_FAIL);
132   }
133
134   for(unsigned char i = 0; i < 10; ++i)
135   {
136     data[i] = i + 4;
137   }
138
139   // No reads from buffer, so will overwrite contents of same buffer
140   buf.Write(&data[0], 10);
141
142   if(ReadTest(buf, data, 10))
143   {
144     tet_result(TET_PASS);
145   }
146   else
147   {
148     tet_result(TET_FAIL);
149   }
150
151   // ReadTest one more time. for coverity.
152   if(ReadTest(buf, data, 10))
153   {
154     tet_result(TET_PASS);
155   }
156   else
157   {
158     tet_result(TET_FAIL);
159   }
160
161   END_TEST;
162 }
163
164 // Simple API test
165 int UtcDaliLocklessBufferGetSize01(void)
166 {
167   Integration::LocklessBuffer buf(10);
168   unsigned int                size = buf.GetSize();
169   if(size == 10)
170   {
171     tet_result(TET_PASS);
172   }
173   else
174   {
175     tet_result(TET_FAIL);
176   }
177   END_TEST;
178 }