259 lines
6.9 KiB
C
259 lines
6.9 KiB
C
/*
|
|
* Unit test for tree.h
|
|
*/
|
|
|
|
|
|
#include "libisofs.h"
|
|
#include "tree.h"
|
|
#include "test.h"
|
|
|
|
#include <assert.h>
|
|
#include <stdio.h>
|
|
#include <sys/types.h>
|
|
#include <sys/stat.h>
|
|
#include <unistd.h>
|
|
#include <string.h>
|
|
|
|
|
|
static void test_new_root() {
|
|
struct iso_tree_node_dir *root;
|
|
printf("Testing iso_tree_new_root()...");
|
|
root = iso_tree_new_root();
|
|
assert(root);
|
|
assert(root->nchildren == 0);
|
|
assert(root->children == NULL);
|
|
assert(root->node.parent == NULL);
|
|
assert(root->node.name == NULL);
|
|
assert( S_ISDIR(root->node.attrib.st_mode) );
|
|
printf("\tOK\n");
|
|
}
|
|
|
|
static void test_add_dir() {
|
|
struct iso_tree_node_dir *root;
|
|
struct iso_tree_node_dir *dir;
|
|
|
|
printf("Testing iso_tree_add_dir()...");
|
|
root = iso_tree_new_root();
|
|
dir = iso_tree_add_dir(root, "New dir name");
|
|
assert(root);
|
|
assert(dir);
|
|
assert(dir->node.parent == root);
|
|
assert(root->nchildren == 1);
|
|
assert(root->children[0] == (struct iso_tree_node *)dir);
|
|
assert( strcmp(dir->node.name, "New dir name") == 0 );
|
|
assert( S_ISDIR(dir->node.attrib.st_mode) );
|
|
printf("\tOK\n");
|
|
}
|
|
|
|
static void test_add_file() {
|
|
struct iso_tree_node_dir *root;
|
|
struct iso_tree_node_file *file;
|
|
|
|
printf("Testing iso_tree_add_file()...");
|
|
root = iso_tree_new_root();
|
|
file = (struct iso_tree_node_file *)
|
|
iso_tree_add_file(root, "/tmp/libisofs_test/README");
|
|
assert(root);
|
|
assert(file);
|
|
assert(file->node.parent == root);
|
|
assert(root->nchildren == 1);
|
|
assert(root->children[0] == (struct iso_tree_node *)file);
|
|
assert( strcmp(file->node.name, "README") == 0 );
|
|
assert( strcmp(file->path, "/tmp/libisofs_test/README") == 0 );
|
|
assert( S_ISREG(file->node.attrib.st_mode) );
|
|
printf("\tOK\n");
|
|
}
|
|
|
|
static void test_add_symlink() {
|
|
struct iso_tree_node_dir *root;
|
|
struct iso_tree_node *lnk;
|
|
|
|
printf("Testing iso_tree_add_symlink()...");
|
|
root = iso_tree_new_root();
|
|
lnk = iso_tree_add_symlink(root, "read", "/tmp/libisofs_test/README");
|
|
assert(root);
|
|
assert(lnk);
|
|
assert(lnk->parent == root);
|
|
assert(root->nchildren == 1);
|
|
assert(root->children[0] == (struct iso_tree_node *)lnk);
|
|
assert( strcmp(lnk->name, "read") == 0 );
|
|
assert( strcmp( ((struct iso_tree_node_symlink*)lnk)->dest,
|
|
"/tmp/libisofs_test/README") == 0 );
|
|
assert( S_ISLNK(lnk->attrib.st_mode) );
|
|
printf("\tOK\n");
|
|
}
|
|
|
|
static void test_radd_dir() {
|
|
struct iso_tree_node_dir *root;
|
|
struct iso_tree_node_dir *dir;
|
|
struct iso_tree_node_dir *child;
|
|
struct iso_tree_radd_dir_behavior behavior = {0,0,0};
|
|
|
|
printf("Testing iso_tree_radd_dir()...");
|
|
root = iso_tree_new_root();
|
|
assert(root);
|
|
|
|
dir = iso_tree_radd_dir(root, "/tmp/libisofs_test", &behavior);
|
|
assert(dir);
|
|
assert(dir->node.parent == root);
|
|
assert(root->nchildren == 1);
|
|
assert(root->children[0] == (struct iso_tree_node *)dir);
|
|
assert( S_ISDIR(dir->node.attrib.st_mode) );
|
|
assert(dir->nchildren == 5);
|
|
assert( strcmp(dir->node.name, "libisofs_test") == 0 );
|
|
|
|
/* test _root_ children */
|
|
child = (struct iso_tree_node_dir *)dir->children[0];
|
|
assert( S_ISDIR(child->node.attrib.st_mode) );
|
|
assert( child->nchildren == 2);
|
|
assert( strcmp(child->node.name, "dir1") == 0 );
|
|
|
|
child = (struct iso_tree_node_dir *)dir->children[1];
|
|
assert( S_ISDIR(child->node.attrib.st_mode) );
|
|
assert( child->nchildren == 0);
|
|
assert( strcmp(child->node.name, "dir2") == 0 );
|
|
|
|
//TODO write really full test
|
|
|
|
printf("\tOK\n");
|
|
//iso_tree_print( (struct iso_tree_node *)root, 4 );
|
|
}
|
|
|
|
void test_tree()
|
|
{
|
|
test_new_root();
|
|
test_add_dir();
|
|
test_add_file();
|
|
test_add_symlink();
|
|
test_radd_dir();
|
|
}
|
|
/*
|
|
* Unit test for tree.h
|
|
*/
|
|
|
|
|
|
#include "libisofs.h"
|
|
#include "tree.h"
|
|
#include "test.h"
|
|
|
|
#include <assert.h>
|
|
#include <stdio.h>
|
|
#include <sys/types.h>
|
|
#include <sys/stat.h>
|
|
#include <unistd.h>
|
|
#include <string.h>
|
|
|
|
|
|
static void test_new_root() {
|
|
struct iso_tree_node_dir *root;
|
|
printf("Testing iso_tree_new_root()...");
|
|
root = iso_tree_new_root();
|
|
assert(root);
|
|
assert(root->nchildren == 0);
|
|
assert(root->children == NULL);
|
|
assert(root->node.parent == NULL);
|
|
assert(root->node.name == NULL);
|
|
assert( S_ISDIR(root->node.attrib.st_mode) );
|
|
printf("\tOK\n");
|
|
}
|
|
|
|
static void test_add_dir() {
|
|
struct iso_tree_node_dir *root;
|
|
struct iso_tree_node_dir *dir;
|
|
|
|
printf("Testing iso_tree_add_dir()...");
|
|
root = iso_tree_new_root();
|
|
dir = iso_tree_add_dir(root, "New dir name");
|
|
assert(root);
|
|
assert(dir);
|
|
assert(dir->node.parent == root);
|
|
assert(root->nchildren == 1);
|
|
assert(root->children[0] == (struct iso_tree_node *)dir);
|
|
assert( strcmp(dir->node.name, "New dir name") == 0 );
|
|
assert( S_ISDIR(dir->node.attrib.st_mode) );
|
|
printf("\tOK\n");
|
|
}
|
|
|
|
static void test_add_file() {
|
|
struct iso_tree_node_dir *root;
|
|
struct iso_tree_node_file *file;
|
|
|
|
printf("Testing iso_tree_add_file()...");
|
|
root = iso_tree_new_root();
|
|
file = (struct iso_tree_node_file *)
|
|
iso_tree_add_file(root, "/tmp/libisofs_test/README");
|
|
assert(root);
|
|
assert(file);
|
|
assert(file->node.parent == root);
|
|
assert(root->nchildren == 1);
|
|
assert(root->children[0] == (struct iso_tree_node *)file);
|
|
assert( strcmp(file->node.name, "README") == 0 );
|
|
assert( strcmp(file->path, "/tmp/libisofs_test/README") == 0 );
|
|
assert( S_ISREG(file->node.attrib.st_mode) );
|
|
printf("\tOK\n");
|
|
}
|
|
|
|
static void test_add_symlink() {
|
|
struct iso_tree_node_dir *root;
|
|
struct iso_tree_node *lnk;
|
|
|
|
printf("Testing iso_tree_add_symlink()...");
|
|
root = iso_tree_new_root();
|
|
lnk = iso_tree_add_symlink(root, "read", "/tmp/libisofs_test/README");
|
|
assert(root);
|
|
assert(lnk);
|
|
assert(lnk->parent == root);
|
|
assert(root->nchildren == 1);
|
|
assert(root->children[0] == (struct iso_tree_node *)lnk);
|
|
assert( strcmp(lnk->name, "read") == 0 );
|
|
assert( strcmp( ((struct iso_tree_node_symlink*)lnk)->dest,
|
|
"/tmp/libisofs_test/README") == 0 );
|
|
assert( S_ISLNK(lnk->attrib.st_mode) );
|
|
printf("\tOK\n");
|
|
}
|
|
|
|
static void test_radd_dir() {
|
|
struct iso_tree_node_dir *root;
|
|
struct iso_tree_node_dir *dir;
|
|
struct iso_tree_node_dir *child;
|
|
struct iso_tree_radd_dir_behavior behavior = {0,0,0};
|
|
|
|
printf("Testing iso_tree_radd_dir()...");
|
|
root = iso_tree_new_root();
|
|
assert(root);
|
|
|
|
dir = iso_tree_radd_dir(root, "/tmp/libisofs_test", &behavior);
|
|
assert(dir);
|
|
assert(dir->node.parent == root);
|
|
assert(root->nchildren == 1);
|
|
assert(root->children[0] == (struct iso_tree_node *)dir);
|
|
assert( S_ISDIR(dir->node.attrib.st_mode) );
|
|
assert(dir->nchildren == 5);
|
|
assert( strcmp(dir->node.name, "libisofs_test") == 0 );
|
|
|
|
/* test _root_ children */
|
|
child = (struct iso_tree_node_dir *)dir->children[0];
|
|
assert( S_ISDIR(child->node.attrib.st_mode) );
|
|
assert( child->nchildren == 2);
|
|
assert( strcmp(child->node.name, "dir1") == 0 );
|
|
|
|
child = (struct iso_tree_node_dir *)dir->children[1];
|
|
assert( S_ISDIR(child->node.attrib.st_mode) );
|
|
assert( child->nchildren == 0);
|
|
assert( strcmp(child->node.name, "dir2") == 0 );
|
|
|
|
//TODO write really full test
|
|
|
|
printf("\tOK\n");
|
|
//iso_tree_print( (struct iso_tree_node *)root, 4 );
|
|
}
|
|
|
|
void test_tree()
|
|
{
|
|
test_new_root();
|
|
test_add_dir();
|
|
test_add_file();
|
|
test_add_symlink();
|
|
test_radd_dir();
|
|
}
|