b869fd1fa2ac0abf24e7ef5dd918b81fa9b5786b
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Radian.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
10 void utc_dali_radian_startup(void)
11 {
12   test_return_value = TET_UNDEF;
13 }
14
15 void utc_dali_radian_cleanup(void)
16 {
17   test_return_value = TET_PASS;
18 }
19
20
21 // Positive test case for constructors
22 int UtcDaliRadianConstructors01(void)
23 {
24   TestApplication application;
25
26   // Default constructor, does not initialise the value
27   Radian radian0( 0.0f );
28
29   // Test float assignment operator
30   radian0 = Math::PI;
31   DALI_TEST_EQUALS( float(radian0), Math::PI, 0.001f, TEST_LOCATION );
32
33   // Constructor from float value
34   Radian radian1( Math::PI );
35   DALI_TEST_EQUALS( float(radian1), Math::PI, 0.001f, TEST_LOCATION );
36
37   // Constructor from a Degree
38   Radian radian2( Degree( 180.0f ) );
39   DALI_TEST_EQUALS( float(radian2), Math::PI, 0.001f, TEST_LOCATION );
40
41   // Assignment from Degree
42   Radian radian3( 0.0f );
43   radian3 = Degree( 180.0f );
44   DALI_TEST_EQUALS( float(radian3), Math::PI, 0.001f, TEST_LOCATION );
45   END_TEST;
46 }
47
48 // Positive test case for comparison
49 int UtcDaliRadianComparison01(void)
50 {
51   TestApplication application;
52
53   // Comparison between radians
54   Radian radian0( Math::PI_2 );
55   Radian radian1( Math::PI_2 );
56   Radian radian2( Math::PI );
57
58   DALI_TEST_CHECK( radian0 == radian1 );
59   DALI_TEST_CHECK( radian0 != radian2 );
60
61   // Comparison between radian to degree
62   Radian radian3( Math::PI );
63   Radian radian4( Math::PI_2 );
64   Degree degree0( 180.0f );
65
66   DALI_TEST_CHECK( radian3 == Radian(degree0) );
67   DALI_TEST_CHECK( radian4 != Radian(degree0) );
68
69   // Comparison with float
70   Radian radian5( Math::PI_2 );
71
72   DALI_TEST_CHECK( radian5 == Math::PI_2 );
73   DALI_TEST_CHECK( radian5 != Math::PI );
74
75   END_TEST;
76 }
77
78
79 // test case for cast operators
80 int UtcDaliRadianCastOperators01(void)
81 {
82   TestApplication application;  // Exceptions require TestApplication
83
84   Radian radian0( Math::PI );
85
86   const float& value0( radian0.radian );
87   DALI_TEST_EQUALS( value0, Math::PI, 0.001f, TEST_LOCATION );
88
89   radian0 = Math::PI_2;
90   DALI_TEST_EQUALS( value0, Math::PI_2, 0.001f, TEST_LOCATION );
91
92   float value1( radian0 );
93   DALI_TEST_EQUALS( value1, Math::PI_2, 0.001f, TEST_LOCATION );
94
95   radian0 = Math::PI;
96   DALI_TEST_EQUALS( float(radian0), Math::PI, 0.001f, TEST_LOCATION );
97   END_TEST;
98 }
99
100
101 int UtcDaliRadianCastOperatorEquals(void)
102 {
103   TestApplication application;
104
105   Radian a(Math::PI_2);
106   Radian b(Math::PI_2);
107   Radian c(Math::PI);
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   DALI_TEST_EQUALS( Degree(c) == c, true, TEST_LOCATION );
113   END_TEST;
114 }
115
116 int UtcDaliRadianCastOperatorNotEquals(void)
117 {
118   TestApplication application;
119
120   Radian a(Math::PI_2);
121   Radian b(Math::PI_2);
122   Radian c(Math::PI);
123
124   DALI_TEST_EQUALS( a != a, false, TEST_LOCATION );
125   DALI_TEST_EQUALS( a != b, false, TEST_LOCATION );
126   DALI_TEST_EQUALS( a != c, true, TEST_LOCATION );
127   DALI_TEST_EQUALS( Degree(a) != c, true, TEST_LOCATION );
128   END_TEST;
129 }
130
131 int UtcDaliRadianCastOperatorLessThan(void)
132 {
133   TestApplication application;
134
135   Radian a(Math::PI_4);
136   Radian b(Math::PI_2);
137   Radian c(Math::PI);
138   Radian d(2.0f*Math::PI);
139   Radian e(-Math::PI);
140
141   DALI_TEST_EQUALS(a < a, false, TEST_LOCATION);
142   DALI_TEST_EQUALS(a < b, true, TEST_LOCATION);
143   DALI_TEST_EQUALS(a < c, true, TEST_LOCATION);
144   DALI_TEST_EQUALS(a < d, true, TEST_LOCATION);
145   DALI_TEST_EQUALS(a < e, false, TEST_LOCATION);
146
147   DALI_TEST_EQUALS(b < a, false, TEST_LOCATION);
148   DALI_TEST_EQUALS(b < b, false, TEST_LOCATION);
149   DALI_TEST_EQUALS(c < b, false, TEST_LOCATION);
150   DALI_TEST_EQUALS(d < b, false, TEST_LOCATION);
151   DALI_TEST_EQUALS(e < b, true, TEST_LOCATION);
152
153   DALI_TEST_EQUALS( Radian(Math::PI_2) < Degree(180.0f), true,  TEST_LOCATION);
154   DALI_TEST_EQUALS( Radian(Math::PI_2) < Degree(90.0f),  false, TEST_LOCATION);
155   DALI_TEST_EQUALS( Radian(Math::PI_2) > Degree(45.0f),  true,  TEST_LOCATION);
156
157   DALI_TEST_EQUALS( Degree(180.0f) > Radian(Math::PI_2), true,  TEST_LOCATION);
158   DALI_TEST_EQUALS( Degree(90.0f)  > Radian(Math::PI_2), false, TEST_LOCATION);
159   DALI_TEST_EQUALS( Degree(45.0f)  < Radian(Math::PI_2), true,  TEST_LOCATION);
160
161   END_TEST;
162 }