2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <dali/public-api/dali-core.h>
22 #include <dali-test-suite-utils.h>
26 void utc_dali_property_map_startup(void)
28 test_return_value = TET_UNDEF;
31 void utc_dali_property_map_cleanup(void)
33 test_return_value = TET_PASS;
36 int UtcDaliPropertyMapPopulate(void)
39 DALI_TEST_CHECK( map.Empty() );
42 map[ "world" ] = "world";
43 map[ "world" ] = 3; // same item as line above
44 DALI_TEST_CHECK( !map.Empty() ); // Should no longer be empty
45 DALI_TEST_CHECK( map.Count() == 2 ); // Should only have two items, not three!!
46 DALI_TEST_CHECK( map["hello"].Get<int>() == 1 );
47 DALI_TEST_CHECK( map["world"].Get<int>() == 3 );
50 DALI_TEST_CHECK( map.Empty() );
54 int UtcDaliPropertyMapCopyAndAssignment(void)
60 Property::Map assignedMap;
61 assignedMap[ "foo" ] = 3;
62 DALI_TEST_CHECK( assignedMap.Count() == 1 );
64 DALI_TEST_CHECK( assignedMap.Count() == 2 );
66 Property::Map copiedMap( map );
67 DALI_TEST_CHECK( copiedMap.Count() == 2 );
70 DALI_TEST_CHECK( map.Count() == 2 );
72 DALI_TEST_CHECK( map.Count() == 2 );
77 int UtcDaliPropertyMapConstOperator(void)
82 DALI_TEST_CHECK( map.Count() == 2 );
84 const Property::Map& constMap( map );
85 DALI_TEST_CHECK( constMap[ "world" ].Get<int>() == 2 );
86 DALI_TEST_CHECK( constMap.Count() == 2 ); // Ensure count hasn't gone up
91 constMap[ "invalid-key" ];
92 tet_result( TET_FAIL );
94 catch ( DaliException& e )
96 DALI_TEST_ASSERT( e, "! \"Invalid Key\"", TEST_LOCATION );
102 int UtcDaliPropertyMapGetValue(void)
108 Property::Value& value = map.GetValue( 0 );
109 DALI_TEST_CHECK( value.Get<int>() == 1 );
110 value = 10; // Allows the actual changing of the value as we have a ref
111 DALI_TEST_CHECK( map[ "hello" ].Get<int>() == 10 );
117 tet_result( TET_FAIL );
119 catch ( DaliException& e )
121 DALI_TEST_ASSERT( e, "position", TEST_LOCATION );
127 int UtcDaliPropertyMapGetKey(void)
133 DALI_TEST_CHECK( map.GetKey( 0 ) == "hello" );
134 DALI_TEST_CHECK( map.GetKey( 1 ) == "world" );
140 tet_result( TET_FAIL );
142 catch ( DaliException& e )
144 DALI_TEST_ASSERT( e, "position", TEST_LOCATION );
150 int UtcDaliPropertyMapGetPair(void)
156 DALI_TEST_CHECK( map.GetPair( 0 ).first == "hello" );
157 DALI_TEST_CHECK( map.GetPair( 0 ).second.Get< int >() == 1 );
158 DALI_TEST_CHECK( map.GetPair( 1 ).first == "world" );
159 DALI_TEST_CHECK( map.GetPair( 1 ).second.Get< int >() == 2 );
165 tet_result( TET_FAIL );
167 catch ( DaliException& e )
169 DALI_TEST_ASSERT( e, "position", TEST_LOCATION );
175 int UtcDaliPropertyMapFind(void)
181 Property::Value* value = NULL;
183 value = map.Find( "hello" );
184 DALI_TEST_CHECK( value );
185 DALI_TEST_CHECK( value->Get<int>() == 1 );
187 value = map.Find( "world" );
188 DALI_TEST_CHECK( value );
189 DALI_TEST_CHECK( value->Get<int>() == 2 );
191 value = map.Find( "invalid-key" );
192 DALI_TEST_CHECK( !value );
197 int UtcDaliPropertyMapMerge(void)
203 DALI_TEST_CHECK( map.Count() == 2 );
205 // Create another map with the same keys but different values
210 // Merge map2 into map1, count should still be 2, map values should be from map2
212 DALI_TEST_CHECK( map.Count() == 2 );
213 DALI_TEST_CHECK( map[ "hello" ].Get< int >() == 3 );
214 DALI_TEST_CHECK( map[ "world"].Get< int >() == 4 );
216 // Create another map with different keys
221 // Merge map3 into map1, count should increase, existing values should match previous and new values should match map3
223 DALI_TEST_CHECK( map.Count() == 4 );
224 DALI_TEST_CHECK( map[ "hello" ].Get< int >() == 3 );
225 DALI_TEST_CHECK( map[ "world"].Get< int >() == 4 );
226 DALI_TEST_CHECK( map[ "foo"].Get< int >() == 5 );
227 DALI_TEST_CHECK( map[ "bar"].Get< int >() == 6 );
229 // Create an empty map and attempt to merge, should be successful, nothing should change
231 DALI_TEST_CHECK( map4.Empty() );
233 DALI_TEST_CHECK( map4.Empty() );
234 DALI_TEST_CHECK( map.Count() == 4 );
235 DALI_TEST_CHECK( map[ "hello" ].Get< int >() == 3 );
236 DALI_TEST_CHECK( map[ "world"].Get< int >() == 4 );
237 DALI_TEST_CHECK( map[ "foo"].Get< int >() == 5 );
238 DALI_TEST_CHECK( map[ "bar"].Get< int >() == 6 );
240 // Merge map into map4, map4 should be the same as map now.
242 DALI_TEST_CHECK( map4.Count() == 4 );
243 DALI_TEST_CHECK( map4[ "hello" ].Get< int >() == 3 );
244 DALI_TEST_CHECK( map4[ "world"].Get< int >() == 4 );
245 DALI_TEST_CHECK( map4[ "foo"].Get< int >() == 5 );
246 DALI_TEST_CHECK( map4[ "bar"].Get< int >() == 6 );
248 // Attempt to merge into itself, should be successful, nothing should change
250 DALI_TEST_CHECK( map.Count() == 4 );
251 DALI_TEST_CHECK( map[ "hello" ].Get< int >() == 3 );
252 DALI_TEST_CHECK( map[ "world"].Get< int >() == 4 );
253 DALI_TEST_CHECK( map[ "foo"].Get< int >() == 5 );
254 DALI_TEST_CHECK( map[ "bar"].Get< int >() == 6 );