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 <boost/bind.hpp>
22 #include <dali/public-api/dali-core.h>
23 #include <dali-test-suite-utils.h>
27 void utc_dali_property_map_startup(void)
29 test_return_value = TET_UNDEF;
32 void utc_dali_property_map_cleanup(void)
34 test_return_value = TET_PASS;
37 int UtcDaliPropertyMapPopulate(void)
40 DALI_TEST_CHECK( map.Empty() );
43 map[ "world" ] = "world";
44 map[ "world" ] = 3; // same item as line above
45 DALI_TEST_CHECK( !map.Empty() ); // Should no longer be empty
46 DALI_TEST_CHECK( map.Count() == 2 ); // Should only have two items, not three!!
47 DALI_TEST_CHECK( map["hello"].Get<int>() == 1 );
48 DALI_TEST_CHECK( map["world"].Get<int>() == 3 );
51 DALI_TEST_CHECK( map.Empty() );
55 int UtcDaliPropertyMapCopyAndAssignment(void)
61 Property::Map assignedMap;
62 assignedMap[ "foo" ] = 3;
63 DALI_TEST_CHECK( assignedMap.Count() == 1 );
65 DALI_TEST_CHECK( assignedMap.Count() == 2 );
67 Property::Map copiedMap( map );
68 DALI_TEST_CHECK( copiedMap.Count() == 2 );
71 DALI_TEST_CHECK( map.Count() == 2 );
73 DALI_TEST_CHECK( map.Count() == 2 );
78 int UtcDaliPropertyMapConstOperator(void)
83 DALI_TEST_CHECK( map.Count() == 2 );
85 const Property::Map& constMap( map );
86 DALI_TEST_CHECK( constMap[ "world" ].Get<int>() == 2 );
87 DALI_TEST_CHECK( constMap.Count() == 2 ); // Ensure count hasn't gone up
92 constMap[ "invalid-key" ];
93 tet_result( TET_FAIL );
95 catch ( DaliException& e )
97 DALI_TEST_ASSERT( e, "! \"Invalid Key\"", TEST_LOCATION );
103 int UtcDaliPropertyMapGetValue(void)
109 Property::Value& value = map.GetValue( 0 );
110 DALI_TEST_CHECK( value.Get<int>() == 1 );
111 value = 10; // Allows the actual changing of the value as we have a ref
112 DALI_TEST_CHECK( map[ "hello" ].Get<int>() == 10 );
118 tet_result( TET_FAIL );
120 catch ( DaliException& e )
122 DALI_TEST_ASSERT( e, "position", TEST_LOCATION );
128 int UtcDaliPropertyMapGetKey(void)
134 DALI_TEST_CHECK( map.GetKey( 0 ) == "hello" );
135 DALI_TEST_CHECK( map.GetKey( 1 ) == "world" );
141 tet_result( TET_FAIL );
143 catch ( DaliException& e )
145 DALI_TEST_ASSERT( e, "position", TEST_LOCATION );
151 int UtcDaliPropertyMapGetPair(void)
157 DALI_TEST_CHECK( map.GetPair( 0 ).first == "hello" );
158 DALI_TEST_CHECK( map.GetPair( 0 ).second.Get< int >() == 1 );
159 DALI_TEST_CHECK( map.GetPair( 1 ).first == "world" );
160 DALI_TEST_CHECK( map.GetPair( 1 ).second.Get< int >() == 2 );
166 tet_result( TET_FAIL );
168 catch ( DaliException& e )
170 DALI_TEST_ASSERT( e, "position", TEST_LOCATION );
176 int UtcDaliPropertyMapFind(void)
182 Property::Value* value = NULL;
184 value = map.Find( "hello" );
185 DALI_TEST_CHECK( value );
186 DALI_TEST_CHECK( value->Get<int>() == 1 );
188 value = map.Find( "world" );
189 DALI_TEST_CHECK( value );
190 DALI_TEST_CHECK( value->Get<int>() == 2 );
192 value = map.Find( "invalid-key" );
193 DALI_TEST_CHECK( !value );
198 int UtcDaliPropertyMapMerge(void)
204 DALI_TEST_CHECK( map.Count() == 2 );
206 // Create another map with the same keys but different values
211 // Merge map2 into map1, count should still be 2, map values should be from map2
213 DALI_TEST_CHECK( map.Count() == 2 );
214 DALI_TEST_CHECK( map[ "hello" ].Get< int >() == 3 );
215 DALI_TEST_CHECK( map[ "world"].Get< int >() == 4 );
217 // Create another map with different keys
222 // Merge map3 into map1, count should increase, existing values should match previous and new values should match map3
224 DALI_TEST_CHECK( map.Count() == 4 );
225 DALI_TEST_CHECK( map[ "hello" ].Get< int >() == 3 );
226 DALI_TEST_CHECK( map[ "world"].Get< int >() == 4 );
227 DALI_TEST_CHECK( map[ "foo"].Get< int >() == 5 );
228 DALI_TEST_CHECK( map[ "bar"].Get< int >() == 6 );
230 // Create an empty map and attempt to merge, should be successful, nothing should change
232 DALI_TEST_CHECK( map4.Empty() );
234 DALI_TEST_CHECK( map4.Empty() );
235 DALI_TEST_CHECK( map.Count() == 4 );
236 DALI_TEST_CHECK( map[ "hello" ].Get< int >() == 3 );
237 DALI_TEST_CHECK( map[ "world"].Get< int >() == 4 );
238 DALI_TEST_CHECK( map[ "foo"].Get< int >() == 5 );
239 DALI_TEST_CHECK( map[ "bar"].Get< int >() == 6 );
241 // Merge map into map4, map4 should be the same as map now.
243 DALI_TEST_CHECK( map4.Count() == 4 );
244 DALI_TEST_CHECK( map4[ "hello" ].Get< int >() == 3 );
245 DALI_TEST_CHECK( map4[ "world"].Get< int >() == 4 );
246 DALI_TEST_CHECK( map4[ "foo"].Get< int >() == 5 );
247 DALI_TEST_CHECK( map4[ "bar"].Get< int >() == 6 );
249 // Attempt to merge into itself, should be successful, nothing should change
251 DALI_TEST_CHECK( map.Count() == 4 );
252 DALI_TEST_CHECK( map[ "hello" ].Get< int >() == 3 );
253 DALI_TEST_CHECK( map[ "world"].Get< int >() == 4 );
254 DALI_TEST_CHECK( map[ "foo"].Get< int >() == 5 );
255 DALI_TEST_CHECK( map[ "bar"].Get< int >() == 6 );