2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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.
17 * @file TestCases_PropertyDAO.cpp
18 * @author Pawel Sikorski (p.sikorski@samsung.com)
20 * @brief This file contains tests for property dao class.
25 #include <dpl/test/test_runner.h>
26 #include <dpl/foreach.h>
27 #include <dpl/exception.h>
28 #include <dpl/wrt-dao-rw/property_dao.h>
29 #include <dpl/wrt-dao-ro/wrt_db_types.h>
31 using namespace WrtDB;
32 using namespace WrtDB::PropertyDAOReadOnly;
34 // Widgets used "tizenid201", "tizenid202", "tizenid203", 2003(saved by wrt_dao_tests_prepare_db.sh)
36 #define RUNNER_ASSERT_WHAT_EQUALS(in, test) \
37 {std::string tmp(in); \
38 RUNNER_ASSERT_MSG(tmp == test, "Equals: [" + tmp + "]");}
40 #define RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(in, test) \
42 if(in.IsNull()) RUNNER_ASSERT_MSG(false, "NULL"); \
43 else RUNNER_ASSERT_WHAT_EQUALS(DPL::ToUTF8String(*in),test);\
46 RUNNER_TEST_GROUP_INIT(DAO)
49 Name: property_dao_get_lists
50 Description: tests returning list of properties for given id
51 Expected: data received should match those, which were inserted in prepare script
53 RUNNER_TEST(property_dao_get_lists)
56 std::map<WrtDB::TizenAppId, size_t> prefsMap;
57 prefsMap.insert(std::pair<WrtDB::TizenAppId, size_t>(L"tizenid201", 2));
58 prefsMap.insert(std::pair<WrtDB::TizenAppId, size_t>(L"tizenid202", 1));
59 prefsMap.insert(std::pair<WrtDB::TizenAppId, size_t>(L"tizenid203", 2));
60 prefsMap.insert(std::pair<WrtDB::TizenAppId, size_t>(L"non_exists", 0)); //no widget
62 FOREACH(it, prefsMap) {
63 PropertyDAOReadOnly::WidgetPreferenceList prefs =
64 PropertyDAOReadOnly::GetPropertyList(it->first);
65 RUNNER_ASSERT(prefs.size() == it->second);
70 WidgetPropertyKeyList orig_2000;
71 orig_2000.push_back(DPL::FromUTF8String("key1_for_2000"));
72 orig_2000.push_back(DPL::FromUTF8String("key2_for_2000"));
74 WidgetPropertyKeyList orig_2001;
75 orig_2001.push_back(DPL::FromUTF8String("key1_for_2001"));
77 WidgetPropertyKeyList orig_2002;
78 orig_2002.push_back(DPL::FromUTF8String("key1_for_2002"));
79 orig_2002.push_back(DPL::FromUTF8String("key2_for_2002"));
81 std::map<WrtDB::TizenAppId, WidgetPropertyKeyList *> prefsKeyMap;
82 prefsKeyMap.insert(std::pair<WrtDB::TizenAppId, WidgetPropertyKeyList *>(
83 L"tizenid201", &orig_2000));
84 prefsKeyMap.insert(std::pair<WrtDB::TizenAppId, WidgetPropertyKeyList *>(
85 L"tizenid202", &orig_2001));
86 prefsKeyMap.insert(std::pair<WrtDB::TizenAppId, WidgetPropertyKeyList *>(
87 L"tizenid203", &orig_2002));
89 FOREACH(it_out, prefsKeyMap) {
90 WidgetPropertyKeyList got = PropertyDAOReadOnly::GetPropertyKeyList(
92 RUNNER_ASSERT(got.size() == it_out->second->size());
94 // FOREACH(it_in, got)
96 // RUNNER_ASSERT(it_out->second.
103 Name: property_dao_set_update_remove
104 Description: tests set new property for widget, updating property and removing it
105 Expected: given operation should works
107 RUNNER_TEST(property_dao_set_update_remove)
109 WidgetPropertyKeyList keys = PropertyDAOReadOnly::GetPropertyKeyList(L"tizenid201");
112 PropertyDAO::SetProperty(L"tizenid201",
113 DPL::FromUTF8String("new_key"),
114 DPL::FromUTF8String("new_value1"));
117 keys.size() + 1 == PropertyDAOReadOnly::GetPropertyKeyList(L"tizenid201").size(),
118 "new property not added");
119 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(
120 PropertyDAOReadOnly::GetPropertyValue(L"tizenid201",
121 DPL::FromUTF8String("new_key")),
125 PropertyDAO::SetProperty(L"tizenid201",
126 DPL::FromUTF8String("new_key"),
127 DPL::FromUTF8String("new_value2"));
129 keys.size() + 1 == PropertyDAOReadOnly::GetPropertyKeyList(L"tizenid201").size(),
130 "new property not added");
131 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(
132 PropertyDAOReadOnly::GetPropertyValue(L"tizenid201",
133 DPL::FromUTF8String("new_key")),
137 PropertyDAO::RemoveProperty(L"tizenid201", DPL::FromUTF8String("new_key"));
140 keys.size() == PropertyDAOReadOnly::GetPropertyKeyList(L"tizenid201").size(),
141 "property not removed");
146 Name: property_dao_get_value
147 Description: tests if properties can be received from database
148 Expected: value, which were inserted before test, should be present
150 RUNNER_TEST(property_dao_get_value)
152 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(
153 PropertyDAOReadOnly::GetPropertyValue(
154 L"tizenid201", DPL::FromUTF8String("key1_for_2000")),
155 "value_for_key1_2000");
157 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(
158 PropertyDAOReadOnly::GetPropertyValue(
159 L"tizenid201", DPL::FromUTF8String("key2_for_2000")),
160 "value_for_key2_2000");
163 #undef RUNNER_ASSERT_WHAT_EQUALS