Impl full-stack of engine-manager feature
[platform/upstream/csr-framework.git] / test / test-api-engine-manager.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-api-engine-manager.cpp
18  * @author      Kyungwook Tak (k.tak@samsung.com)
19  * @version     1.0
20  * @brief       CSR Engine manager API test
21  */
22 #include <csr/engine-manager.h>
23
24 #include <string>
25 #include <boost/test/unit_test.hpp>
26
27 #include "test-common.h"
28
29 namespace {
30
31 class Engine {
32 public:
33         Engine(csr_engine_id_e id)
34         {
35                 ASSERT_IF(csr_get_current_engine(id, &m_engine), CSR_ERROR_NONE);
36         }
37
38         ~Engine()
39         {
40                 ASSERT_IF(csr_engine_destroy(m_engine), CSR_ERROR_NONE);
41         }
42
43         csr_engine_h &get(void)
44         {
45                 return m_engine;
46         }
47
48 private:
49         csr_engine_h m_engine;
50 };
51
52 } // namespace anonymous
53
54 BOOST_AUTO_TEST_SUITE(API_ENGINE_MANAGER)
55 BOOST_AUTO_TEST_SUITE(CS)
56
57 BOOST_AUTO_TEST_CASE(fields_getters)
58 {
59         EXCEPTION_GUARD_START
60
61         Engine e(CSR_ENGINE_CS);
62
63         const char *vendor = nullptr;
64         ASSERT_IF(csr_engine_get_vendor(e.get(), &vendor), CSR_ERROR_NONE);
65         ASSERT_IF(std::string("TEST_VENDOR"), vendor);
66
67         const char *name = nullptr;
68         ASSERT_IF(csr_engine_get_name(e.get(), &name), CSR_ERROR_NONE);
69         ASSERT_IF(std::string("TEST_LOCAL_TCS_ENGINE"), name);
70
71         const char *version = nullptr;
72         ASSERT_IF(csr_engine_get_version(e.get(), &version), CSR_ERROR_NONE);
73         ASSERT_IF(std::string("0.0.1"), version);
74
75         const char *dataVersion = nullptr;
76         ASSERT_IF(csr_engine_get_version(e.get(), &dataVersion), CSR_ERROR_NONE);
77         ASSERT_IF(std::string("0.0.1"), dataVersion);
78
79         csr_activated_e activated;
80         ASSERT_IF(csr_engine_get_activated(e.get(), &activated), CSR_ERROR_NONE);
81         ASSERT_IF(activated, CSR_ACTIVATED);
82
83         csr_state_e state = CSR_ENABLE;
84         ASSERT_IF(csr_engine_set_state(e.get(), state), CSR_ERROR_NONE);
85
86         ASSERT_IF(csr_engine_get_state(e.get(), &state), CSR_ERROR_NONE);
87         ASSERT_IF(state, CSR_ENABLE);
88
89         EXCEPTION_GUARD_END
90 }
91
92 BOOST_AUTO_TEST_SUITE_END() // CS
93
94 BOOST_AUTO_TEST_SUITE(WP)
95
96 BOOST_AUTO_TEST_CASE(fields_getters)
97 {
98         EXCEPTION_GUARD_START
99
100         Engine e(CSR_ENGINE_WP);
101
102         const char *vendor = nullptr;
103         ASSERT_IF(csr_engine_get_vendor(e.get(), &vendor), CSR_ERROR_NONE);
104         ASSERT_IF(std::string("TEST_VENDOR"), vendor);
105
106         const char *name = nullptr;
107         ASSERT_IF(csr_engine_get_name(e.get(), &name), CSR_ERROR_NONE);
108         ASSERT_IF(std::string("TEST_LOCAL_TWP_ENGINE"), name);
109
110         const char *version = nullptr;
111         ASSERT_IF(csr_engine_get_version(e.get(), &version), CSR_ERROR_NONE);
112         ASSERT_IF(std::string("0.0.1"), version);
113
114         const char *dataVersion = nullptr;
115         ASSERT_IF(csr_engine_get_version(e.get(), &dataVersion), CSR_ERROR_NONE);
116         ASSERT_IF(std::string("0.0.1"), dataVersion);
117
118         csr_activated_e activated;
119         ASSERT_IF(csr_engine_get_activated(e.get(), &activated), CSR_ERROR_NONE);
120         ASSERT_IF(activated, CSR_ACTIVATED);
121
122         csr_state_e state = CSR_ENABLE;
123         ASSERT_IF(csr_engine_set_state(e.get(), state), CSR_ERROR_NONE);
124
125         ASSERT_IF(csr_engine_get_state(e.get(), &state), CSR_ERROR_NONE);
126         ASSERT_IF(state, CSR_ENABLE);
127
128         EXCEPTION_GUARD_END
129 }
130
131 BOOST_AUTO_TEST_SUITE_END() // WP
132 BOOST_AUTO_TEST_SUITE_END() // API_ENGINE_MANAGER