-
Notifications
You must be signed in to change notification settings - Fork 3
/
api_test.c
94 lines (86 loc) · 5.42 KB
/
api_test.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
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
//
// Created by kirill on 04.06.2020.
//
#include <ccos_image.h>
#include <ccos_private.h>
#include <stdio.h>
#include <string.h>
#define __STR(X) #X
#define STR(X) __STR(X)
#define ASSERT(CONDITION) \
do { \
if (!(CONDITION)) { \
fprintf(stderr, "%s:%d: \"%s\" Failed!\n", __FUNCTION__, __LINE__, STR(CONDITION)); \
return -1; \
} \
} while (0)
uint8_t test_inode_data[] = {
0x98U, 0x00U, 0x00U, 0x00U, 0x84U, 0xD0U, 0x00U, 0x00U, 0x15U, 0x47U, 0x52U, 0x69U, 0x44U, 0x50U, 0x61U, 0x69U,
0x6EU, 0x74U, 0x7EU, 0x52U, 0x75U, 0x6EU, 0x20U, 0x43U, 0x61U, 0x6EU, 0x76U, 0x61U, 0x73U, 0x7EU, 0x00U, 0x00U,
0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U,
0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U,
0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U,
0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0xC0U, 0x07U, 0x0AU, 0x1DU, 0x0EU, 0x02U, 0x09U,
0x01U, 0x02U, 0x2FU, 0x01U, 0x05U, 0x00U, 0xC0U, 0x07U, 0x0CU, 0x11U, 0x10U, 0x0FU, 0x0EU, 0x03U, 0x02U, 0x60U,
0x01U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U,
0x00U, 0x00U, 0x00U, 0x05U, 0x00U, 0x00U, 0x00U, 0x00U, 0x01U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U,
0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x01U, 0x03U, 0x01U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U,
0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x05U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U,
0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U,
0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x3FU, 0x7DU, 0x98U, 0x00U, 0x00U, 0x00U,
0x1DU, 0x56U, 0xFFU, 0xFFU, 0x98U, 0x00U, 0xFFU, 0xFFU, 0x99U, 0x00U, 0x9AU, 0x00U, 0x9BU, 0x00U, 0x9CU, 0x00U,
0x9DU, 0x00U, 0x9EU, 0x00U, 0x9FU, 0x00U, 0xA0U, 0x00U, 0xA1U, 0x00U, 0xA2U, 0x00U, 0xA3U, 0x00U, 0xA4U, 0x00U,
0xA5U, 0x00U, 0xA6U, 0x00U, 0xA7U, 0x00U, 0xA8U, 0x00U, 0xA9U, 0x00U, 0xAAU, 0x00U, 0xABU, 0x00U, 0xACU, 0x00U,
0xADU, 0x00U, 0xA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xFDU, 0x00U, 0xFEU, 0x00U, 0xFFU, 0x00U, 0x00U, 0x01U, 0x01U, 0x01U, 0x02U, 0x01U, 0xFFU, 0xFFU, 0xFFU, 0xFFU,
0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU,
0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU,
0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU,
0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU,
0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0x00U, 0x00U, 0x00U, 0x00U};
int check_image_test() {
uint8_t data[0x200] = {0};
ASSERT(ccos_check_image(data) == 0);
data[0] = 'I';
data[1] = 'M';
data[2] = 'D';
data[3] = ' ';
ASSERT(ccos_check_image(data) == -1);
memset(data, 0, 0x200);
data[0] = 0xEB;
data[2] = 0x90;
*((uint16_t *)(&data[0x1FE])) = 0xAA55;
ASSERT(ccos_check_image(data) == -1);
return 0;
}
int ccos_get_file_version_test() {
ccos_inode_t inode = *((ccos_inode_t *)&test_inode_data);
version_t version = ccos_get_file_version(&inode);
ASSERT(version.major == 3);
ASSERT(version.minor == 1);
ASSERT(version.patch == 5);
return 0;
}
int ccos_get_file_name_test() {
ccos_inode_t inode = *((ccos_inode_t *)&test_inode_data);
short_string_t *name = ccos_get_file_name(&inode);
ASSERT(name->length == 21);
ASSERT(!strncmp(name->data, "GRiDPaint~Run Canvas~", name->length));
return 0;
}
int main() {
ASSERT(check_image_test() == 0);
ASSERT(ccos_get_file_version_test() == 0);
ASSERT(ccos_get_file_name_test() == 0);
printf("All tests completed!\n");
return 0;
}