Dali 3D User Interface Engine
dali-test-suite-utils.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 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 // CLASS HEADER
19 #include "dali-test-suite-utils.h"
20 
21 // EXTERNAL INCLUDES
22 #include <ostream>
23 
24 // INTERNAL INCLUDES
26 
27 using namespace Dali;
28 
30 
31 void tet_result(int value)
32 {
33  // First TET_PASS should set to zero
34  // first TET_FAIL should prevent any further TET_PASS from setting back to zero
35  // Any TET_FAIL should set to fail or leave as fail
36  if( test_return_value != 1 )
37  test_return_value = value;
38 }
39 
40 #define END_TEST \
41  return ((test_return_value>0)?1:0)
42 
43 
44 void tet_infoline(const char* str)
45 {
46  fprintf(stderr, "%s\n", str);
47 }
48 
49 void tet_printf(const char *format, ...)
50 {
51  va_list arg;
52  va_start(arg, format);
53  vfprintf(stderr, format, arg);
54  va_end(arg);
55 }
56 
58 {
60 }
61 
62 std::ostream& operator<<( std::ostream& ostream, TimePeriod value )
63 {
64  return ostream << "( Duration:" << value.durationSeconds << " Delay:" << value.delaySeconds << ")";
65 }
66 
67 std::ostream& operator<<( std::ostream& ostream, Radian angle )
68 {
69  ostream << angle.radian;
70  return ostream;
71 }
72 
73 std::ostream& operator<<( std::ostream& ostream, Degree angle )
74 {
75  ostream << angle.degree;
76  return ostream;
77 }
78 
79 void DALI_TEST_EQUALS( const BaseHandle& baseHandle1, const BaseHandle& baseHandle2, const char* location )
80 {
81  DALI_TEST_EQUALS< const BaseHandle& >( baseHandle1, baseHandle2, location );
82 }
83 
84 void DALI_TEST_EQUALS( const size_t value1, const unsigned int value2, const char* location )
85 {
86  DALI_TEST_EQUALS< unsigned int>( ( unsigned int )( value1 ), value2, location );
87 }
88 
89 void DALI_TEST_EQUALS( const unsigned int value1, const size_t value2, const char* location )
90 {
91  DALI_TEST_EQUALS< unsigned int >( value1, ( unsigned int )( value2 ), location );
92 }
93 
94 void DALI_TEST_EQUALS( const Matrix3& matrix1, const Matrix3& matrix2, const char* location)
95 {
96  const float* m1 = matrix1.AsFloat();
97  const float* m2 = matrix2.AsFloat();
98  bool equivalent = true;
99 
100  for (int i=0;i<9;++i)
101  {
102  if( ! (fabsf(m1[i] - m2[i])< GetRangedEpsilon(m1[i], m2[i])) )
103  {
104  equivalent = false;
105  }
106  }
107 
108  if( !equivalent )
109  {
110  fprintf(stderr, "%s, checking\n"
111  "(%f, %f, %f) (%f, %f, %f)\n"
112  "(%f, %f, %f) == (%f, %f, %f)\n"
113  "(%f, %f, %f) (%f, %f, %f)\n",
114  location,
115  m1[0], m1[1], m1[2], m2[0], m2[1], m2[2],
116  m1[3], m1[4], m1[5], m2[3], m2[4], m2[5],
117  m1[6], m1[7], m1[8], m2[6], m2[7], m2[8]);
118 
120  }
121  else
122  {
124  }
125 }
126 
127 void DALI_TEST_EQUALS( const Matrix3& matrix1, const Matrix3& matrix2, float epsilon, const char* location)
128 {
129  const float* m1 = matrix1.AsFloat();
130  const float* m2 = matrix2.AsFloat();
131  bool equivalent = true;
132 
133  for (int i=0;i<9;++i)
134  {
135  equivalent &= (fabsf(m1[i] - m2[i])<epsilon);
136  }
137 
138  if (!equivalent)
139  {
140  fprintf(stderr, "%s, checking\n"
141  "(%f, %f, %f) (%f, %f, %f)\n"
142  "(%f, %f, %f) == (%f, %f, %f)\n"
143  "(%f, %f, %f) (%f, %f, %f)\n",
144  location,
145  m1[0], m1[1], m1[2], m2[0], m2[1], m2[2],
146  m1[3], m1[4], m1[5], m2[3], m2[4], m2[5],
147  m1[6], m1[7], m1[8], m2[6], m2[7], m2[8]);
148 
150  }
151  else
152  {
154  }
155 }
156 
157 void DALI_TEST_EQUALS( const Matrix& matrix1, const Matrix& matrix2, const char* location)
158 {
159  const float* m1 = matrix1.AsFloat();
160  const float* m2 = matrix2.AsFloat();
161  bool identical = true;
162 
163  int i;
164  for (i=0;i<16;++i)
165  {
166  if(m1[i] != m2[i])
167  {
168  identical = false;
169  break;
170  }
171  }
172 
173  if (!identical)
174  {
175  fprintf(stderr, "%s, checking\n"
176  "(%f, %f, %f, %f) (%f, %f, %f, %f)\n"
177  "(%f, %f, %f, %f) == (%f, %f, %f, %f)\n"
178  "(%f, %f, %f, %f) (%f, %f, %f, %f)\n"
179  "(%f, %f, %f, %f) (%f, %f, %f, %f)\n", location,
180  m1[0], m1[1], m1[2], m1[3], m2[0], m2[1], m2[2], m2[3],
181  m1[4], m1[5], m1[6], m1[7], m2[4], m2[5], m2[6], m2[7],
182  m1[8], m1[9], m1[10], m1[11], m2[8], m2[9], m2[10], m2[11],
183  m1[12], m1[13], m1[14], m1[15], m2[12], m2[13], m2[14], m2[15]);
184 
186  }
187  else
188  {
190  }
191 }
192 
193 void DALI_TEST_EQUALS( const Matrix& matrix1, const Matrix& matrix2, float epsilon, const char* location)
194 {
195  const float* m1 = matrix1.AsFloat();
196  const float* m2 = matrix2.AsFloat();
197  bool equivalent = true;
198 
199  for (int i=0;i<16;++i)
200  {
201  equivalent &= (fabsf(m1[i] - m2[i])<epsilon);
202  }
203 
204  if (!equivalent)
205  {
206  fprintf(stderr, "%s, checking\n"
207  "(%f, %f, %f, %f) (%f, %f, %f, %f)\n"
208  "(%f, %f, %f, %f) == (%f, %f, %f, %f)\n"
209  "(%f, %f, %f, %f) (%f, %f, %f, %f)\n"
210  "(%f, %f, %f, %f) (%f, %f, %f, %f)\n", location,
211  m1[0], m1[1], m1[2], m1[3], m2[0], m2[1], m2[2], m2[3],
212  m1[4], m1[5], m1[6], m1[7], m2[4], m2[5], m2[6], m2[7],
213  m1[8], m1[9], m1[10], m1[11], m2[8], m2[9], m2[10], m2[11],
214  m1[12], m1[13], m1[14], m1[15], m2[12], m2[13], m2[14], m2[15]);
215 
217  }
218  else
219  {
221  }
222 }
223 
224 
231 void DALI_TEST_EQUALS( const std::string &str1, const char* str2, const char* location)
232 {
233  DALI_TEST_EQUALS(str1.c_str(), str2, location);
234 }
235 
242 void DALI_TEST_EQUALS( const char* str1, const std::string &str2, const char* location)
243 {
244  DALI_TEST_EQUALS(str1, str2.c_str(), location);
245 }
246 
247 void DALI_TEST_ASSERT( DaliException& e, std::string conditionSubString, const char* location )
248 {
249  if( NULL == strstr( e.condition, conditionSubString.c_str() ) )
250  {
251  fprintf(stderr, "Expected substring '%s' : actual exception string '%s' : location %s\n", conditionSubString.c_str(), e.condition, location );
253  }
254  else
255  {
257  }
258 }
259 
260 // Functor to test whether an Applied signal is emitted
262 : mSignalReceived( signalReceived )
263 {
264 }
265 
267 {
268  mSignalReceived = true;
269 }
270 
272 {
273  mSignalReceived = false;
274 }
275 
277 {
278  if ( !mSignalReceived )
279  {
280  fprintf(stderr, "Expected Applied signal was not received\n" );
281  tet_result( TET_FAIL );
282  }
283  else
284  {
285  tet_result( TET_PASS );
286  }
287 }
288 
290 {
291  if ( mSignalReceived )
292  {
293  fprintf(stderr, "Unexpected Applied signal was received\n" );
294  tet_result( TET_FAIL );
295  }
296  else
297  {
298  tet_result( TET_PASS );
299  }
300 }
301 
303 {
304  BufferImage image = BufferImage::New(width, height, Pixel::RGBA8888);
305 
306  PixelBuffer* pixbuf = image.GetBuffer();
307 
308  // Using a 4x4 image gives a better blend with the GL implementation
309  // than a 3x3 image
310  for(size_t i=0; i<16; i++)
311  {
312  pixbuf[i*4+0] = color.r*255;
313  pixbuf[i*4+1] = color.g*255;
314  pixbuf[i*4+2] = color.b*255;
315  pixbuf[i*4+3] = color.a*255;
316  }
317 
318  return image;
319 }
320 
322 {
323  return CreateBufferImage(4, 4, Color::WHITE);
324 }
Dali Docs Home
Read more about Dali