Implemented numeber of multisession options, reading, modifying tree, and a number of improvements

This commit is contained in:
Mario Danic
2007-08-10 09:35:10 +00:00
parent ca09f3948d
commit e159dd0f1c
25 changed files with 2099 additions and 232 deletions

View File

@ -43,6 +43,7 @@ void help()
int main(int argc, char **argv)
{
struct ecma119_source_opts opts;
struct iso_volset *volset;
struct iso_volume *volume;
struct iso_tree_node_dir *root;
@ -50,6 +51,7 @@ int main(int argc, char **argv)
unsigned char buf[2048];
FILE *fd;
int c;
int constraints;
struct iso_tree_radd_dir_behavior behav = {0,0,0};
int level=1, flags=0;
char *boot_img = NULL;
@ -104,15 +106,15 @@ int main(int argc, char **argv)
if ( boot_img ) {
/* adds El-Torito boot info. Tunned for isolinux */
struct el_torito_boot_image *bootimg;
struct iso_tree_node_dir *boot = (struct iso_tree_node_dir *)
iso_tree_volume_path_to_node(volume, "isolinux");
struct iso_tree_node *img = iso_tree_volume_path_to_node(volume, boot_img);
if (!img) {
err(1, "boot image patch is not valid");
}
struct el_torito_boot_image *bootimg =
iso_volume_create_boot_catalog(volume, img, ELTORITO_NO_EMUL,
boot, "boot.cat");
bootimg = iso_volume_create_boot_catalog(volume, img, ELTORITO_NO_EMUL,
boot, "boot.cat");
el_torito_set_load_size(bootimg, 4);
el_torito_set_write_boot_info(bootimg);
}
@ -123,12 +125,16 @@ int main(int argc, char **argv)
iso_volume_set_application_id(volume, "Libburnia");
iso_volume_set_copyright_file_id(volume, "LICENSE");
int constraints = ECMA119_OMIT_VERSION_NUMBERS |
constraints = ECMA119_OMIT_VERSION_NUMBERS |
ECMA119_37_CHAR_FILENAMES | ECMA119_NO_DIR_REALOCATION |
ECMA119_RELAXED_FILENAMES;
struct ecma119_source_opts opts = {0, level, flags, constraints, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, "UTF-8", "UTF-8"};
memset(&opts, 0, sizeof(struct ecma119_source_opts));
opts.level = level;
opts.flags = flags;
opts.relaxed_constraints = 0;//constraints;
opts.input_charset = "UTF-8";
opts.ouput_charset = "UTF-8";
src = iso_source_new_ecma119(volset, &opts);

View File

@ -8,6 +8,8 @@ static void create_test_suite()
add_file_hashtable_suite();
add_ecma119_tree_suite();
add_volume_suite();
add_data_source_suite();
add_isoread_suite();
}
int main(int argc, char **argv)

View File

@ -21,4 +21,8 @@ void add_ecma119_tree_suite();
void add_volume_suite();
void add_data_source_suite();
void add_isoread_suite();
#endif /*TEST_H_*/

View File

@ -1,17 +1,12 @@
/*
* Unit test for ecma119_tree.h
*/
//FIXME not implemented yet!!
#include "libisofs.h"
#include "tree.h"
#include "test.h"
//#include "ecma119_tree.h"
/*
* Also including C file, testing internal functions
*/
//#include "ecma119_tree.c"
#include "ecma119.h"
#include "ecma119_tree.h"
#include <assert.h>
#include <stdio.h>
@ -19,16 +14,109 @@
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
static void test_calc_dirent_len()
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 calc_dirent_len()", test_calc_dirent_len);
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);
}

View File

@ -21,7 +21,7 @@ static void test_iso_file_new()
file->node.attrib.st_size = 12;
file->node.attrib.st_dev = 15;
file->node.attrib.st_ino = 204;
file->path = "/tmp/filename";
file->loc.path = "/tmp/filename";
file->sort_weight = 1;
iso = iso_file_new(file);
@ -56,7 +56,7 @@ static void test_add_lookup()
file1->node.name = "fileName";
file1->node.attrib.st_dev = 15;
file1->node.attrib.st_ino = 204;
file1->path = "/tmp/filename";
file1->loc.path = "/tmp/filename";
iso1 = iso_file_new(file1);
@ -72,7 +72,7 @@ static void test_add_lookup()
file2->node.name = "fileName2";
file2->node.attrib.st_dev = 152;
file2->node.attrib.st_ino = 2042;
file2->path = "/tmp/filename2";
file2->loc.path = "/tmp/filename2";
iso3 = iso_file_new(file2);
r = iso_file_table_add_file(table, iso3);
@ -128,7 +128,7 @@ static void test_cache_inodes()
file1->node.name = "fileName";
file1->node.attrib.st_dev = 15;
file1->node.attrib.st_ino = 204;
file1->path = "/tmp/filename";
file1->loc.path = "/tmp/filename";
iso1 = iso_file_new(file1);
@ -140,7 +140,7 @@ static void test_cache_inodes()
file2->node.name = "another file";
file2->node.attrib.st_dev = 15;
file2->node.attrib.st_ino = 204;
file2->path = "/tmp/another";
file2->loc.path = "/tmp/another";
iso2 = iso_file_new(file2);
/* ensure it's not added again... */
@ -159,7 +159,7 @@ static void test_cache_inodes()
file2->node.name = "different file";
file2->node.attrib.st_dev = 16; /* different dev id */
file2->node.attrib.st_ino = 204;
file2->path = "/tmp/different";
file2->loc.path = "/tmp/different";
iso2 = iso_file_new(file2);
r = iso_file_table_add_file(table, iso2);
@ -195,7 +195,7 @@ static void test_no_cache_inodes()
file1->node.name = "fileName";
file1->node.attrib.st_dev = 15;
file1->node.attrib.st_ino = 204;
file1->path = "/tmp/filename";
file1->loc.path = "/tmp/filename";
iso1 = iso_file_new(file1);
@ -207,7 +207,7 @@ static void test_no_cache_inodes()
file2->node.name = "another file";
file2->node.attrib.st_dev = 15;
file2->node.attrib.st_ino = 204;
file2->path = "/tmp/another";
file2->loc.path = "/tmp/another";
iso2 = iso_file_new(file2);
/* ensure is added */
@ -222,7 +222,7 @@ static void test_no_cache_inodes()
file3->node.name = "different file";
file3->node.attrib.st_dev = 15;
file3->node.attrib.st_ino = 204;
file3->path = "/tmp/filename";
file3->loc.path = "/tmp/filename";
iso3 = iso_file_new(file3);
r = iso_file_table_add_file(table, iso3);
@ -237,12 +237,78 @@ static void test_no_cache_inodes()
free(table);
}
static void test_prev_img_files()
{
struct iso_file_table *table;
struct iso_tree_node_file *file1;
struct iso_tree_node_file *file2;
struct iso_tree_node_file *file3;
struct iso_file *iso1;
struct iso_file *iso2;
struct iso_file *iso3;
int r;
table = iso_file_table_new(0);
CU_ASSERT_PTR_NOT_NULL( table );
CU_ASSERT_FALSE( table->cache_inodes );
CU_ASSERT_EQUAL(table->count, 0);
file1 = calloc(1, sizeof(struct iso_tree_node_file) );
file1->node.name = "fileName";
file1->node.procedence = LIBISO_PREVIMG;
file1->node.attrib.st_dev = 0;
file1->node.attrib.st_ino = 204;
file1->loc.block = 567;
iso1 = iso_file_new(file1);
r = iso_file_table_add_file(table, iso1);
CU_ASSERT_EQUAL(r, 1);
/* another file, different but with the same inode id */
file2 = calloc(1, sizeof(struct iso_tree_node_file) );
file2->node.name = "another file";
file2->node.procedence = LIBISO_PREVIMG;
file2->node.attrib.st_dev = 0;
file2->node.attrib.st_ino = 204;
file2->loc.block = 567;
iso2 = iso_file_new(file2);
/* ensure is not added */
r = iso_file_table_add_file(table, iso2);
CU_ASSERT_EQUAL(r, 0);
iso3 = iso_file_table_lookup(table, file2);
CU_ASSERT_PTR_EQUAL(iso3, iso1);
/* and now a file added new */
file3 = calloc(1, sizeof(struct iso_tree_node_file) );
file3->node.name = "different file";
file3->node.attrib.st_dev = 0;
file3->node.attrib.st_ino = 204;
file3->loc.path = "/tmp/filename";
iso3 = iso_file_new(file3);
/* assert it's added */
r = iso_file_table_add_file(table, iso3);
CU_ASSERT_EQUAL(r, 1);
iso1 = iso_file_table_lookup(table, file3);
CU_ASSERT_PTR_EQUAL(iso1, iso3);
iso_file_table_clear(table);
free(file1);
free(file2);
free(file3);
free(table);
}
void add_file_hashtable_suite()
{
CU_pSuite pSuite = CU_add_suite("FileHashtableSuite", NULL, NULL);
CU_add_test(pSuite, "test of iso_file_new()", test_iso_file_new);
CU_add_test(pSuite, "test of add and lookup", test_add_lookup);
CU_add_test(pSuite, "test with cache_inodes", test_cache_inodes);
CU_add_test(pSuite, "test without cache_inodes", test_no_cache_inodes);
CU_add_test(pSuite, "iso_file_new()", test_iso_file_new);
CU_add_test(pSuite, "add and lookup", test_add_lookup);
CU_add_test(pSuite, "with cache_inodes", test_cache_inodes);
CU_add_test(pSuite, "with files from previous img", test_prev_img_files);
}

View File

@ -2,7 +2,6 @@
* Unit test for tree.h
*/
#include "libisofs.h"
#include "tree.h"
#include "test.h"
@ -56,7 +55,7 @@ static void test_add_file() {
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_STRING_EQUAL( file->loc.path, "/tmp/libisofs_test/README" );
CU_ASSERT( S_ISREG(file->node.attrib.st_mode) );
iso_tree_free((struct iso_tree_node *)root);
}
@ -116,7 +115,7 @@ static void test_add_node() {
CU_ASSERT( S_ISREG(node->attrib.st_mode) );
CU_ASSERT( ISO_ISREG(node) );
CU_ASSERT_STRING_EQUAL( node->name, "README" );
CU_ASSERT_STRING_EQUAL( ((struct iso_tree_node_file *) node)->path,
CU_ASSERT_STRING_EQUAL( ((struct iso_tree_node_file *) node)->loc.path,
"/tmp/libisofs_test/README" );
/* test no exiting file */
@ -140,38 +139,6 @@ static void test_add_node() {
iso_tree_free((struct iso_tree_node *)root);
}
static void test_radd_dir() {
struct iso_tree_node_dir *root;
struct iso_tree_node_dir *child;
struct iso_tree_node_file *file;
struct iso_tree_radd_dir_behavior behavior = {0,0,0};
//TODO write really full test
root = iso_tree_new_root();
CU_ASSERT_PTR_NOT_NULL(root);
iso_tree_radd_dir(root, "/tmp/libisofs_test", &behavior);
/* test _root_ children */
/*
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 *)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" );
file = (struct iso_tree_node_file *)root->children[2];
CU_ASSERT( S_ISREG(file->node.attrib.st_mode) );
CU_ASSERT_STRING_EQUAL( file->node.name, "README" );
*/
//iso_tree_print( (struct iso_tree_node *)root, 4 );
}
static void test_set_name() {
struct iso_tree_node_dir *root;
struct iso_tree_node *node;
@ -202,6 +169,33 @@ static void test_set_name() {
iso_tree_free((struct iso_tree_node *)root);
}
static void test_get_name() {
struct iso_tree_node_dir *root;
struct iso_tree_node *node;
root = iso_tree_new_root();
/* test on a dir */
node = iso_tree_add_node(root, "/tmp/libisofs_test/dir1");
CU_ASSERT_STRING_EQUAL( iso_tree_node_get_name(node), "dir1");
iso_tree_node_set_name(node, "newname");
CU_ASSERT_STRING_EQUAL( iso_tree_node_get_name(node), "newname");
/* test on a link */
node = iso_tree_add_node(root, "/tmp/libisofs_test/link to readme");
CU_ASSERT_STRING_EQUAL( iso_tree_node_get_name(node), "link to readme");
iso_tree_node_set_name(node, "new link name");
CU_ASSERT_STRING_EQUAL( iso_tree_node_get_name(node), "new link name");
/* test on a file */
node = iso_tree_add_node(root, "/tmp/libisofs_test/README");
CU_ASSERT_STRING_EQUAL( iso_tree_node_get_name(node), "README" );
iso_tree_node_set_name(node, "new file name");
CU_ASSERT_STRING_EQUAL( iso_tree_node_get_name(node), "new file name");
iso_tree_free((struct iso_tree_node *)root);
}
static void test_set_hidden() {
struct iso_tree_node_dir *root;
struct iso_tree_node *node;
@ -244,6 +238,45 @@ static void test_set_hidden() {
iso_tree_free((struct iso_tree_node *)root);
}
static void test_is_hidden() {
struct iso_tree_node_dir *root;
struct iso_tree_node *node;
root = iso_tree_new_root();
/* test on a dir */
node = iso_tree_add_node(root, "/tmp/libisofs_test/dir1");
CU_ASSERT_FALSE(iso_tree_node_is_hidden(node));
iso_tree_node_set_hidden(node, LIBISO_HIDE_ON_RR);
CU_ASSERT_EQUAL(iso_tree_node_is_hidden(node), LIBISO_HIDE_ON_RR);
iso_tree_node_set_hidden(node, LIBISO_HIDE_ON_JOLIET);
CU_ASSERT_EQUAL(iso_tree_node_is_hidden(node), LIBISO_HIDE_ON_JOLIET);
iso_tree_node_set_hidden(node, LIBISO_HIDE_ON_RR|LIBISO_HIDE_ON_JOLIET);
CU_ASSERT_EQUAL(iso_tree_node_is_hidden(node), LIBISO_HIDE_ON_RR|LIBISO_HIDE_ON_JOLIET);
/* test on a link */
node = iso_tree_add_node(root, "/tmp/libisofs_test/link to readme");
CU_ASSERT_FALSE(iso_tree_node_is_hidden(node));
iso_tree_node_set_hidden(node, LIBISO_HIDE_ON_RR);
CU_ASSERT_EQUAL(iso_tree_node_is_hidden(node), LIBISO_HIDE_ON_RR);
iso_tree_node_set_hidden(node, LIBISO_HIDE_ON_JOLIET);
CU_ASSERT_EQUAL(iso_tree_node_is_hidden(node), LIBISO_HIDE_ON_JOLIET);
iso_tree_node_set_hidden(node, LIBISO_HIDE_ON_RR|LIBISO_HIDE_ON_JOLIET);
CU_ASSERT_EQUAL(iso_tree_node_is_hidden(node), LIBISO_HIDE_ON_RR|LIBISO_HIDE_ON_JOLIET);
/* test on a file */
node = iso_tree_add_node(root, "/tmp/libisofs_test/README");
CU_ASSERT_FALSE(iso_tree_node_is_hidden(node));
iso_tree_node_set_hidden(node, LIBISO_HIDE_ON_RR);
CU_ASSERT_EQUAL(iso_tree_node_is_hidden(node), LIBISO_HIDE_ON_RR);
iso_tree_node_set_hidden(node, LIBISO_HIDE_ON_JOLIET);
CU_ASSERT_EQUAL(iso_tree_node_is_hidden(node), LIBISO_HIDE_ON_JOLIET);
iso_tree_node_set_hidden(node, LIBISO_HIDE_ON_RR|LIBISO_HIDE_ON_JOLIET);
CU_ASSERT_EQUAL(iso_tree_node_is_hidden(node), LIBISO_HIDE_ON_RR|LIBISO_HIDE_ON_JOLIET);
iso_tree_free((struct iso_tree_node *)root);
}
static void test_set_gid() {
struct iso_tree_node_dir *root;
struct iso_tree_node *node;
@ -275,6 +308,34 @@ static void test_set_gid() {
iso_tree_free((struct iso_tree_node *)root);
}
static void test_get_gid() {
struct iso_tree_node_dir *root;
struct iso_tree_node *node;
gid_t mygid = getgid();
root = iso_tree_new_root();
/* test on a dir */
node = iso_tree_add_node(root, "/tmp/libisofs_test/dir1");
CU_ASSERT_EQUAL(iso_tree_node_get_gid(node), mygid);
iso_tree_node_set_gid(node, 1234);
CU_ASSERT_EQUAL(iso_tree_node_get_gid(node), 1234);
/* test on a link */
node = iso_tree_add_node(root, "/tmp/libisofs_test/link to readme");
CU_ASSERT_EQUAL(iso_tree_node_get_gid(node), mygid);
iso_tree_node_set_gid(node, 1234);
CU_ASSERT_EQUAL(iso_tree_node_get_gid(node), 1234);
/* test on a file */
node = iso_tree_add_node(root, "/tmp/libisofs_test/README");
CU_ASSERT_EQUAL(iso_tree_node_get_gid(node), mygid);
iso_tree_node_set_gid(node, 1234);
CU_ASSERT_EQUAL(iso_tree_node_get_gid(node), 1234);
iso_tree_free((struct iso_tree_node *)root);
}
static void test_set_uid() {
struct iso_tree_node_dir *root;
struct iso_tree_node *node;
@ -308,6 +369,34 @@ static void test_set_uid() {
iso_tree_free((struct iso_tree_node *)root);
}
static void test_get_uid() {
struct iso_tree_node_dir *root;
struct iso_tree_node *node;
uid_t myuid = getuid();
root = iso_tree_new_root();
/* test on a dir */
node = iso_tree_add_node(root, "/tmp/libisofs_test/dir1");
CU_ASSERT_EQUAL(iso_tree_node_get_uid(node), myuid);
iso_tree_node_set_uid(node, 1234);
CU_ASSERT_EQUAL(iso_tree_node_get_uid(node), 1234);
/* test on a link */
node = iso_tree_add_node(root, "/tmp/libisofs_test/link to readme");
CU_ASSERT_EQUAL(iso_tree_node_get_uid(node), myuid);
iso_tree_node_set_uid(node, 1234);
CU_ASSERT_EQUAL(iso_tree_node_get_uid(node), 1234);
/* test on a file */
node = iso_tree_add_node(root, "/tmp/libisofs_test/README");
CU_ASSERT_EQUAL(iso_tree_node_get_uid(node), myuid);
iso_tree_node_set_uid(node, 1234);
CU_ASSERT_EQUAL(iso_tree_node_get_uid(node), 1234);
iso_tree_free((struct iso_tree_node *)root);
}
static void test_set_permissions() {
struct iso_tree_node_dir *root;
struct iso_tree_node *node;
@ -350,6 +439,45 @@ static void test_set_permissions() {
iso_tree_free((struct iso_tree_node *)root);
}
static void test_get_permissions() {
struct iso_tree_node_dir *root;
struct iso_tree_node *node;
root = iso_tree_new_root();
/* test on a dir */
node = iso_tree_add_node(root, "/tmp/libisofs_test/dir1");
CU_ASSERT_EQUAL(iso_tree_node_get_permissions(node), 0755);
iso_tree_node_set_permissions(node, 0777);
CU_ASSERT_EQUAL(iso_tree_node_get_permissions(node), 0777);
iso_tree_node_set_permissions(node, 0744);
CU_ASSERT_EQUAL(iso_tree_node_get_permissions(node), 0744);
iso_tree_node_set_permissions(node, 0411);
CU_ASSERT_EQUAL(iso_tree_node_get_permissions(node), 0411);
/* test on a link */
node = iso_tree_add_node(root, "/tmp/libisofs_test/link to readme");
CU_ASSERT_EQUAL(iso_tree_node_get_permissions(node), 0777);
iso_tree_node_set_permissions(node, 0555);
CU_ASSERT_EQUAL(iso_tree_node_get_permissions(node), 0555);
iso_tree_node_set_permissions(node, 0744);
CU_ASSERT_EQUAL(iso_tree_node_get_permissions(node), 0744);
iso_tree_node_set_permissions(node, 0411);
CU_ASSERT_EQUAL(iso_tree_node_get_permissions(node), 0411);
/* test on a file */
node = iso_tree_add_node(root, "/tmp/libisofs_test/README");
CU_ASSERT_EQUAL(iso_tree_node_get_permissions(node), 0555);
iso_tree_node_set_permissions(node, 0777);
CU_ASSERT_EQUAL(iso_tree_node_get_permissions(node), 0777);
iso_tree_node_set_permissions(node, 0744);
CU_ASSERT_EQUAL(iso_tree_node_get_permissions(node), 0744);
iso_tree_node_set_permissions(node, 0411);
CU_ASSERT_EQUAL(iso_tree_node_get_permissions(node), 0411);
iso_tree_free((struct iso_tree_node *)root);
}
static void test_set_sort_weight() {
struct iso_tree_node_dir *root;
struct iso_tree_node_dir *dir;
@ -375,6 +503,519 @@ static void test_set_sort_weight() {
iso_tree_free((struct iso_tree_node *)root);
}
static void test_set_dest() {
struct iso_tree_node_dir *root;
struct iso_tree_node *node;
struct iso_tree_node_symlink *link;
root = iso_tree_new_root();
node = iso_tree_add_node(root, "/tmp/libisofs_test/link to readme");
link = (struct iso_tree_node_symlink *) node;
CU_ASSERT_STRING_EQUAL( link->dest, "/tmp/libisofs_test/README");
iso_tree_node_symlink_set_dest(link, "/tmp/inexistent");
CU_ASSERT_STRING_EQUAL( link->dest, "/tmp/inexistent");
iso_tree_free((struct iso_tree_node *)root);
}
static void test_get_dest() {
struct iso_tree_node_dir *root;
struct iso_tree_node *node;
struct iso_tree_node_symlink *link;
root = iso_tree_new_root();
node = iso_tree_add_node(root, "/tmp/libisofs_test/link to readme");
link = (struct iso_tree_node_symlink *) node;
CU_ASSERT_STRING_EQUAL( iso_tree_node_symlink_get_dest(link), "/tmp/libisofs_test/README");
iso_tree_node_symlink_set_dest(link, "/tmp/inexistent");
CU_ASSERT_STRING_EQUAL( iso_tree_node_symlink_get_dest(link), "/tmp/inexistent");
iso_tree_free((struct iso_tree_node *)root);
}
static void test_get_node_type() {
struct iso_tree_node_dir *root;
struct iso_tree_node *node;
root = iso_tree_new_root();
/* test on a dir */
node = iso_tree_add_node(root, "/tmp/libisofs_test/dir1");
CU_ASSERT_EQUAL(iso_tree_node_get_type(node), LIBISO_NODE_DIR);
/* test on a link */
node = iso_tree_add_node(root, "/tmp/libisofs_test/link to readme");
CU_ASSERT_EQUAL(iso_tree_node_get_type(node), LIBISO_NODE_SYMLINK);
/* test on a file */
node = iso_tree_add_node(root, "/tmp/libisofs_test/README");
CU_ASSERT_EQUAL(iso_tree_node_get_type(node), LIBISO_NODE_FILE);
iso_tree_free((struct iso_tree_node *)root);
}
static void test_children_iter() {
struct iso_tree_node_dir *root;
struct iso_tree_iter *iter;
struct iso_tree_node *child;
struct iso_tree_node *node1, *node2, *node3;
root = iso_tree_new_root();
node1 = iso_tree_add_node(root, "/tmp/libisofs_test/dir1");
node2 = iso_tree_add_node(root, "/tmp/libisofs_test/link to readme");
node3 = iso_tree_add_node(root, "/tmp/libisofs_test/README");
/* get the iterator */
iter = iso_tree_node_children(root);
CU_ASSERT_PTR_NOT_NULL(iter);
/* test correct iteration */
child = iso_tree_iter_next(iter);
CU_ASSERT_PTR_NOT_NULL(child);
CU_ASSERT_PTR_EQUAL(child, node1);
child = iso_tree_iter_next(iter);
CU_ASSERT_PTR_NOT_NULL(child);
CU_ASSERT_PTR_EQUAL(child, node2);
child = iso_tree_iter_next(iter);
CU_ASSERT_PTR_NOT_NULL(child);
CU_ASSERT_PTR_EQUAL(child, node3);
/* and NULL when no more children */
child = iso_tree_iter_next(iter);
CU_ASSERT_PTR_NULL(child);
iso_tree_iter_free(iter);
/* now an iter on a empty dir */
iter = iso_tree_node_children((struct iso_tree_node_dir *)node1);
CU_ASSERT_PTR_NOT_NULL(iter);
child = iso_tree_iter_next(iter);
CU_ASSERT_PTR_NULL(child);
iso_tree_free((struct iso_tree_node *)root);
}
static void test_tree_node_take() {
int res;
struct iso_tree_node_dir *root;
struct iso_tree_iter *iter;
struct iso_tree_node *child;
struct iso_tree_node *node1, *node2, *node3;
root = iso_tree_new_root();
node1 = iso_tree_add_node(root, "/tmp/libisofs_test/dir1");
node2 = iso_tree_add_node(root, "/tmp/libisofs_test/link to readme");
node3 = iso_tree_add_node(root, "/tmp/libisofs_test/README");
/* we take a ref to each node to test current reference behavior */
iso_tree_node_ref(node1);
iso_tree_node_ref(node2);
iso_tree_node_ref(node3);
/* remove node2 */
res = iso_tree_node_take(root, node2);
CU_ASSERT_EQUAL(res, 0);
CU_ASSERT_EQUAL(root->nchildren, 2);
CU_ASSERT_PTR_NULL(node2->parent);
/* node2 should keep both refs */
CU_ASSERT_EQUAL(node2->refcount, 2);
/* test iteration */
iter = iso_tree_node_children(root);
CU_ASSERT_PTR_NOT_NULL(iter);
child = iso_tree_iter_next(iter);
CU_ASSERT_PTR_NOT_NULL(child);
CU_ASSERT_PTR_EQUAL(child, node1);
child = iso_tree_iter_next(iter);
CU_ASSERT_PTR_NOT_NULL(child);
CU_ASSERT_PTR_EQUAL(child, node3);
child = iso_tree_iter_next(iter);
CU_ASSERT_PTR_NULL(child);
iso_tree_iter_free(iter);
/* try to remove again node2 */
res = iso_tree_node_take(root, node2);
CU_ASSERT_EQUAL(res, -1);
CU_ASSERT_EQUAL(root->nchildren, 2);
iso_tree_free(node2);
/* ok, now remove node1, and then node3 */
res = iso_tree_node_take(root, node1);
CU_ASSERT_EQUAL(res, 0);
CU_ASSERT_EQUAL(root->nchildren, 1);
CU_ASSERT_EQUAL(node1->refcount, 2);
CU_ASSERT_PTR_NULL(node1->parent);
iter = iso_tree_node_children(root);
CU_ASSERT_PTR_NOT_NULL(iter);
child = iso_tree_iter_next(iter);
CU_ASSERT_PTR_NOT_NULL(child);
CU_ASSERT_PTR_EQUAL(child, node3);
child = iso_tree_iter_next(iter);
CU_ASSERT_PTR_NULL(child);
iso_tree_iter_free(iter);
res = iso_tree_node_take(root, node3);
CU_ASSERT_EQUAL(res, 0);
CU_ASSERT_EQUAL(root->nchildren, 0);
CU_ASSERT_EQUAL(node3->refcount, 2);
CU_ASSERT_PTR_NULL(node3->parent);
iter = iso_tree_node_children(root);
CU_ASSERT_PTR_NOT_NULL(iter);
child = iso_tree_iter_next(iter);
CU_ASSERT_PTR_NULL(child);
iso_tree_iter_free(iter);
/* and try to remove on an empty dir */
res = iso_tree_node_take(root, node3);
CU_ASSERT_EQUAL(res, -1);
iso_tree_free(node1);
iso_tree_free(node3);
iso_tree_free((struct iso_tree_node *)root);
iso_tree_free(node1);
iso_tree_free(node2);
iso_tree_free(node3);
}
static void test_tree_node_remove() {
int res;
struct iso_tree_node_dir *root;
struct iso_tree_iter *iter;
struct iso_tree_node *child;
struct iso_tree_node *node1, *node2, *node3;
root = iso_tree_new_root();
node1 = iso_tree_add_node(root, "/tmp/libisofs_test/dir1");
node2 = iso_tree_add_node(root, "/tmp/libisofs_test/link to readme");
node3 = iso_tree_add_node(root, "/tmp/libisofs_test/README");
/* we take a ref to each node to test current reference behavior */
iso_tree_node_ref(node1);
iso_tree_node_ref(node2);
iso_tree_node_ref(node3);
/* remove node2 */
res = iso_tree_node_remove(root, node2);
CU_ASSERT_EQUAL(res, 0);
CU_ASSERT_EQUAL(root->nchildren, 2);
CU_ASSERT_PTR_NULL(node2->parent);
/* node2 should be unref */
CU_ASSERT_EQUAL(node2->refcount, 1);
/* test iteration */
iter = iso_tree_node_children(root);
CU_ASSERT_PTR_NOT_NULL(iter);
child = iso_tree_iter_next(iter);
CU_ASSERT_PTR_NOT_NULL(child);
CU_ASSERT_PTR_EQUAL(child, node1);
child = iso_tree_iter_next(iter);
CU_ASSERT_PTR_NOT_NULL(child);
CU_ASSERT_PTR_EQUAL(child, node3);
child = iso_tree_iter_next(iter);
CU_ASSERT_PTR_NULL(child);
iso_tree_iter_free(iter);
/* try to remove again node2 */
res = iso_tree_node_remove(root, node2);
CU_ASSERT_EQUAL(res, -1);
CU_ASSERT_EQUAL(root->nchildren, 2);
CU_ASSERT_EQUAL(node2->refcount, 1);
/* ok, now remove node1, and then node3 */
res = iso_tree_node_remove(root, node1);
CU_ASSERT_EQUAL(res, 0);
CU_ASSERT_EQUAL(root->nchildren, 1);
CU_ASSERT_EQUAL(node1->refcount, 1);
CU_ASSERT_PTR_NULL(node1->parent);
iter = iso_tree_node_children(root);
CU_ASSERT_PTR_NOT_NULL(iter);
child = iso_tree_iter_next(iter);
CU_ASSERT_PTR_NOT_NULL(child);
CU_ASSERT_PTR_EQUAL(child, node3);
child = iso_tree_iter_next(iter);
CU_ASSERT_PTR_NULL(child);
iso_tree_iter_free(iter);
res = iso_tree_node_remove(root, node3);
CU_ASSERT_EQUAL(res, 0);
CU_ASSERT_EQUAL(root->nchildren, 0);
CU_ASSERT_EQUAL(node3->refcount, 1);
CU_ASSERT_PTR_NULL(node3->parent);
iter = iso_tree_node_children(root);
CU_ASSERT_PTR_NOT_NULL(iter);
child = iso_tree_iter_next(iter);
CU_ASSERT_PTR_NULL(child);
iso_tree_iter_free(iter);
/* and try to remove on an empty dir */
res = iso_tree_node_remove(root, node3);
CU_ASSERT_EQUAL(res, -1);
CU_ASSERT_EQUAL(node3->refcount, 1);
iso_tree_free((struct iso_tree_node *)root);
iso_tree_free(node1);
iso_tree_free(node2);
iso_tree_free(node3);
}
static void test_tree_node_take_iter() {
int res;
struct iso_tree_node_dir *root;
struct iso_tree_iter *iter;
struct iso_tree_node *child;
struct iso_tree_node *node1, *node2, *node3;
root = iso_tree_new_root();
node1 = iso_tree_add_node(root, "/tmp/libisofs_test/dir1");
node2 = iso_tree_add_node(root, "/tmp/libisofs_test/link to readme");
node3 = iso_tree_add_node(root, "/tmp/libisofs_test/README");
/* we take a ref to each node to test current reference behavior */
iso_tree_node_ref(node1);
iso_tree_node_ref(node2);
iso_tree_node_ref(node3);
/* begin iteration */
iter = iso_tree_node_children(root);
CU_ASSERT_PTR_NOT_NULL(iter);
child = iso_tree_iter_next(iter);
CU_ASSERT_PTR_NOT_NULL(child);
CU_ASSERT_PTR_EQUAL(child, node1);
child = iso_tree_iter_next(iter);
CU_ASSERT_PTR_NOT_NULL(child);
CU_ASSERT_PTR_EQUAL(child, node2);
/* ok, take node 2 */
res = iso_tree_node_take_iter(iter);
CU_ASSERT_EQUAL(res, 0);
CU_ASSERT_EQUAL(root->nchildren, 2);
CU_ASSERT_EQUAL(node2->refcount, 2);
CU_ASSERT_PTR_NULL(node2->parent);
/* the iter have to work after remove */
child = iso_tree_iter_next(iter);
CU_ASSERT_PTR_NOT_NULL(child);
CU_ASSERT_PTR_EQUAL(child, node3);
child = iso_tree_iter_next(iter);
CU_ASSERT_PTR_NULL(child);
iso_tree_iter_free(iter);
/* ok, now remove before the begining */
iter = iso_tree_node_children(root);
CU_ASSERT_PTR_NOT_NULL(iter);
res = iso_tree_node_take_iter(iter);
CU_ASSERT_TRUE(res < 0);
/* and the iter still works */
child = iso_tree_iter_next(iter);
CU_ASSERT_PTR_NOT_NULL(child);
CU_ASSERT_PTR_EQUAL(child, node1);
child = iso_tree_iter_next(iter);
CU_ASSERT_PTR_NOT_NULL(child);
CU_ASSERT_PTR_EQUAL(child, node3);
child = iso_tree_iter_next(iter);
CU_ASSERT_PTR_NULL(child);
/* and now try to remove at the end */
res = iso_tree_node_take_iter(iter);
CU_ASSERT_TRUE(res < 0);
iso_tree_iter_free(iter);
/* ok, now remove all during iteration */
iter = iso_tree_node_children(root);
CU_ASSERT_PTR_NOT_NULL(iter);
child = iso_tree_iter_next(iter);
CU_ASSERT_PTR_NOT_NULL(child);
CU_ASSERT_PTR_EQUAL(child, node1);
res = iso_tree_node_take_iter(iter);
CU_ASSERT_EQUAL(res, 0);
CU_ASSERT_EQUAL(root->nchildren, 1);
CU_ASSERT_EQUAL(node1->refcount, 2);
CU_ASSERT_PTR_NULL(node1->parent);
child = iso_tree_iter_next(iter);
CU_ASSERT_PTR_NOT_NULL(child);
CU_ASSERT_PTR_EQUAL(child, node3);
res = iso_tree_node_take_iter(iter);
CU_ASSERT_EQUAL(res, 0);
CU_ASSERT_EQUAL(root->nchildren, 0);
CU_ASSERT_EQUAL(node3->refcount, 2);
CU_ASSERT_PTR_NULL(node3->parent);
child = iso_tree_iter_next(iter);
CU_ASSERT_PTR_NULL(child);
iso_tree_iter_free(iter);
iso_tree_free(node1);
iso_tree_free(node2);
iso_tree_free(node3);
iso_tree_free((struct iso_tree_node *)root);
iso_tree_free(node1);
iso_tree_free(node2);
iso_tree_free(node3);
}
static void test_tree_node_remove_iter() {
int res;
struct iso_tree_node_dir *root;
struct iso_tree_iter *iter;
struct iso_tree_node *child;
struct iso_tree_node *node1, *node2, *node3;
root = iso_tree_new_root();
node1 = iso_tree_add_node(root, "/tmp/libisofs_test/dir1");
node2 = iso_tree_add_node(root, "/tmp/libisofs_test/link to readme");
node3 = iso_tree_add_node(root, "/tmp/libisofs_test/README");
/* we take a ref to each node to test current reference behavior */
iso_tree_node_ref(node1);
iso_tree_node_ref(node2);
iso_tree_node_ref(node3);
/* begin iteration */
iter = iso_tree_node_children(root);
CU_ASSERT_PTR_NOT_NULL(iter);
child = iso_tree_iter_next(iter);
CU_ASSERT_PTR_NOT_NULL(child);
CU_ASSERT_PTR_EQUAL(child, node1);
child = iso_tree_iter_next(iter);
CU_ASSERT_PTR_NOT_NULL(child);
CU_ASSERT_PTR_EQUAL(child, node2);
/* ok, remove node 2 */
res = iso_tree_node_remove_iter(iter);
CU_ASSERT_EQUAL(res, 0);
CU_ASSERT_EQUAL(root->nchildren, 2);
CU_ASSERT_EQUAL(node2->refcount, 1);
CU_ASSERT_PTR_NULL(node2->parent);
/* the iter have to work after remove */
child = iso_tree_iter_next(iter);
CU_ASSERT_PTR_NOT_NULL(child);
CU_ASSERT_PTR_EQUAL(child, node3);
child = iso_tree_iter_next(iter);
CU_ASSERT_PTR_NULL(child);
iso_tree_iter_free(iter);
/* ok, now remove before the begining */
iter = iso_tree_node_children(root);
CU_ASSERT_PTR_NOT_NULL(iter);
res = iso_tree_node_remove_iter(iter);
CU_ASSERT_TRUE(res < 0);
/* and the iter still works */
child = iso_tree_iter_next(iter);
CU_ASSERT_PTR_NOT_NULL(child);
CU_ASSERT_PTR_EQUAL(child, node1);
child = iso_tree_iter_next(iter);
CU_ASSERT_PTR_NOT_NULL(child);
CU_ASSERT_PTR_EQUAL(child, node3);
child = iso_tree_iter_next(iter);
CU_ASSERT_PTR_NULL(child);
/* and now try to remove at the end */
res = iso_tree_node_remove_iter(iter);
CU_ASSERT_TRUE(res < 0);
iso_tree_iter_free(iter);
/* ok, now remove all during iteration */
iter = iso_tree_node_children(root);
CU_ASSERT_PTR_NOT_NULL(iter);
child = iso_tree_iter_next(iter);
CU_ASSERT_PTR_NOT_NULL(child);
CU_ASSERT_PTR_EQUAL(child, node1);
res = iso_tree_node_remove_iter(iter);
CU_ASSERT_EQUAL(res, 0);
CU_ASSERT_EQUAL(root->nchildren, 1);
CU_ASSERT_EQUAL(node1->refcount, 1);
CU_ASSERT_PTR_NULL(node1->parent);
child = iso_tree_iter_next(iter);
CU_ASSERT_PTR_NOT_NULL(child);
CU_ASSERT_PTR_EQUAL(child, node3);
res = iso_tree_node_remove_iter(iter);
CU_ASSERT_EQUAL(res, 0);
CU_ASSERT_EQUAL(root->nchildren, 0);
CU_ASSERT_EQUAL(node3->refcount, 1);
CU_ASSERT_PTR_NULL(node3->parent);
child = iso_tree_iter_next(iter);
CU_ASSERT_PTR_NULL(child);
iso_tree_iter_free(iter);
iso_tree_free((struct iso_tree_node *)root);
iso_tree_free(node1);
iso_tree_free(node2);
iso_tree_free(node3);
}
static void test_tree_node_get_parent() {
struct iso_tree_node_dir *root;
struct iso_tree_node_dir *parent;
struct iso_tree_node *node1, *node2, *node3;
root = iso_tree_new_root();
node1 = iso_tree_add_node(root, "/tmp/libisofs_test/dir1");
node2 = iso_tree_add_node(root, "/tmp/libisofs_test/link to readme");
node3 = iso_tree_add_node( (struct iso_tree_node_dir*)node1,
"/tmp/libisofs_test/README");
parent = iso_tree_node_get_parent((struct iso_tree_node *)root);
CU_ASSERT_PTR_NULL(parent);
parent = iso_tree_node_get_parent(node1);
CU_ASSERT_PTR_NOT_NULL(parent);
CU_ASSERT_PTR_EQUAL(parent, root);
parent = iso_tree_node_get_parent(node2);
CU_ASSERT_PTR_NOT_NULL(parent);
CU_ASSERT_PTR_EQUAL(parent, root);
parent = iso_tree_node_get_parent(node3);
CU_ASSERT_PTR_NOT_NULL(parent);
CU_ASSERT_PTR_EQUAL(parent, node1);
iso_tree_node_take(root, node1);
parent = iso_tree_node_get_parent(node1);
CU_ASSERT_PTR_NULL(parent);
iso_tree_free((struct iso_tree_node *)root);
iso_tree_free(node1);
}
void add_tree_suite()
{
CU_pSuite pSuite = CU_add_suite("TreeSuite", NULL, NULL);
@ -384,12 +1025,27 @@ void add_tree_suite()
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_add_node()", test_add_node);
CU_add_test(pSuite, "test of iso_tree_radd_dir()", test_radd_dir);
CU_add_test(pSuite, "test of iso_tree_node_set_name()", test_set_name);
CU_add_test(pSuite, "test of iso_tree_node_get_name()", test_get_name);
CU_add_test(pSuite, "test of iso_tree_node_set_hidden()", test_set_hidden);
CU_add_test(pSuite, "test of iso_tree_node_is_hidden()", test_is_hidden);
CU_add_test(pSuite, "test of iso_tree_node_set_gid()", test_set_gid);
CU_add_test(pSuite, "test of iso_tree_node_get_gid()", test_get_gid);
CU_add_test(pSuite, "test of iso_tree_node_set_uid()", test_set_uid);
CU_add_test(pSuite, "test of iso_tree_node_get_uid()", test_get_uid);
CU_add_test(pSuite, "test of iso_tree_node_set_permissions()", test_set_permissions);
CU_add_test(pSuite, "test of iso_tree_node_get_permissions()", test_get_permissions);
CU_add_test(pSuite, "test of iso_tree_node_set_sort_weight()", test_set_sort_weight);
CU_add_test(pSuite, "test of iso_tree_node_symlink_set_dest()", test_set_dest);
CU_add_test(pSuite, "test of iso_tree_node_symlink_get_dest()", test_get_dest);
CU_add_test(pSuite, "test of iso_tree_node_get_type()", test_get_node_type);
CU_add_test(pSuite, "test of children iteration", test_children_iter);
CU_add_test(pSuite, "test of iso_tree_node_take()", test_tree_node_take);
CU_add_test(pSuite, "test of iso_tree_node_remove()", test_tree_node_remove);
CU_add_test(pSuite, "test of iso_tree_node_take_iter()", test_tree_node_take_iter);
CU_add_test(pSuite, "test of iso_tree_node_remove_iter()", test_tree_node_remove_iter);
CU_add_test(pSuite, "test of iso_tree_node_get_parent()", test_tree_node_get_parent);
}

View File

@ -4,8 +4,10 @@
* This test utiliy functions
*
*/
#include "test.h"
#include <time.h>
#include <locale.h>
#include "test.h"
#include "util.h"
static void test_div_up()
@ -56,6 +58,122 @@ static void test_iso_lsb_msb()
CU_ASSERT_EQUAL( buf[1], 0x04 );
}
static void test_iso_read_lsb_msb()
{
uint8_t buf[4];
uint32_t num;
buf[0] = 0x04;
buf[1] = 0x03;
buf[2] = 0x02;
buf[3] = 0x01;
num = iso_read_lsb(buf, 4);
CU_ASSERT_EQUAL(num, 0x01020304);
num = iso_read_msb(buf, 4);
CU_ASSERT_EQUAL(num, 0x04030201);
num = iso_read_lsb(buf, 2);
CU_ASSERT_EQUAL(num, 0x0304);
num = iso_read_msb(buf, 2);
CU_ASSERT_EQUAL(num, 0x0403);
}
static void test_iso_bb()
{
uint8_t buf[8];
uint32_t num;
num = 0x01020304;
iso_bb(buf, num, 4);
CU_ASSERT_EQUAL( buf[0], 0x04 );
CU_ASSERT_EQUAL( buf[1], 0x03 );
CU_ASSERT_EQUAL( buf[2], 0x02 );
CU_ASSERT_EQUAL( buf[3], 0x01 );
CU_ASSERT_EQUAL( buf[4], 0x01 );
CU_ASSERT_EQUAL( buf[5], 0x02 );
CU_ASSERT_EQUAL( buf[6], 0x03 );
CU_ASSERT_EQUAL( buf[7], 0x04 );
iso_bb(buf, num, 2);
CU_ASSERT_EQUAL( buf[0], 0x04 );
CU_ASSERT_EQUAL( buf[1], 0x03 );
CU_ASSERT_EQUAL( buf[2], 0x03 );
CU_ASSERT_EQUAL( buf[3], 0x04 );
}
static void test_iso_read_bb()
{
uint8_t buf[8];
uint32_t num;
int error = 0;
buf[0] = 0x04;
buf[1] = 0x03;
buf[2] = 0x02;
buf[3] = 0x01;
buf[4] = 0x01;
buf[5] = 0x02;
buf[6] = 0x03;
buf[7] = 0x04;
num = iso_read_bb(buf, 4, &error);
CU_ASSERT_EQUAL( num, 0x01020304 );
CU_ASSERT_FALSE(error);
num = iso_read_bb(buf, 4, NULL);
CU_ASSERT_EQUAL( num, 0x01020304 );
buf[2] = 3;
num = iso_read_bb(buf, 4, &error);
/* return the LSB */
CU_ASSERT_EQUAL( num, 0x01030304 );
CU_ASSERT_TRUE(error);
num = iso_read_bb(buf, 4, NULL);
/* return the LSB */
CU_ASSERT_EQUAL( num, 0x01030304 );
error = 0;
buf[3] = 0x04;
num = iso_read_bb(buf, 2, &error);
CU_ASSERT_EQUAL( num, 0x0304 );
CU_ASSERT_FALSE(error);
num = iso_read_bb(buf, 2, NULL);
CU_ASSERT_EQUAL( num, 0x0304 );
}
static void test_iso_datetime_7()
{
uint8_t buf[7];
time_t t, t2;
struct tm tp;
strptime("01-03-1976 13:27:45", "%d-%m-%Y %T", &tp);
t = mktime(&tp);
iso_datetime_7(buf, t);
CU_ASSERT_EQUAL( buf[0], 76 ); /* year since 1900 */
CU_ASSERT_EQUAL( buf[1], 3 ); /* month */
CU_ASSERT_EQUAL( buf[2], 1 ); /* day */
CU_ASSERT_EQUAL( buf[3], 13 ); /* hour */
CU_ASSERT_EQUAL( buf[4], 27 ); /* minute */
CU_ASSERT_EQUAL( buf[5], 45 ); /* second */
/* the offset depends on current timezone and it's not easy to test */
//CU_ASSERT_EQUAL( buf[6], 4 ); /* 15 min offset */
/* check that reading returns the same time */
t2 = iso_datetime_read_7(buf);
CU_ASSERT_EQUAL(t2, t);
//TODO check with differnt timezones for reading and writting
}
static void test_iso_1_dirid()
{
CU_ASSERT_STRING_EQUAL( iso_1_dirid("dir1", "UTF-8"), "DIR1" );
@ -253,13 +371,17 @@ void add_util_suite()
{
CU_pSuite pSuite = CU_add_suite("UtilSuite", NULL, NULL);
CU_add_test(pSuite, "test of div_up()", test_div_up);
CU_add_test(pSuite, "test of round_up()", test_round_up);
CU_add_test(pSuite, "test of iso_lsb_msb()", test_iso_lsb_msb);
CU_add_test(pSuite, "test of iso_1_dirid()", test_iso_1_dirid);
CU_add_test(pSuite, "test of iso_2_dirid()", test_iso_2_dirid);
CU_add_test(pSuite, "test of iso_r_dirid()", test_iso_r_dirid);
CU_add_test(pSuite, "test of iso_1_fileid()", test_iso_1_fileid);
CU_add_test(pSuite, "test of iso_2_fileid()", test_iso_2_fileid);
CU_add_test(pSuite, "test of iso_r_fileid()", test_iso_r_fileid);
CU_add_test(pSuite, "div_up()", test_div_up);
CU_add_test(pSuite, "round_up()", test_round_up);
CU_add_test(pSuite, "iso_lsb() and iso_msb()", test_iso_lsb_msb);
CU_add_test(pSuite, "iso_read_lsb() and iso_read_msb()", test_iso_read_lsb_msb);
CU_add_test(pSuite, "iso_bb()", test_iso_bb);
CU_add_test(pSuite, "iso_read_bb()", test_iso_read_bb);
CU_add_test(pSuite, "iso_datetime_7()", test_iso_datetime_7);
CU_add_test(pSuite, "iso_1_dirid()", test_iso_1_dirid);
CU_add_test(pSuite, "iso_2_dirid()", test_iso_2_dirid);
CU_add_test(pSuite, "iso_r_dirid()", test_iso_r_dirid);
CU_add_test(pSuite, "iso_1_fileid()", test_iso_1_fileid);
CU_add_test(pSuite, "iso_2_fileid()", test_iso_2_fileid);
CU_add_test(pSuite, "iso_r_fileid()", test_iso_r_fileid);
}

View File

@ -105,6 +105,20 @@ static void test_iso_volume_set_volume_id()
iso_volume_free(volume);
}
static void test_iso_volume_get_volume_id()
{
struct iso_volume *volume;
volume = iso_volume_new("volume_id", "publisher_id", "data_preparer_id");
CU_ASSERT_STRING_EQUAL( iso_volume_get_volume_id(volume), "volume_id" );
char *volid = "new volume id";
iso_volume_set_volume_id(volume, volid);
CU_ASSERT_STRING_EQUAL( iso_volume_get_volume_id(volume), "new volume id" );
iso_volume_free(volume);
}
static void test_iso_volume_set_publisher_id()
{
struct iso_volume *volume;
@ -121,6 +135,20 @@ static void test_iso_volume_set_publisher_id()
iso_volume_free(volume);
}
static void test_iso_volume_get_publisher_id()
{
struct iso_volume *volume;
volume = iso_volume_new("volume_id", "publisher_id", "data_preparer_id");
CU_ASSERT_STRING_EQUAL( iso_volume_get_publisher_id(volume), "publisher_id" );
char *pubid = "new publisher id";
iso_volume_set_publisher_id(volume, pubid);
CU_ASSERT_STRING_EQUAL( iso_volume_get_publisher_id(volume), "new publisher id" );
iso_volume_free(volume);
}
static void test_iso_volume_set_data_preparer_id()
{
struct iso_volume *volume;
@ -137,6 +165,20 @@ static void test_iso_volume_set_data_preparer_id()
iso_volume_free(volume);
}
static void test_iso_volume_get_data_preparer_id()
{
struct iso_volume *volume;
volume = iso_volume_new("volume_id", "publisher_id", "data_preparer_id");
CU_ASSERT_STRING_EQUAL( iso_volume_get_data_preparer_id(volume), "data_preparer_id" );
char *dpid = "new data preparer id";
iso_volume_set_data_preparer_id(volume, dpid);
CU_ASSERT_STRING_EQUAL( iso_volume_get_data_preparer_id(volume), "new data preparer id" );
iso_volume_free(volume);
}
static void test_iso_volume_set_system_id()
{
struct iso_volume *volume;
@ -153,6 +195,20 @@ static void test_iso_volume_set_system_id()
iso_volume_free(volume);
}
static void test_iso_volume_get_system_id()
{
struct iso_volume *volume;
volume = iso_volume_new("volume_id", "publisher_id", "data_preparer_id");
CU_ASSERT_PTR_NULL(iso_volume_get_system_id(volume));
char *sysid = "new system id";
iso_volume_set_system_id(volume, sysid);
CU_ASSERT_STRING_EQUAL( iso_volume_get_system_id(volume), "new system id" );
iso_volume_free(volume);
}
static void test_iso_volume_set_application_id()
{
struct iso_volume *volume;
@ -169,6 +225,50 @@ static void test_iso_volume_set_application_id()
iso_volume_free(volume);
}
static void test_iso_volume_get_application_id()
{
struct iso_volume *volume;
volume = iso_volume_new("volume_id", "publisher_id", "data_preparer_id");
CU_ASSERT_PTR_NULL(iso_volume_get_application_id(volume));
char *appid = "new application id";
iso_volume_set_application_id(volume, appid);
CU_ASSERT_STRING_EQUAL( iso_volume_get_application_id(volume), "new application id" );
iso_volume_free(volume);
}
static void test_iso_volume_set_copyright_file_id()
{
struct iso_volume *volume;
volume = iso_volume_new("volume_id", "publisher_id", "data_preparer_id");
CU_ASSERT_PTR_NULL(volume->copyright_file_id);
char *copid = "new copyright id";
iso_volume_set_copyright_file_id(volume, copid);
CU_ASSERT_STRING_EQUAL( volume->copyright_file_id, "new copyright id" );
/* check string was strdup'ed */
CU_ASSERT_PTR_NOT_EQUAL( volume->copyright_file_id, copid );
iso_volume_free(volume);
}
static void test_iso_volume_get_copyright_file_id()
{
struct iso_volume *volume;
volume = iso_volume_new("volume_id", "publisher_id", "data_preparer_id");
CU_ASSERT_PTR_NULL(iso_volume_get_copyright_file_id(volume));
char *copid = "new copyright id";
iso_volume_set_copyright_file_id(volume, copid);
CU_ASSERT_STRING_EQUAL( iso_volume_get_copyright_file_id(volume), "new copyright id" );
iso_volume_free(volume);
}
static void test_iso_volume_set_abstract_file_id()
{
struct iso_volume *volume;
@ -185,6 +285,20 @@ static void test_iso_volume_set_abstract_file_id()
iso_volume_free(volume);
}
static void test_iso_volume_get_abstract_file_id()
{
struct iso_volume *volume;
volume = iso_volume_new("volume_id", "publisher_id", "data_preparer_id");
CU_ASSERT_PTR_NULL(iso_volume_get_abstract_file_id(volume));
char *absid = "new abstract id";
iso_volume_set_abstract_file_id(volume, absid);
CU_ASSERT_STRING_EQUAL(iso_volume_get_abstract_file_id(volume), "new abstract id");
iso_volume_free(volume);
}
static void test_iso_volume_set_biblio_file_id()
{
struct iso_volume *volume;
@ -201,6 +315,20 @@ static void test_iso_volume_set_biblio_file_id()
iso_volume_free(volume);
}
static void test_iso_volume_get_biblio_file_id()
{
struct iso_volume *volume;
volume = iso_volume_new("volume_id", "publisher_id", "data_preparer_id");
CU_ASSERT_PTR_NULL(iso_volume_get_biblio_file_id(volume));
char *bibid = "new biblio id";
iso_volume_set_biblio_file_id(volume, bibid);
CU_ASSERT_STRING_EQUAL(iso_volume_get_biblio_file_id(volume), "new biblio id");
iso_volume_free(volume);
}
static void test_iso_volset_new()
{
struct iso_volume *volume;
@ -228,11 +356,20 @@ void add_volume_suite()
CU_add_test(pSuite, "test of iso_volume_new_with_root()", test_iso_volume_new_with_root);
CU_add_test(pSuite, "test of iso_volume_get_root()", test_iso_volume_get_root);
CU_add_test(pSuite, "test of iso_volume_set_volume_id()", test_iso_volume_set_volume_id);
CU_add_test(pSuite, "test of iso_volume_get_volume_id()", test_iso_volume_get_volume_id);
CU_add_test(pSuite, "test of iso_volume_set_publisher_id()", test_iso_volume_set_publisher_id);
CU_add_test(pSuite, "test of iso_volume_get_publisher_id()", test_iso_volume_get_publisher_id);
CU_add_test(pSuite, "test of iso_volume_set_data_preparer_id()", test_iso_volume_set_data_preparer_id);
CU_add_test(pSuite, "test of iso_volume_get_data_preparer_id()", test_iso_volume_get_data_preparer_id);
CU_add_test(pSuite, "test of iso_volume_set_system_id()", test_iso_volume_set_system_id);
CU_add_test(pSuite, "test of iso_volume_get_system_id()", test_iso_volume_get_system_id);
CU_add_test(pSuite, "test of iso_volume_set_application_id()", test_iso_volume_set_application_id);
CU_add_test(pSuite, "test of iso_volume_get_application_id()", test_iso_volume_get_application_id);
CU_add_test(pSuite, "test of iso_volume_set_copyright_file_id()", test_iso_volume_set_copyright_file_id);
CU_add_test(pSuite, "test of iso_volume_get_copyright_file_id()", test_iso_volume_get_copyright_file_id);
CU_add_test(pSuite, "test of iso_volume_set_abstract_file_id()", test_iso_volume_set_abstract_file_id);
CU_add_test(pSuite, "test of iso_volume_get_abstract_file_id()", test_iso_volume_get_abstract_file_id);
CU_add_test(pSuite, "test of iso_volume_set_biblio_file_id()", test_iso_volume_set_biblio_file_id);
CU_add_test(pSuite, "test of iso_volume_get_biblio_file_id()", test_iso_volume_get_biblio_file_id);
CU_add_test(pSuite, "test of iso_volset_new()", test_iso_volset_new);
}