Removed dead code from SimpleUI
[profile/tv/apps/web/browser.git] / unit_tests / ut_FavoriteService.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  * Created on: Apr, 2014
20  *     Author: k.dobkowski
21  */
22
23 #include <string>
24
25 #include <boost/test/unit_test.hpp>
26 #include <boost/any.hpp>
27
28 #include "ServiceManager.h"
29 #include "BrowserLogger.h"
30 #include "FavoriteService.h"
31 #include "BookmarkItem.h"
32
33
34 BOOST_AUTO_TEST_SUITE(bookmarks)
35
36 bool item_is_empty(std::shared_ptr<tizen_browser::services::BookmarkItem> item) { return item->getAddress() == std::string(); };
37
38 BOOST_AUTO_TEST_CASE(bookmark_add_remove)
39 {
40     BROWSER_LOGI("BOOKMARKS_TEST_CASE START --> ");
41
42     /// \todo: clean casts, depends on ServiceManager
43     std::shared_ptr<tizen_browser::services::FavoriteService> fs =
44     std::dynamic_pointer_cast
45     <
46         tizen_browser::services::FavoriteService,
47         tizen_browser::core::AbstractService
48     >
49     (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.favoriteservice"));
50
51     fs->setStorageServiceTestMode();
52
53     int bookcount = -1;
54     int bookcount2 = -1;
55     bool resultflag = false;
56
57 //  getBookmarks method test
58     std::shared_ptr<tizen_browser::services::BookmarkItem> bitem;
59     std::vector<std::shared_ptr<tizen_browser::services::BookmarkItem>> bookmarks_list = fs->getBookmarks();
60     while(!bookmarks_list.empty()) {
61         bitem = bookmarks_list.back();
62         BROWSER_LOGI("Element from cached bookmark list: id: %d, tittle: %s, URL: %s", bitem->getId(),
63                             bitem->getTittle().c_str(), bitem->getAddress().c_str());
64         bookmarks_list.pop_back();
65     }
66
67     BROWSER_LOGI("Above - current stored bookmarks (recently adder order");
68
69 //  clean all bookmarks
70     resultflag = fs->deleteAllBookmarks();
71     BOOST_CHECK(resultflag);
72     fs->getBookmarks();
73     BROWSER_LOGI("Above - current stored bookmarks after deleteAll, deleting resultflag: %d", resultflag);
74
75 //  Empty bookmark test
76     bookcount = fs->countBookmarksAndSubFolders();
77     BOOST_CHECK(item_is_empty(fs->addToBookmarks("","")));
78     bookcount2 = fs->countBookmarksAndSubFolders();
79     BOOST_CHECK_EQUAL(bookcount, bookcount2);
80     BROWSER_LOGI("Add empty bookmark test summary - number of bookmarks before: %d, after: %d", bookcount ,bookcount2);
81     fs->getBookmarks();
82
83 //  Add bookmark with the same tittle
84     BOOST_CHECK(!item_is_empty(fs->addToBookmarks("www.thisis.url1","Tittle")));
85     BOOST_CHECK(!item_is_empty(fs->addToBookmarks("www.thisis.url4","Tittle")));
86     std::shared_ptr<tizen_browser::services::BookmarkItem> item_to_delete = fs->addToBookmarks("www.thisis.url5","Tittle");
87     BOOST_CHECK(!item_is_empty(item_to_delete));
88     fs->getBookmarks();
89     BROWSER_LOGI("Before delete last bookmark (%s)", item_to_delete->getAddress().c_str());
90     BOOST_CHECK(fs->deleteBookmark(item_to_delete->getAddress()));
91     BROWSER_LOGI("After delete bookmark");
92     fs->getBookmarks();
93
94 //  Add duplicated url
95     BROWSER_LOGI("Add duplicated url");
96     BOOST_CHECK(item_is_empty(fs->addToBookmarks("www.thisis.url4","Not duplicateTittle")));
97     fs->getBookmarks();
98
99 //  check existing url
100     resultflag = fs->bookmarkExists("www.not_existing.url");
101     BROWSER_LOGI("Check not existing url (%s) resultflag: %d", "www.not_existing.url", resultflag);
102     BOOST_CHECK(!resultflag);
103     resultflag = fs->bookmarkExists("www.thisis.url4");
104     BROWSER_LOGI("Check existing url (%s) resultflag: %d", "www.thisis.url4", resultflag);
105     BOOST_CHECK(resultflag);
106 }
107
108 BOOST_AUTO_TEST_CASE(bookmark_synchro)
109 {
110     /// \todo: clean casts, depends on ServiceManager
111     std::shared_ptr<tizen_browser::services::FavoriteService> fs =
112     std::dynamic_pointer_cast
113     <
114         tizen_browser::services::FavoriteService,
115         tizen_browser::core::AbstractService
116     >
117     (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.favoriteservice"));
118
119     BROWSER_LOGI("Bookmarks synchronize test");
120     fs->synchronizeBookmarks();
121     BOOST_CHECK(!fs->getBookmarks().empty());
122
123     BROWSER_LOGI("<-- BOOKMARKS_TEST_CASE END");
124 }
125
126 BOOST_AUTO_TEST_SUITE_END()
127