merge with master
[platform/framework/web/wrt-commons.git] / tests / dao / TestCases_GlobalDAO.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 /**
17  * @file   TestCases_GlobalDAO.cpp
18  * @author  Pawel Sikorski (p.sikorski@samsung.com)
19  * @version 1.0
20  * @brief   This file contains tests for global dao class.
21  */
22
23 #include <list>
24 #include <vector>
25 #include <set>
26 #include <dpl/test/test_runner.h>
27 #include <dpl/foreach.h>
28 #include <dpl/exception.h>
29 #include <dpl/string.h>
30 #include <dpl/wrt-dao-rw/global_dao.h>
31 #include <dpl/wrt-dao-ro/wrt_db_types.h>
32
33 using namespace WrtDB;
34
35 namespace {
36 const DPL::String widgetPackage5(L"widgetpackage5");
37 } // namespace
38
39 RUNNER_TEST_GROUP_INIT(DAO)
40
41 /*
42  * Name: global_dao_developer_mode
43  * Description: tests if developer mode is correctly set and get
44  * Expected: received developer shoudl match the one was set
45  */
46 RUNNER_TEST(global_dao_developer_mode)
47 {
48     bool prev_mode = GlobalDAO::GetDeveloperMode();
49     GlobalDAO::SetDeveloperMode(false);
50     RUNNER_ASSERT_MSG(!GlobalDAO::GetDeveloperMode(), "set false failed");
51
52     GlobalDAO::SetDeveloperMode(true);
53     RUNNER_ASSERT_MSG(GlobalDAO::GetDeveloperMode(), "set true failed");
54     GlobalDAO::SetDeveloperMode(prev_mode);
55 }
56
57 /*
58  * Name: home_network_data_usage
59  * Description: tests if HomeNetworkDataUsage is correctly set and get
60  * Expected: received developer shoudl match the one was set
61  */
62 RUNNER_TEST(home_network_data_usage)
63 {
64     GlobalDAO::NetworkAccessMode original =
65         GlobalDAO::GetHomeNetworkDataUsage();
66
67     GlobalDAO::SetHomeNetworkDataUsage(GlobalDAO::CONNECT_AUTOMATICALLY);
68     RUNNER_ASSERT_MSG(GlobalDAO::CONNECT_AUTOMATICALLY ==
69                       GlobalDAO::GetHomeNetworkDataUsage(), "Value not updated");
70
71     GlobalDAO::SetHomeNetworkDataUsage(GlobalDAO::ALWAYS_ASK);
72     RUNNER_ASSERT_MSG(GlobalDAO::ALWAYS_ASK ==
73                       GlobalDAO::GetHomeNetworkDataUsage(), "Value not updated");
74
75     GlobalDAO::SetHomeNetworkDataUsage(GlobalDAO::NEVER_CONNECT);
76     RUNNER_ASSERT_MSG(GlobalDAO::NEVER_CONNECT ==
77                       GlobalDAO::GetHomeNetworkDataUsage(), "Value not updated");
78
79     GlobalDAO::SetHomeNetworkDataUsage(original);
80     RUNNER_ASSERT_MSG(original == GlobalDAO::GetHomeNetworkDataUsage(),
81                       "Value not updated");
82 }
83
84 /*
85  * Name: roaming_data_usage
86  * Description: tests if RoamingDataUsage is correctly set and get
87  * Expected: received developer shoudl match the one was set
88  */
89 RUNNER_TEST(roaming_data_usage)
90 {
91     GlobalDAO::NetworkAccessMode original =
92         GlobalDAO::GetRoamingDataUsage();
93
94     GlobalDAO::SetRoamingDataUsage(GlobalDAO::CONNECT_AUTOMATICALLY);
95     RUNNER_ASSERT_MSG(GlobalDAO::CONNECT_AUTOMATICALLY ==
96                       GlobalDAO::GetRoamingDataUsage(), "Value not updated");
97
98     GlobalDAO::SetRoamingDataUsage(GlobalDAO::ALWAYS_ASK);
99     RUNNER_ASSERT_MSG(GlobalDAO::ALWAYS_ASK ==
100                       GlobalDAO::GetRoamingDataUsage(), "Value not updated");
101
102     GlobalDAO::SetRoamingDataUsage(GlobalDAO::NEVER_CONNECT);
103     RUNNER_ASSERT_MSG(GlobalDAO::NEVER_CONNECT ==
104                       GlobalDAO::GetRoamingDataUsage(), "Value not updated");
105
106     GlobalDAO::SetRoamingDataUsage(original);
107     RUNNER_ASSERT_MSG(original == GlobalDAO::GetRoamingDataUsage(),
108                       "Value not updated");
109 }