[Tizen] Make mScene nullptr when the Actor is disconnected from Scene recursively
[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 // Simple API test
102 int UtcDaliLocklessBufferGetSize01(void)
103 {
104   Integration::LocklessBuffer buf(10);
105   unsigned int                size = buf.GetSize();
106   if(size == 10)
107   {
108     tet_result(TET_PASS);
109   }
110   else
111   {
112     tet_result(TET_FAIL);
113   }
114   END_TEST;
115 }