-
Notifications
You must be signed in to change notification settings - Fork 0
/
unit_tests.cpp
125 lines (87 loc) · 3.65 KB
/
unit_tests.cpp
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
#include "main_proc.h"
void test_line_split()
{
printf( "test 1\n");
pointer_on_line test;
char t_push1[10] = "PUSH 12";
test.start = t_push1;
Commands cur_cmd1 = {};
if (split_line(test, &cur_cmd1) != 0) printf("error != 0\n");
if ( ((int) cur_cmd1.cmd_num) != PUSH) printf("err in cmd number push\n");
if ( ((int) cur_cmd1.arg_num) != 12) printf("err in arg push\n");
if ( ((int) cur_cmd1.type_arg) != ELEM_T) printf("err in type_arg push\n");
printf( "test 2\n");
char t_push2[10] = "PUSH AX";
test.start = t_push2;
Commands cur_cmd2 = {};
if (split_line(test, &cur_cmd2) != 0)
printf("error != 0\n");
if (cur_cmd2.cmd_num != PUSH)
printf("err in cmd number push reg %d %d\n", PUSH, cur_cmd2.cmd_num);
if (cur_cmd2.arg_num != AX)
printf("err in arg push reg %d %d\n", AX, cur_cmd2.arg_num);
if (cur_cmd2.type_arg != REG)
printf("err in type_arg push reg %d %d\n", cur_cmd2.type_arg, REG);
printf( "test 3\n");
char test_ram1[10] = "PUSH [12]";
test.start = test_ram1;
Commands cur_cmd3 = {};
if (split_line(test, &cur_cmd3) != 0)
printf("error != 0");
if (cur_cmd3.cmd_num != PUSH)
printf("err in cmd number push ram\n");
if (cur_cmd3.arg_num != 12)
printf("err in arg push ram\n");
if (cur_cmd3.type_arg != RAM)
printf("err in type_arg push ram %d %d\n", RAM | ELEM_T, cur_cmd3.type_arg);
printf( "test 4\n");
char test_ram2[10] = "PUSH [AX]";
test.start = test_ram2;
Commands cur_cmd4 = {};
if (split_line(test, &cur_cmd4) != 0)
printf("error != 0\n");
if (cur_cmd4.cmd_num != PUSH)
printf("err in cmd number push ram reg\n");
if (cur_cmd4.arg_num != AX)
printf("err in arg push ram reg\n");
if (cur_cmd4.type_arg != (RAM | REG))
printf("111err in type_arg push ram reg %d %d\n", RAM | REG, cur_cmd4.type_arg);
printf( "test 5\n");
char test_label1[10] = ":label";
test.start = test_label1;
Commands cur_cmd5 = {};
if (split_line(test, &cur_cmd5) != 0)
printf("error != 0\n");
if (cur_cmd5.cmd_num != 0)
printf("err in cmd number label\n");
if (cur_cmd5.arg_num != 0)
printf("err in arg label\n");
if (cur_cmd5.type_arg != LABEL)
printf("err in type_arg push label %d %d\n", LABEL, cur_cmd5.type_arg);
if (strcmp(cur_cmd5.label_name, ":label"))
printf("bad label name %s\n", cur_cmd5.label_name);
printf( "test 6\n");
char test_label2[20] = "JMP something";
test.start = test_label2;
Commands cur_cmd6 = {};
if (split_line(test, &cur_cmd6) != 0) printf("error != 0\n");
if (cur_cmd6.cmd_num != JMP) printf("err in cmd number push\n");
if (cur_cmd6.arg_num != 0) printf("err in arg push\n");
if (cur_cmd6.type_arg != LABEL) printf("err in type_arg push label\n");
if (strcmp(cur_cmd6.label_name, "something")) printf("bad label name %s\n", cur_cmd6.label_name);
printf( "test 7\n");
char test_label3[15] = "JA something";
test.start = test_label3;
Commands cur_cmd7 = {};
if (split_line(test, &cur_cmd7) != 0) printf("error != 0\n");
if (cur_cmd7.cmd_num != JA) printf("err in cmd number push\n");
if (cur_cmd7.arg_num != 0) printf("err in arg push\n");
if (cur_cmd7.type_arg != LABEL) printf("err in type_arg push label\n");
if (strcmp(cur_cmd7.label_name, "something")) printf("bad label name %s\n", cur_cmd7.label_name);
printf("End of test line split\n----------------------------------------------------------------------------\n");
}
void unit_tests()
{
test_line_split();
// test_disassembler();
}