Dali 3D User Interface Engine
utc-Dali-LocklessBuffer.cpp
Go to the documentation of this file.
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>
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
48 {
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  {
62  }
63  else
64  {
66  }
67  END_TEST;
68 }
69 
70 // test multiple writes, one read
72 {
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  {
95  }
96  else
97  {
99  }
100  END_TEST;
101 }
102 
103 // Simple API test
105 {
107  unsigned int size = buf.GetSize();
108  if( size == 10 )
109  {
111  }
112  else
113  {
115  }
116  END_TEST;
117 }
Dali Docs Home
Read more about Dali