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
17 * @file test-api-engine-manager.cpp
18 * @author Kyungwook Tak (k.tak@samsung.com)
20 * @brief CSR Engine manager API test
22 #include <csr-engine-manager.h>
25 #include <boost/test/unit_test.hpp>
27 #include "test-common.h"
28 #include "test-helper.h"
29 #include "test-resource.h"
35 Engine(csr_engine_id_e id)
37 ASSERT_SUCCESS(csr_get_current_engine(id, &m_engine));
42 ASSERT_SUCCESS(csr_engine_destroy(m_engine));
45 csr_engine_h &get(void)
51 csr_engine_h m_engine;
54 } // namespace anonymous
56 BOOST_AUTO_TEST_SUITE(API_ENGINE_MANAGER)
57 BOOST_AUTO_TEST_SUITE(CS)
59 BOOST_AUTO_TEST_CASE(fields_getters)
63 Engine e(CSR_ENGINE_CS);
65 Test::ScopedCstr vendor;
66 ASSERT_SUCCESS(csr_engine_get_vendor(e.get(), &vendor.ptr));
67 ASSERT_IF(vendor.ptr, std::string("TEST_VENDOR"));
69 Test::ScopedCstr name;
70 ASSERT_SUCCESS(csr_engine_get_name(e.get(), &name.ptr));
71 ASSERT_IF(name.ptr, std::string("TEST_LOCAL_TCS_ENGINE"));
73 Test::ScopedCstr version;
74 ASSERT_SUCCESS(csr_engine_get_version(e.get(), &version.ptr));
75 ASSERT_IF(version.ptr, std::string("0.0.1"));
77 Test::ScopedCstr dataVersion;
78 ASSERT_SUCCESS(csr_engine_get_version(e.get(), &dataVersion.ptr));
79 ASSERT_IF(dataVersion.ptr, std::string("0.0.1"));
81 csr_activated_e activated;
82 ASSERT_SUCCESS(csr_engine_get_activated(e.get(), &activated));
83 ASSERT_IF(activated, CSR_ACTIVATED);
85 csr_state_e state = CSR_STATE_ENABLE;
86 ASSERT_SUCCESS(csr_engine_set_state(e.get(), state));
88 ASSERT_SUCCESS(csr_engine_get_state(e.get(), &state));
89 ASSERT_IF(state, CSR_STATE_ENABLE);
94 BOOST_AUTO_TEST_CASE(set_state)
98 Engine e(CSR_ENGINE_CS);
100 csr_state_e state = CSR_STATE_ENABLE;
103 ASSERT_SUCCESS(csr_engine_set_state(e.get(), CSR_STATE_ENABLE));
104 ASSERT_SUCCESS(csr_engine_get_state(e.get(), &state));
105 ASSERT_IF(state, CSR_STATE_ENABLE);
108 auto c = Test::Context<csr_cs_context_h>();
109 auto context = c.get();
110 csr_cs_malware_h detected;
111 unsigned char data[100] = {0, };
113 // check if engine is working well
114 memcpy(data, MALWARE_HIGH_SIGNATURE, strlen(MALWARE_HIGH_SIGNATURE));
115 ASSERT_SUCCESS(csr_cs_scan_data(context, data, sizeof(data), &detected));
118 ASSERT_SUCCESS(csr_engine_set_state(e.get(), CSR_STATE_DISABLE));
119 ASSERT_SUCCESS(csr_engine_get_state(e.get(), &state));
120 ASSERT_IF(state, CSR_STATE_DISABLE);
123 ASSERT_IF(csr_cs_scan_data(context, data, sizeof(data), &detected),
124 CSR_ERROR_ENGINE_DISABLED);
125 ASSERT_IF(csr_cs_scan_file(context, TEST_FILE_NORMAL, &detected),
126 CSR_ERROR_ENGINE_DISABLED);
129 ASSERT_SUCCESS(csr_engine_set_state(e.get(), CSR_STATE_ENABLE));
130 ASSERT_SUCCESS(csr_engine_get_state(e.get(), &state));
131 ASSERT_IF(state, CSR_STATE_ENABLE);
134 ASSERT_SUCCESS(csr_cs_scan_data(context, data, sizeof(data), &detected));
135 ASSERT_SUCCESS(csr_cs_scan_file(context, TEST_FILE_NORMAL, &detected));
140 BOOST_AUTO_TEST_SUITE_END() // CS
142 BOOST_AUTO_TEST_SUITE(WP)
144 BOOST_AUTO_TEST_CASE(fields_getters)
146 EXCEPTION_GUARD_START
148 Engine e(CSR_ENGINE_WP);
150 Test::ScopedCstr vendor;
151 ASSERT_SUCCESS(csr_engine_get_vendor(e.get(), &vendor.ptr));
152 ASSERT_IF(vendor.ptr, std::string("TEST_VENDOR"));
154 Test::ScopedCstr name;
155 ASSERT_SUCCESS(csr_engine_get_name(e.get(), &name.ptr));
156 ASSERT_IF(name.ptr, std::string("TEST_LOCAL_TWP_ENGINE"));
158 Test::ScopedCstr version;
159 ASSERT_SUCCESS(csr_engine_get_version(e.get(), &version.ptr));
160 ASSERT_IF(version.ptr, std::string("0.0.1"));
162 Test::ScopedCstr dataVersion;
163 ASSERT_SUCCESS(csr_engine_get_version(e.get(), &dataVersion.ptr));
164 ASSERT_IF(dataVersion.ptr, std::string("0.0.1"));
166 csr_activated_e activated;
167 ASSERT_SUCCESS(csr_engine_get_activated(e.get(), &activated));
168 ASSERT_IF(activated, CSR_ACTIVATED);
170 csr_state_e state = CSR_STATE_ENABLE;
171 ASSERT_SUCCESS(csr_engine_set_state(e.get(), state));
173 ASSERT_SUCCESS(csr_engine_get_state(e.get(), &state));
174 ASSERT_IF(state, CSR_STATE_ENABLE);
179 BOOST_AUTO_TEST_CASE(set_state)
181 EXCEPTION_GUARD_START
183 Engine e(CSR_ENGINE_WP);
185 csr_state_e state = CSR_STATE_ENABLE;
188 ASSERT_SUCCESS(csr_engine_set_state(e.get(), CSR_STATE_ENABLE));
189 ASSERT_SUCCESS(csr_engine_get_state(e.get(), &state));
190 ASSERT_IF(state, CSR_STATE_ENABLE);
193 auto c = Test::Context<csr_wp_context_h>();
194 auto context = c.get();
195 csr_wp_check_result_h result;
197 // check if engine is working well
198 ASSERT_SUCCESS(csr_wp_check_url(context, RISK_HIGH_URL, &result));
201 ASSERT_SUCCESS(csr_engine_set_state(e.get(), CSR_STATE_DISABLE));
202 ASSERT_SUCCESS(csr_engine_get_state(e.get(), &state));
203 ASSERT_IF(state, CSR_STATE_DISABLE);
206 ASSERT_IF(csr_wp_check_url(context, RISK_HIGH_URL, &result),
207 CSR_ERROR_ENGINE_DISABLED);
210 ASSERT_SUCCESS(csr_engine_set_state(e.get(), CSR_STATE_ENABLE));
211 ASSERT_SUCCESS(csr_engine_get_state(e.get(), &state));
212 ASSERT_IF(state, CSR_STATE_ENABLE);
215 ASSERT_SUCCESS(csr_wp_check_url(context, RISK_HIGH_URL, &result));
221 BOOST_AUTO_TEST_SUITE_END() // WP
222 BOOST_AUTO_TEST_SUITE_END() // API_ENGINE_MANAGER