Removed dead code from SimpleUI
[profile/tv/apps/web/browser.git] / unit_tests / ut_StorageService.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
19 #include <memory>
20 #include <string>
21 #include <boost/test/unit_test.hpp>
22
23 #include "ServiceManager.h"
24 #include "BrowserLogger.h"
25 #include "StorageService.h"
26 #include "StorageException.h"
27
28 #define CHANNEL_AUTH01 "Gall Anonim 1"
29 #define CHANNEL_DESCR01 "Test channel - description 1"
30 #define CHANNEL_DATE01 "2001-01-20 23:59:59.000"
31 #define CHANNEL_URL01 "www.gallanonim-test1.com"
32 #define CHANNEL_TITLE01 "Test CHANNEL title 1"
33
34 #define CHANNEL_AUTH02 "Gall Anonim 2"
35 #define CHANNEL_DESCR02 "Test channel - description 2"
36 #define CHANNEL_DATE02 "2002-02-22 23:59:59.000"
37 #define CHANNEL_URL02 "www.gallanonim-test2.com"
38 #define CHANNEL_TITLE02 "Test CHANNEL title 2"
39
40 #define CHANNEL_AUTH11 "Gall Anonim 11"
41 #define CHANNEL_DESCR11 "Test channel - description 11"
42 #define CHANNEL_DATE11 "2011-01-20 23:59:59.000"
43 #define CHANNEL_URL11 "www.gallanonim-test11.com"
44 #define CHANNEL_TITLE11 "Test CHANNEL title 11"
45
46
47 #define ITEM_DESCRIPTION01 "Test item - description 1"
48 #define ITEM_DATE01 "1987-01-20 23:59:59.000"
49 #define ITEM_URL01 "www.item01.com"
50 #define ITEM_TITLE01 "Test ITEM title 1"
51
52 #define ITEM_DESCRIPTION02 "Test item - description 2"
53 #define ITEM_DATE02 "1988-01-20 23:59:59.000"
54 #define ITEM_URL02 "www.item02.com"
55 #define ITEM_TITLE02 "Test ITEM title 2"
56
57 #define ITEM_DESCRIPTION11 "Test item - description 11"
58 #define ITEM_DATE11 "1988-01-20 23:59:59.000"
59 #define ITEM_URL11 "www.item11.com"
60 #define ITEM_TITLE11 "Test ITEM title 11"
61
62 #define ITEM_DESCRIPTION12 "Test item - description 12"
63 #define ITEM_DATE12 "1989-01-20 23:59:59.000"
64 #define ITEM_URL12 "www.item12.com"
65 #define ITEM_TITLE12 "Test ITEM title 12"
66
67 #define ITEM_DESCRIPTION13 "Test item - description 13"
68 #define ITEM_DATE13 "1990-01-20 23:59:59.000"
69 #define ITEM_URL13 "www.item13.com"
70 #define ITEM_TITLE13 "Test ITEM title 13"
71
72 #define ITEM_DESCRIPTION14 "Test item - description 14"
73 #define ITEM_DATE14 "1991-01-20 23:59:59.000"
74 #define ITEM_URL14 "www.item14.com"
75 #define ITEM_TITLE14 "Test ITEM title 14"
76
77
78
79 BOOST_AUTO_TEST_SUITE(StorageService)
80
81
82 BOOST_AUTO_TEST_CASE(storage_settings)
83 {
84     BROWSER_LOGI("StorageService - history - START --> ");
85
86     std::shared_ptr<tizen_browser::services::StorageService> storageManager = std::dynamic_pointer_cast <
87                                                                               tizen_browser::services::StorageService,
88                                                                               tizen_browser::core::AbstractService > (
89                                                                                   tizen_browser::core::ServiceManager::getInstance().getService(
90                                                                                           DOMAIN_STORAGE_SERVICE));
91
92     storageManager->init(true);
93
94     const std::string keyInt = "keyINT";
95     storageManager->setSettingsInt(keyInt, 12);
96     auto i12 = storageManager->getSettingsInt(keyInt, 0);
97     BOOST_CHECK(12 == i12);
98
99     const std::string keyDouble = "keyDouble";
100     storageManager->setSettingsDouble(keyDouble, 22.45);
101     auto d22_45 = storageManager->getSettingsDouble(keyDouble, 0.0);
102     BOOST_CHECK(22.45 == d22_45);
103
104     const std::string keyString = "keyString";
105     storageManager->setSettingsString(keyString, "String");
106     auto sString = storageManager->getSettingsText(keyString, "0.0");
107     BOOST_CHECK("String" == sString);
108
109
110     BROWSER_LOGI("<-- StorageService - history - END");
111 }
112
113 BOOST_AUTO_TEST_CASE(storage_bookmark)
114 {
115     BROWSER_LOGI("StorageService - bookmark - START --> ");
116
117     std::shared_ptr<tizen_browser::services::StorageService> storageManager = std::dynamic_pointer_cast <
118                                                                               tizen_browser::services::StorageService,
119                                                                               tizen_browser::core::AbstractService > (
120                                                                                   tizen_browser::core::ServiceManager::getInstance().getService(
121                                                                                           DOMAIN_STORAGE_SERVICE));
122
123     storageManager->init(true);
124
125     std::shared_ptr<tizen_browser::tools::BrowserImage> bi = std::make_shared<tizen_browser::tools::BrowserImage>();
126     bi->imageType = tizen_browser::tools::BrowserImage::ImageTypeNoImage;
127     bi->id = 1;
128     bi->url = "URL1";
129
130     /*storageManager->addThumbnail(1, bi, tizen_browser::tools::BrowserImage::ImageTypeNoImage);
131
132     auto biLoaded = storageManager->getThumbnail(1);
133     BROWSER_LOGI("biLoaded->url = %s", biLoaded->url.c_str());
134
135     BOOST_CHECK(biLoaded->url == "URL1");
136
137     storageManager->deleteThumbnail(1);*/
138
139     BROWSER_LOGI("<-- StorageService - bookmark - END");
140 }
141
142 BOOST_AUTO_TEST_CASE(storage_history)
143 {
144     BROWSER_LOGI("StorageService - history - START --> ");
145
146     std::shared_ptr<tizen_browser::services::StorageService> storageManager = std::dynamic_pointer_cast <
147                                                                               tizen_browser::services::StorageService,
148                                                                               tizen_browser::core::AbstractService > (
149                                                                                   tizen_browser::core::ServiceManager::getInstance().getService(
150                                                                                           DOMAIN_STORAGE_SERVICE));
151
152     storageManager->init(true);
153
154     std::shared_ptr<tizen_browser::tools::BrowserImage> bi = std::make_shared<tizen_browser::tools::BrowserImage>();
155     std::shared_ptr<tizen_browser::services::HistoryItem> hi = std::make_shared<tizen_browser::services::HistoryItem>("URL", "Title", bi);
156     storageManager->addHistoryItem(hi);
157
158     std::shared_ptr<tizen_browser::services::HistoryItem> hi2 = std::make_shared<tizen_browser::services::HistoryItem>("URL2", "Title2", bi);
159     storageManager->addHistoryItem(hi2);
160
161     auto countItems_2 = storageManager->getHistoryItems(100, 2);
162     auto countItems_1 = storageManager->getHistoryItems(100, 1);
163     BOOST_CHECK(countItems_2.size() == 2);
164     BOOST_CHECK(countItems_1.size() == 1);
165     storageManager->deleteHistory(hi2->getUrl());
166
167     auto hiauto = storageManager->getHistoryItem("URL");
168     BOOST_CHECK(hiauto->getTitle() == "Title");
169
170     auto iHistCount = storageManager->getHistoryItemsCount();
171     BROWSER_LOGD("iHistCount = %d", iHistCount);
172     BOOST_CHECK(iHistCount == 1);
173
174     auto iVisitCounter = storageManager->getHistoryVisitCounter(hiauto->getUrl());
175     BROWSER_LOGD("iVisitCounter = %d", iVisitCounter);
176     BOOST_CHECK(iVisitCounter == 1);
177
178     hi->setTitle("New Title");
179     storageManager->insertOrRefresh(hi);
180     auto newHistItem = storageManager->getHistoryItem("URL");
181     BOOST_CHECK(hi->getTitle() == "New Title");
182     auto iNewVisitCounter = storageManager->getHistoryVisitCounter(hi->getUrl());
183     BROWSER_LOGD("iVisitCounter = %d", iNewVisitCounter);
184     BOOST_CHECK(iNewVisitCounter == 2);
185
186     storageManager->deleteHistory();
187     iHistCount = storageManager->getHistoryItemsCount();
188     BROWSER_LOGD("iHistCount = %d", iHistCount);
189     BOOST_CHECK(iHistCount == 0);
190
191     BROWSER_LOGI("<-- StorageService - history - END");
192 }
193
194
195 BOOST_AUTO_TEST_SUITE_END()