-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_tests.c
51 lines (41 loc) · 1.58 KB
/
config_tests.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
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include "action.h"
#include "config.h"
#include "hash.h"
int main() {
// basic config
char *filename = "config_examples/basic";
parse_config(filename);
parent_action_t *parent = get_action("act1");
assert(parent->num_children == 3);
assert(strcmp(parent->command, "\"Action 1 called!\"") == 0);
// multiple parents
filename = "config_examples/multiple_parents";
parse_config(filename);
parent_action_t* parent1 = get_action("act1");
parent_action_t* parent2 = get_action("act2");
assert(parent1 != NULL);
assert(parent2 != NULL);
assert(parent1->num_children == 3);
assert(strcmp(parent1->command, "\"Action 1 called!\"") == 0);
assert(parent2->num_children == 4);
assert(strcmp(parent2->command, "\"Action 2 called!\"") == 0);
filename = "config_examples/undo_actions";
parse_config(filename);
parent_action_t* parent3 = get_action("act4");
parent_action_t* parent4 = get_action("act5");
assert(parent3 != NULL);
assert(parent4 != NULL);
assert(parent3->num_children == 3);
assert(strcmp(parent1->command, "\"Action 1 called!\"") == 0);
assert(parent3->children[0].num_undos == 1);
assert(parent3->children[0].undoes[0] == 0);
assert(parent3->children[1].num_undos == 0);
assert(parent3->children[2].num_undos == 2);
assert(parent3->children[2].undoes[0] == 2);
assert(parent3->children[2].undoes[1] == 0);
assert(parent4->num_children == 4);
assert(strcmp(parent2->command, "\"Action 2 called!\"") == 0);
}