Commit 93c5cf4f authored by Oliver Heidmann's avatar Oliver Heidmann
Browse files

fixed bandit tests

parent 28d98b0d
......@@ -4,15 +4,32 @@
#include "../../src/modules.h"
#include "../../src/operator_help.h"
#include "../../src/process_int.h"
#include "../../src/cdo_options.h"
#include "test_module_list.h"
#include <iostream>
ProcessManager g_processManager;
void
cdoExit()
{
g_processManager.killProcesses();
exit(EXIT_FAILURE);
}
go_bandit([]() {
add_module("in1_out1", module_in1_out1);
add_module("in2_out1", module_in2_out1);
add_module("inVariable_out1", module_inVariable_out1);
Cdo::progname = "cdo_bandit_test";
CdoOut::setExitFunction(cdoExit);
CdoOut::setContextFunction(processInqPrompt);
modules={
{"in1_out1", module_in1_out1},
{"in2_out1", module_in2_out1},
{"inVariable_out1", module_inVariable_out1}};
registerOperatorsFromModules();
// this test checks if operators with non variable input numbers can be
// chained
......
......@@ -4,20 +4,31 @@
#include "../../src/modules.h"
#include "../../src/operator_help.h"
#include "../../src/process_int.h"
#include "../../src/cdo_options.h"
#include "test_module_list.h"
#include <iostream>
/* clang-format off */
using namespace snowhouse;
ProcessManager g_processManager;
void
cdoExit()
{
g_processManager.killProcesses();
exit(EXIT_FAILURE);
}
go_bandit([]() {
//==============================================================================
add_module("in0_out1", module_in0_out1);
add_module("in1_out1", module_in1_out1);
add_module("in2_out1", module_in2_out1);
add_module("inVariable_out0", module_inVariable_out0);
Cdo::progname = "cdo_bandit_test";
CdoOut::setExitFunction(cdoExit);
CdoOut::setContextFunction(processInqPrompt);
modules={
{"in0_out1", module_in0_out1},
{"in1_out1", module_in1_out1},
{"in2_out1", module_in2_out1},
{"inVariable_out0", module_inVariable_out0}};
registerOperatorsFromModules();
/* clang-format on */
......@@ -29,140 +40,141 @@ go_bandit([]() {
int result_process;
int expected_process;
bandit::before_each([&]() { g_processManager.clearProcesses(); });
bandit::before_each([&]() {
g_processManager.clearProcesses(); });
//-----------------------------Test_01------------------------------------------
//------------------------------------------------------------------------------
bandit::describe("Negative test for unprocessed inputs", [&]() {
/* clang-format off */
/* clang-format off */
std::vector<const char *> argv_unprocessedInput{
"-in2_out1", "-in0_out1", "-in0_out1", "-in0_out1", "out" };
/* clang-format on */
parseStatus = g_processManager.createProcessesFromInput(
argv_unprocessedInput.size(), &argv_unprocessedInput[0]);
/* clang-format on */
parseStatus = g_processManager.createProcessesFromInput(
argv_unprocessedInput.size(), &argv_unprocessedInput[0]);
result_parse = static_cast<int>(parseStatus);
expected_parse = static_cast<int>(ParseStatus::UnprocessedInput);
result_parse = static_cast<int>(parseStatus);
expected_parse = static_cast<int>(ParseStatus::UnprocessedInput);
bandit::it("has unprocessed Input", [&]() {
AssertThat(result_parse, snowhouse::Equals(expected_parse));
});
bandit::it("has unprocessed Input", [&]() {
AssertThat(result_parse, snowhouse::Equals(expected_parse));
});
});
//-----------------------------Test_02------------------------------------------
//------------------------------------------------------------------------------
bandit::describe("Negative test for miss placement of brackets", [&]() {
/* clang-format off */
/* clang-format off */
std::vector<const char *> argv_missingCloseBracket{
"-in2_out1", "[", "-in0_out1", "-in0_out1", "out"
};
/* clang-format on */
parseStatus = g_processManager.createProcessesFromInput(
argv_missingCloseBracket.size(), &argv_missingCloseBracket[0]);
result_parse = static_cast<int>(parseStatus);
expected_parse = static_cast<int>(ParseStatus::ClosingBracketMissing);
bandit::it("it misses a ']'", [&]() {
AssertThat(result_parse, snowhouse::Equals(expected_parse));
});
/* clang-format on */
parseStatus = g_processManager.createProcessesFromInput(
argv_missingCloseBracket.size(), &argv_missingCloseBracket[0]);
result_parse = static_cast<int>(parseStatus);
expected_parse = static_cast<int>(ParseStatus::ClosingBracketMissing);
bandit::it("it misses a ']'", [&]() {
AssertThat(result_parse, snowhouse::Equals(expected_parse));
});
});
//-----------------------------Test_03------------------------------------------
//------------------------------------------------------------------------------
bandit::describe("Negative test for miss placement of brackets", [&]() {
/* clang-format off */
/* clang-format off */
std::vector<const char *> argv_missingOpenBracket{
"-in2_out1", "-in0_out1", "-in0_out1", "]", "out"
};
/* clang-format on */
parseStatus = g_processManager.createProcessesFromInput(
argv_missingOpenBracket.size(), &argv_missingOpenBracket[0]);
result_parse = static_cast<int>(parseStatus);
expected_parse = static_cast<int>(ParseStatus::OpenBracketMissing);
bandit::it("it misses a '['", [&]() {
AssertThat(result_parse, snowhouse::Equals(expected_parse));
});
/* clang-format on */
parseStatus = g_processManager.createProcessesFromInput(
argv_missingOpenBracket.size(), &argv_missingOpenBracket[0]);
result_parse = static_cast<int>(parseStatus);
expected_parse = static_cast<int>(ParseStatus::OpenBracketMissing);
bandit::it("it misses a '['", [&]() {
AssertThat(result_parse, snowhouse::Equals(expected_parse));
});
});
//-----------------------------Test_04------------------------------------------
//------------------------------------------------------------------------------
bandit::describe("Negative test for miss placement of brackets", [&]() {
/* clang-format off */
/* clang-format off */
std::vector<const char *> argv_wrongBracketTooMany{
"-in2_out1", "[", "-in0_out1", "-in0_out1", "-in0_out1", "]", "out"
};
/* clang-format on */
parseStatus = g_processManager.createProcessesFromInput(
argv_wrongBracketTooMany.size(), &argv_wrongBracketTooMany[0]);
processStatus = g_processManager.getProcess(0).checkStreamCnt();
result_parse = static_cast<int>(parseStatus);
expected_parse = static_cast<int>(ParseStatus::Ok);
result_process = static_cast<int>(processStatus);
expected_process = static_cast<int>(ProcessStatus::TooManyStreams);
bandit::it("this one has too many inputs", [&]() {
AssertThat(result_parse, Is().EqualTo(expected_parse));
AssertThat(result_process, Is().EqualTo(expected_process));
});
/* clang-format on */
parseStatus = g_processManager.createProcessesFromInput(
argv_wrongBracketTooMany.size(), &argv_wrongBracketTooMany[0]);
processStatus = g_processManager.getProcess(0).checkStreamCnt();
result_parse = static_cast<int>(parseStatus);
expected_parse = static_cast<int>(ParseStatus::Ok);
result_process = static_cast<int>(processStatus);
expected_process = static_cast<int>(ProcessStatus::TooManyStreams);
bandit::it("this one has too many inputs", [&]() {
AssertThat(result_parse, Is().EqualTo(expected_parse));
AssertThat(result_process, Is().EqualTo(expected_process));
});
});
//-----------------------------Test_05------------------------------------------
//------------------------------------------------------------------------------
bandit::describe("Negative test for miss placement of brackets", [&]() {
/* clang-format off */
/* clang-format off */
std::vector<const char *> argv_wrongBracketTooFew{
"-in2_out1", "[", "-in0_out1", "]", "out"
};
/* clang-format on */
parseStatus = g_processManager.createProcessesFromInput(
argv_wrongBracketTooFew.size(), &argv_wrongBracketTooFew[0]);
processStatus = g_processManager.getProcess(0).checkStreamCnt();
bandit::it("this one has too few inputs", [&]() {
AssertThat(static_cast<int>(parseStatus),
Is().EqualTo(static_cast<int>(ParseStatus::Ok)));
AssertThat(static_cast<int>(processStatus),
Is().EqualTo(static_cast<int>(ProcessStatus::TooFewStreams)));
});
/* clang-format on */
parseStatus = g_processManager.createProcessesFromInput(
argv_wrongBracketTooFew.size(), &argv_wrongBracketTooFew[0]);
processStatus = g_processManager.getProcess(0).checkStreamCnt();
bandit::it("this one has too few inputs", [&]() {
AssertThat(static_cast<int>(parseStatus),
Is().EqualTo(static_cast<int>(ParseStatus::Ok)));
AssertThat(static_cast<int>(processStatus),
Is().EqualTo(static_cast<int>(ProcessStatus::TooFewStreams)));
});
});
//-----------------------------Test_06------------------------------------------
//------------------------------------------------------------------------------
bandit::describe("Negative test for unprocessed inputs", [&]() {
/* clang-format off */
/* clang-format off */
std::vector<const char *> argv_missingOutFileOperHasDash{
"-in2_out1"};
/* clang-format on */
parseStatus = g_processManager.createProcessesFromInput(
argv_missingOutFileOperHasDash.size(),
&argv_missingOutFileOperHasDash[0]);
/* clang-format on */
parseStatus = g_processManager.createProcessesFromInput(
argv_missingOutFileOperHasDash.size(),
&argv_missingOutFileOperHasDash[0]);
result_parse = static_cast<int>(parseStatus);
expected_parse = static_cast<int>(ParseStatus::MissingOutFile);
result_parse = static_cast<int>(parseStatus);
expected_parse = static_cast<int>(ParseStatus::MissingOutFile);
bandit::it("has unprocessed Input", [&]() {
AssertThat(result_parse, snowhouse::Equals(expected_parse));
});
bandit::it("has unprocessed Input", [&]() {
AssertThat(result_parse, snowhouse::Equals(expected_parse));
});
});
//-----------------------------Test_06------------------------------------------
//------------------------------------------------------------------------------
bandit::describe("Negative test for unprocessed inputs", [&]() {
/* clang-format off */
/* clang-format off */
std::vector<const char *> argv_missingOutFileOperHasntDash{
"in2_out1"};
/* clang-format on */
parseStatus = g_processManager.createProcessesFromInput(
argv_missingOutFileOperHasntDash.size(),
&argv_missingOutFileOperHasntDash[0]);
/* clang-format on */
parseStatus = g_processManager.createProcessesFromInput(
argv_missingOutFileOperHasntDash.size(),
&argv_missingOutFileOperHasntDash[0]);
result_parse = static_cast<int>(parseStatus);
expected_parse = static_cast<int>(ParseStatus::MissingOutFile);
result_parse = static_cast<int>(parseStatus);
expected_parse = static_cast<int>(ParseStatus::MissingOutFile);
bandit::it("has unprocessed Input", [&]() {
AssertThat(result_parse, snowhouse::Equals(expected_parse));
});
bandit::it("has unprocessed Input", [&]() {
AssertThat(result_parse, snowhouse::Equals(expected_parse));
});
});
});
......
#include "bandit/bandit/bandit.h"
//BANDIT NEEDS TO BE INCLUDED FIRST!!!
// BANDIT NEEDS TO BE INCLUDED FIRST!!!
#include "../../src/modules.h"
#include "../../src/operator_help.h"
#include "../../src/process_int.h"
#include "../../src/cdo_options.h"
#include "test_module_list.h"
#include <iostream>
ProcessManager g_processManager;
void
cdoExit()
{
g_processManager.killProcesses();
exit(EXIT_FAILURE);
}
go_bandit([]() {
Cdo::progname = "cdo_bandit_test";
CdoOut::setExitFunction(cdoExit);
CdoOut::setContextFunction(processInqPrompt);
bandit::describe("Process creation", []() {
// inVariable_out0: child oper 2
// inVariable_out1: child oper3 and oper4:
// oper3: infile: 1
// oper4: infile 2
// outfile: filled by inVariable_out0
std::vector<std::vector<const char *>> test_argvs = {{"-inVariable_out0","in1","in2"},{"-inVariable_out0","in1"}, {"-inVariable_out1","in1","in2", "ofile1"},{"-inVariable_out1","in1","ofile2"}};
std::vector<std::vector<const char *>> test_argvs
= { { "-inVariable_out0", "in1", "in2" },
{ "-inVariable_out0", "in1" },
{ "-inVariable_out1", "in1", "in2", "ofile1" },
{ "-inVariable_out1", "in1", "ofile2" } };
const int numberOfRuns = 4;
unsigned int expectedInputForRun[numberOfRuns] = {2,1,2,1};
unsigned int expectedOutputs[numberOfRuns] = {0,0,1,1};
unsigned int expectedInputForRun[numberOfRuns] = { 2, 1, 2, 1 };
unsigned int expectedOutputs[numberOfRuns] = { 0, 0, 1, 1 };
/*clang-format off*/
// Name Func Help oper mod in
// num out
add_module("inVariable_out0",module_inVariable_out0);
add_module("inVariable_out1",module_inVariable_out1);
modules = {
{"inVariable_out0",module_inVariable_out0},
{"inVariable_out1",module_inVariable_out1}
};
registerOperatorsFromModules();
/*clang-format on*/
unsigned int i;
for (i = 0; i < numberOfRuns; i++) {
g_processManager.createProcessesFromInput(test_argvs[i].size(),&test_argvs[i][0]);
for (i = 0; i < numberOfRuns; i++)
{
g_processManager.createProcessesFromInput(test_argvs[i].size(),
&test_argvs[i][0]);
auto process = g_processManager.getProcess(0);
std::string runInfo = std::string(g_processManager.getProcess(0).operatorName) + " in run " + std::to_string(i + 1);
bandit::it(
"created inputs for:"+ runInfo, [&]() {
AssertThat(
process.childProcesses.size() + process.inputStreams.size(),
snowhouse::Equals(expectedInputForRun[i]));
});
bandit::it("created outputs for: " + runInfo, [&]() {
AssertThat(
process.parentProcesses.size() + process.outputStreams.size(),
snowhouse::Equals(expectedOutputs[i]));
});
bandit::it("created right amount of processes",[&]() {
AssertThat(1, snowhouse::Equals(g_processManager.processNums()));
std::string runInfo
= std::string(g_processManager.getProcess(0).operatorName)
+ " in run " + std::to_string(i + 1);
bandit::it("created inputs for:" + runInfo, [&]() {
AssertThat(process.childProcesses.size()
+ process.inputStreams.size(),
snowhouse::Equals(expectedInputForRun[i]));
});
bandit::it("created outputs for: " + runInfo, [&]() {
AssertThat(process.parentProcesses.size()
+ process.outputStreams.size(),
snowhouse::Equals(expectedOutputs[i]));
});
bandit::it("created right amount of processes", [&]() {
AssertThat(1, snowhouse::Equals(g_processManager.processNums()));
});
g_processManager.clearProcesses();
}
g_processManager.clearProcesses();
}
});
});
int main(int argc, char **argv) {
int
main(int argc, char **argv)
{
PROCESS_MANAGER=1;
int result = bandit::run(argc, argv);
return result;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment