Implemented relaxed iso constraints & Cunit based unit-tests

This commit is contained in:
Mario Danic
2007-06-21 11:19:11 +00:00
parent beb88c79cd
commit f57c1f4652
15 changed files with 624 additions and 407 deletions

View File

@ -17,242 +17,97 @@
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");
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) );
}
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");
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) );
}
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");
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) );
}
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");
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) );
}
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);
CU_ASSERT_PTR_NOT_NULL(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 );
iso_tree_radd_dir(root, "/tmp/libisofs_test", &behavior);
/* 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 *)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" );
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 );
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" );
//TODO write really full test
printf("\tOK\n");
//iso_tree_print( (struct iso_tree_node *)root, 4 );
}
void test_tree()
void add_tree_suite()
{
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;
CU_pSuite pSuite = CU_add_suite("TreeSuite", NULL, NULL);
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();
}
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);
}