Upload package dali_0.9.11.
[platform/core/uifw/dali-core.git] / automated-tests / TET / dali-test-suite / text / utc-Dali-Character.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
19 #include <stdlib.h>
20 #include <tet_api.h>
21
22 #include <dali/public-api/dali-core.h>
23 #include <dali/internal/event/text/character-impl.h>
24 #include <dali-test-suite-utils.h>
25
26 using namespace Dali;
27
28 static void Startup();
29 static void Cleanup();
30
31 extern "C" {
32   void (*tet_startup)() = Startup;
33   void (*tet_cleanup)() = Cleanup;
34 }
35
36 enum {
37   POSITIVE_TC_IDX = 0x01,
38   NEGATIVE_TC_IDX,
39 };
40
41 #define MAX_NUMBER_OF_TESTS 10000
42 extern "C" {
43   struct tet_testlist tet_testlist[MAX_NUMBER_OF_TESTS];
44 }
45
46 // Add test functionality for all APIs in the class (Positive and Negative)
47 TEST_FUNCTION( UtcDaliCharacterCopyConstructor, POSITIVE_TC_IDX );
48 TEST_FUNCTION( UtcDaliCharacterComparissonOperators, POSITIVE_TC_IDX );
49 TEST_FUNCTION( UtcDaliCharacterAssignmentOperator, POSITIVE_TC_IDX );
50 TEST_FUNCTION( UtcDaliCharacterIsLeftToRight, POSITIVE_TC_IDX );
51 TEST_FUNCTION( UtcDaliGetCharacterDirection, POSITIVE_TC_IDX );
52 TEST_FUNCTION( UtcDaliCharacterIsWhiteSpace, POSITIVE_TC_IDX );
53 TEST_FUNCTION( UtcDaliCharacterIsNewLine, POSITIVE_TC_IDX );
54 TEST_FUNCTION( UtcDaliCharacterGetImplementation,POSITIVE_TC_IDX );
55
56 // Called only once before first test is run.
57 static void Startup()
58 {
59 }
60
61 // Called only once after last test is run
62 static void Cleanup()
63 {
64 }
65
66 static void UtcDaliCharacterCopyConstructor()
67 {
68   tet_infoline("UtcDaliCharacterCopyConstructor ");
69   TestApplication application;
70
71   Text text( std::string("12") );
72
73   Character c1 = text[0];
74   Character c2 = text[1];
75
76   Character c3( c1 );
77   Character c4 = c2;
78
79   DALI_TEST_CHECK( (c1==c3) && (c2==c4) );
80 }
81
82 static void UtcDaliCharacterComparissonOperators()
83 {
84   tet_infoline("UtcDaliCharacterComparissonOperators ");
85   TestApplication application;
86
87   Text text( std::string("12") );
88
89   Character c1 = text[0];
90   Character c2 = text[1];
91
92   Character c3( c1 );
93   Character c4 = c2;
94
95   DALI_TEST_CHECK( (c1==c3) && (c2==c4) && (c1!=c2) && (c1!=c4) );
96 }
97
98 static void UtcDaliCharacterAssignmentOperator()
99 {
100   tet_infoline("UtcDaliCharacterAssignmentOperator ");
101   TestApplication application;
102
103   Text text( std::string("12") );
104   Character c1 = text[0];
105   Character c2 = text[1];
106   c1 = c2; //assign
107   DALI_TEST_CHECK( c1 == c1);
108
109   // this should do nothing
110   c1 = c1;
111   DALI_TEST_CHECK(  c1 == c2);
112
113 }
114
115 static void UtcDaliCharacterIsLeftToRight()
116 {
117   tet_infoline("UtcDaliCharacterIsLeftToRight ");
118   TestApplication application;
119
120   Text text( std::string("12בא") );
121
122   Character c1 = text[0];
123   Character c2 = text[1];
124   Character c3 = text[2];
125   Character c4 = text[3];
126
127   DALI_TEST_CHECK( c1.GetCharacterDirection() != Character::RightToLeft &&
128                    c2.GetCharacterDirection() != Character::RightToLeft &&
129                    c3.GetCharacterDirection() == Character::RightToLeft &&
130                    c4.GetCharacterDirection() == Character::RightToLeft );
131 }
132
133 static void UtcDaliGetCharacterDirection()
134 {
135   tet_infoline("UtcDaliGetCharacterDirection ");
136   TestApplication application;
137
138   Text text( std::string("Aבא ") );
139
140   Character c1 = text[0];
141   Character c2 = text[1];
142   Character c3 = text[2];
143   Character c4 = text[3];
144
145   DALI_TEST_EQUALS( c1.GetCharacterDirection(), Character::LeftToRight, TEST_LOCATION );
146   DALI_TEST_EQUALS( c2.GetCharacterDirection(), Character::RightToLeft, TEST_LOCATION );
147   DALI_TEST_EQUALS( c3.GetCharacterDirection(), Character::RightToLeft, TEST_LOCATION );
148   DALI_TEST_EQUALS( c4.GetCharacterDirection(), Character::Neutral, TEST_LOCATION );
149 }
150
151 static void UtcDaliCharacterIsWhiteSpace()
152 {
153   tet_infoline("UtcDaliCharacterIsWhiteSpace ");
154   TestApplication application;
155
156   Text text( std::string("ab c\n\tdef") );
157
158   DALI_TEST_CHECK(!text[0].IsWhiteSpace()); // 'a'
159   DALI_TEST_CHECK(!text[1].IsWhiteSpace()); // 'b'
160   DALI_TEST_CHECK(text[2].IsWhiteSpace());  // ' '
161   DALI_TEST_CHECK(!text[3].IsWhiteSpace()); // 'c'
162   DALI_TEST_CHECK(text[4].IsWhiteSpace());  // '\n'
163   DALI_TEST_CHECK(text[5].IsWhiteSpace());  // '\t'
164   DALI_TEST_CHECK(!text[6].IsWhiteSpace()); // 'd'
165   DALI_TEST_CHECK(!text[7].IsWhiteSpace()); // 'e'
166   DALI_TEST_CHECK(!text[8].IsWhiteSpace()); // 'f'
167 }
168
169 static void UtcDaliCharacterIsNewLine()
170 {
171   tet_infoline("UtcDaliCharacterIsWhiteSpace ");
172   TestApplication application;
173
174   Text text( std::string("ab c\n\tdef") );
175
176   DALI_TEST_CHECK(!text[0].IsNewLine()); // 'a'
177   DALI_TEST_CHECK(!text[1].IsNewLine()); // 'b'
178   DALI_TEST_CHECK(!text[2].IsNewLine());  // ' '
179   DALI_TEST_CHECK(!text[3].IsNewLine()); // 'c'
180   DALI_TEST_CHECK(text[4].IsNewLine());  // '\n'
181   DALI_TEST_CHECK(!text[5].IsNewLine());  // '\t'
182   DALI_TEST_CHECK(!text[6].IsNewLine()); // 'd'
183   DALI_TEST_CHECK(!text[7].IsNewLine()); // 'e'
184   DALI_TEST_CHECK(!text[8].IsNewLine()); // 'f'
185 }
186
187 static void UtcDaliCharacterGetImplementation()
188 {
189   tet_infoline("UtcDaliCharacterIsWhiteSpace ");
190   TestApplication application;
191
192   Text text( std::string("a") );
193   Character c1 = text[0];
194   const Dali::Internal::Character& impl = c1.GetImplementation();
195   DALI_TEST_CHECK( impl.GetCharacter() == 'a' );
196 }