[dali_1.0.7] Merge branch 'tizen'
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Degree.cpp
1 #include <iostream>
2
3 #include <stdlib.h>
4 #include <dali/public-api/dali-core.h>
5 #include <dali-test-suite-utils.h>
6
7 using namespace Dali;
8
9 void utc_dali_degree_startup(void)
10 {
11   test_return_value = TET_UNDEF;
12 }
13
14 void utc_dali_degree_cleanup(void)
15 {
16   test_return_value = TET_PASS;
17 }
18
19
20 // Positive test case for constructors
21 int UtcDaliDegreeConstructors01(void)
22 {
23   TestApplication application;
24
25   // Default constructor, does not initialise the value
26   Degree degree0( 0.0f );
27
28   // Test float assignment operator
29   degree0 = 180.0f;
30   DALI_TEST_EQUALS( float(degree0), 180.0f, 0.001f, TEST_LOCATION );
31
32   // Constructor from float value
33   Degree degree1( 180.0f );
34   DALI_TEST_EQUALS( float(degree1), 180.0f, 0.001f, TEST_LOCATION );
35
36   // Constructor from a Radian
37   Degree degree2( Radian( Math::PI ) );
38   DALI_TEST_EQUALS( float(degree2), 180.0f, 0.001f, TEST_LOCATION );
39
40   // Assignment from Radian
41   Degree degree3( 0.0f );
42   degree3 = Radian( Math::PI );
43   DALI_TEST_EQUALS( float(degree3), 180.0f, 0.001f, TEST_LOCATION );
44   END_TEST;
45 }
46
47 // Positive test case for comparison
48 int UtcDaliDegreeComparison01(void)
49 {
50   TestApplication application;
51
52   // Comparison between radians
53   Degree degree0( 90.0f );
54   Degree degree1( 90.0f );
55   Degree degree2( 180.0f );
56
57   DALI_TEST_CHECK( degree0 == degree1 );
58   DALI_TEST_CHECK( degree0 != degree2 );
59
60   // Comparison between radian to degree
61   Degree degree3( 180.0f );
62   Degree degree4( 90.0f );
63   Radian radian0( Math::PI );
64
65   DALI_TEST_CHECK( degree3 == radian0 );
66   DALI_TEST_CHECK( degree4 != radian0 );
67
68   // Comparison with float
69   Degree degree5( 90.0f );
70
71   DALI_TEST_CHECK( degree5 == 90.0f );
72   DALI_TEST_CHECK( degree5 != 180.0f );
73
74   END_TEST;
75 }
76
77
78 // test case for cast operators
79 int UtcDaliDegreeCastOperators01(void)
80 {
81   TestApplication application;  // Exceptions require TestApplication
82
83   Degree degree0( 180.0f );
84
85   const float& value0( degree0 );
86   DALI_TEST_EQUALS( value0, 180.0f, 0.001f, TEST_LOCATION );
87
88   degree0 = 90.0f;
89   DALI_TEST_EQUALS( value0, 90.0f, 0.001f, TEST_LOCATION );
90
91   float& value1( degree0 );
92   DALI_TEST_EQUALS( value1, 90.0f, 0.001f, TEST_LOCATION );
93
94   value1 = 180.0f;
95   DALI_TEST_EQUALS( float(degree0), 180.0f, 0.001f, TEST_LOCATION );
96   END_TEST;
97 }
98
99
100
101 int UtcDaliDegreeCastOperatorEquals(void)
102 {
103   TestApplication application;
104
105   Degree a(90.0f);
106   Degree b(90.0f);
107   Degree c(180.0f);
108
109   DALI_TEST_EQUALS(a == a, true, TEST_LOCATION);
110   DALI_TEST_EQUALS(a == b, true, TEST_LOCATION);
111   DALI_TEST_EQUALS(a == c, false, TEST_LOCATION);
112   END_TEST;
113 }
114
115 int UtcDaliDegreeCastOperatorNotEquals(void)
116 {
117   TestApplication application;
118
119   Degree a(90.0f);
120   Degree b(90.0f);
121   Degree c(180.0f);
122
123   DALI_TEST_EQUALS(a != a, false, TEST_LOCATION);
124   DALI_TEST_EQUALS(a != b, false, TEST_LOCATION);
125   DALI_TEST_EQUALS(a != c, true, TEST_LOCATION);
126   END_TEST;
127 }
128
129 int UtcDaliDegreeCastOperatorLessThan(void)
130 {
131   TestApplication application;
132
133   Degree a(45.0f);
134   Degree b(90.0f);
135   Degree c(180.0f);
136   Degree d(360.0f);
137   Degree e(-180.0f);
138
139   DALI_TEST_EQUALS(a < a, false, TEST_LOCATION);
140   DALI_TEST_EQUALS(a < b, true, TEST_LOCATION);
141   DALI_TEST_EQUALS(a < c, true, TEST_LOCATION);
142   DALI_TEST_EQUALS(a < d, true, TEST_LOCATION);
143   DALI_TEST_EQUALS(a < e, false, TEST_LOCATION);
144
145   DALI_TEST_EQUALS(b < a, false, TEST_LOCATION);
146   DALI_TEST_EQUALS(b < b, false, TEST_LOCATION);
147   DALI_TEST_EQUALS(c < b, false, TEST_LOCATION);
148   DALI_TEST_EQUALS(d < b, false, TEST_LOCATION);
149   DALI_TEST_EQUALS(e < b, true, TEST_LOCATION);
150   END_TEST;
151 }