Implemented advanced unit tests and trivial fixes

This commit is contained in:
Mario Danic 2007-06-25 05:42:29 +00:00
parent f57c1f4652
commit 0a06659b28
6 changed files with 511 additions and 15 deletions

View File

@ -88,6 +88,7 @@ iso_file_table_clear(struct iso_file_table *ft)
node = next; node = next;
} while (node); } while (node);
} }
ft->count = 0;
} }
/** /**

View File

@ -5,7 +5,13 @@
* \file file.h * \file file.h
* *
* Declare the structs to keep track of the files to be written into image. * Declare the structs to keep track of the files to be written into image.
* * These files are stored in a hash table. Two modes of operation are supported:
* when cache inodes is enabled, the files are indexed into the table by the
* device and inode id in the local filesystem. This way, two different files
* with same inode and device id are treated as if they were a single file.
* This is usually the correct behavior, as a different file with same inode
* and device used to be a hard link.
* When cache inode is disabled, indexing is done by path on local filesystem.
*/ */
#ifndef FILE_H_ #ifndef FILE_H_
@ -14,7 +20,7 @@
#define FILE_HASH_NODES 2048 #define FILE_HASH_NODES 2048
struct iso_file { struct iso_file {
char *path; char *path; /**< Path of the file on local filesystem */
off_t size; /**< size of this file */ off_t size; /**< size of this file */
ino_t ino; /**< This will be the inode number on CD of the file (RR) */ ino_t ino; /**< This will be the inode number on CD of the file (RR) */
nlink_t nlink; /**< Number of hard links of the file on CD (RR) */ nlink_t nlink; /**< Number of hard links of the file on CD (RR) */
@ -37,6 +43,10 @@ struct iso_file_table {
struct iso_tree_node_file; struct iso_tree_node_file;
/**
* Create a struct that represents the specified iso_tree_node_file,
* suitable to be stored into the table,
*/
struct iso_file *iso_file_new(struct iso_tree_node_file*); struct iso_file *iso_file_new(struct iso_tree_node_file*);
struct iso_file_table *iso_file_table_new(int cache_inodes); struct iso_file_table *iso_file_table_new(int cache_inodes);
@ -47,6 +57,10 @@ struct iso_file_table *iso_file_table_new(int cache_inodes);
*/ */
void iso_file_table_clear(struct iso_file_table *ft); void iso_file_table_clear(struct iso_file_table *ft);
/**
* Add a new file to the table.
* \return 1 if the file is added, 0 if the file already exist on table
*/
int iso_file_table_add_file(struct iso_file_table *ft, struct iso_file *f); int iso_file_table_add_file(struct iso_file_table *ft, struct iso_file *f);
struct iso_file *iso_file_table_lookup(struct iso_file_table *ft, struct iso_file *iso_file_table_lookup(struct iso_file_table *ft,

View File

@ -187,7 +187,6 @@ iso_tree_node_set_sort_weight(struct iso_tree_node *node, int w)
for (i=0; i < dir->nchildren; i++) { for (i=0; i < dir->nchildren; i++) {
iso_tree_node_set_sort_weight(dir->children[i], w); iso_tree_node_set_sort_weight(dir->children[i], w);
} }
free(dir->children);
} else if ( ISO_ISREG(node) ) { } else if ( ISO_ISREG(node) ) {
struct iso_tree_node_file *file; struct iso_tree_node_file *file;
file = (struct iso_tree_node_file *) node; file = (struct iso_tree_node_file *) node;

View File

@ -7,6 +7,8 @@ rm -rf $TEST_ROOT
#create test folders #create test folders
mkdir -p $TEST_ROOT mkdir -p $TEST_ROOT
mkdir -p $TEST_ROOT/dir1/dir11 mkdir -p $TEST_ROOT/dir1/dir11
chmod 755 $TEST_ROOT/dir1
chmod 755 $TEST_ROOT/dir1/dir11
touch $TEST_ROOT/dir1/dir11/a touch $TEST_ROOT/dir1/dir11/a
echo "This file is to check correct file permissions. set them to 754" > $TEST_ROOT/dir1/permtest echo "This file is to check correct file permissions. set them to 754" > $TEST_ROOT/dir1/permtest
@ -16,6 +18,7 @@ mkdir -p $TEST_ROOT/dir2
ln -s $TEST_ROOT/dir1 "$TEST_ROOT/link to dir1" ln -s $TEST_ROOT/dir1 "$TEST_ROOT/link to dir1"
echo "README file" > $TEST_ROOT/README echo "README file" > $TEST_ROOT/README
chmod 555 $TEST_ROOT/README
ln -s $TEST_ROOT/README "$TEST_ROOT/link to readme" ln -s $TEST_ROOT/README "$TEST_ROOT/link to readme"
echo "No read file" > $TEST_ROOT/no_read echo "No read file" > $TEST_ROOT/no_read

View File

@ -2,7 +2,6 @@
* Unit test for file.h * Unit test for file.h
*/ */
#include "test.h" #include "test.h"
#include "file.h" #include "file.h"
#include "tree.h" #include "tree.h"
@ -12,39 +11,238 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
static void test_iso_file_new()
{
struct iso_tree_node_file *file;
struct iso_file *iso;
file = calloc(1, sizeof(struct iso_tree_node_file) );
file->node.name = "fileName";
file->node.attrib.st_size = 12;
file->node.attrib.st_dev = 15;
file->node.attrib.st_ino = 204;
file->path = "/tmp/filename";
file->sort_weight = 1;
iso = iso_file_new(file);
CU_ASSERT_PTR_NOT_NULL(iso);
CU_ASSERT_STRING_EQUAL(iso->path, "/tmp/filename");
CU_ASSERT_EQUAL(iso->size, 12);
CU_ASSERT_EQUAL(iso->ino, 0);
CU_ASSERT_EQUAL(iso->nlink, 1);
CU_ASSERT_EQUAL(iso->sort_weight, 1);
CU_ASSERT_EQUAL(iso->real_dev, 15);
CU_ASSERT_EQUAL(iso->real_ino, 204);
}
static void test_add_lookup()
{
struct iso_file_table *table;
struct iso_tree_node_file *file1;
struct iso_tree_node_file *file2;
struct iso_file *iso1;
struct iso_file *iso2;
struct iso_file *iso3;
int r;
table = iso_file_table_new(1);
CU_ASSERT_PTR_NOT_NULL( table );
CU_ASSERT_TRUE( table->cache_inodes );
CU_ASSERT_EQUAL(table->count, 0);
file1 = calloc(1, sizeof(struct iso_tree_node_file) );
file1->node.name = "fileName";
file1->node.attrib.st_dev = 15;
file1->node.attrib.st_ino = 204;
file1->path = "/tmp/filename";
iso1 = iso_file_new(file1);
r = iso_file_table_add_file(table, iso1);
CU_ASSERT_EQUAL(r, 1);
CU_ASSERT_EQUAL(table->count, 1);
iso2 = iso_file_table_lookup(table, file1);
CU_ASSERT_PTR_NOT_NULL(iso2);
CU_ASSERT_PTR_EQUAL(iso2, iso1);
file2 = calloc(1, sizeof(struct iso_tree_node_file) );
file2->node.name = "fileName2";
file2->node.attrib.st_dev = 152;
file2->node.attrib.st_ino = 2042;
file2->path = "/tmp/filename2";
iso3 = iso_file_new(file2);
r = iso_file_table_add_file(table, iso3);
CU_ASSERT_EQUAL(r, 1);
CU_ASSERT_EQUAL(table->count, 2);
/* treat to add the same file again */
r = iso_file_table_add_file(table, iso3);
CU_ASSERT_EQUAL(r, 0);
CU_ASSERT_EQUAL(table->count, 2);
iso2 = iso_file_table_lookup(table, file1);
CU_ASSERT_PTR_NOT_NULL(iso2);
CU_ASSERT_PTR_EQUAL(iso2, iso1);
iso2 = iso_file_table_lookup(table, file2);
CU_ASSERT_PTR_NOT_NULL(iso2);
CU_ASSERT_PTR_EQUAL(iso2, iso3);
iso3 = iso_file_new(file2);
r = iso_file_table_add_file(table, iso3);
CU_ASSERT_EQUAL(r, 0);
CU_ASSERT_EQUAL(table->count, 2);
iso_file_table_clear(table);
CU_ASSERT_EQUAL(table->count, 0);
iso2 = iso_file_table_lookup(table, file2);
CU_ASSERT_PTR_NULL(iso2);
free( file1 );
free( file2 );
free( table );
}
static void test_cache_inodes() static void test_cache_inodes()
{
struct iso_file_table *table;
struct iso_tree_node_file *file1;
struct iso_tree_node_file *file2;
struct iso_file *iso1;
struct iso_file *iso2;
struct iso_file *iso3;
int r;
table = iso_file_table_new(1);
CU_ASSERT_PTR_NOT_NULL( table );
CU_ASSERT_TRUE( table->cache_inodes );
CU_ASSERT_EQUAL(table->count, 0);
file1 = calloc(1, sizeof(struct iso_tree_node_file) );
file1->node.name = "fileName";
file1->node.attrib.st_dev = 15;
file1->node.attrib.st_ino = 204;
file1->path = "/tmp/filename";
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.attrib.st_dev = 15;
file2->node.attrib.st_ino = 204;
file2->path = "/tmp/another";
iso2 = iso_file_new(file2);
/* ensure it's not added again... */
r = iso_file_table_add_file(table, iso2);
CU_ASSERT_EQUAL(r, 0);
/* ...and the lookup returns the first */
iso3 = iso_file_table_lookup(table, file2);
CU_ASSERT_PTR_EQUAL(iso1, iso3);
free(iso2);
free(file2);
/* and now a file with same inode but different device */
file2 = calloc(1, sizeof(struct iso_tree_node_file) );
file2->node.name = "different file";
file2->node.attrib.st_dev = 16; /* different dev id */
file2->node.attrib.st_ino = 204;
file2->path = "/tmp/different";
iso2 = iso_file_new(file2);
r = iso_file_table_add_file(table, iso2);
CU_ASSERT_EQUAL(r, 1);
iso3 = iso_file_table_lookup(table, file2);
CU_ASSERT_PTR_NOT_EQUAL(iso3, iso1);
CU_ASSERT_PTR_EQUAL(iso3, iso2);
iso_file_table_clear(table);
free( file1 );
free( file2 );
free( table );
}
static void test_no_cache_inodes()
{ {
struct iso_file_table *table; struct iso_file_table *table;
struct iso_tree_node_file *file1; struct iso_tree_node_file *file1;
struct iso_tree_node_file *file2; struct iso_tree_node_file *file2;
struct iso_tree_node_file *file3; struct iso_tree_node_file *file3;
struct iso_file *iso1; struct iso_file *iso1;
struct iso_file *iso2;
struct iso_file *iso3;
int r;
table = iso_file_table_new(1); table = iso_file_table_new(0);
CU_ASSERT_PTR_NOT_NULL( table ); CU_ASSERT_PTR_NOT_NULL( table );
CU_ASSERT_TRUE( table->cache_inodes ); CU_ASSERT_FALSE( table->cache_inodes );
CU_ASSERT_EQUAL(table->count, 0);
file1 = calloc(1, sizeof(struct iso_tree_node_file) ); file1 = calloc(1, sizeof(struct iso_tree_node_file) );
file1->node.name = "fileName"; file1->node.name = "fileName";
file1->node.attrib.st_size = 12;
file1->node.attrib.st_dev = 15; file1->node.attrib.st_dev = 15;
file1->node.attrib.st_ino = 204; file1->node.attrib.st_ino = 204;
file1->path = "/tmp/filename"; file1->path = "/tmp/filename";
file1->sort_weight = 1;
iso1 = iso_file_new(file1); iso1 = iso_file_new(file1);
CU_ASSERT_STRING_EQUAL(iso1->path, "/tmp/filename"); r = iso_file_table_add_file(table, iso1);
CU_ASSERT_EQUAL(r, 1);
//TODO /* 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.attrib.st_dev = 15;
file2->node.attrib.st_ino = 204;
file2->path = "/tmp/another";
iso2 = iso_file_new(file2);
free( file1 ); /* ensure is added */
r = iso_file_table_add_file(table, iso2);
CU_ASSERT_EQUAL(r, 1);
iso3 = iso_file_table_lookup(table, file2);
CU_ASSERT_PTR_EQUAL(iso3, iso2);
/* and now a file with same inode and path */
file3 = calloc(1, sizeof(struct iso_tree_node_file) );
file3->node.name = "different file";
file3->node.attrib.st_dev = 15;
file3->node.attrib.st_ino = 204;
file3->path = "/tmp/filename";
iso3 = iso_file_new(file3);
r = iso_file_table_add_file(table, iso3);
CU_ASSERT_EQUAL(r, 0);
iso3 = iso_file_table_lookup(table, file3);
CU_ASSERT_PTR_EQUAL(iso3, iso1);
iso_file_table_clear(table);
free(file1);
free(file2);
free(file3);
free(table);
} }
void add_file_hashtable_suite() void add_file_hashtable_suite()
{ {
CU_pSuite pSuite = CU_add_suite("FileHashtableSuite", NULL, NULL); CU_pSuite pSuite = CU_add_suite("FileHashtableSuite", NULL, NULL);
CU_add_test(pSuite, "test of cache_inodes", test_cache_inodes); 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);
} }

View File

@ -31,6 +31,7 @@ static void test_add_dir() {
struct iso_tree_node_dir *dir; struct iso_tree_node_dir *dir;
root = iso_tree_new_root(); root = iso_tree_new_root();
CU_ASSERT_PTR_NOT_NULL(root);
dir = iso_tree_add_dir(root, "New dir name"); dir = iso_tree_add_dir(root, "New dir name");
CU_ASSERT_PTR_NOT_NULL(root); CU_ASSERT_PTR_NOT_NULL(root);
CU_ASSERT_PTR_NOT_NULL(dir); CU_ASSERT_PTR_NOT_NULL(dir);
@ -39,6 +40,7 @@ static void test_add_dir() {
CU_ASSERT_PTR_EQUAL(root->children[0], (struct iso_tree_node *)dir); CU_ASSERT_PTR_EQUAL(root->children[0], (struct iso_tree_node *)dir);
CU_ASSERT_STRING_EQUAL( dir->node.name, "New dir name"); CU_ASSERT_STRING_EQUAL( dir->node.name, "New dir name");
CU_ASSERT( S_ISDIR(dir->node.attrib.st_mode) ); CU_ASSERT( S_ISDIR(dir->node.attrib.st_mode) );
iso_tree_free((struct iso_tree_node *)root);
} }
static void test_add_file() { static void test_add_file() {
@ -56,6 +58,7 @@ static void test_add_file() {
CU_ASSERT_STRING_EQUAL( file->node.name, "README" ); CU_ASSERT_STRING_EQUAL( file->node.name, "README" );
CU_ASSERT_STRING_EQUAL( file->path, "/tmp/libisofs_test/README" ); CU_ASSERT_STRING_EQUAL( file->path, "/tmp/libisofs_test/README" );
CU_ASSERT( S_ISREG(file->node.attrib.st_mode) ); CU_ASSERT( S_ISREG(file->node.attrib.st_mode) );
iso_tree_free((struct iso_tree_node *)root);
} }
static void test_add_symlink() { static void test_add_symlink() {
@ -73,13 +76,78 @@ static void test_add_symlink() {
CU_ASSERT_STRING_EQUAL( ((struct iso_tree_node_symlink*)lnk)->dest, CU_ASSERT_STRING_EQUAL( ((struct iso_tree_node_symlink*)lnk)->dest,
"/tmp/libisofs_test/README" ); "/tmp/libisofs_test/README" );
CU_ASSERT( S_ISLNK(lnk->attrib.st_mode) ); CU_ASSERT( S_ISLNK(lnk->attrib.st_mode) );
iso_tree_free((struct iso_tree_node *)root);
}
static void test_add_node() {
struct iso_tree_node_dir *root;
struct iso_tree_node *node;
root = iso_tree_new_root();
/* test addition of a dir */
node = iso_tree_add_node(root, "/tmp/libisofs_test/dir1");
CU_ASSERT_PTR_NOT_NULL(node);
CU_ASSERT_PTR_EQUAL(node->parent, root);
CU_ASSERT_EQUAL(root->nchildren, 1);
CU_ASSERT_PTR_EQUAL(root->children[0], node);
CU_ASSERT_STRING_EQUAL( node->name, "dir1");
CU_ASSERT( ISO_ISDIR(node) );
CU_ASSERT( S_ISDIR(node->attrib.st_mode) );
/* test addition of a link */
node = iso_tree_add_node(root, "/tmp/libisofs_test/link to readme");
CU_ASSERT_PTR_NOT_NULL(node);
CU_ASSERT_PTR_EQUAL(node->parent, root);
CU_ASSERT_EQUAL(root->nchildren, 2);
CU_ASSERT_PTR_EQUAL(root->children[1], node);
CU_ASSERT( ISO_ISLNK(node) );
CU_ASSERT( S_ISLNK(node->attrib.st_mode) );
CU_ASSERT_STRING_EQUAL( node->name, "link to readme");
CU_ASSERT_STRING_EQUAL( ((struct iso_tree_node_symlink*)node)->dest,
"/tmp/libisofs_test/README" );
/* test addition of a file */
node = iso_tree_add_node(root, "/tmp/libisofs_test/README");
CU_ASSERT_PTR_NOT_NULL(node);
CU_ASSERT_PTR_EQUAL(node->parent, root);
CU_ASSERT_EQUAL(root->nchildren, 3);
CU_ASSERT_PTR_EQUAL(root->children[2], 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,
"/tmp/libisofs_test/README" );
/* test no exiting file */
node = iso_tree_add_node(root, "/tmp/libisofs_test/THISNOTEXIST");
CU_ASSERT_PTR_NULL(node);
CU_ASSERT_EQUAL(libisofs_errno, NO_FILE);
CU_ASSERT_EQUAL(root->nchildren, 3);
/* test no valid file */
node = iso_tree_add_node(root, "/dev/zero");
CU_ASSERT_PTR_NULL(node);
CU_ASSERT_EQUAL(libisofs_errno, UNEXPECTED_FILE_TYPE);
CU_ASSERT_EQUAL(root->nchildren, 3);
/* test no read perm file */
node = iso_tree_add_node(root, "/tmp/libisofs_test/no_read");
CU_ASSERT_PTR_NULL(node);
CU_ASSERT_EQUAL(libisofs_errno, NO_READ_ACCESS);
CU_ASSERT_EQUAL(root->nchildren, 3);
iso_tree_free((struct iso_tree_node *)root);
} }
static void test_radd_dir() { static void test_radd_dir() {
struct iso_tree_node_dir *root; struct iso_tree_node_dir *root;
struct iso_tree_node_dir *child; struct iso_tree_node_dir *child;
struct iso_tree_node_file *file;
struct iso_tree_radd_dir_behavior behavior = {0,0,0}; struct iso_tree_radd_dir_behavior behavior = {0,0,0};
//TODO write really full test
root = iso_tree_new_root(); root = iso_tree_new_root();
CU_ASSERT_PTR_NOT_NULL(root); CU_ASSERT_PTR_NOT_NULL(root);
@ -96,11 +164,216 @@ static void test_radd_dir() {
CU_ASSERT_EQUAL( child->nchildren, 0); CU_ASSERT_EQUAL( child->nchildren, 0);
CU_ASSERT_STRING_EQUAL( child->node.name, "dir2" ); CU_ASSERT_STRING_EQUAL( child->node.name, "dir2" );
//TODO write really full test 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 ); //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;
root = iso_tree_new_root();
/* test on a dir */
node = iso_tree_add_node(root, "/tmp/libisofs_test/dir1");
CU_ASSERT_PTR_NOT_NULL(node);
CU_ASSERT_STRING_EQUAL( node->name, "dir1");
iso_tree_node_set_name(node, "newname");
CU_ASSERT_STRING_EQUAL( node->name, "newname");
/* test on a link */
node = iso_tree_add_node(root, "/tmp/libisofs_test/link to readme");
CU_ASSERT_PTR_NOT_NULL(node);
CU_ASSERT_STRING_EQUAL( node->name, "link to readme");
iso_tree_node_set_name(node, "new link name");
CU_ASSERT_STRING_EQUAL( node->name, "new link name");
/* test on a file */
node = iso_tree_add_node(root, "/tmp/libisofs_test/README");
CU_ASSERT_PTR_NOT_NULL(node);
CU_ASSERT_STRING_EQUAL( node->name, "README" );
iso_tree_node_set_name(node, "new file name");
CU_ASSERT_STRING_EQUAL( node->name, "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;
root = iso_tree_new_root();
/* test on a dir */
node = iso_tree_add_node(root, "/tmp/libisofs_test/dir1");
CU_ASSERT_PTR_NOT_NULL(node);
CU_ASSERT_EQUAL(node->hide_flags, 0);
iso_tree_node_set_hidden(node, LIBISO_HIDE_ON_RR);
CU_ASSERT_EQUAL(node->hide_flags, LIBISO_HIDE_ON_RR);
iso_tree_node_set_hidden(node, LIBISO_HIDE_ON_JOLIET);
CU_ASSERT_EQUAL(node->hide_flags, LIBISO_HIDE_ON_JOLIET);
iso_tree_node_set_hidden(node, LIBISO_HIDE_ON_RR|LIBISO_HIDE_ON_JOLIET);
CU_ASSERT_EQUAL(node->hide_flags, 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_PTR_NOT_NULL(node);
CU_ASSERT_EQUAL(node->hide_flags, 0);
iso_tree_node_set_hidden(node, LIBISO_HIDE_ON_RR);
CU_ASSERT_EQUAL(node->hide_flags, LIBISO_HIDE_ON_RR);
iso_tree_node_set_hidden(node, LIBISO_HIDE_ON_JOLIET);
CU_ASSERT_EQUAL(node->hide_flags, LIBISO_HIDE_ON_JOLIET);
iso_tree_node_set_hidden(node, LIBISO_HIDE_ON_RR|LIBISO_HIDE_ON_JOLIET);
CU_ASSERT_EQUAL(node->hide_flags, LIBISO_HIDE_ON_RR|LIBISO_HIDE_ON_JOLIET);
/* test on a file */
node = iso_tree_add_node(root, "/tmp/libisofs_test/README");
CU_ASSERT_PTR_NOT_NULL(node);
CU_ASSERT_EQUAL(node->hide_flags, 0);
iso_tree_node_set_hidden(node, LIBISO_HIDE_ON_RR);
CU_ASSERT_EQUAL(node->hide_flags, LIBISO_HIDE_ON_RR);
iso_tree_node_set_hidden(node, LIBISO_HIDE_ON_JOLIET);
CU_ASSERT_EQUAL(node->hide_flags, LIBISO_HIDE_ON_JOLIET);
iso_tree_node_set_hidden(node, LIBISO_HIDE_ON_RR|LIBISO_HIDE_ON_JOLIET);
CU_ASSERT_EQUAL(node->hide_flags, 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;
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_PTR_NOT_NULL(node);
CU_ASSERT_EQUAL(node->attrib.st_gid, mygid);
iso_tree_node_set_gid(node, 1234);
CU_ASSERT_EQUAL(node->attrib.st_gid, 1234);
/* test on a link */
node = iso_tree_add_node(root, "/tmp/libisofs_test/link to readme");
CU_ASSERT_PTR_NOT_NULL(node);
CU_ASSERT_EQUAL(node->attrib.st_gid, mygid);
iso_tree_node_set_gid(node, 1234);
CU_ASSERT_EQUAL(node->attrib.st_gid, 1234);
/* test on a file */
node = iso_tree_add_node(root, "/tmp/libisofs_test/README");
CU_ASSERT_PTR_NOT_NULL(node);
CU_ASSERT_EQUAL(node->attrib.st_gid, mygid);
iso_tree_node_set_gid(node, 1234);
CU_ASSERT_EQUAL(node->attrib.st_gid, 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;
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_PTR_NOT_NULL(node);
CU_ASSERT_EQUAL(node->attrib.st_uid, myuid);
iso_tree_node_set_uid(node, 1234);
CU_ASSERT_EQUAL(node->attrib.st_uid, 1234);
/* test on a link */
node = iso_tree_add_node(root, "/tmp/libisofs_test/link to readme");
CU_ASSERT_PTR_NOT_NULL(node);
CU_ASSERT_EQUAL(node->attrib.st_uid, myuid);
iso_tree_node_set_uid(node, 1234);
CU_ASSERT_EQUAL(node->attrib.st_uid, 1234);
/* test on a file */
node = iso_tree_add_node(root, "/tmp/libisofs_test/README");
CU_ASSERT_PTR_NOT_NULL(node);
CU_ASSERT_EQUAL(node->attrib.st_uid, myuid);
iso_tree_node_set_uid(node, 1234);
CU_ASSERT_EQUAL(node->attrib.st_uid, 1234);
//TODO
iso_tree_free((struct iso_tree_node *)root);
}
static void test_set_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_PTR_NOT_NULL(node);
CU_ASSERT_EQUAL(node->attrib.st_mode, S_IFDIR | 0755);
iso_tree_node_set_permissions(node, 0777);
CU_ASSERT_EQUAL(node->attrib.st_mode, S_IFDIR | 0777);
iso_tree_node_set_permissions(node, 0744);
CU_ASSERT_EQUAL(node->attrib.st_mode, S_IFDIR | 0744);
iso_tree_node_set_permissions(node, 0411);
CU_ASSERT_EQUAL(node->attrib.st_mode, S_IFDIR | 0411);
/* test on a link */
node = iso_tree_add_node(root, "/tmp/libisofs_test/link to readme");
CU_ASSERT_PTR_NOT_NULL(node);
CU_ASSERT_EQUAL(node->attrib.st_mode, S_IFLNK | 0777);
iso_tree_node_set_permissions(node, 0555);
CU_ASSERT_EQUAL(node->attrib.st_mode, S_IFLNK | 0555);
iso_tree_node_set_permissions(node, 0744);
CU_ASSERT_EQUAL(node->attrib.st_mode, S_IFLNK | 0744);
iso_tree_node_set_permissions(node, 0411);
CU_ASSERT_EQUAL(node->attrib.st_mode, S_IFLNK | 0411);
/* test on a file */
node = iso_tree_add_node(root, "/tmp/libisofs_test/README");
CU_ASSERT_PTR_NOT_NULL(node);
CU_ASSERT_EQUAL(node->attrib.st_mode, S_IFREG | 0555);
iso_tree_node_set_permissions(node, 0777);
CU_ASSERT_EQUAL(node->attrib.st_mode, S_IFREG | 0777);
iso_tree_node_set_permissions(node, 0744);
CU_ASSERT_EQUAL(node->attrib.st_mode, S_IFREG | 0744);
iso_tree_node_set_permissions(node, 0411);
CU_ASSERT_EQUAL(node->attrib.st_mode, S_IFREG | 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;
struct iso_tree_node_file *file;
root = iso_tree_new_root();
dir = iso_tree_add_dir(root, "New dir name");
CU_ASSERT_PTR_NOT_NULL(dir);
file = (struct iso_tree_node_file *)
iso_tree_add_file(dir, "/tmp/libisofs_test/README");
CU_ASSERT_EQUAL(file->sort_weight, 0);
iso_tree_node_set_sort_weight((struct iso_tree_node *) file, 15);
CU_ASSERT_EQUAL(file->sort_weight, 15);
iso_tree_node_set_sort_weight((struct iso_tree_node *) file, -15);
CU_ASSERT_EQUAL(file->sort_weight, -15);
/* changes to dir involve update files inside it */
iso_tree_node_set_sort_weight((struct iso_tree_node *) dir, 28);
CU_ASSERT_EQUAL(file->sort_weight, 28);
iso_tree_free((struct iso_tree_node *)root);
}
void add_tree_suite() void add_tree_suite()
{ {
CU_pSuite pSuite = CU_add_suite("TreeSuite", NULL, NULL); CU_pSuite pSuite = CU_add_suite("TreeSuite", NULL, NULL);
@ -109,5 +382,13 @@ void add_tree_suite()
CU_add_test(pSuite, "test of iso_tree_add_dir()", test_add_dir); 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_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_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_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_set_hidden()", test_set_hidden);
CU_add_test(pSuite, "test of iso_tree_node_set_gid()", test_set_gid);
CU_add_test(pSuite, "test of iso_tree_node_set_uid()", test_set_uid);
CU_add_test(pSuite, "test of iso_tree_node_set_permissions()", test_set_permissions);
CU_add_test(pSuite, "test of iso_tree_node_set_sort_weight()", test_set_sort_weight);
} }