[dali_2.3.41] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit-internal / utc-Dali-PropertyHelper.cpp
1 /*
2  * Copyright (c) 2020 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/property-helper.h>
20
21 #if defined(ELDBUS_ENABLED)
22 #include <automated-tests/src/dali-toolkit-internal/dali-toolkit-test-utils/dbus-wrapper.h>
23 #endif
24
25 using namespace Dali;
26 using namespace Dali::Toolkit;
27
28 void dali_property_helper_startup(void)
29 {
30   test_return_value = TET_UNDEF;
31 #if defined(ELDBUS_ENABLED)
32   DBusWrapper::Install(std::unique_ptr<DBusWrapper>(new TestDBusWrapper));
33 #endif
34 }
35
36 void dali_property_helper_cleanup(void)
37 {
38   test_return_value = TET_PASS;
39 #if defined(ELDBUS_ENABLED)
40   DBusWrapper::Install({}); // Clean up TestDBusWrapper
41 #endif
42 }
43
44 int UtcDaliPropertyHelperGetStringFromPropertyWithString(void)
45 {
46   tet_infoline( "Test to check if a simple string is parsed correctly" );
47
48   const std::string inputString = "Hello World";
49   Property::Value value( inputString );
50
51   std::string output;
52   DALI_TEST_CHECK( Toolkit::Internal::GetStringFromProperty( value, output ) );
53   DALI_TEST_EQUALS( output, inputString, TEST_LOCATION );
54
55   END_TEST;
56 }
57
58 int UtcDaliPropertyHelperGetStringFromPropertyWithEmptyValue(void)
59 {
60   tet_infoline( "Test to ensure if an empty value returns false" );
61
62   std::string output;
63   DALI_TEST_CHECK( ! Toolkit::Internal::GetStringFromProperty( Property::Value(), output ) );
64
65   END_TEST;
66 }
67
68 int UtcDaliPropertyHelperGetStringFromPropertyWithStringArray(void)
69 {
70   tet_infoline( "Test to check if a string array is parsed correctly and adds new line characters too" );
71
72   Property::Value value( Property::Array().Add( "Hello World" )
73                                           .Add( "The Quick Brown Fox" )
74                                           .Add( "Jumps over the lazy dog" ) );
75
76   std::string output;
77   DALI_TEST_CHECK( Toolkit::Internal::GetStringFromProperty( value, output ) );
78   DALI_TEST_CHECK( output.find( "Hello World\n" ) != std::string::npos );
79   DALI_TEST_CHECK( output.find( "The Quick Brown Fox\n" ) != std::string::npos );
80   DALI_TEST_CHECK( output.find( "Jumps over the lazy dog\n" ) != std::string::npos );
81
82   END_TEST;
83 }
84
85 int UtcDaliPropertyHelperGetStringFromPropertyWithEmptyArray(void)
86 {
87   tet_infoline( "Test to check if an empty array returns false" );
88
89   Property::Array array;
90
91   std::string output;
92   DALI_TEST_CHECK( ! Toolkit::Internal::GetStringFromProperty( Property::Value( array ), output ) );
93
94   END_TEST;
95 }
96
97 int UtcDaliPropertyHelperGetStringFromPropertyWithMultipleTypesInArray(void)
98 {
99   tet_infoline( "Test to ensure an array with multiple types returns false" );
100
101   Property::Value value( Property::Array().Add( "Hello World" )
102                                           .Add( "The Quick Brown Fox" )
103                                           .Add( 1 )
104                                           .Add( "Jumps" )
105                                           .Add( 25 )
106                                           .Add( "Over" ) );
107
108   std::string output;
109   DALI_TEST_CHECK( ! Toolkit::Internal::GetStringFromProperty( value, output ) );
110   DALI_TEST_CHECK( output.empty() );
111
112   END_TEST;
113 }