[CAPI Changed] Enum value names and scan cloud
[platform/upstream/csr-framework.git] / test / test-main.cpp
1 /*
2  *  Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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
15  */
16 /*
17  * @file       test-main.cpp
18  * @author     Kyungwook Tak(k.tak@samsung.com)
19  * @version    1.0
20  */
21 #define BOOST_TEST_MODULE CSR_API_TEST
22 #include <boost/test/unit_test.hpp>
23 #include <boost/test/unit_test_log.hpp>
24 #include <boost/test/results_reporter.hpp>
25 #include <colour_log_formatter.h>
26
27 #include <csr-engine-manager.h>
28
29 namespace {
30
31 csr_state_e setEngineState(csr_engine_id_e id, csr_state_e state)
32 {
33         csr_engine_h handle;
34         auto ret = csr_get_current_engine(id, &handle);
35         if (ret != CSR_ERROR_NONE)
36                 throw std::logic_error("Failed to csr_get_current_engine.");
37
38         csr_state_e current;
39         ret = csr_engine_get_state(handle, &current);
40         if (ret != CSR_ERROR_NONE)
41                 throw std::logic_error("Failed to csr_get_state.");
42
43         if (current == state)
44                 return current;
45
46         ret = csr_engine_set_state(handle, state);
47         if (ret != CSR_ERROR_NONE)
48                 throw std::logic_error("Failed to csr_engine_set_state.");
49
50         return current;
51 }
52
53 }
54
55 struct TestConfig {
56         TestConfig()
57         {
58                 boost::unit_test::unit_test_log.set_threshold_level(
59                         boost::unit_test::log_test_units);
60                 boost::unit_test::results_reporter::set_level(boost::unit_test::SHORT_REPORT);
61                 boost::unit_test::unit_test_log.set_formatter(new Csr::Test::colour_log_formatter);
62         }
63 };
64
65 bool isEngineInitialized = false;
66 struct Initializer {
67         Initializer()
68         {
69                 m_oldCsState = setEngineState(CSR_ENGINE_CS, CSR_STATE_ENABLE);
70                 m_oldWpState = setEngineState(CSR_ENGINE_WP, CSR_STATE_ENABLE);
71         }
72
73         ~Initializer()
74         {
75                 setEngineState(CSR_ENGINE_CS, m_oldCsState);
76                 setEngineState(CSR_ENGINE_WP, m_oldWpState);
77         }
78
79         csr_state_e m_oldCsState;
80         csr_state_e m_oldWpState;
81 };
82
83 BOOST_GLOBAL_FIXTURE(TestConfig)
84 BOOST_GLOBAL_FIXTURE(Initializer)