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>
30 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
32 using namespace WrtDB;
33 using namespace WrtDB::PropertyDAOReadOnly;
35 // Widgets used "tizenid201", "tizenid202", "tizenid203", 2003(saved by
36 // wrt_dao_tests_prepare_db.sh)
38 #define RUNNER_ASSERT_WHAT_EQUALS(in, test) \
39 { std::string tmp(in); \
40 RUNNER_ASSERT_MSG(tmp == test, "Equals: [" + tmp + "]"); }
42 #define RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(in, test) \
44 if (!in) { RUNNER_ASSERT_MSG(false, "NULL"); } \
45 else { RUNNER_ASSERT_WHAT_EQUALS(DPL::ToUTF8String(*in), test); } \
48 RUNNER_TEST_GROUP_INIT(DAO)
52 * Name: property_dao_get_lists
53 * Description: tests returning list of properties for given id
54 * Expected: data received should match those, which were inserted in prepare
57 RUNNER_TEST(property_dao_get_lists)
61 WrtDB::TizenAppId tappid;
62 DbWidgetHandle whandleid;
67 std::list<three_field> prefList;
68 std::list<three_field>::iterator it;
70 f3.tappid=L"tizenid201";f3.whandleid=2000;f3.nrow=2;
71 prefList.push_back(f3);
72 f3.tappid=L"tizenid202"; f3.whandleid=2001;f3.nrow=1;
73 prefList.push_back(f3);
74 f3.tappid=L"tizenid203"; f3.whandleid=2002;f3.nrow=2;
75 prefList.push_back(f3);
76 f3.tappid=L"tizenid204"; f3.whandleid=2003;f3.nrow=0;
77 prefList.push_back(f3);
79 for(it=prefList.begin();it!=prefList.end();++it)
81 PropertyDAOReadOnly::WidgetPreferenceList prefs_tid =
82 PropertyDAOReadOnly::GetPropertyList(it->tappid);
83 RUNNER_ASSERT(prefs_tid.size() == it->nrow);
87 WidgetPropertyKeyList orig_2000;
88 orig_2000.push_back(DPL::FromUTF8String("key1_for_2000"));
89 orig_2000.push_back(DPL::FromUTF8String("key2_for_2000"));
91 WidgetPropertyKeyList orig_2001;
92 orig_2001.push_back(DPL::FromUTF8String("key1_for_2001"));
94 WidgetPropertyKeyList orig_2002;
95 orig_2002.push_back(DPL::FromUTF8String("key1_for_2002"));
96 orig_2002.push_back(DPL::FromUTF8String("key2_for_2002"));
98 std::map<WrtDB::TizenAppId, WidgetPropertyKeyList *> prefsKeyMap;
99 prefsKeyMap.insert(std::pair<WrtDB::TizenAppId, WidgetPropertyKeyList *>(
100 L"tizenid201", &orig_2000));
101 prefsKeyMap.insert(std::pair<WrtDB::TizenAppId, WidgetPropertyKeyList *>(
102 L"tizenid202", &orig_2001));
103 prefsKeyMap.insert(std::pair<WrtDB::TizenAppId, WidgetPropertyKeyList *>(
104 L"tizenid203", &orig_2002));
106 FOREACH(it_out, prefsKeyMap) {
107 WidgetPropertyKeyList got = PropertyDAOReadOnly::GetPropertyKeyList(
109 RUNNER_ASSERT(got.size() == it_out->second->size());
111 // FOREACH(it_in, got)
113 // RUNNER_ASSERT(it_out->second.
121 * Name: property_dao_get_list_exceptions
122 * Description: tests returning exception for given tizen_appid if is
123 * not inserted into WidgetInfo table
124 * Expected: procedure passes when is exception. Widget absent in the WidgetInfo
127 RUNNER_TEST(property_dao_get_list_exceptions)
131 WrtDB::TizenAppId app_id_non_exists = L"non_exists";
135 PropertyDAOReadOnly::WidgetPreferenceList prefs =
136 PropertyDAOReadOnly::GetPropertyList(app_id_non_exists);
137 } Catch(WidgetDAOReadOnly::Exception::WidgetNotExist)
141 RUNNER_ASSERT_MSG(!(assert_flag),"Error, value doesn't make exception");
147 * Name: property_dao_set_update_remove
148 * Description: tests set new property for widget, updating property and
150 * Expected: given operation should works
152 RUNNER_TEST(property_dao_set_update_remove)
154 WidgetPropertyKeyList keys = PropertyDAOReadOnly::GetPropertyKeyList(
158 PropertyDAO::SetProperty(L"tizenid201",
159 DPL::FromUTF8String("new_key"),
160 DPL::FromUTF8String("new_value1"));
164 PropertyDAOReadOnly::GetPropertyKeyList(L"tizenid201").size(),
165 "new property not added");
166 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(
167 PropertyDAOReadOnly::GetPropertyValue(L"tizenid201",
168 DPL::FromUTF8String("new_key")),
172 PropertyDAO::SetProperty(L"tizenid201",
173 DPL::FromUTF8String("new_key"),
174 DPL::FromUTF8String("new_value2"));
177 PropertyDAOReadOnly::GetPropertyKeyList(L"tizenid201").size(),
178 "new property not added");
179 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(
180 PropertyDAOReadOnly::GetPropertyValue(L"tizenid201",
181 DPL::FromUTF8String("new_key")),
185 PropertyDAO::RemoveProperty(L"tizenid201", DPL::FromUTF8String("new_key"));
188 keys.size() == PropertyDAOReadOnly::GetPropertyKeyList(
189 L"tizenid201").size(),
190 "property not removed");
194 * Name: property_dao_get_value
195 * Description: tests if properties can be received from database
196 * Expected: value, which were inserted before test, should be present
198 RUNNER_TEST(property_dao_get_value)
200 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(
201 PropertyDAOReadOnly::GetPropertyValue(
202 L"tizenid201", DPL::FromUTF8String("key1_for_2000")),
203 "value_for_key1_2000");
205 RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(
206 PropertyDAOReadOnly::GetPropertyValue(
207 L"tizenid201", DPL::FromUTF8String("key2_for_2000")),
208 "value_for_key2_2000");
211 #undef RUNNER_ASSERT_WHAT_EQUALS