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, const std::string &funcname, unsigned int line)
61 BOOST_REQUIRE_MESSAGE(value == expected,
62 "[" << filename << " > " << funcname << " : " << line << "]"
63 << " returned code: " << value
64 << " expected: " << expected);
67 void exceptionGuard(const std::function<void()> &);
72 Context() : m_context(nullptr)
74 BOOST_REQUIRE_MESSAGE(0, "Type[" << typeid(T).name()
75 << "] isn't specialized for context template");
80 BOOST_REQUIRE_MESSAGE(0, "Type[" << typeid(T).name()
81 << "] isn't specialized for context template");
86 BOOST_REQUIRE_MESSAGE(0, "Type[" << typeid(T).name()
87 << "] isn't specialized for context template");
97 class Context<csr_cs_context_h> {
99 Context() : m_context(nullptr)
101 ASSERT_IF(csr_cs_context_create(&m_context), CSR_ERROR_NONE);
102 BOOST_REQUIRE(m_context != nullptr);
107 ASSERT_IF(csr_cs_context_destroy(m_context), CSR_ERROR_NONE);
110 csr_cs_context_h get(void) const
116 csr_cs_context_h m_context;
120 class Context<csr_wp_context_h> {
122 Context() : m_context(nullptr)
124 ASSERT_IF(csr_wp_context_create(&m_context), CSR_ERROR_NONE);
125 BOOST_REQUIRE(m_context != nullptr);
130 ASSERT_IF(csr_wp_context_destroy(m_context), CSR_ERROR_NONE);
133 csr_wp_context_h get(void) const
139 csr_wp_context_h m_context;
143 class Context<csre_cs_context_h> {
145 Context() : m_context(nullptr)
147 ASSERT_IF(csre_cs_context_create(&m_context), CSRE_ERROR_NONE);
148 BOOST_REQUIRE(m_context != nullptr);
153 ASSERT_IF(csre_cs_context_destroy(m_context), CSRE_ERROR_NONE);
156 csre_cs_context_h get(void) const
162 csre_cs_context_h m_context;
166 class Context<csre_wp_context_h> {
168 Context() : m_context(nullptr)
170 ASSERT_IF(csre_wp_context_create(&m_context), CSRE_ERROR_NONE);
171 BOOST_REQUIRE(m_context != nullptr);
176 ASSERT_IF(csre_wp_context_destroy(m_context), CSRE_ERROR_NONE);
179 csre_wp_context_h get(void) const
185 csre_wp_context_h m_context;
189 class Context<csre_cs_engine_h> {
191 Context() : m_context(nullptr)
193 ASSERT_IF(csre_cs_engine_get_info(&m_context), CSRE_ERROR_NONE);
194 BOOST_REQUIRE(m_context != nullptr);
199 ASSERT_IF(csre_cs_engine_destroy(m_context), CSRE_ERROR_NONE);
202 csre_cs_engine_h get(void) const
208 csre_cs_engine_h m_context;
212 class Context<csre_wp_engine_h> {
214 Context() : m_context(nullptr)
216 ASSERT_IF(csre_wp_engine_get_info(&m_context), CSRE_ERROR_NONE);
217 BOOST_REQUIRE(m_context != nullptr);
222 ASSERT_IF(csre_wp_engine_destroy(m_context), CSRE_ERROR_NONE);
225 csre_wp_engine_h get(void) const
231 csre_wp_engine_h m_context;