Fawkes API Fawkes Development Version
gtest_fawkes.cpp
1/***************************************************************************
2 * gtest_fawkes.cpp - Unit testing in a Fawkes plugin requiring the framework
3 *
4 *
5 * Created: Aug 24, 2016 11:40:46 PM 2016
6 * Copyright 2016 Frederik Zwilling
7 ****************************************************************************/
8
9/* This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Library General Public License for more details.
18 *
19 * Read the full text in the LICENSE.GPL file in the doc directory.
20 */
21
22#include <gtest/gtest.h>
23
24#include <stdexcept>
25
26//for running fawkes in main
27#include <baseapp/run.h>
28#include <config/yaml.h>
29#include <core/exception.h>
30#include <utils/misc/string_conversions.h>
31
32#include <cstdio>
33
34//TEST(GTestTest, TestsWorking)
35//{
36// ASSERT_EQ(1, 3-2);
37//}
38
39/** GTest main function starting fawkes with test plugins
40 * test plugins implement tests and call the RUN_ALL_TESTS function
41 * @param argc argument count
42 * @param argv array of arguments
43 */
44int
45main(int argc, char **argv)
46{
47 ::testing::InitGoogleTest(&argc, argv);
48 try {
49 int retval = 0;
50
51 //get config values
52 std::string cfg_path = fawkes::StringConversions::resolve_path("@CONFDIR@/conf.d/gtest.yaml");
53 printf("Config path: %s\n", cfg_path.c_str());
55 config.load(cfg_path.c_str());
56 std::string plugins =
57 config.get_string("gtest/plugin-dependencies") + "," + config.get_string("gtest/test-plugin");
58 std::string config_path = config.get_string("gtest/config");
59
60 //init arguments to start fawkes with
61 char **fawkes_argv;
62 fawkes_argv = new char *[5];
63 fawkes_argv[0] = new char[7];
64 strcpy(fawkes_argv[0], "fawkes");
65 fawkes_argv[1] = new char[3];
66 strcpy(fawkes_argv[1], "-p");
67 fawkes_argv[2] = new char[128];
68 strcpy(fawkes_argv[2], plugins.c_str());
69 fawkes_argv[3] = new char[3];
70 strcpy(fawkes_argv[3], "-c");
71 fawkes_argv[4] = new char[128];
72 strcpy(fawkes_argv[4], config_path.c_str());
73
74 if (!fawkes::runtime::init(5, fawkes_argv, retval)) {
75 return retval;
76 }
77 fawkes::runtime::run();
78 fawkes::runtime::cleanup();
79
80 delete[] fawkes_argv;
81 } catch (fawkes::Exception &e) {
82 printf("Fawkes Test execution ended.\n");
83 // e.print_trace();
84 return 1;
85 }
86
87 return 0;
88}
virtual void load(const char *file_path)=0
Load configuration.
virtual std::string get_string(const char *path)=0
Get value from configuration which is of type string.
Base class for exceptions in Fawkes.
Definition: exception.h:36
static std::string resolve_path(std::string s)
Resolves path-string with @...@ tags.
Configuration store using YAML documents.
Definition: yaml.h:43