-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestAction.c
More file actions
53 lines (39 loc) · 1.08 KB
/
testAction.c
File metadata and controls
53 lines (39 loc) · 1.08 KB
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
#include <assert.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "action.h"
void test_action_simple(void);
void test_action_loop(void);
int main(int argc, char **argv) {
printf("Running test_action_simple()\n");
test_action_simple();
printf("Running test_action_loop()\n");
test_action_loop();
return 0;
}
void test_action_simple(void) {
char *buffer;
Action action;
buffer = malloc(20);
memcpy(buffer, "thisrandomteststring", 20);
action = bs_new_action(HASH_CHUNK, buffer);
assert(memcmp(action->data, buffer, 20) == 0);
assert(action->type == HASH_CHUNK);
free(buffer);
free(action);
}
void test_action_loop(void) {
int i;
char *buffer, *format = "thisisrandomteststringnumber%04d";
Action action;
buffer = malloc(32);
for (i = 0; i < 10000; i++) {
snprintf(buffer, 32, format, i);
action = bs_new_action(HASH_CHUNK, buffer);
assert(memcmp(action->data, buffer, 32) == 0);
assert(action->type == HASH_CHUNK);
free(action);
}
free(buffer);
}