SlimFunctions.cpp
2.66 KB
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
100
#include "SlimFunctions.h"
#include <cstring>
#include "TestManager.h"
#include "Toolbox.h"
#define MAX_ANSWER_SIZE 2048
using namespace TREPS::Common;
using namespace TREPS::Test;
typedef struct TREPSTestStruct
{
TestManagerClass testMgr;
char answer[MAX_ANSWER_SIZE];
} TREPSTestStruct;
TREPSTestStruct *castToTestStruct(void *void_self)
{
return reinterpret_cast<TREPSTestStruct*>(void_self);
}
void writeAnswer(TREPSTestStruct *self, const char *a)
{
strncpy(self->answer,a,MAX_ANSWER_SIZE-1);
self->answer[MAX_ANSWER_SIZE-1] = '\0';
}
void* TREPSTest_Create(StatementExecutor* errorHandler, SlimList* args)
{
TREPSTestStruct* self = new TREPSTestStruct;
return self;
}
void TREPSTest_Destroy(void* void_self)
{
TREPSTestStruct* self = castToTestStruct(void_self);
delete self;
}
static char* returnTest(void *void_self, SlimList *args)
{
TREPSTestStruct* self = castToTestStruct(void_self);
writeAnswer(self,"OK");
return self->answer;
}
static char* setKernelDir(void *void_self, SlimList *args)
{
TREPSTestStruct* self = castToTestStruct(void_self);
self->testMgr.setKernelDir(SlimList_GetStringAt(args, 0));
writeAnswer(self,self->testMgr.getKernelDir().c_str());
return self->answer;
}
static char* setCOTSDir(void *void_self, SlimList *args)
{
TREPSTestStruct* self = castToTestStruct(void_self);
self->testMgr.setCOTSDir(SlimList_GetStringAt(args, 0));
writeAnswer(self,self->testMgr.getCOTSDir().c_str());
return self->answer;
}
static char* executeRequestRequestValgrind(void *void_self, SlimList *args)
{
TREPSTestStruct* self = castToTestStruct(void_self);
bool useValgrind = false;
if (SlimList_GetLength(args) > 1)
{
string useVal = SlimList_GetStringAt(args, 1);
useValgrind = (useVal.compare("true") == 0);
}
if (self->testMgr.executeRequest(SlimList_GetStringAt(args, 0),useValgrind))
writeAnswer(self,"OK");
else
writeAnswer(self,"ERROR");
return self->answer;
}
static char* executeRequest(void *void_self, SlimList *args)
{
return executeRequestRequestValgrind(void_self,args);
}
static char* getResultContentFileXpath(void *void_self, SlimList *args)
{
TREPSTestStruct* self = castToTestStruct(void_self);
string output = self->testMgr.getResultVar(SlimList_GetStringAt(args, 0), SlimList_GetStringAt(args, 1));
writeAnswer(self,output.c_str());
return self->answer;
}
static char* getResultAttributeFileXpathAttribute(void *void_self, SlimList *args)
{
TREPSTestStruct* self = castToTestStruct(void_self);
string output = self->testMgr.getResultVar(SlimList_GetStringAt(args, 0), SlimList_GetStringAt(args, 1), SlimList_GetStringAt(args, 2));
writeAnswer(self,output.c_str());
return self->answer;
}