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_IF(csr_get_current_engine(id, &m_engine), CSR_ERROR_NONE);
42 ASSERT_IF(csr_engine_destroy(m_engine), CSR_ERROR_NONE);
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_IF(csr_engine_get_vendor(e.get(), &vendor.ptr), CSR_ERROR_NONE);
67 ASSERT_IF(std::string("TEST_VENDOR"), vendor.ptr);
69 Test::ScopedCstr name;
70 ASSERT_IF(csr_engine_get_name(e.get(), &name.ptr), CSR_ERROR_NONE);
71 ASSERT_IF(std::string("TEST_LOCAL_TCS_ENGINE"), name.ptr);
73 Test::ScopedCstr version;
74 ASSERT_IF(csr_engine_get_version(e.get(), &version.ptr), CSR_ERROR_NONE);
75 ASSERT_IF(std::string("0.0.1"), version.ptr);
77 Test::ScopedCstr dataVersion;
78 ASSERT_IF(csr_engine_get_version(e.get(), &dataVersion.ptr), CSR_ERROR_NONE);
79 ASSERT_IF(std::string("0.0.1"), dataVersion.ptr);
81 csr_activated_e activated;
82 ASSERT_IF(csr_engine_get_activated(e.get(), &activated), CSR_ERROR_NONE);
83 ASSERT_IF(activated, CSR_ACTIVATED);
85 csr_state_e state = CSR_ENABLE;
86 ASSERT_IF(csr_engine_set_state(e.get(), state), CSR_ERROR_NONE);
88 ASSERT_IF(csr_engine_get_state(e.get(), &state), CSR_ERROR_NONE);
89 ASSERT_IF(state, CSR_ENABLE);
94 BOOST_AUTO_TEST_CASE(set_state)
98 Engine e(CSR_ENGINE_CS);
100 csr_state_e state = CSR_ENABLE;
103 ASSERT_IF(csr_engine_set_state(e.get(), CSR_ENABLE), CSR_ERROR_NONE);
104 ASSERT_IF(csr_engine_get_state(e.get(), &state), CSR_ERROR_NONE);
105 ASSERT_IF(state, CSR_ENABLE);
108 auto c = Test::Context<csr_cs_context_h>();
109 auto context = c.get();
110 csr_cs_detected_h detected;
111 unsigned char data[100] = {0, };
112 //const char *files[1] = { TEST_FILE_NORMAL };
113 //const char *dirs[1] = { TEST_DIR };
115 // check if engine is working well
116 memcpy(data, MALWARE_HIGH_SIGNATURE, strlen(MALWARE_HIGH_SIGNATURE));
117 ASSERT_IF(csr_cs_scan_data(context, data, sizeof(data), &detected), CSR_ERROR_NONE);
120 ASSERT_IF(csr_engine_set_state(e.get(), CSR_DISABLE), CSR_ERROR_NONE);
121 ASSERT_IF(csr_engine_get_state(e.get(), &state), CSR_ERROR_NONE);
122 ASSERT_IF(state, CSR_DISABLE);
125 ASSERT_IF(csr_cs_scan_data(context, data, sizeof(data), &detected), CSR_ERROR_ENGINE_DISABLED);
126 ASSERT_IF(csr_cs_scan_file(context, TEST_FILE_NORMAL, &detected), CSR_ERROR_ENGINE_DISABLED);
127 //ASSERT_IF(csr_cs_scan_files_async(context, files, sizeof(files) / sizeof(const char *), nullptr),
128 // CSR_ERROR_ENGINE_DISABLED);
129 //ASSERT_IF(csr_cs_scan_dir_async(context, TEST_DIR, nullptr), CSR_ERROR_ENGINE_DISABLED);
130 //ASSERT_IF(csr_cs_scan_dirs_async(context, dirs, sizeof(dirs) / sizeof(const char *), nullptr),
131 // CSR_ERROR_ENGINE_DISABLED);
134 ASSERT_IF(csr_engine_set_state(e.get(), CSR_ENABLE), CSR_ERROR_NONE);
135 ASSERT_IF(csr_engine_get_state(e.get(), &state), CSR_ERROR_NONE);
136 ASSERT_IF(state, CSR_ENABLE);
139 ASSERT_IF(csr_cs_scan_data(context, data, sizeof(data), &detected), CSR_ERROR_NONE);
140 ASSERT_IF(csr_cs_scan_file(context, TEST_FILE_NORMAL, &detected), CSR_ERROR_NONE);
141 //ASSERT_IF(csr_cs_scan_files_async(context, files, sizeof(files) / sizeof(const char *), nullptr),
143 //ASSERT_IF(csr_cs_scan_dir_async(context, TEST_DIR, nullptr), CSR_ERROR_NONE);
144 //ASSERT_IF(csr_cs_scan_dirs_async(context, dirs, sizeof(dirs) / sizeof(const char *), nullptr),
150 BOOST_AUTO_TEST_SUITE_END() // CS
152 BOOST_AUTO_TEST_SUITE(WP)
154 BOOST_AUTO_TEST_CASE(fields_getters)
156 EXCEPTION_GUARD_START
158 Engine e(CSR_ENGINE_WP);
160 Test::ScopedCstr vendor;
161 ASSERT_IF(csr_engine_get_vendor(e.get(), &vendor.ptr), CSR_ERROR_NONE);
162 ASSERT_IF(std::string("TEST_VENDOR"), vendor.ptr);
164 Test::ScopedCstr name;
165 ASSERT_IF(csr_engine_get_name(e.get(), &name.ptr), CSR_ERROR_NONE);
166 ASSERT_IF(std::string("TEST_LOCAL_TWP_ENGINE"), name.ptr);
168 Test::ScopedCstr version;
169 ASSERT_IF(csr_engine_get_version(e.get(), &version.ptr), CSR_ERROR_NONE);
170 ASSERT_IF(std::string("0.0.1"), version.ptr);
172 Test::ScopedCstr dataVersion;
173 ASSERT_IF(csr_engine_get_version(e.get(), &dataVersion.ptr), CSR_ERROR_NONE);
174 ASSERT_IF(std::string("0.0.1"), dataVersion.ptr);
176 csr_activated_e activated;
177 ASSERT_IF(csr_engine_get_activated(e.get(), &activated), CSR_ERROR_NONE);
178 ASSERT_IF(activated, CSR_ACTIVATED);
180 csr_state_e state = CSR_ENABLE;
181 ASSERT_IF(csr_engine_set_state(e.get(), state), CSR_ERROR_NONE);
183 ASSERT_IF(csr_engine_get_state(e.get(), &state), CSR_ERROR_NONE);
184 ASSERT_IF(state, CSR_ENABLE);
189 BOOST_AUTO_TEST_CASE(set_state)
191 EXCEPTION_GUARD_START
193 Engine e(CSR_ENGINE_WP);
195 csr_state_e state = CSR_ENABLE;
198 ASSERT_IF(csr_engine_set_state(e.get(), CSR_ENABLE), CSR_ERROR_NONE);
199 ASSERT_IF(csr_engine_get_state(e.get(), &state), CSR_ERROR_NONE);
200 ASSERT_IF(state, CSR_ENABLE);
203 auto c = Test::Context<csr_wp_context_h>();
204 auto context = c.get();
205 csr_wp_check_result_h result;
207 // check if engine is working well
208 ASSERT_IF(csr_wp_check_url(context, RISK_HIGH_URL, &result), CSR_ERROR_NONE);
211 ASSERT_IF(csr_engine_set_state(e.get(), CSR_DISABLE), CSR_ERROR_NONE);
212 ASSERT_IF(csr_engine_get_state(e.get(), &state), CSR_ERROR_NONE);
213 ASSERT_IF(state, CSR_DISABLE);
216 ASSERT_IF(csr_wp_check_url(context, RISK_HIGH_URL, &result), CSR_ERROR_ENGINE_DISABLED);
219 ASSERT_IF(csr_engine_set_state(e.get(), CSR_ENABLE), CSR_ERROR_NONE);
220 ASSERT_IF(csr_engine_get_state(e.get(), &state), CSR_ERROR_NONE);
221 ASSERT_IF(state, CSR_ENABLE);
224 ASSERT_IF(csr_wp_check_url(context, RISK_HIGH_URL, &result), CSR_ERROR_NONE);
230 BOOST_AUTO_TEST_SUITE_END() // WP
231 BOOST_AUTO_TEST_SUITE_END() // API_ENGINE_MANAGER