2 * Copyright (c) 2016 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
18 * @author Kyungwook Tak (k.tak@samsung.com)
20 * @brief Common utilities for test
29 #include <boost/test/unit_test.hpp>
31 #include <csr/content-screening.h>
32 #include <csr/web-protection.h>
34 #include <csre/content-screening.h>
35 #include <csre/web-protection.h>
37 #include <csre/content-screening-engine-info.h>
38 #include <csre/web-protection-engine-info.h>
41 #define __FILENAME__ (::strrchr(__FILE__, '/') ? ::strrchr(__FILE__, '/') + 1 : __FILE__)
44 #define ASSERT_IF_(value, expected, file, f, l) \
45 Test::_assert(value, expected, file, f, l)
47 #define ASSERT_IF(value, expected) \
48 ASSERT_IF_(value, expected, __FILENAME__, __func__, __LINE__)
50 #define EXCEPTION_GUARD_START Test::exceptionGuard([&] {
51 #define EXCEPTION_GUARD_END });
53 #define CHECK_IS_NULL(ptr) BOOST_REQUIRE(ptr == nullptr)
54 #define CHECK_IS_NOT_NULL(ptr) BOOST_REQUIRE(ptr != nullptr)
58 template <typename T, typename U>
59 void _assert(const T &value, const U &expected, const std::string &filename,
60 const std::string &funcname, unsigned int line)
62 BOOST_REQUIRE_MESSAGE(value == expected,
63 "[" << filename << " > " << funcname << " : " << line << "]"
64 << " returned code: " << value
65 << " expected: " << expected);
68 void exceptionGuard(const std::function<void()> &);
73 Context() : m_context(nullptr)
75 BOOST_REQUIRE_MESSAGE(0, "Type[" << typeid(T).name()
76 << "] isn't specialized for context template");
81 BOOST_REQUIRE_MESSAGE(0, "Type[" << typeid(T).name()
82 << "] isn't specialized for context template");
87 BOOST_REQUIRE_MESSAGE(0, "Type[" << typeid(T).name()
88 << "] isn't specialized for context template");
98 class Context<csr_cs_context_h> {
100 Context() : m_context(nullptr)
102 ASSERT_IF(csr_cs_context_create(&m_context), CSR_ERROR_NONE);
103 BOOST_REQUIRE(m_context != nullptr);
108 ASSERT_IF(csr_cs_context_destroy(m_context), CSR_ERROR_NONE);
111 csr_cs_context_h get(void) const
117 csr_cs_context_h m_context;
121 class Context<csr_wp_context_h> {
123 Context() : m_context(nullptr)
125 ASSERT_IF(csr_wp_context_create(&m_context), CSR_ERROR_NONE);
126 BOOST_REQUIRE(m_context != nullptr);
131 ASSERT_IF(csr_wp_context_destroy(m_context), CSR_ERROR_NONE);
134 csr_wp_context_h get(void) const
140 csr_wp_context_h m_context;
144 class Context<csre_cs_context_h> {
146 Context() : m_context(nullptr)
148 ASSERT_IF(csre_cs_context_create(&m_context), CSRE_ERROR_NONE);
149 BOOST_REQUIRE(m_context != nullptr);
154 ASSERT_IF(csre_cs_context_destroy(m_context), CSRE_ERROR_NONE);
157 csre_cs_context_h get(void) const
163 csre_cs_context_h m_context;
167 class Context<csre_wp_context_h> {
169 Context() : m_context(nullptr)
171 ASSERT_IF(csre_wp_context_create(&m_context), CSRE_ERROR_NONE);
172 BOOST_REQUIRE(m_context != nullptr);
177 ASSERT_IF(csre_wp_context_destroy(m_context), CSRE_ERROR_NONE);
180 csre_wp_context_h get(void) const
186 csre_wp_context_h m_context;
190 class Context<csre_cs_engine_h> {
192 Context() : m_context(nullptr)
194 ASSERT_IF(csre_cs_engine_get_info(&m_context), CSRE_ERROR_NONE);
195 BOOST_REQUIRE(m_context != nullptr);
200 ASSERT_IF(csre_cs_engine_destroy(m_context), CSRE_ERROR_NONE);
203 csre_cs_engine_h get(void) const
209 csre_cs_engine_h m_context;
213 class Context<csre_wp_engine_h> {
215 Context() : m_context(nullptr)
217 ASSERT_IF(csre_wp_engine_get_info(&m_context), CSRE_ERROR_NONE);
218 BOOST_REQUIRE(m_context != nullptr);
223 ASSERT_IF(csre_wp_engine_destroy(m_context), CSRE_ERROR_NONE);
226 csre_wp_engine_h get(void) const
232 csre_wp_engine_h m_context;