Browse Source

+ tests

master
Alex 'AdUser' Z 7 years ago
parent
commit
3845d3238e
  1. 46
      tests/filelist.c
  2. 49
      tests/group.c

46
tests/filelist.c

@ -0,0 +1,46 @@
#include <assert.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "../src/filelist.h"
int main() {
filelist_t *list = NULL;
int ret = 0;
list = filelist_create(0);
assert(list != NULL);
assert(list->size == 0);
assert(list->caps == 0);
assert(list->files == NULL);
ret = filelist_append(list, "test");
assert(ret == 1);
assert(list->size == 1);
assert(list->caps >= list->size);
assert(list->files != NULL);
assert(strcmp(list->files[0], "test") == 0);
filelist_del(list, 1);
assert(list->size == 0);
assert(list->caps >= list->size);
/* trigger list expand */
for (int i = list->caps; i >= 0; i--) {
ret = filelist_append(list, "test");
assert(ret > 0);
}
filelist_set(list, 17, "test2");
filelist_set(list, 17, "test3");
filelist_free(list);
assert(list->size == 0);
assert(list->caps == 0);
free(list);
return EXIT_SUCCESS;
}

49
tests/group.c

@ -0,0 +1,49 @@
#include <assert.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "../src/group.h"
int main() {
group_t *group;
bool ret;
group = group_create(7, 0);
assert(group != NULL);
assert(group->num == 7);
assert(group->ids == NULL);
assert(group->caps == 0);
assert(group->size == 0);
ret = group_append(group, 17);
assert(ret == true);
assert(group->size == 1);
assert(group->caps >= group->size);
assert(group->ids != NULL);
ret = group_append(group, 19);
assert(ret == true);
assert(group->size == 2);
ret = group_append(group, 21);
assert(ret == true);
assert(group->size == 3);
ret = group_append(group, 17); /* duplicate */
assert(ret == true);
assert(group->size == 3);
/* trigger group expand */
for (int i = group->caps, n = 46; i >= 0; i--, n++)
group_append(group, n);
group_free(group);
assert(group->size == 0);
assert(group->caps == 0);
free(group);
return EXIT_SUCCESS;
}
Loading…
Cancel
Save