Remove ewk_context_favicon_database_directory_set internal API call
[profile/tv/apps/web/browser.git] / unit_tests / ut_Config.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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 /*
18  * ut_Config.cpp
19  * Unit test of Config component
20  *
21  * Created on: Mar 18, 2014
22  *     Author: k.dobkowski
23  */
24
25 #include <string>
26
27 #include <boost/test/unit_test.hpp>
28 #include <boost/any.hpp>
29
30 #include "BrowserLogger.h"
31 #include "Config.h"
32
33 BOOST_AUTO_TEST_SUITE(config)
34
35 BOOST_AUTO_TEST_CASE(config_simple_get_set)
36 {
37     std::unique_ptr<tizen_browser::config::DefaultConfig> defconf(new tizen_browser::config::DefaultConfig());
38     BOOST_CHECK(defconf);
39
40     boost::any testvalue = defconf->get(std::string("testkey"));
41     BOOST_CHECK(testvalue.empty());
42
43     int testval = 100;
44     defconf->set("intTestKey", testval);
45     int retval = boost::any_cast<int>(defconf->get(std::string("intTestKey")));
46     BOOST_CHECK_EQUAL(testval, retval);
47 }
48
49 /*
50  * This is test case of load and store methods.
51  */
52 BOOST_AUTO_TEST_CASE(config_load_store)
53 {
54     std::unique_ptr<tizen_browser::config::DefaultConfig> configuration1(new tizen_browser::config::DefaultConfig());
55     std::unique_ptr<tizen_browser::config::DefaultConfig> configuration2(new tizen_browser::config::DefaultConfig());
56     BOOST_CHECK(&configuration1);
57     std::string teststr("UseEFL");
58     configuration1->set("userInterface", teststr);
59     configuration1->store(std::string("config_file.cfg"));
60     configuration1.reset();
61
62     configuration2->load(std::string("config_file.cfg"));
63
64     std::string retstring;
65     try{
66         retstring = boost::any_cast<std::string>(configuration2->get(std::string("userInterface")));
67     } catch(boost::bad_any_cast & e){
68         /// \todo Need to resolve bad type (void *) from boost::any(empty_string))
69         BROWSER_LOGI("[i] Catched error, msg: %s",e.what());
70         BROWSER_LOGI("[i] std::map not found map[key] and returns NULL to boost::any_cast as type (void*) instead of std::string (this case)\n");
71     }
72     /// \todo Below test should be enabled when saving and loading to/from config file will be implemented.
73     ///  BOOST_CHECK_EQUAL(teststr, retstring);
74     configuration2.reset();
75 }
76
77
78 /*
79  * This is test of boundary conditions
80  */
81 BOOST_AUTO_TEST_CASE(config_boundary_conditions)
82 {
83     std::unique_ptr<tizen_browser::config::DefaultConfig> configuration(new tizen_browser::config::DefaultConfig());
84     BOOST_CHECK(&configuration);
85     std::string retstring;
86
87 // Wrong keys tests
88     BOOST_CHECK(retstring.empty());
89     boost::any retany;
90     try{
91         retany = configuration->get(NULL);
92     } catch(std::logic_error & e){
93         /// \todo get() function expects string and cannot construct empty string from NULL
94         BROWSER_LOGI("[i] Catched error, msg: %s",e.what());
95         BROWSER_LOGI("[i] get() function expects string and cannot construct empty string from NULL\n");
96     }
97
98     try{
99         retstring = boost::any_cast<std::string>(retany);
100         BOOST_CHECK(retstring.empty());
101     }catch(boost::bad_any_cast & e){
102         /// \todo Need to resolve bad type (void *) from boost::any(empty_string))
103         BROWSER_LOGI("[i] Catched error, msg: %s",e.what());
104         BROWSER_LOGI("[i] std::map not found map[key] and returns NULL to boost::any_cast as type (void*) instead of std::string (this case)\n");
105     }
106     configuration->set(std::string(""), std::string("value"));
107     retstring = boost::any_cast<std::string>(configuration->get(std::string("")));
108     BOOST_CHECK_EQUAL(retstring, std::string("value"));
109
110     configuration->set(std::string(" "), std::string("anothervalue"));
111     retstring = boost::any_cast<std::string>(configuration->get(std::string(" ")));
112     BOOST_CHECK_EQUAL(retstring, std::string("anothervalue"));
113
114     configuration->set(std::string("    "), std::string("value3"));
115     retstring = boost::any_cast<std::string>(configuration->get(std::string("   ")));
116     BOOST_CHECK_EQUAL(retstring, std::string("value3"));
117
118 // Wrong value tests
119 // NOTE Check that value is allowed to be empty.
120     configuration->set(std::string("TestKey"), std::string(""));
121     retstring = boost::any_cast<std::string>(configuration->get(std::string("TestKey")));
122     BOOST_CHECK(retstring.empty());
123
124     configuration->set(std::string("TestKey"), std::string(" "));
125     retstring = boost::any_cast<std::string>(configuration->get(std::string("TestKey")));
126     BOOST_CHECK(!retstring.empty());
127
128     configuration->set(std::string("AnotherTestKey"), std::string("     "));
129     retstring = boost::any_cast<std::string>(configuration->get(std::string("AnotherTestKey")));
130     BOOST_CHECK(!retstring.empty());
131
132 // Set two the same keys or values
133 // NOTE Check that key or value are allowed have duplicates. This test case not allowed duplicates
134     configuration->set(std::string("SameTestKey"), std::string("valueA"));
135     configuration->set(std::string("SameTestKey"), std::string("valueB"));
136     retstring = boost::any_cast<std::string>(configuration->get(std::string("SameTestKey")));
137     BOOST_CHECK_EQUAL(std::string("valueB"), retstring);
138     BOOST_CHECK_PREDICATE( std::not_equal_to<std::string>(), (retstring)(std::string("valueA")) );
139 }
140
141 BOOST_AUTO_TEST_SUITE_END()