#include "SlimFunctions.h" #include #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(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; }