2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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.
19 * Created on: Apr, 2014
25 #include <boost/test/unit_test.hpp>
26 #include <boost/any.hpp>
28 #include "ServiceManager.h"
29 #include "BrowserLogger.h"
30 #include "FavoriteService.h"
31 #include "BookmarkItem.h"
34 BOOST_AUTO_TEST_SUITE(bookmarks)
36 bool item_is_empty(std::shared_ptr<tizen_browser::services::BookmarkItem> item) { return item->getAddress() == std::string(); };
38 BOOST_AUTO_TEST_CASE(bookmark_add_remove)
40 BROWSER_LOGI("BOOKMARKS_TEST_CASE START --> ");
42 /// \todo: clean casts, depends on ServiceManager
43 std::shared_ptr<tizen_browser::services::FavoriteService> fs =
44 std::dynamic_pointer_cast
46 tizen_browser::services::FavoriteService,
47 tizen_browser::core::AbstractService
49 (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.favoriteservice"));
51 fs->setStorageServiceTestMode();
55 bool resultflag = false;
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();
67 BROWSER_LOGI("Above - current stored bookmarks (recently adder order");
69 // clean all bookmarks
70 resultflag = fs->deleteAllBookmarks();
71 BOOST_CHECK(resultflag);
73 BROWSER_LOGI("Above - current stored bookmarks after deleteAll, deleting resultflag: %d", resultflag);
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);
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));
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");
95 BROWSER_LOGI("Add duplicated url");
96 BOOST_CHECK(item_is_empty(fs->addToBookmarks("www.thisis.url4","Not duplicateTittle")));
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);
108 BOOST_AUTO_TEST_CASE(bookmark_synchro)
110 /// \todo: clean casts, depends on ServiceManager
111 std::shared_ptr<tizen_browser::services::FavoriteService> fs =
112 std::dynamic_pointer_cast
114 tizen_browser::services::FavoriteService,
115 tizen_browser::core::AbstractService
117 (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.favoriteservice"));
119 BROWSER_LOGI("Bookmarks synchronize test");
120 fs->synchronizeBookmarks();
121 BOOST_CHECK(!fs->getBookmarks().empty());
123 BROWSER_LOGI("<-- BOOKMARKS_TEST_CASE END");
126 BOOST_AUTO_TEST_SUITE_END()