-
Notifications
You must be signed in to change notification settings - Fork 0
/
json_parser.c
67 lines (63 loc) · 2.11 KB
/
json_parser.c
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
#define UNICODE
#include <windows.h>
#include <stdio.h>
#include "./json_parser.h"
#include "./file_reader.h"
int main() {
COLORREF labelColor = RGB(1, 2, 3);
COLORREF borderColor = RGB(4, 5, 6);
Hook hooks[3] = {
{ .call = expectObject, .frameCount = 0 },
{
.call = parseColor,
.param = NULL,
.dest = &borderColor,
.frames = { "borderColor" },
.frameCount = 1,
},
{
.call = parseColor,
.param = NULL,
.dest = &labelColor,
.frames = { "labelColor" },
.frameCount = 1,
},
};
LPCBYTE stop;
LPBYTE buffer = readFile(L"settings.json", &stop);
int lineNumber;
LPCWSTR error = parseJSON(buffer, stop, hooks, 3, &lineNumber);
free(buffer);
if (error) { wprintf(L"%s\n", error); }
wprintf(
L"labelColor: red = %d, green = %d, blue = %d\n",
GetRValue(labelColor), GetGValue(labelColor), GetBValue(labelColor)
);
wprintf(
L"borderColor: red = %d, green = %d, blue = %d\n",
GetRValue(borderColor), GetGValue(borderColor), GetBValue(borderColor)
);
WCHAR path[MAX_PATH] = L"../JSONTestSuite/test_parsing/";
LPWSTR name = path + wcsnlen(path, MAX_PATH);
// https://docs.microsoft.com/en-us/windows/win32/fileio/listing-the-files-in-a-directory
WIN32_FIND_DATA info;
wcsncpy(name, L"*", path + MAX_PATH - name);
HANDLE find = FindFirstFile(path, &info);
if (find == INVALID_HANDLE_VALUE) { return 1; }
do {
if (info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { continue; }
wcsncpy(name, info.cFileName, path + MAX_PATH - name);
LPCBYTE stop;
LPBYTE buffer = readFile(path, &stop);
LPCWSTR error = parseJSON(buffer, stop, NULL, 0, &lineNumber);
if (error || info.cFileName[0] == L'n') {
wprintf(
L"%-50s %s\n", info.cFileName, error ? error : L"No error!"
);
}
free(buffer);
} while (FindNextFile(find, &info));
FindClose(find);
wprintf(L"tests complete\n");
return 0;
}