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
35 // wrt_dao_tests_prepare_db.sh)
37 #define RUNNER_ASSERT_WHAT_EQUALS(in, test) \
38 { std::string tmp(in); \
39 RUNNER_ASSERT_MSG(tmp == test, "Equals: [" + tmp + "]"); }
41 #define RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(in, test) \
43 if (in.IsNull()) { RUNNER_ASSERT_MSG(false, "NULL"); } \
44 else { RUNNER_ASSERT_WHAT_EQUALS(DPL::ToUTF8String(*in), test); } \
47 RUNNER_TEST_GROUP_INIT(DAO)
50 * Name: property_dao_get_lists
51 * Description: tests returning list of properties for given id
52 * Expected: data received should match those, which were inserted in prepare
55 RUNNER_TEST(property_dao_get_lists)
58 std::map<WrtDB::TizenAppId, size_t> prefsMap;
59 prefsMap.insert(std::pair<WrtDB::TizenAppId, size_t>(L"tizenid201", 2));
60 prefsMap.insert(std::pair<WrtDB::TizenAppId, size_t>(L"tizenid202", 1));
61 prefsMap.insert(std::pair<WrtDB::TizenAppId, size_t>(L"tizenid203", 2));
63 prefsMap.insert(std::pair<WrtDB::TizenAppId, size_t>(L"non_exists", 0));
65 FOREACH(it, prefsMap) {
66 PropertyDAOReadOnly::WidgetPreferenceList prefs =
67 PropertyDAOReadOnly::GetPropertyList(it->first);
68 RUNNER_ASSERT(prefs.size() == it->second);
73 WidgetPropertyKeyList orig_2000;
74 orig_2000.push_back(DPL::FromUTF8String("key1_for_2000"));
75 orig_2000.push_back(DPL::FromUTF8String("key2_for_2000"));
77 WidgetPropertyKeyList orig_2001;
78 orig_2001.push_back(DPL::FromUTF8String("key1_for_2001"));
80 WidgetPropertyKeyList orig_2002;
81 orig_2002.push_back(DPL::FromUTF8String("key1_for_2002"));
82 orig_2002.push_back(DPL::FromUTF8String("key2_for_2002"));
84 std::map<WrtDB::TizenAppId, WidgetPropertyKeyList *> prefsKeyMap;
85 prefsKeyMap.insert(std::pair<WrtDB::TizenAppId, WidgetPropertyKeyList *>(
86 L"tizenid201", &orig_2000));
87 prefsKeyMap.insert(std::pair<WrtDB::TizenAppId, WidgetPropertyKeyList *>(
88 L"tizenid202", &orig_2001));
89 prefsKeyMap.insert(std::pair<WrtDB::TizenAppId, WidgetPropertyKeyList *>(
90 L"tizenid203", &orig_2002));
92 FOREACH(it_out, prefsKeyMap) {
93 WidgetPropertyKeyList got = PropertyDAOReadOnly::GetPropertyKeyList(
95 RUNNER_ASSERT(got.size() == it_out->second->size());
97 // FOREACH(it_in, got)
99 // RUNNER_ASSERT(it_out->second.
106 * Name: property_dao_set_update_remove
107 * Description: tests set new property for widget, updating property and
109 * Expected: given operation should works
111 RUNNER_TEST(property_dao_set_update_remove)
113 WidgetPropertyKeyList keys = PropertyDAOReadOnly::GetPropertyKeyList(
117 PropertyDAO::SetProperty(L"tizenid201",
118 DPL::FromUTF8String("new_key"),
119 DPL::FromUTF8String("new_value1"));
123 PropertyDAOReadOnly::GetPropertyKeyList(L"tizenid201").size(),
124 "new property not added");
125 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(
126 PropertyDAOReadOnly::GetPropertyValue(L"tizenid201",
127 DPL::FromUTF8String("new_key")),
131 PropertyDAO::SetProperty(L"tizenid201",
132 DPL::FromUTF8String("new_key"),
133 DPL::FromUTF8String("new_value2"));
136 PropertyDAOReadOnly::GetPropertyKeyList(L"tizenid201").size(),
137 "new property not added");
138 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(
139 PropertyDAOReadOnly::GetPropertyValue(L"tizenid201",
140 DPL::FromUTF8String("new_key")),
144 PropertyDAO::RemoveProperty(L"tizenid201", DPL::FromUTF8String("new_key"));
147 keys.size() == PropertyDAOReadOnly::GetPropertyKeyList(
148 L"tizenid201").size(),
149 "property not removed");
153 * Name: property_dao_get_value
154 * Description: tests if properties can be received from database
155 * Expected: value, which were inserted before test, should be present
157 RUNNER_TEST(property_dao_get_value)
159 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(
160 PropertyDAOReadOnly::GetPropertyValue(
161 L"tizenid201", DPL::FromUTF8String("key1_for_2000")),
162 "value_for_key1_2000");
164 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(
165 PropertyDAOReadOnly::GetPropertyValue(
166 L"tizenid201", DPL::FromUTF8String("key2_for_2000")),
167 "value_for_key2_2000");
170 #undef RUNNER_ASSERT_WHAT_EQUALS