-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tests.cpp
99 lines (81 loc) · 2.37 KB
/
Tests.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include "Tests.h"
#include <iostream>
#include <string>
#include <boost/archive/tmpdir.hpp>
#include <boost/archive/xml_oarchive.hpp>
#include "Module.h"
void Testing::SaveXMLtest()
{
Module testms=genTestModule();
saveModuleXML(testms, "testModule.xml");
saveModuleBIN(testms, "testModule.bin");
}
void Testing::LoadXMLtest()
{
Module testms;
loadModuleXML(testms, "testModule.xml");
}
void Testing::SystemExecute()
{
system("ls");
}
void Testing::BoostExecutionTest()
{
}
void Testing::ExecutionTest()
{
//fix to use Boost::process
/*std::string outputstring;
redi::ipstream lsExecution("ls");
std::getline(lsExecution,outputstring);
std::cout << lsExecution <<std:: endl;
const redi::pstreams::pmode mode = redi::pstreams::pstdout|redi::pstreams::pstderr;
redi::ipstream child("echo OUT1; sleep 1; echo ERR >&2; sleep 1; echo OUT2; ls", mode);
char buf[1024];
std::streamsize n;
bool finished[2] = { false, false };
while (!finished[0] || !finished[1])
{
if (!finished[0])
{
while ((n = child.err().readsome(buf, sizeof(buf))) > 0)
std::cerr.write(buf, n).flush();
if (child.eof())
{
finished[0] = true;
if (!finished[1])
child.clear();
}
}
if (!finished[1])
{
while ((n = child.out().readsome(buf, sizeof(buf))) > 0)
std::cout.write(buf, n).flush();
if (child.eof())
{
finished[1] = true;
if (!finished[0])
child.clear();
}
}
}*/
boost::process::ipstream pipe_stream;
//gcc --version
boost::process::child c("dir", boost::process::std_out > pipe_stream);
std::string line;
while (pipe_stream && std::getline(pipe_stream, line) && !line.empty())
std::cerr << line << std::endl;
c.wait();
Module testms=genTestModule();
testms.Execute(0);
}
Module Testing::genTestModule()
{
Module ms;
ms.Name="Test Module";
ms.Description="This is a module used only for testing purposes.";
ms.os.push_back("Windows XP"); ms.os.push_back("Windows Vista");
ms.input_variables.push_back(std::pair<std::string, std::string>("Test","test"));
ms.Script="#!/bin/bash\necho \"hello world\\n\"";
return ms;
}