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)
33 const DPL::String P_TARGET(L"p_target");
34 const DPL::String P_BASE_URL(L"p_base_url");
35 const DPL::String P_URL(L"p_url");
36 const DPL::String P_TITLE(L"p_title");
38 const DPL::String C_TARGET(L"c_target");
39 const DPL::String C_BASE_URL(L"c_base_url");
40 const DPL::String C_URL(L"c_url");
41 const DPL::String C_TITLE(L"c_title");
43 void checkHandlersExistence(CustomHandlerDAOReadOnly& dao,
47 CustomHandlerDB::CustomHandlerPtr handler;
48 handler = dao.getProtocolHandler(P_TARGET, P_URL);
49 RUNNER_ASSERT_MSG((!!handler) == protocol, "Protocol handler check");
50 handler = dao.getContentHandler(C_TARGET, C_URL);
51 RUNNER_ASSERT_MSG((!!handler) == content, "Content handler check");
55 RUNNER_TEST(custom_handler_empty_db_read)
57 CustomHandlerDAOReadOnly dao(DPL::String(L"test"));
60 RUNNER_TEST(custom_handlers)
62 CustomHandlerDAOReadOnly dao_ro(L"test");
63 CustomHandlerDAO dao_rw(L"test");
65 CustomHandlerDB::CustomHandlerPtr handler;
66 CustomHandlerDB::CustomHandler p_handler;
67 p_handler.target = P_TARGET;
68 p_handler.base_url = P_BASE_URL;
69 p_handler.url = P_URL;
70 p_handler.title = P_TITLE;
71 p_handler.user_decision = Agreed;
74 checkHandlersExistence(dao_ro, false, false);
76 // Protocol handler registration
77 dao_rw.registerProtocolHandler(p_handler);
78 checkHandlersExistence(dao_ro, true, false);
80 handler = dao_ro.getProtocolHandler(P_TARGET, P_URL);
81 RUNNER_ASSERT(handler);
82 RUNNER_ASSERT(handler->target == P_TARGET);
83 RUNNER_ASSERT(handler->base_url == P_BASE_URL);
84 RUNNER_ASSERT(handler->url == P_URL);
85 RUNNER_ASSERT(handler->title == P_TITLE);
86 RUNNER_ASSERT(handler->user_decision == Agreed);
88 // Content handler registration
89 CustomHandlerDB::CustomHandler c_handler;
90 c_handler.target = C_TARGET;
91 c_handler.base_url = C_BASE_URL;
92 c_handler.url = C_URL;
93 c_handler.title = C_TITLE;
94 c_handler.user_decision = DeclinedPermanently;
96 dao_rw.registerContentHandler(c_handler);
97 checkHandlersExistence(dao_ro, true, true);
98 handler = dao_ro.getContentHandler(C_TARGET, C_URL);
100 RUNNER_ASSERT(handler);
101 RUNNER_ASSERT(handler->target == C_TARGET);
102 RUNNER_ASSERT(handler->base_url == C_BASE_URL);
103 RUNNER_ASSERT(handler->url == C_URL);
104 RUNNER_ASSERT(handler->title == C_TITLE);
105 RUNNER_ASSERT(handler->user_decision == DeclinedPermanently);
107 // Handler unregistration
108 dao_rw.unregisterProtocolHandler(P_TARGET, P_URL);
109 checkHandlersExistence(dao_ro, false, true);
111 // Nonexistent unregistration
112 dao_rw.unregisterContentHandler(L"blah", L"blah");
113 checkHandlersExistence(dao_ro, false, true);
116 dao_rw.unregisterContentHandler(C_TARGET, C_URL);
117 checkHandlersExistence(dao_ro, false, false);