2 * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
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.
17 * @file TestCases_CustomHandlerDAO.cpp
18 * @author Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
20 * @brief This file contains tests for custom handler dao class.
23 #include <dpl/test/test_runner.h>
24 #include <dpl/foreach.h>
25 #include <wrt-commons/custom-handler-dao-rw/custom_handler_dao.h>
26 #include <wrt-commons/custom-handler-dao-ro/common_dao_types.h>
28 using namespace CustomHandlerDB;
30 RUNNER_TEST_GROUP_INIT(DAO)
34 const DPL::String P_TARGET(L"p_target");
35 const DPL::String P_BASE_URL(L"p_base_url");
36 const DPL::String P_URL(L"p_url");
37 const DPL::String P_TITLE(L"p_title");
39 const DPL::String C_TARGET(L"c_target");
40 const DPL::String C_BASE_URL(L"c_base_url");
41 const DPL::String C_URL(L"c_url");
42 const DPL::String C_TITLE(L"c_title");
44 void checkHandlersExistence(CustomHandlerDAOReadOnly& dao, bool protocol, bool content)
46 CustomHandlerDB::CustomHandlerPtr handler;
47 handler = dao.getProtocolHandler(P_TARGET, P_URL);
48 RUNNER_ASSERT_MSG((!!handler) == protocol, "Protocol handler check");
49 handler = dao.getContentHandler(C_TARGET, C_URL);
50 RUNNER_ASSERT_MSG((!!handler) == content, "Content handler check");
55 RUNNER_TEST(custom_handler_empty_db_read)
57 CustomHandlerDAOReadOnly dao(DPL::String(L"test"));
61 RUNNER_TEST(custom_handlers)
63 CustomHandlerDAOReadOnly dao_ro(L"test");
64 CustomHandlerDAO dao_rw(L"test");
66 CustomHandlerDB::CustomHandlerPtr handler;
67 CustomHandlerDB::CustomHandler p_handler;
68 p_handler.target = P_TARGET;
69 p_handler.base_url = P_BASE_URL;
70 p_handler.url = P_URL;
71 p_handler.title = P_TITLE;
72 p_handler.user_decision = Agreed;
75 checkHandlersExistence(dao_ro,false,false);
77 // Protocol handler registration
78 dao_rw.registerProtocolHandler(p_handler);
79 checkHandlersExistence(dao_ro,true,false);
81 handler = dao_ro.getProtocolHandler(P_TARGET, P_URL);
82 RUNNER_ASSERT(handler);
83 RUNNER_ASSERT(handler->target == P_TARGET);
84 RUNNER_ASSERT(handler->base_url == P_BASE_URL);
85 RUNNER_ASSERT(handler->url == P_URL);
86 RUNNER_ASSERT(handler->title == P_TITLE);
87 RUNNER_ASSERT(handler->user_decision == Agreed);
90 // Content handler registration
91 CustomHandlerDB::CustomHandler c_handler;
92 c_handler.target = C_TARGET;
93 c_handler.base_url = C_BASE_URL;
94 c_handler.url = C_URL;
95 c_handler.title = C_TITLE;
96 c_handler.user_decision = DeclinedPermanently;
98 dao_rw.registerContentHandler(c_handler);
99 checkHandlersExistence(dao_ro,true,true);
100 handler = dao_ro.getContentHandler(C_TARGET, C_URL);
102 RUNNER_ASSERT(handler);
103 RUNNER_ASSERT(handler->target == C_TARGET);
104 RUNNER_ASSERT(handler->base_url == C_BASE_URL);
105 RUNNER_ASSERT(handler->url == C_URL);
106 RUNNER_ASSERT(handler->title == C_TITLE);
107 RUNNER_ASSERT(handler->user_decision == DeclinedPermanently);
109 // Handler unregistration
110 dao_rw.unregisterProtocolHandler(P_TARGET, P_URL);
111 checkHandlersExistence(dao_ro,false,true);
113 // Nonexistent unregistration
114 dao_rw.unregisterContentHandler(L"blah", L"blah");
115 checkHandlersExistence(dao_ro,false,true);
118 dao_rw.unregisterContentHandler(C_TARGET, C_URL);
119 checkHandlersExistence(dao_ro,false,false);