-
Notifications
You must be signed in to change notification settings - Fork 9
/
data_test.c
169 lines (159 loc) · 4.83 KB
/
data_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
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
#include "data.h"
#include <check.h>
#define T0_BYTE(data,byte,exp) ck_assert_uint_eq( \
data_t0_analyze((data),(byte)), (exp))
START_TEST(t0_empty_ack)
{
struct data data;
data_init(&data);
// Get data, 4 bytes
T0_BYTE(&data, 0x00, CONTINUE);
T0_BYTE(&data, 0xCA, CONTINUE);
T0_BYTE(&data, 0x01, CONTINUE);
T0_BYTE(&data, 0x00, CONTINUE);
T0_BYTE(&data, 0x04, T0_DATA_CMD_HEADER);
// ACK
T0_BYTE(&data, 0xCA, T0_DATA_ACK);
// Remaining bytes
T0_BYTE(&data, 0x01, CONTINUE);
T0_BYTE(&data, 0x02, CONTINUE);
T0_BYTE(&data, 0x03, CONTINUE);
T0_BYTE(&data, 0x04, T0_DATA_RESP_BODY);
// Extra ACKs, no data remaining
T0_BYTE(&data, 0xCA, T0_DATA_ACK);
T0_BYTE(&data, 0xCA, T0_DATA_ACK);
T0_BYTE(&data, 0xCA, T0_DATA_ACK);
// Status bytes
T0_BYTE(&data, 0x90, CONTINUE);
T0_BYTE(&data, 0x00, T0_DATA_RESP_SW);
}
END_TEST
START_TEST(t0_null_procedure_byte)
{
struct data data;
data_init(&data);
// Get data, 4 bytes
T0_BYTE(&data, 0x00, CONTINUE);
T0_BYTE(&data, 0xCA, CONTINUE);
T0_BYTE(&data, 0x01, CONTINUE);
T0_BYTE(&data, 0x00, CONTINUE);
T0_BYTE(&data, 0x04, T0_DATA_CMD_HEADER);
// NULL procedure byte
T0_BYTE(&data, 0x60, T0_DATA_NULL);
T0_BYTE(&data, 0x60, T0_DATA_NULL);
T0_BYTE(&data, 0x60, T0_DATA_NULL);
T0_BYTE(&data, 0x60, T0_DATA_NULL);
// ACK
T0_BYTE(&data, 0xCA, T0_DATA_ACK);
// Remaining bytes
T0_BYTE(&data, 0x01, CONTINUE);
T0_BYTE(&data, 0x02, CONTINUE);
T0_BYTE(&data, 0x03, CONTINUE);
T0_BYTE(&data, 0x04, T0_DATA_RESP_BODY);
// NULL procedure byte
T0_BYTE(&data, 0x60, T0_DATA_NULL);
T0_BYTE(&data, 0x60, T0_DATA_NULL);
// Status bytes
T0_BYTE(&data, 0x90, CONTINUE);
T0_BYTE(&data, 0x00, T0_DATA_RESP_SW);
}
END_TEST
START_TEST(t0_single_byte_transfer)
{
struct data data;
data_init(&data);
// Get data, 4 bytes
T0_BYTE(&data, 0x00, CONTINUE);
T0_BYTE(&data, 0xCA, CONTINUE);
T0_BYTE(&data, 0x01, CONTINUE);
T0_BYTE(&data, 0x00, CONTINUE);
T0_BYTE(&data, 0x04, T0_DATA_CMD_HEADER);
// Single-byte ACK
T0_BYTE(&data, 0xFF ^ 0xCA, T0_DATA_ACK);
// One byte
T0_BYTE(&data, 0x01, T0_DATA_RESP_BODY);
// Repeat
T0_BYTE(&data, 0xFF ^ 0xCA, T0_DATA_ACK);
T0_BYTE(&data, 0x02, T0_DATA_RESP_BODY);
T0_BYTE(&data, 0xFF ^ 0xCA, T0_DATA_ACK);
T0_BYTE(&data, 0x03, T0_DATA_RESP_BODY);
T0_BYTE(&data, 0xFF ^ 0xCA, T0_DATA_ACK);
T0_BYTE(&data, 0x04, T0_DATA_RESP_BODY);
// Extra single-byte acks with no data
T0_BYTE(&data, 0xFF ^ 0xCA, T0_DATA_ACK);
T0_BYTE(&data, 0xFF ^ 0xCA, T0_DATA_ACK);
// Status bytes
T0_BYTE(&data, 0x90, CONTINUE);
T0_BYTE(&data, 0x00, T0_DATA_RESP_SW);
}
END_TEST
START_TEST(t0_get_response)
{
struct data data;
data_init(&data);
// Select DF, 4 bytes
T0_BYTE(&data, 0x00, CONTINUE);
T0_BYTE(&data, 0xA4, CONTINUE);
T0_BYTE(&data, 0x04, CONTINUE);
T0_BYTE(&data, 0x00, CONTINUE);
T0_BYTE(&data, 0x04, T0_DATA_CMD_HEADER);
// ACK
T0_BYTE(&data, 0xA4, T0_DATA_ACK);
// DF name
T0_BYTE(&data, 'T', CONTINUE);
T0_BYTE(&data, 'e', CONTINUE);
T0_BYTE(&data, 's', CONTINUE);
T0_BYTE(&data, 't', T0_DATA_CMD_BODY);
// Status bytes
T0_BYTE(&data, 0x61, CONTINUE);
T0_BYTE(&data, 0x03, T0_DATA_RESP_SW);
// Get response
T0_BYTE(&data, 0x00, CONTINUE);
T0_BYTE(&data, 0xC0, CONTINUE);
T0_BYTE(&data, 0x00, CONTINUE);
T0_BYTE(&data, 0x00, CONTINUE);
T0_BYTE(&data, 0x03, T0_DATA_CMD_HEADER);
// ACK
T0_BYTE(&data, 0xC0, T0_DATA_ACK);
// Response bytes
T0_BYTE(&data, 'Y', CONTINUE);
T0_BYTE(&data, 'a', CONTINUE);
T0_BYTE(&data, 'y', T0_DATA_RESP_BODY);
// Status bytes
T0_BYTE(&data, 0x90, CONTINUE);
T0_BYTE(&data, 0x00, T0_DATA_RESP_SW);
}
END_TEST
START_TEST(t0_unknown_direction)
{
struct data data;
data_init(&data);
// Unknown command with 4 bytes payload
T0_BYTE(&data, 0x00, CONTINUE);
T0_BYTE(&data, 0x23, CONTINUE);
T0_BYTE(&data, 0x00, CONTINUE);
T0_BYTE(&data, 0x00, CONTINUE);
T0_BYTE(&data, 0x04, T0_DATA_CMD_HEADER);
// ACK
T0_BYTE(&data, 0x23, T0_DATA_ACK);
// Payload bytes
T0_BYTE(&data, 0x01, CONTINUE);
T0_BYTE(&data, 0x02, CONTINUE);
T0_BYTE(&data, 0x03, CONTINUE);
T0_BYTE(&data, 0x04, T0_DATA_UNK_BODY);
// Status bytes
T0_BYTE(&data, 0x90, CONTINUE);
T0_BYTE(&data, 0x00, T0_DATA_RESP_SW);
}
END_TEST
Suite* data_tests(void) {
Suite* suite = suite_create("data");
TCase* test = tcase_create("data");
tcase_add_test(test, t0_empty_ack);
tcase_add_test(test, t0_null_procedure_byte);
tcase_add_test(test, t0_single_byte_transfer);
tcase_add_test(test, t0_get_response);
tcase_add_test(test, t0_unknown_direction);
suite_add_tcase(suite, test);
return suite;
}