1 #include "bandit/bandit/bandit.h"
2 // BANDIT NEEDS TO BE INCLUDED FIRST!!!
3
4 #include "../../src/modules.h"
5 #include "../../src/process_int.h"
6 #include "../../src/cdo_options.h"
7 #include "test_module_list.h"
8 #include <iostream>
9 /* clang-format off */
10
11 using namespace snowhouse;
12 ProcessManager g_processManager;
13 void
cdoExit()14 cdoExit()
15 {
16 g_processManager.kill_processes();
17 exit(EXIT_FAILURE);
18 }
19
__anone6f12add0102() 20 go_bandit([]() {
21 //==============================================================================
22 cdo::progname = "cdo_bandit_test";
23 cdo::set_exit_function(cdoExit);
24 cdo::set_context_function(process_inq_prompt);
25
26 /* clang-format on */
27
28 ParseStatus parseStatus;
29 ProcessStatus processStatus;
30
31 int result_parse;
32 int expected_parse;
33 int result_process;
34 int expected_process;
35
36 bandit::before_each([&]() {
37 g_processManager.clear_processes(); });
38
39 //-----------------------------Test_01------------------------------------------
40 //------------------------------------------------------------------------------
41 bandit::describe("Negative test for unprocessed inputs", [&]() {
42 /* clang-format off */
43 std::vector<std::string> argv_unprocessedInput{
44 "-in2_out1", "-in0_out1", "-in0_out1", "-in0_out1", "out" };
45 /* clang-format on */
46 parseStatus = g_processManager.create_processes_from_input(
47 argv_unprocessedInput.size(), argv_unprocessedInput);
48
49 result_parse = static_cast<int>(parseStatus);
50 expected_parse = static_cast<int>(ParseStatus::UnprocessedInput);
51
52 bandit::it("has detected unprocessed Input", [&]() {
53 AssertThat(result_parse, snowhouse::Equals(expected_parse));
54 });
55 });
56
57 //-----------------------------Test_02------------------------------------------
58 //------------------------------------------------------------------------------
59 bandit::describe("Negative test for miss placement of brackets", [&]() {
60 /* clang-format off */
61 std::vector<std::string> argv_missingCloseBracket{
62 "-in2_out1", "[", "-in0_out1", "-in0_out1", "out"
63 };
64 /* clang-format on */
65 parseStatus = g_processManager.create_processes_from_input(
66 argv_missingCloseBracket.size(), argv_missingCloseBracket);
67
68 result_parse = static_cast<int>(parseStatus);
69 expected_parse = static_cast<int>(ParseStatus::ClosingBracketMissing);
70 bandit::it("it detected a missing ']'", [&]() {
71 AssertThat(result_parse, snowhouse::Equals(expected_parse));
72 });
73 });
74
75 //-----------------------------Test_03------------------------------------------
76 //------------------------------------------------------------------------------
77 bandit::describe("Negative test for miss placement of brackets", [&]() {
78 /* clang-format off */
79 std::vector<std::string> argv_missingOpenBracket{
80 "-in2_out1", "-in0_out1", "-in0_out1", "]", "out"
81 };
82 /* clang-format on */
83 parseStatus = g_processManager.create_processes_from_input(
84 argv_missingOpenBracket.size(), argv_missingOpenBracket);
85
86 result_parse = static_cast<int>(parseStatus);
87 expected_parse = static_cast<int>(ParseStatus::OpenBracketMissing);
88 bandit::it("it detected a mising '[' ", [&]() {
89 AssertThat(result_parse, snowhouse::Equals(expected_parse));
90 });
91 });
92
93 //-----------------------------Test_04------------------------------------------
94 //------------------------------------------------------------------------------
95 bandit::describe("Negative test for miss placement of brackets", [&]() {
96 /* clang-format off */
97 std::vector<std::string> argv_wrongBracketTooMany{
98 "-in2_out1", "[", "-in0_out1", "-in0_out1", "-in0_out1", "]", "out"
99 };
100 /* clang-format on */
101 parseStatus = g_processManager.create_processes_from_input(
102 argv_wrongBracketTooMany.size(), argv_wrongBracketTooMany);
103 g_processManager.get_process_from_id(0)->check_stream_cnt();
104 processStatus = g_processManager.get_process_from_id(0)->m_status;
105
106 result_parse = static_cast<int>(parseStatus);
107 expected_parse = static_cast<int>(ParseStatus::Ok);
108 result_process = static_cast<int>(processStatus);
109 expected_process = static_cast<int>(ProcessStatus::TooManyStreams);
110
111 bandit::it("detected too many inputs", [&]() {
112 AssertThat(result_parse, Is().EqualTo(expected_parse));
113 AssertThat(result_process, Is().EqualTo(expected_process));
114 });
115 });
116
117 //-----------------------------Test_05------------------------------------------
118 //------------------------------------------------------------------------------
119 bandit::describe("Negative test for miss placement of brackets", [&]() {
120 /* clang-format off */
121 std::vector<std::string> argv_wrongBracketTooFew{
122 "-in2_out1", "[", "-in0_out1", "]", "out"
123 };
124 /* clang-format on */
125 parseStatus = g_processManager.create_processes_from_input(
126 argv_wrongBracketTooFew.size(), argv_wrongBracketTooFew);
127 g_processManager.get_process_from_id(0)->check_stream_cnt();
128 processStatus = g_processManager.get_process_from_id(0)->m_status;
129
130 bandit::it("detected too few inputs", [&]() {
131 AssertThat(static_cast<int>(parseStatus),
132 Is().EqualTo(static_cast<int>(ParseStatus::Ok)));
133 AssertThat(static_cast<int>(processStatus),
134 Is().EqualTo(static_cast<int>(ProcessStatus::TooFewStreams)));
135 });
136 });
137
138 //-----------------------------Test_06------------------------------------------
139 //------------------------------------------------------------------------------
140 bandit::describe("Negative test for unprocessed inputs", [&]() {
141 /* clang-format off */
142 std::vector<std::string> argv_missingOutFileOperHasDash{
143 "-in2_out1"};
144 /* clang-format on */
145 parseStatus = g_processManager.create_processes_from_input(
146 argv_missingOutFileOperHasDash.size(),
147 argv_missingOutFileOperHasDash);
148
149 result_parse = static_cast<int>(parseStatus);
150 expected_parse = static_cast<int>(ParseStatus::MissingOutFile);
151
152 bandit::it("detected unprocessed Input", [&]() {
153 AssertThat(result_parse, snowhouse::Equals(expected_parse));
154 });
155 });
156 bandit::describe("Testing if cdo wildcards with additional unnecessary [] works", [&]() {
157 /* clang-format off */
158 std::vector<std::string> argv_unnecessaty_brackets{
159 "-in2_out1", "[", "[", "-in0_out1", "-in0_out1", "]", "]", "out"
160 };
161
162 /* clang-format on */
163 parseStatus = g_processManager.create_processes_from_input(
164 argv_unnecessaty_brackets.size(), argv_unnecessaty_brackets);
165 g_processManager.get_process_from_id(0)->check_stream_cnt();
166 processStatus = g_processManager.get_process_from_id(0)->m_status;
167
168 bandit::it("should work", [&]() {
169 AssertThat(static_cast<int>(parseStatus),
170 Is().EqualTo(static_cast<int>(ParseStatus::Ok)));
171 AssertThat(static_cast<int>(processStatus),
172 Is().EqualTo(static_cast<int>(ProcessStatus::Ok)));
173 });
174 });
175 });
176
177 //==============================================================================
178 int
main(int argc,char ** argv)179 main(int argc, char **argv)
180 {
181 int result = bandit::run(argc, argv);
182
183 return result;
184 }
185