Copy latest code to master
[ric-plt/e2.git] / RIC-E2-TERMINATION / TEST / ConfigurationFileTest / testConfigFile.cpp
1 /*
2  * Copyright 2019 AT&T Intellectual Property
3  * Copyright 2019 Nokia
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 //
19 // Created by adi ENZEL on 11/19/19.
20 //
21
22 #include "ReadConfigFile.h"
23 #include <mdclog/mdclog.h>
24 #include <cgreen/cgreen.h>
25
26 Describe(Cgreen);
27 BeforeEach(Cgreen) {}
28 AfterEach(Cgreen) {}
29
30 using namespace cgreen;
31
32 void init_log() {
33     mdclog_attr_t *attr;
34     mdclog_attr_init(&attr);
35     mdclog_attr_set_ident(attr, "TestConfiguration");
36     mdclog_init(attr);
37     mdclog_attr_destroy(attr);
38 }
39
40 Ensure(Cgreen, fileNotExist) {
41     ReadConfigFile  conf {};
42     assert_that( conf.openConfigFile("kuku") == -1);
43 }
44
45 Ensure(Cgreen, fileExists) {
46     ReadConfigFile  conf {};
47     assert_that(conf.openConfigFile("config/config.conf") == 0);
48 }
49
50 Ensure(Cgreen, goodparams) {
51     ReadConfigFile  conf {};
52     assert_that(conf.openConfigFile("config/config.conf") == 0);
53     assert_that(conf.getIntValue("nano") == 38000);
54     assert_that(conf.getStringValue("loglevel") == "info");
55     assert_that(conf.getStringValue("volume") == "log");
56
57 }
58
59 Ensure(Cgreen, badParams) {
60     ReadConfigFile  conf {};
61     assert_that(conf.openConfigFile("config/config.conf") == 0);
62     assert_that(conf.getIntValue("nano") != 38002);
63     assert_that(conf.getStringValue("loglevel") != "");
64     assert_that(conf.getStringValue("volume") != "bob");
65     assert_that(conf.getStringValue("volum") != "bob");
66 }
67
68 Ensure(Cgreen, wrongType) {
69     ReadConfigFile  conf {};
70     assert_that(conf.openConfigFile("config/config.conf") == 0);
71     assert_that(conf.getStringValue("nano") != "debug");
72     assert_that(conf.getIntValue("loglevel") != 3);
73     assert_that(conf.getDoubleValue("loglevel") != 3.0);
74 }
75
76 Ensure(Cgreen, badValues) {
77     ReadConfigFile  conf {};
78     assert_that(conf.openConfigFile("config/config.bad") == 0);
79 }
80
81 Ensure(Cgreen, sectionTest) {
82     ReadConfigFile  conf {};
83     assert_that(conf.openConfigFile("config/config.sec") == 0);
84     assert_that(conf.getIntValue("config.nano") == 38000);
85 }
86
87 Ensure(Cgreen, sectionBadTest) {
88     ReadConfigFile  conf {};
89     assert_that(conf.openConfigFile("config/config.secbad") == -1);
90     //assert_that(conf.getIntValue("config.nano") == 38000);
91 }
92
93 int main(const int argc, char **argv) {
94     mdclog_severity_t loglevel = MDCLOG_INFO;
95     init_log();
96     mdclog_level_set(loglevel);
97
98     //TestSuite *suite = create_test_suite();
99     TestSuite *suite = create_named_test_suite_(__FUNCTION__, __FILE__, __LINE__);
100
101     add_test_with_context(suite, Cgreen, fileNotExist);
102     add_test_with_context(suite, Cgreen, fileExists);
103     add_test_with_context(suite, Cgreen, goodparams);
104     add_test_with_context(suite, Cgreen, badParams);
105     add_test_with_context(suite, Cgreen, wrongType);
106     add_test_with_context(suite, Cgreen, badValues);
107     add_test_with_context(suite, Cgreen, sectionTest);
108     add_test_with_context(suite, Cgreen, sectionBadTest);
109
110     return cgreen::run_test_suite(suite, create_text_reporter());
111
112 }