2007-06-01 12:57:09 +00:00
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
root = iso_tree_new_root();
|
2007-06-21 11:19:11 +00:00
|
|
|
CU_ASSERT_PTR_NOT_NULL(root);
|
|
|
|
CU_ASSERT_EQUAL(root->nchildren, 0);
|
|
|
|
CU_ASSERT_PTR_NULL(root->children);
|
|
|
|
CU_ASSERT_PTR_NULL(root->node.parent);
|
|
|
|
CU_ASSERT_PTR_NULL(root->node.name);
|
|
|
|
CU_ASSERT(S_ISDIR(root->node.attrib.st_mode) );
|
2007-06-01 12:57:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_add_dir() {
|
|
|
|
struct iso_tree_node_dir *root;
|
|
|
|
struct iso_tree_node_dir *dir;
|
|
|
|
|
|
|
|
root = iso_tree_new_root();
|
|
|
|
dir = iso_tree_add_dir(root, "New dir name");
|
2007-06-21 11:19:11 +00:00
|
|
|
CU_ASSERT_PTR_NOT_NULL(root);
|
|
|
|
CU_ASSERT_PTR_NOT_NULL(dir);
|
|
|
|
CU_ASSERT_PTR_EQUAL(dir->node.parent, root);
|
|
|
|
CU_ASSERT_EQUAL(root->nchildren, 1);
|
|
|
|
CU_ASSERT_PTR_EQUAL(root->children[0], (struct iso_tree_node *)dir);
|
|
|
|
CU_ASSERT_STRING_EQUAL( dir->node.name, "New dir name");
|
|
|
|
CU_ASSERT( S_ISDIR(dir->node.attrib.st_mode) );
|
2007-06-01 12:57:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_add_file() {
|
|
|
|
struct iso_tree_node_dir *root;
|
|
|
|
struct iso_tree_node_file *file;
|
|
|
|
|
|
|
|
root = iso_tree_new_root();
|
|
|
|
file = (struct iso_tree_node_file *)
|
|
|
|
iso_tree_add_file(root, "/tmp/libisofs_test/README");
|
2007-06-21 11:19:11 +00:00
|
|
|
CU_ASSERT_PTR_NOT_NULL(root);
|
|
|
|
CU_ASSERT_PTR_NOT_NULL(file);
|
|
|
|
CU_ASSERT_PTR_EQUAL(file->node.parent, root);
|
|
|
|
CU_ASSERT_EQUAL(root->nchildren, 1);
|
|
|
|
CU_ASSERT_PTR_EQUAL(root->children[0], (struct iso_tree_node *)file);
|
|
|
|
CU_ASSERT_STRING_EQUAL( file->node.name, "README" );
|
|
|
|
CU_ASSERT_STRING_EQUAL( file->path, "/tmp/libisofs_test/README" );
|
|
|
|
CU_ASSERT( S_ISREG(file->node.attrib.st_mode) );
|
2007-06-01 12:57:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_add_symlink() {
|
|
|
|
struct iso_tree_node_dir *root;
|
|
|
|
struct iso_tree_node *lnk;
|
|
|
|
|
|
|
|
root = iso_tree_new_root();
|
|
|
|
lnk = iso_tree_add_symlink(root, "read", "/tmp/libisofs_test/README");
|
2007-06-21 11:19:11 +00:00
|
|
|
CU_ASSERT_PTR_NOT_NULL(root);
|
|
|
|
CU_ASSERT_PTR_NOT_NULL(lnk);
|
|
|
|
CU_ASSERT_PTR_EQUAL(lnk->parent, root);
|
|
|
|
CU_ASSERT_EQUAL(root->nchildren, 1);
|
|
|
|
CU_ASSERT_PTR_EQUAL(root->children[0], (struct iso_tree_node *)lnk);
|
|
|
|
CU_ASSERT_STRING_EQUAL( lnk->name, "read");
|
|
|
|
CU_ASSERT_STRING_EQUAL( ((struct iso_tree_node_symlink*)lnk)->dest,
|
|
|
|
"/tmp/libisofs_test/README" );
|
|
|
|
CU_ASSERT( S_ISLNK(lnk->attrib.st_mode) );
|
2007-06-01 12:57:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_radd_dir() {
|
|
|
|
struct iso_tree_node_dir *root;
|
|
|
|
struct iso_tree_node_dir *child;
|
|
|
|
struct iso_tree_radd_dir_behavior behavior = {0,0,0};
|
|
|
|
|
|
|
|
root = iso_tree_new_root();
|
2007-06-21 11:19:11 +00:00
|
|
|
CU_ASSERT_PTR_NOT_NULL(root);
|
2007-06-01 12:57:09 +00:00
|
|
|
|
2007-06-21 11:19:11 +00:00
|
|
|
iso_tree_radd_dir(root, "/tmp/libisofs_test", &behavior);
|
2007-06-01 12:57:09 +00:00
|
|
|
|
|
|
|
/* test _root_ children */
|
2007-06-21 11:19:11 +00:00
|
|
|
child = (struct iso_tree_node_dir *)root->children[0];
|
|
|
|
CU_ASSERT( S_ISDIR(child->node.attrib.st_mode) );
|
|
|
|
CU_ASSERT_EQUAL( child->nchildren, 2);
|
|
|
|
CU_ASSERT_STRING_EQUAL( child->node.name, "dir1" );
|
2007-06-01 12:57:09 +00:00
|
|
|
|
2007-06-21 11:19:11 +00:00
|
|
|
child = (struct iso_tree_node_dir *)root->children[1];
|
|
|
|
CU_ASSERT( S_ISDIR(child->node.attrib.st_mode) );
|
|
|
|
CU_ASSERT_EQUAL( child->nchildren, 0);
|
|
|
|
CU_ASSERT_STRING_EQUAL( child->node.name, "dir2" );
|
2007-06-01 12:57:09 +00:00
|
|
|
|
|
|
|
//TODO write really full test
|
|
|
|
|
|
|
|
//iso_tree_print( (struct iso_tree_node *)root, 4 );
|
|
|
|
}
|
|
|
|
|
2007-06-21 11:19:11 +00:00
|
|
|
void add_tree_suite()
|
2007-06-01 12:57:09 +00:00
|
|
|
{
|
2007-06-21 11:19:11 +00:00
|
|
|
CU_pSuite pSuite = CU_add_suite("TreeSuite", NULL, NULL);
|
|
|
|
|
|
|
|
CU_add_test(pSuite, "test of iso_tree_new_root()", test_new_root);
|
|
|
|
CU_add_test(pSuite, "test of iso_tree_add_dir()", test_add_dir);
|
|
|
|
CU_add_test(pSuite, "test of iso_tree_add_file()", test_add_file);
|
|
|
|
CU_add_test(pSuite, "test of iso_tree_add_symlink()", test_add_symlink);
|
|
|
|
CU_add_test(pSuite, "test of iso_tree_radd_dir()", test_radd_dir);
|
|
|
|
}
|