Provided color-conversion helpers
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit-internal / utc-Dali-ColorConversion.cpp
1 /*
2  * Copyright (c) 2017 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 #include <dali-toolkit-test-suite-utils.h>
19 #include <dali-toolkit/internal/helpers/color-conversion.h>
20
21 using namespace Dali;
22 using namespace Dali::Toolkit;
23
24 void dali_color_conversion_startup(void)
25 {
26   test_return_value = TET_UNDEF;
27 }
28
29 void dali_color_conversion_cleanup(void)
30 {
31   test_return_value = TET_PASS;
32 }
33
34 int UtcDaliPropertyHelperConvertHtmlStringToColor(void)
35 {
36   tet_infoline( "Test to check whether An HTML style hex string can be converted" );
37
38   const std::string stringColor( "#FF0000" );
39
40   Vector4 result;
41   DALI_TEST_CHECK( Toolkit::Internal::ConvertStringToColor( stringColor, result ) );
42
43   DALI_TEST_EQUALS( result, Color::RED, TEST_LOCATION );
44
45   END_TEST;
46 }
47
48 int UtcDaliPropertyHelperConvertStringPropertyToColor(void)
49 {
50   tet_infoline( "Test to check whether A Property value containing a string can be converted" );
51
52   const std::string stringColor( "#00FF00" );
53   Property::Value colorProperty( stringColor );
54
55   Vector4 result;
56   DALI_TEST_CHECK( Toolkit::Internal::ConvertPropertyToColor( colorProperty, result ) );
57
58   DALI_TEST_EQUALS( result, Color::GREEN, TEST_LOCATION );
59
60   END_TEST;
61 }
62
63 int UtcDaliPropertyHelperConvertVector4PropertyToColor(void)
64 {
65   tet_infoline( "Test to check whether A Property value containing a string can be converted" );
66
67   const Vector4 color( 0.0, 0.0, 1.0, 1.0 );
68   Property::Value colorProperty( color );
69
70   Vector4 result;
71   DALI_TEST_CHECK( Toolkit::Internal::ConvertPropertyToColor( colorProperty, result ) );
72
73   DALI_TEST_EQUALS( result, Color::BLUE, TEST_LOCATION );
74
75   END_TEST;
76 }