2 * Copyright 2019 AT&T Intellectual Property
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 // Created by adi ENZEL on 11/19/19.
22 #include "ReadConfigFile.h"
23 #include <mdclog/mdclog.h>
24 #include <cgreen/cgreen.h>
30 using namespace cgreen;
34 mdclog_attr_init(&attr);
35 mdclog_attr_set_ident(attr, "TestConfiguration");
37 mdclog_attr_destroy(attr);
40 Ensure(Cgreen, fileNotExist) {
41 ReadConfigFile conf {};
42 assert_that( conf.openConfigFile("kuku") == -1);
45 Ensure(Cgreen, fileExists) {
46 ReadConfigFile conf {};
47 assert_that(conf.openConfigFile("config/config.conf") == 0);
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");
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");
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);
76 Ensure(Cgreen, badValues) {
77 ReadConfigFile conf {};
78 assert_that(conf.openConfigFile("config/config.bad") == 0);
81 Ensure(Cgreen, sectionTest) {
82 ReadConfigFile conf {};
83 assert_that(conf.openConfigFile("config/config.sec") == 0);
84 assert_that(conf.getIntValue("config.nano") == 38000);
87 Ensure(Cgreen, sectionBadTest) {
88 ReadConfigFile conf {};
89 assert_that(conf.openConfigFile("config/config.secbad") == -1);
90 //assert_that(conf.getIntValue("config.nano") == 38000);
93 int main(const int argc, char **argv) {
94 mdclog_severity_t loglevel = MDCLOG_INFO;
96 mdclog_level_set(loglevel);
98 //TestSuite *suite = create_test_suite();
99 TestSuite *suite = create_named_test_suite_(__FUNCTION__, __FILE__, __LINE__);
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);
110 return cgreen::run_test_suite(suite, create_text_reporter());