Add tests for creating fifo and device nodes

This commit is contained in:
Nathan Fisher 2023-09-15 19:15:01 -04:00
parent 7671e9e29e
commit d12eb47b25
3 changed files with 44 additions and 0 deletions

View file

@ -67,6 +67,8 @@ tests += linkmap_init
tests += linkmap_put
tests += create_dir_node
tests += create_symlink_node
tests += create_fifo_node
tests += create_dev_node
total != echo $(tests) | wc -w | awk '{ print $$1 }'

20
test/create_dev_node.c Normal file
View file

@ -0,0 +1,20 @@
#include <assert.h>
#include <sys/stat.h>
#include "haggis.h"
int main() {
haggis_linkmap *map;
haggis_node *node;
char *path = "/dev/null";
map = haggis_linkmap_init();
assert(map != NULL);
node = haggis_create_node(path, sha256, map);
assert(node->filetype.tag == character || node->filetype.tag == block);
assert(node->filetype.f_type.dev.major.val == 1);
assert(node->filetype.f_type.dev.minor.val == 3);
haggis_node_deinit(node);
haggis_linkmap_deinit(map);
return 0;
}

22
test/create_fifo_node.c Normal file
View file

@ -0,0 +1,22 @@
#include <assert.h>
#include <fcntl.h>
#include <string.h>
#include <sys/stat.h>
#include "haggis.h"
int main() {
haggis_linkmap *map;
haggis_node *node;
char *path = "output/fifo";
map = haggis_linkmap_init();
assert(map != NULL);
assert(mkfifo(path, 0644) == 0);
node = haggis_create_node(path, sha256, map);
assert(node->filetype.tag == fifo);
assert(memcmp(path, node->name.name, 11) == 0);
haggis_node_deinit(node);
haggis_linkmap_deinit(map);
return 0;
}