legacy/libisofs/trunk/test/test_ecma119_tree.c

123 lines
2.5 KiB
C

/*
* Unit test for ecma119_tree.h
*/
#include "libisofs.h"
#include "tree.h"
#include "test.h"
#include "ecma119.h"
#include "ecma119_tree.h"
#include <assert.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
struct ecma119_write_target t;
static void reset_write_target()
{
/* inititalize t with default values */
t.root = NULL;
t.joliet_root = NULL;
t.volset = NULL;
t.volnum = time(NULL);
t.now;
t.total_size = 0;
t.vol_space_size = 0;
t.rockridge = 0;
t.joliet = 0;
t.iso_level = 1;
t.eltorito = 0;
t.relaxed_constraints = 0;
t.catalog = NULL;
t.replace_mode = 0;
t.dir_mode = 0777;
t.file_mode = 0777;
t.gid = 0;
t.uid = 0;
t.input_charset = "UTF-8";
t.ouput_charset = "UTF-8";
t.cache_inodes = 0;
t.sort_files = 0;
t.ino = 0;
t.curblock = 0;
t.block_size = 2048;
t.path_table_size = 0;
t.path_table_size_joliet = 0;
t.l_path_table_pos = 0;
t.m_path_table_pos = 0;
t.l_path_table_pos_joliet = 0;
t.m_path_table_pos_joliet = 0;
t.total_dir_size = 0;
t.total_dir_size_joliet = 0;
t.dirlist = NULL;
t.pathlist = NULL;
t.dirlist_len = 0;
t.file_table = NULL;
t.filelist = NULL;
t.filelist_len = 0;
t.curfile = 0;
t.dirlist_joliet = NULL;
t.pathlist_joliet = NULL;
t.dirlist_len_joliet = 0;
t.state = ECMA119_WRITE_SYSTEM_AREA;
}
void test_create_tree_only_root()
{
struct iso_tree_node *root;
struct ecma119_tree_node *node;
reset_write_target();
root = (struct iso_tree_node*) iso_tree_new_root();
node = ecma119_tree_create(&t, root);
CU_ASSERT_PTR_NOT_NULL(node);
/* root has no name */
CU_ASSERT_PTR_NULL(node->iso_name);
CU_ASSERT_PTR_NULL(node->full_name);
/* target root has been set */
CU_ASSERT_PTR_EQUAL(t.root, node);
CU_ASSERT_PTR_EQUAL(node->target, &t);
CU_ASSERT_PTR_NULL(node->parent);
CU_ASSERT_EQUAL(node->attrib.st_mode, root->attrib.st_mode);
CU_ASSERT_EQUAL(node->attrib.st_uid, root->attrib.st_uid);
CU_ASSERT_EQUAL(node->attrib.st_gid, root->attrib.st_gid);
/* the node is a directory */
CU_ASSERT_EQUAL(node->type, ECMA119_DIR);
CU_ASSERT_EQUAL(node->info.dir.nchildren, 0);
iso_tree_free((struct iso_tree_node *)root);
ecma119_tree_free(node);
}
void add_ecma119_tree_suite()
{
CU_pSuite pSuite = CU_add_suite("Ecma119TreeSuite", NULL, NULL);
CU_add_test(pSuite, "test of ecma119_tree_create() with only root dir", test_create_tree_only_root);
//CU_add_test(pSuite, "test of create_dir()", test_create_dir);
}