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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
|
#include "main.h"
#include "./testSuiteLoader.h"
#include "../../xml/obj_xml.h"
#include <api/service/waservicefactory.h>
#include <strsafe.h>
typedef void (CALLBACK *LOADERTAGCALLBACK)(TestSuiteLoader* /*loader*/, const wchar_t* /*value*/);
typedef struct LOADERTAG
{
const wchar_t *name;
LOADERTAGCALLBACK callback;
} LOADERTAG;
static void CALLBACK
LoaderTag_ImageBase(TestSuiteLoader *loader, const wchar_t *value)
{
String_Free(loader->imageBase);
loader->imageBase = String_Duplicate(value);
}
static void CALLBACK
LoaderTag_Connect(TestSuiteLoader *loader, const wchar_t *value)
{
if (IS_STRING_EMPTY(value))
return;
const wchar_t *block, *cursor;
char *name;
size_t length;
block = value;
cursor = block;
for(;;)
{
if (L'\0' == *cursor ||
L';' == *cursor ||
L',' == *cursor)
{
if (block < cursor)
{
length = cursor - block;
name = String_ToAnsi(CP_UTF8, 0, block, (int)length, NULL, NULL);
if (NULL != name)
loader->connectList.push_back(name);
}
if (L'\0' == *cursor)
break;
block = cursor + 1;
}
cursor++;
}
//loader->SetImageBase(value);
}
static const LOADERTAG knownTags[LOADER_TAG_MAX] =
{
{L"imageBase", LoaderTag_ImageBase},
{L"connect", LoaderTag_Connect},
};
TestSuiteLoader::TestSuiteLoader()
: imageBase(NULL)
{
}
TestSuiteLoader::~TestSuiteLoader()
{
size_t index;
index = connectList.size();
while(index--)
{
AnsiString_Free(connectList[index]);
}
String_Free(imageBase);
}
BOOL TestSuiteLoader::Load(const wchar_t *path, TestSuite *testSuite)
{
BOOL result;
HANDLE fileHandle;
obj_xml *reader;
if (NULL == testSuite)
return FALSE;
if (NULL == path || L'\0' == *path)
return FALSE;
fileHandle = CreateFile(path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
if (INVALID_HANDLE_VALUE == fileHandle)
return FALSE;
result = FALSE;
if (NULL != WASABI_API_SVC)
{
waServiceFactory *sf = WASABI_API_SVC->service_getServiceByGuid(obj_xmlGUID);
reader = (NULL != sf) ? (obj_xml*)sf->getInterface() : NULL;
if (NULL != reader)
{
if (OBJ_XML_SUCCESS == reader->xmlreader_open())
{
reader->xmlreader_registerCallback(L"testprovider\fimageBase", this);
reader->xmlreader_registerCallback(L"testprovider\fconnect", this);
ZeroMemory(hitList, sizeof(hitList));
deviceParser.Begin(reader, testSuite);
typeParser.Begin(reader, testSuite);
connectionParser.Begin(reader, testSuite);
commandParser.Begin(reader, testSuite);
result = FeedFile(reader, fileHandle, 8192);
deviceParser.End();
typeParser.End();
connectionParser.End();
commandParser.End();
reader->xmlreader_close();
testSuite->SetIconBase(imageBase);
testSuite->SetConnectList(connectList.begin(), connectList.size());
}
sf->releaseInterface(reader);
}
}
CloseHandle(fileHandle);
return result;
}
BOOL TestSuiteLoader::FeedFile(obj_xml *reader, HANDLE fileHandle, DWORD bufferSize)
{
BOOL result;
DWORD read;
BYTE *buffer;
int readerCode;
if (NULL == reader ||
INVALID_HANDLE_VALUE == fileHandle ||
0 == bufferSize)
{
return FALSE;
}
buffer = (BYTE*)malloc(bufferSize);
if (NULL == buffer)
return FALSE;
readerCode = OBJ_XML_SUCCESS;
result = TRUE;
for(;;)
{
if (FALSE == ReadFile(fileHandle, buffer, bufferSize, &read, NULL) || 0 == read)
{
result = FALSE;
if (0 == read && OBJ_XML_SUCCESS == readerCode)
reader->xmlreader_feed(0, 0);
break;
}
readerCode = reader->xmlreader_feed(buffer, read);
if (OBJ_XML_SUCCESS != readerCode)
{
result = FALSE;
break;
}
}
free(buffer);
return result;
}
void TestSuiteLoader::Event_XmlStartElement(const wchar_t *xmlpath, const wchar_t *xmltag, ifc_xmlreaderparams *params)
{
elementString.Clear();
}
void TestSuiteLoader::Event_XmlEndElement(const wchar_t *xmlpath, const wchar_t *xmltag)
{
for (size_t i = 0; i < LOADER_TAG_MAX; i++)
{
if (FALSE == hitList[i] &&
CSTR_EQUAL == CompareString(CSTR_INVARIANT, NORM_IGNORECASE, knownTags[i].name, -1, xmltag, -1))
{
knownTags[i].callback(this, elementString.Get());
hitList[i] = TRUE;
break;
}
}
}
void TestSuiteLoader::Event_XmlCharData(const wchar_t *xmlpath, const wchar_t *xmltag, const wchar_t *value)
{
elementString.Append(value);
}
void TestSuiteLoader::Event_XmlError(int linenum, int errcode, const wchar_t *errstr)
{
elementString.Clear();
}
#define CBCLASS TestSuiteLoader
START_DISPATCH;
VCB(ONSTARTELEMENT, Event_XmlStartElement)
VCB(ONENDELEMENT, Event_XmlEndElement)
VCB(ONCHARDATA, Event_XmlCharData)
VCB(ONERROR, Event_XmlError)
END_DISPATCH;
#undef CBCLASS
|