1 #ifndef DOSBOX_TEST_FIXTURE_H
2 #define DOSBOX_TEST_FIXTURE_H
3 
4 #include <iterator>
5 #include <string>
6 
7 #include <gtest/gtest.h>
8 
9 #define SDL_MAIN_HANDLED
10 
11 #include "control.h"
12 
13 class DOSBoxTestFixture : public ::testing::Test {
14 public:
DOSBoxTestFixture()15 	DOSBoxTestFixture()
16 	        : arg_c_str("-conf tests/files/dosbox-staging-tests.conf\0"),
17 	          argv{arg_c_str},
18 	          com_line(1, argv),
19 	          config(Config(&com_line))
20 	{
21 		control = &config;
22 	}
23 
SetUp()24 	void SetUp() override
25 	{
26 		// Create DOSBox Staging's config directory, which is a
27 		// pre-requisite that's asserted during the Init process.
28 		//
29 		CROSS_DetermineConfigPaths();
30 		const auto config_path = CROSS_GetPlatformConfigDir();
31 		SETUP_ParseConfigFiles(config_path);
32 
33 		Section *_sec;
34 		// This will register all the init functions, but won't run them
35 		DOSBOX_Init();
36 
37 		for (auto section_name : sections) {
38 			_sec = control->GetSection(section_name);
39 			// NOTE: Some of the sections will return null pointers,
40 			// if you add a section below, make sure to test for
41 			// nullptr before executing early init.
42 			_sec->ExecuteEarlyInit();
43 		}
44 
45 		for (auto section_name : sections) {
46 			_sec = control->GetSection(section_name);
47 			_sec->ExecuteInit();
48 		}
49 	}
50 
TearDown()51 	void TearDown() override
52 	{
53 		std::vector<std::string>::reverse_iterator r = sections.rbegin();
54 		for (; r != sections.rend(); ++r)
55 			control->GetSection(*r)->ExecuteDestroy();
56 	}
57 
58 private:
59 	char const *arg_c_str;
60 	const char *argv[1];
61 	CommandLine com_line;
62 	Config config;
63 	// Only init these sections for our tests
64 	std::vector<std::string> sections{"dosbox", "cpu",      "mixer",
65 	                                  "midi",   "sblaster", "speaker",
66 	                                  "serial", "dos",      "autoexec"};
67 };
68 
69 #endif
70