46f1dc20b3e404520b55005c304759a962c603b1
[platform/core/uifw/dali-core.git] / automated-tests / src / dali-unmanaged / 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 <iostream>
19
20 #include <stdlib.h>
21 #include <dali/public-api/dali-core.h>
22 #include <dali/integration-api/lockless-buffer.h>
23 #include <dali-test-suite-utils.h>
24
25 using namespace Dali;
26
27 namespace
28 {
29
30 static bool ReadTest(Integration::LocklessBuffer& buf, const unsigned char exp[], size_t size)
31 {
32   const unsigned char *res = buf.Read();
33   for (size_t i=0; i<size; ++i, ++res)
34   {
35     if(*res != exp[i])
36     {
37       tet_printf("FAIL: expected 0x%X result 0x%X\n", (int)exp[i], (int)*res);
38       return false;
39     }
40   }
41   return true;
42 }
43 } // anonymous namespace
44
45
46 // Simple write - read test
47 int UtcDaliLocklessBufferWriteRead01(void)
48 {
49   Integration::LocklessBuffer buf(10);
50   unsigned char data[10];
51
52   for( unsigned char i=0; i<10; ++i )
53   {
54     data[i]=i;
55   }
56
57   buf.Write( &data[0], 10 );
58
59   if( ReadTest( buf, data, 10 ) )
60   {
61     tet_result(TET_PASS);
62   }
63   else
64   {
65     tet_result(TET_FAIL);
66   }
67   END_TEST;
68 }
69
70 // test multiple writes, one read
71 int UtcDaliLocklessBufferMultipleWrites01(void)
72 {
73   Integration::LocklessBuffer buf(10);
74   unsigned char data[10];
75
76   for( unsigned char i=0; i<10; ++i )
77   {
78     data[i]=i;
79   }
80
81   // Write to a buffer
82   buf.Write( &data[0], 10 );
83
84   for (unsigned char i=0; i<10; ++i)
85   {
86       data[i]=i+4;
87   }
88
89   // No reads from buffer, so will overwrite contents of same buffer
90   buf.Write( &data[0], 10 );
91
92   if( ReadTest(buf, data, 10) )
93   {
94     tet_result(TET_PASS);
95   }
96   else
97   {
98     tet_result(TET_FAIL);
99   }
100   END_TEST;
101 }
102
103 // Simple API test
104 int UtcDaliLocklessBufferGetSize01(void)
105 {
106   Integration::LocklessBuffer buf(10);
107   unsigned int size = buf.GetSize();
108   if( size == 10 )
109   {
110     tet_result(TET_PASS);
111   }
112   else
113   {
114     tet_result(TET_FAIL);
115   }
116   END_TEST;
117 }