-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.c
44 lines (35 loc) · 1.07 KB
/
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
#include "hydra.h"
#include <string.h>
#include <assert.h>
#include <stdio.h>
void TestStart(char *name) {
setbuf(stdout, NULL);
printf("-- Testing %s\n", name);
}
void TestNewCommand() {
TestStart("NewCommand");
Command *cmd = NewCommand('k', "name", "command");
assert(cmd != NULL);
assert(cmd->key == 'k');
assert(cmd->name != NULL && strcmp(cmd->name, "name") == 0);
assert(cmd->command != NULL && strcmp(cmd->command, "command") == 0);
assert(cmd->children == NULL);
assert(cmd->next == NULL);
}
void TestCommandAddChild() {
TestStart("CommandAddChild");
Command *parent = NewCommand(0, 0, 0);
Command *firstChild = NewCommand('a', 0, 0);
Command *secondChild = NewCommand('b', 0, 0);
Command *thirdChild = NewCommand('c', 0, 0);
CommandAddChild(parent, thirdChild);
CommandAddChild(parent, firstChild);
CommandAddChild(parent, secondChild);
assert(parent->children == firstChild);
assert(parent->children->next == secondChild);
assert(parent->children->next->next == thirdChild);
}
int main() {
TestNewCommand();
TestCommandAddChild();
}