509099cc7bd2d8a8bba99f6a3aa4bf7df1362049
[platform/core/uifw/dali-core.git] / automated-tests / TET / dali-test-suite / images / utc-Dali-DistanceField.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 #include <iostream>
18 #include <algorithm>
19
20 #include <stdlib.h>
21 #include <tet_api.h>
22
23 #include <dali/public-api/dali-core.h>
24 #include <dali/public-api/images/distance-field.h>
25 #include <dali-test-suite-utils.h>
26
27 using std::max;
28 using namespace Dali;
29
30 static void Startup();
31 static void Cleanup();
32
33 extern "C" {
34   void (*tet_startup)() = Startup;
35   void (*tet_cleanup)() = Cleanup;
36 }
37
38 static void UtcDaliGenerateDistanceField();
39
40 enum {
41   POSITIVE_TC_IDX = 0x01,
42   NEGATIVE_TC_IDX,
43 };
44
45 static const float ROTATION_EPSILON = 0.0001f;
46
47 // Add test functionality for all APIs in the class (Positive and Negative)
48 extern "C" {
49   struct tet_testlist tet_testlist[] = {
50     { UtcDaliGenerateDistanceField, POSITIVE_TC_IDX },
51     { NULL, 0 }
52   };
53 }
54
55 static TestApplication* gApplication = NULL;
56
57 // Called only once before first test is run.
58 static void Startup()
59 {
60   gApplication = new TestApplication();
61 }
62
63 // Called only once after last test is run
64 static void Cleanup()
65 {
66   delete gApplication;
67 }
68
69 static unsigned char sourceImage[] =
70 {
71  0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,
72  0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,
73  0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,
74  0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,
75  0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
76  0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
77  0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
78  0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
79 };
80
81 static void UtcDaliGenerateDistanceField()
82 {
83   unsigned char distanceField[4*4];
84
85   GenerateDistanceFieldMap(sourceImage, Size(8.0f, 8.0f), distanceField, Size(4.0f, 4.0f), 0, Size(4.0f, 4.0f));
86
87   if(distanceField[0]  <= distanceField[5] &&
88      distanceField[5]  <= distanceField[10] &&
89      distanceField[10] <= distanceField[15])
90   {
91     tet_result(TET_PASS);
92   }
93   else
94   {
95     tet_result(TET_FAIL);
96   }
97 }