Add test for extracting directory nodes
This commit is contained in:
parent
d63b9f29d0
commit
ba69c2b8e9
4 changed files with 41 additions and 1 deletions
3
haggis.c
3
haggis.c
|
@ -651,6 +651,9 @@ haggis_node* haggis_create_node(
|
|||
return NULL;
|
||||
} else if (S_ISDIR(st.st_mode)) {
|
||||
node->filetype.tag = directory;
|
||||
body.f_name = strndup(file, PATH_MAX);
|
||||
msg = haggis_msg_init(NodeCreated, body);
|
||||
haggis_mq_push(mq, msg);
|
||||
} else if (S_ISFIFO(st.st_mode)) {
|
||||
node->filetype.tag = fifo;
|
||||
if (st.st_nlink > 1) {
|
||||
|
|
|
@ -72,6 +72,7 @@ tests += create_dev_node
|
|||
tests += create_file_node
|
||||
tests += mq_push_pop
|
||||
tests += extract_dev_node
|
||||
tests += extract_dir_node
|
||||
|
||||
total != echo $(tests) | wc -w | awk '{ print $$1 }'
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ int main() {
|
|||
haggis_linkmap *map = NULL;
|
||||
haggis_mq mq;
|
||||
haggis_msg *msg;
|
||||
char *path = "/dev/null", *msg_text;
|
||||
char *path = "/dev/null";
|
||||
int ret = 0;
|
||||
|
||||
if (geteuid() != 0)
|
||||
|
|
36
test/extract_dir_node.c
Normal file
36
test/extract_dir_node.c
Normal file
|
@ -0,0 +1,36 @@
|
|||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "haggis.h"
|
||||
#include "mq.h"
|
||||
|
||||
int main() {
|
||||
haggis_node *node = NULL;
|
||||
haggis_linkmap *map = NULL;
|
||||
haggis_mq mq;
|
||||
haggis_msg *msg = NULL;
|
||||
char *path = "output";
|
||||
int ret = 0;
|
||||
|
||||
map = haggis_linkmap_init();
|
||||
assert(map != NULL);
|
||||
assert(haggis_mq_init(&mq) == 0);
|
||||
node = haggis_create_node(path, skip, map, &mq);
|
||||
assert(node != NULL);
|
||||
assert(node->filetype.tag == directory);
|
||||
assert(memcmp(node->name.name, path, 6) == 0);
|
||||
msg = haggis_mq_pop(&mq);
|
||||
assert(msg->tag == NodeCreated);
|
||||
assert(memcmp(msg->body.f_name, path, 6) == 0);
|
||||
haggis_msg_deinit(msg);
|
||||
ret = haggis_extract_node("output/extracted", node, &mq);
|
||||
assert(ret == 0);
|
||||
msg = haggis_mq_pop(&mq);
|
||||
assert(msg->tag == NodeExtracted);
|
||||
assert(memcmp(msg->body.f_name, path, 6) == 0);
|
||||
haggis_msg_deinit(msg);
|
||||
haggis_node_deinit(node);
|
||||
haggis_linkmap_deinit(map);
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Reference in a new issue