diff --git a/Makefile.am b/Makefile.am index ef951d0..28374a3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -48,6 +48,21 @@ test_iso_CPPFLAGS = -Ilibisofs test_iso_LDADD = $(libisofs_libisofs_la_OBJECTS) $(THREAD_LIBS) test_iso_SOURCES = test/iso.c +## Build unit test + +check_PROGRAMS = \ + test/test + +test_test_CPPFLAGS = -Ilibisofs +test_test_LDADD = $(libisofs_libisofs_la_OBJECTS) $(THREAD_LIBS) -lcunit +test_test_LDFLAGS = -L.. -lm + +test_test_SOURCES = \ + test/test_exclude.c \ + test/test_tree.c \ + test/test_file_hashtable.c \ + test/test_util.c \ + test/test.c ## ========================================================================= ## diff --git a/libisofs/ecma119.c b/libisofs/ecma119.c index 7e2b5e0..7747b2c 100755 --- a/libisofs/ecma119.c +++ b/libisofs/ecma119.c @@ -269,45 +269,62 @@ calc_file_pos(struct ecma119_write_target *t, t->curfile = 0; } -struct ecma119_write_target* + +/** + * Create a new ecma119_write_target from the given volume number of the + * given volume set. + * + * \pre \p volnum is less than \p volset-\>volset_size. + * \post For each node in the tree, writer_data has been allocated. + * \post The directory heirarchy has been reorganised to be ecma119-compatible. + */ +static struct ecma119_write_target* ecma119_target_new(struct iso_volset *volset, - int volnum, - int level, - int flags) + const struct ecma119_source_opts *opts) { struct ecma119_write_target *t = calloc(1, sizeof(struct ecma119_write_target)); size_t i, j, cur; struct iso_tree_node *iso_root = - (struct iso_tree_node*) volset->volume[volnum]->root; + (struct iso_tree_node*) volset->volume[opts->volnum]->root; - //TODO default values here, need an API for this - t->cache_inodes = 1; - t->replace_mode = 1; - t->dir_mode = 0555; - t->file_mode = 0444; - t->gid = 0; - t->uid = 0; - t->input_charset = "UTF-8"; - t->ouput_charset = "UTF-8"; - t->sort_files = 1; + t->cache_inodes = opts->no_cache_inodes ? 0 : 1; + t->replace_mode = opts->default_mode ? 0 : 1; + if ( opts->replace_dir_mode ) + t->replace_mode |= 0x02; + if ( opts->replace_file_mode ) + t->replace_mode |= 0x04; + if ( opts->replace_gid ) + t->replace_mode |= 0x08; + if ( opts->replace_uid ) + t->replace_mode |= 0x10; + t->dir_mode = opts->dir_mode; + t->file_mode = opts->file_mode; + t->gid = opts->gid; + t->uid = opts->uid; + + //TODO get defailt values for current locale, no UTF-8 + t->input_charset = opts->input_charset ? opts->input_charset : "UTF-8"; + t->ouput_charset = opts->ouput_charset ? opts->ouput_charset : "UTF-8"; + t->sort_files = opts->sort_files; t->file_table = iso_file_table_new(t->cache_inodes); volset->refcount++; - t->iso_level = level; + t->iso_level = opts->level; t->block_size = 2048; + t->relaxed_constraints = opts->relaxed_constraints; - t->rockridge = (flags & ECMA119_ROCKRIDGE) ? 1 : 0; - t->joliet = (flags & ECMA119_JOLIET) ? 1 : 0; + t->rockridge = (opts->flags & ECMA119_ROCKRIDGE) ? 1 : 0; + t->joliet = (opts->flags & ECMA119_JOLIET) ? 1 : 0; - t->catalog = volset->volume[volnum]->bootcat; + t->catalog = volset->volume[opts->volnum]->bootcat; t->eltorito = t->catalog ? 1 : 0; t->root = ecma119_tree_create(t, iso_root); if (t->joliet) t->joliet_root = joliet_tree_create(t, iso_root); t->volset = volset; - t->volnum = volnum; + t->volnum = opts->volnum; t->now = time(NULL); if (t->rockridge) @@ -811,15 +828,13 @@ bs_free_data(struct burn_source *bs) } struct burn_source *iso_source_new_ecma119(struct iso_volset *volset, - int volnum, - int level, - int flags) + struct ecma119_source_opts *opts) { struct burn_source *ret = calloc(1, sizeof(struct burn_source)); ret->refcount = 1; ret->read = bs_read; ret->get_size = bs_get_size; ret->free_data = bs_free_data; - ret->data = ecma119_target_new(volset, volnum, level, flags); + ret->data = ecma119_target_new(volset, opts); return ret; } diff --git a/libisofs/ecma119.h b/libisofs/ecma119.h index 2b893cd..0600d04 100755 --- a/libisofs/ecma119.h +++ b/libisofs/ecma119.h @@ -65,6 +65,8 @@ struct ecma119_write_target unsigned int iso_level:2; unsigned int eltorito:1; + int relaxed_constraints; /**< see ecma119_relaxed_constraints_flag */ + struct el_torito_boot_catalog *catalog; int replace_mode; /**< Replace ownership and modes of files @@ -168,19 +170,6 @@ struct ecma119_write_target } state_files; }; -/** - * Create a new ecma119_write_target from the given volume number of the - * given volume set. - * - * \pre \p volnum is less than \p volset-\>volset_size. - * \post For each node in the tree, writer_data has been allocated. - * \post The directory heirarchy has been reorganised to be ecma119-compatible. - */ -struct ecma119_write_target *ecma119_target_new(struct iso_volset *volset, - int volnum, - int level, - int flags); - #define BP(a,b) [(b) - (a) + 1] struct ecma119_pri_vol_desc diff --git a/libisofs/ecma119_tree.c b/libisofs/ecma119_tree.c index db9f926..5645954 100644 --- a/libisofs/ecma119_tree.c +++ b/libisofs/ecma119_tree.c @@ -74,12 +74,23 @@ create_ecma119_node(struct ecma119_write_target *t, char *(*iso_name)(const char *, const char *) = ISO_ISDIR(iso) ? ((t->iso_level == 1) ? iso_1_dirid : iso_2_dirid) : ((t->iso_level == 1) ? iso_1_fileid : iso_2_fileid); + char *(*iso_r_name)(const char *, const char *, int) = + ISO_ISDIR(iso) ? iso_r_dirid : iso_r_fileid; assert(t && (!parent || parent->type == ECMA119_DIR) && iso ); ret = calloc(1, sizeof(struct ecma119_tree_node)); - ret->iso_name = iso->name ? iso_name(iso->name, t->input_charset) : NULL; + /* + * If selected one ISO relaxed constraints other than NO_DIR_REALOCATION, + * we use the function that computes the relaxed name, otherwise normal + * function for specified level is used. + */ + ret->iso_name = iso->name ? + ( t->relaxed_constraints & ~ECMA119_NO_DIR_REALOCATION ? + iso_r_name(iso->name, t->input_charset, t->relaxed_constraints) : + iso_name(iso->name, t->input_charset) + ) : NULL; ret->dirent_len = calc_dirent_len(ret); ret->attrib = iso->attrib; if ( t->rockridge && t->replace_mode ) @@ -507,7 +518,8 @@ ecma119_tree_create(struct ecma119_write_target *t, struct iso_tree_node *iso_root) { t->root = create_tree(t, NULL, iso_root); - reorder_tree(t, t->root, t->root); + if ( !(t->relaxed_constraints & ECMA119_NO_DIR_REALOCATION) ) + reorder_tree(t, t->root, t->root); sort_tree(t->root); mangle_all(t->root); return t->root; diff --git a/libisofs/libisofs.h b/libisofs/libisofs.h index 5bfcae7..5ef0681 100755 --- a/libisofs/libisofs.h +++ b/libisofs/libisofs.h @@ -64,6 +64,69 @@ enum eltorito_boot_media_type { ELTORITO_NO_EMUL }; +enum ecma119_relaxed_constraints_flag { + ECMA119_OMIT_VERSION_NUMBERS = (1<<0), + /* 37 char filenames involves no version number */ + ECMA119_37_CHAR_FILENAMES = (1<<1) | (1<<0), + ECMA119_NO_DIR_REALOCATION = (1<<2), + ECMA119_RELAXED_FILENAMES = (1<<3) +}; + +/** + * Holds the options for the image generation. + */ +struct ecma119_source_opts { + int volnum; /**< The volume in the set which you want to write (usually 0) */ + int level; /**< ISO level to write at. */ + int flags; /**< Which extensions to support. */ + int relaxed_constraints; /**< see ecma119_relaxed_constraints_flag */ + unsigned int no_cache_inodes:1; + /**< If use inode caching or not. Set it to 1 to prevent + * inode caching. + * Usage of inode caching allows detection of hard-links, + * which contents are only written once to disc this way. + * Don't use inode caching in systems with non unique inodes + * per device. + */ + unsigned int sort_files:1; + /**< If files should be sorted based on their weight. */ + unsigned int default_mode:1; + /**< + * The default values for files and directory permissions, + * gid and uid. This option can be overwritten when set + * one of the following. + * 0 to use useful values, 1 to use node modes (this are + * the same as filesystem ones if not changed after added + * to tree). + */ + unsigned int replace_dir_mode:1; + /**< + * When 1, permissions for all dirs will be replaced by the + * specified in dir_mode field. + */ + unsigned int replace_file_mode:1; + /**< + * When 1, permissions for all files will be replaced by the + * specified in file_mode field. + */ + unsigned int replace_uid:1; + /**< + * When 1, uid of all nodes (both files and dirs) will be + * replaced by the specified in uid field. + */ + unsigned int replace_gid:1; + /**< + * When 1, gid of all nodes (both files and dirs) will be + * replaced by the specified in gid field. + */ + mode_t dir_mode; /**< Mode to use on dirs when replace_dir_mode is set. */ + mode_t file_mode; /**< Mode to use on files when replace_file_mode is set. */ + gid_t gid; /**< gid to use when replace_gid is set. */ + uid_t uid; /**< uid to use when replace_uid is set. */ + char *input_charset; /**< NULL to use default charset */ + char *ouput_charset; /**< NULL to use default charset */ +}; + /** * This will hold the error code for some functions, if them fail. */ @@ -433,33 +496,19 @@ void iso_tree_node_set_sort_weight(struct iso_tree_node *node, int w); */ void iso_tree_print(const struct iso_tree_node *root, int spaces); - -/** - * Holds the options for the image generation. - */ -//struct ecma119_source_opts { -// int volnum; /**< The volume in the set which you want to write (usually 0) */ -// int level; /**< ISO level to write at. */ -// int flags; /**< Which extensions to support. */ -//}; - /** Create a burn_source which can be used as a data source for a track * * The volume set used to create the libburn_source can _not_ be modified * until the libburn_source is freed. * * \param volumeset The volume set from which you want to write - * \param volnum The volume in the set which you want to write (usually 0) - * \param level ISO level to write at. - * \param flags Which extensions to support. + * \param opts The options for image generation * * \pre \p volumeset is non-NULL * \pre \p volnum is less than \p volset->volset_size. * \return A burn_source to be used for the data source for a track */ -struct burn_source* iso_source_new_ecma119 (struct iso_volset *volumeset, - int volnum, - int level, - int flags); +struct burn_source* iso_source_new_ecma119(struct iso_volset *volumeset, + struct ecma119_source_opts *opts); #endif /* LIBISO_LIBISOFS_H */ diff --git a/libisofs/util.c b/libisofs/util.c index d4e8d26..c9e68a9 100755 --- a/libisofs/util.c +++ b/libisofs/util.c @@ -20,6 +20,7 @@ #include #include "util.h" +#include "libisofs.h" /* avoids warning and names in iso, joliet and rockridge can't be > 255 bytes * anyway. There are at most 31 characters in iso level 1, 255 for rockridge, @@ -401,6 +402,33 @@ char *iso_2_dirid(const char *src, const char *icharset) return iso_dirid(src, 31, icharset); } +char *iso_r_dirid(const char *src, const char *icharset, int flags) +{ + char *ret = str2ascii(src, icharset); + size_t size, len, i; + + if (!ret) + return NULL; + + size = flags & ECMA119_37_CHAR_FILENAMES ? 37 : 31; + + len = strlen(ret); + if (len > size) { + ret[size] = '\0'; + len = size; + } + + if (flags & ECMA119_RELAXED_FILENAMES) + return ret; + + for (i = 0; i < len; i++) { + char c = toupper(ret[i]); + ret[i] = valid_d_char(c) ? c : '_'; + } + + return ret; +} + char *iso_1_fileid(const char *src_arg, const char *icharset) { char *src = str2ascii(src_arg, icharset); @@ -470,7 +498,7 @@ char *iso_2_fileid(const char *src_arg, const char *icharset) extension, we need to calculate their new lengths (lnname and lnext). If the original filename is too long, we start by trimming the extension, but keep a minimum extension length of 3. */ - if (dot == NULL || dot == src || *(dot + 1) == '\0') { + if (dot == NULL || *(dot + 1) == '\0') { lname = strlen(src); lnname = (lname > 30) ? 30 : lname; lext = lnext = 0; @@ -511,6 +539,85 @@ char *iso_2_fileid(const char *src_arg, const char *icharset) return dest; } +char * +iso_r_fileid(const char *src_arg, const char *icharset, int flag) +{ + char *src = str2ascii(src_arg, icharset); + char *dest; + char *dot; + int lname, lext, lnname, lnext, pos, i; + + size_t size = flag & (1<<1) ? 37 : 33; + + if (!src) + return NULL; + + dest = malloc(size+1); + + if (flag & ECMA119_RELAXED_FILENAMES) { + strncpy(dest, src, size); + dest[size] = '\0'; /* ensure 37 / 33 max length */ + pos = strlen(dest); + pos = pos < (size == 37 ? 37 : 31) ? pos : (size == 37 ? 37 : 31); + if ( !(flag & ECMA119_OMIT_VERSION_NUMBERS) ) { + dest[pos++] = ';'; + dest[pos++] = '1'; + } + dest[pos] = '\0'; + return dest; + } + + /* no relaxed filenames */ + dot = strrchr(src, '.'); + + size_t max = size == 37 ? 36 : 30; + /* Since the maximum length can be divided freely over the name and + extension, we need to calculate their new lengths (lnname and + lnext). If the original filename is too long, we start by trimming + the extension, but keep a minimum extension length of 3. */ + if (dot == NULL || *(dot + 1) == '\0') { + lname = strlen(src); + lnname = (lname > max) ? max : lname; + lext = lnext = 0; + } else { + lext = strlen(dot + 1); + lname = strlen(src) - lext - 1; + lnext = (strlen(src) > max + 1 && lext > 3) + ? (lname < max - 3 ? max - lname : 3) : lext; + lnname = (strlen(src) > max +1) ? max - lnext : lname; + } + + if (lnname == 0 && lnext == 0) { + free(src); + free(dest); + return NULL; + } + + pos = 0; + /* Convert up to lnname characters of the filename. */ + for (i = 0; i < lnname; i++) { + char c = toupper(src[i]); + + dest[pos++] = valid_d_char(c) ? c : '_'; + } + dest[pos++] = '.'; + /* Convert up to lnext characters of the extension, if any. */ + for (i = 0; i < lnext; i++) { + char c = toupper(src[lname + 1 + i]); + + dest[pos++] = valid_d_char(c) ? c : '_'; + } + if ( !(flag & ECMA119_OMIT_VERSION_NUMBERS) ) { + dest[pos++] = ';'; + dest[pos++] = '1'; + } + dest[pos] = '\0'; + dest = (char *)realloc(dest, pos + 1); + + free(src); + return dest; +} + char * iso_p_fileid(const char *src, const char *icharset) { diff --git a/libisofs/util.h b/libisofs/util.h index 6bc1eb5..7f8fd74 100755 --- a/libisofs/util.h +++ b/libisofs/util.h @@ -49,6 +49,11 @@ char *iso_1_dirid(const char *src, const char *); */ char *iso_2_dirid(const char *src, const char *); +/** + * Create a directory identifier with relaxed constraints + */ +char *iso_r_dirid(const char *src, const char *icharset, int flags); + /** * Create a level 1 file identifier that consists of a name, extension and * version number. The resulting string will have a file name of maximum @@ -67,6 +72,11 @@ char *iso_1_fileid(const char *src, const char *); */ char *iso_2_fileid(const char *src, const char *); +/** + * Create a file identifier with relaxed constraints. + */ +char *iso_r_fileid(const char *src, const char *icharset, int flags); + /** * Create a Joliet file or directory identifier that consists of a name, * extension and version number. The combined name and extension length will diff --git a/test.sh b/test.sh index 8b6ca30..71c662e 100644 --- a/test.sh +++ b/test.sh @@ -28,33 +28,3 @@ fi test/test -#!/bin/bash - -TEST_ROOT=/tmp/libisofs_test - -rm -rf $TEST_ROOT - -#create test folders -mkdir -p $TEST_ROOT -mkdir -p $TEST_ROOT/dir1/dir11 - -touch $TEST_ROOT/dir1/dir11/a -echo "This file is to check correct file permissions. set them to 754" > $TEST_ROOT/dir1/permtest -chmod 754 $TEST_ROOT/dir1/permtest - -mkdir -p $TEST_ROOT/dir2 -ln -s $TEST_ROOT/dir1 "$TEST_ROOT/link to dir1" - -echo "README file" > $TEST_ROOT/README -ln -s $TEST_ROOT/README "$TEST_ROOT/link to readme" - -echo "No read file" > $TEST_ROOT/no_read -chmod 000 $TEST_ROOT/no_read - -if ! make check -then - exit 1 -fi - -test/test - diff --git a/test/iso.c b/test/iso.c index ef83dda..da3d12d 100644 --- a/test/iso.c +++ b/test/iso.c @@ -123,7 +123,14 @@ int main(int argc, char **argv) iso_volume_set_application_id(volume, "Libburnia"); iso_volume_set_copyright_file_id(volume, "LICENSE"); - src = iso_source_new_ecma119(volset, 0, level, flags); + int 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"}; + + src = iso_source_new_ecma119(volset, &opts); while (src->read(src, buf, 2048) == 2048) { fwrite(buf, 1, 2048, fd); diff --git a/test/test.c b/test/test.c index c7c3a91..dad8ccd 100644 --- a/test/test.c +++ b/test/test.c @@ -1,18 +1,26 @@ #include "test.h" +static void create_test_suite() +{ + add_util_suite(); + add_tree_suite(); + add_exclude_suite(); + add_file_hashtable_suite(); +} + int main(int argc, char **argv) { - test_tree(); - test_exclude(); - test_file_hashtable(); - return 0; -} -#include "test.h" + CU_pSuite pSuite = NULL; -int main(int argc, char **argv) -{ - test_tree(); - test_exclude(); - test_file_hashtable(); - return 0; + /* initialize the CUnit test registry */ + if (CUE_SUCCESS != CU_initialize_registry()) + return CU_get_error(); + + create_test_suite(); + + /* Run all tests using the console interface */ + CU_basic_set_mode(CU_BRM_VERBOSE); + CU_basic_run_tests(); + CU_cleanup_registry(); + return CU_get_error(); } diff --git a/test/test.h b/test/test.h index be911bb..c25d96d 100644 --- a/test/test.h +++ b/test/test.h @@ -3,24 +3,18 @@ #include #include +#include -void test_tree(); +#include -void test_exclude(); +#include "libisofs.h" -void test_file_hashtable(); - -#endif /*TEST_H_*/ -#ifndef TEST_H_ -#define TEST_H_ - -#include -#include - -void test_tree(); - -void test_exclude(); - -void test_file_hashtable(); +void add_tree_suite(); + +void add_exclude_suite(); + +void add_file_hashtable_suite(); + +void add_util_suite(); #endif /*TEST_H_*/ diff --git a/test/test_exclude.c b/test/test_exclude.c index 0ff7aad..1102b0f 100644 --- a/test/test_exclude.c +++ b/test/test_exclude.c @@ -9,50 +9,25 @@ #include #include -void test_exclude() +static void test_exclude() { struct iso_hash_table table = { {0,}, 0}; - - printf("Testing exclude hashtable..."); - assert( !iso_exclude_lookup(&table, "/dir") ); - assert( !iso_exclude_lookup(&table, "/otherdir") ); + CU_ASSERT_FALSE( iso_exclude_lookup(&table, "/dir") ); + CU_ASSERT_FALSE( iso_exclude_lookup(&table, "/otherdir") ); iso_exclude_add_path(&table, "/otherdir"); - assert( iso_exclude_lookup(&table, "/otherdir") ); - assert( !iso_exclude_lookup(&table, "/dir") ); + CU_ASSERT_TRUE( iso_exclude_lookup(&table, "/otherdir") ); + CU_ASSERT_FALSE( iso_exclude_lookup(&table, "/dir") ); iso_exclude_add_path(&table, "/dir"); - assert( iso_exclude_lookup(&table, "/otherdir") ); - assert( iso_exclude_lookup(&table, "/dir") ); + CU_ASSERT_TRUE( iso_exclude_lookup(&table, "/otherdir") ); + CU_ASSERT_TRUE( iso_exclude_lookup(&table, "/dir") ); iso_exclude_empty(&table); - assert( !iso_exclude_lookup(&table, "/dir") ); - assert( !iso_exclude_lookup(&table, "/otherdir") ); - printf("\tOK\n"); + CU_ASSERT_FALSE( iso_exclude_lookup(&table, "/dir") ); + CU_ASSERT_FALSE( iso_exclude_lookup(&table, "/otherdir") ); } -/* - * Unit test for exclude.h - */ - -#include "exclude.h" -#include "test.h" - -#include -#include - -void test_exclude() +void add_exclude_suite() { - struct iso_hash_table table = { {0,}, 0}; + CU_pSuite pSuite = CU_add_suite("ExcludeSuite", NULL, NULL); - printf("Testing exclude hashtable..."); - assert( !iso_exclude_lookup(&table, "/dir") ); - assert( !iso_exclude_lookup(&table, "/otherdir") ); - iso_exclude_add_path(&table, "/otherdir"); - assert( iso_exclude_lookup(&table, "/otherdir") ); - assert( !iso_exclude_lookup(&table, "/dir") ); - iso_exclude_add_path(&table, "/dir"); - assert( iso_exclude_lookup(&table, "/otherdir") ); - assert( iso_exclude_lookup(&table, "/dir") ); - iso_exclude_empty(&table); - assert( !iso_exclude_lookup(&table, "/dir") ); - assert( !iso_exclude_lookup(&table, "/otherdir") ); - printf("\tOK\n"); + CU_add_test(pSuite, "test of exclude", test_exclude); } diff --git a/test/test_file_hashtable.c b/test/test_file_hashtable.c index 76e79dd..c035d06 100644 --- a/test/test_file_hashtable.c +++ b/test/test_file_hashtable.c @@ -1,5 +1,5 @@ /* - * Unit test for exclude.h + * Unit test for file.h */ @@ -20,12 +20,10 @@ static void test_cache_inodes() struct iso_tree_node_file *file3; struct iso_file *iso1; - printf("Testing file hashtable with cache inodes..."); - table = iso_file_table_new(1); - assert( table ); - assert( table->cache_inodes ); + CU_ASSERT_PTR_NOT_NULL( table ); + CU_ASSERT_TRUE( table->cache_inodes ); file1 = calloc(1, sizeof(struct iso_tree_node_file) ); file1->node.name = "fileName"; @@ -37,68 +35,16 @@ static void test_cache_inodes() iso1 = iso_file_new(file1); - assert( !strcmp(iso1->path, "/tmp/filename") ); + CU_ASSERT_STRING_EQUAL(iso1->path, "/tmp/filename"); //TODO free( file1 ); - printf("\tOK\n"); } -void test_file_hashtable() +void add_file_hashtable_suite() { - test_cache_inodes(); -} -/* - * Unit test for exclude.h - */ - - -#include "test.h" -#include "file.h" -#include "tree.h" - -#include -#include -#include -#include - -static void test_cache_inodes() -{ - 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; - - printf("Testing file hashtable with cache inodes..."); - - table = iso_file_table_new(1); - - assert( table ); - assert( table->cache_inodes ); - - file1 = calloc(1, sizeof(struct iso_tree_node_file) ); - file1->node.name = "fileName"; - file1->node.attrib.st_size = 12; - file1->node.attrib.st_dev = 15; - file1->node.attrib.st_ino = 204; - file1->path = "/tmp/filename"; - file1->sort_weight = 1; - - iso1 = iso_file_new(file1); - - assert( !strcmp(iso1->path, "/tmp/filename") ); - - //TODO - - free( file1 ); - printf("\tOK\n"); -} - - -void test_file_hashtable() -{ - test_cache_inodes(); + CU_pSuite pSuite = CU_add_suite("FileHashtableSuite", NULL, NULL); + CU_add_test(pSuite, "test of cache_inodes", test_cache_inodes); } diff --git a/test/test_tree.c b/test/test_tree.c index f89a75c..f1991ad 100644 --- a/test/test_tree.c +++ b/test/test_tree.c @@ -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 -#include -#include -#include -#include -#include - - -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); +} \ No newline at end of file diff --git a/test/test_util.c b/test/test_util.c new file mode 100644 index 0000000..274ebd3 --- /dev/null +++ b/test/test_util.c @@ -0,0 +1,265 @@ +/* + * Unit test for util.h + * + * This test utiliy functions + * + */ +#include "test.h" + +#include "util.h" + +static void test_div_up() +{ + CU_ASSERT_EQUAL( div_up(1, 2), 1 ); + CU_ASSERT_EQUAL( div_up(2, 2), 1 ); + CU_ASSERT_EQUAL( div_up(0, 2), 0 ); + CU_ASSERT_EQUAL( div_up(-1, 2), 0 ); + CU_ASSERT_EQUAL( div_up(3, 2), 2 ); +} + +static void test_round_up() +{ + CU_ASSERT_EQUAL( round_up(1, 2), 2 ); + CU_ASSERT_EQUAL( round_up(2, 2), 2 ); + CU_ASSERT_EQUAL( round_up(0, 2), 0 ); + CU_ASSERT_EQUAL( round_up(-1, 2), 0 ); + CU_ASSERT_EQUAL( round_up(3, 2), 4 ); + CU_ASSERT_EQUAL( round_up(15, 7), 21 ); + CU_ASSERT_EQUAL( round_up(13, 7), 14 ); + CU_ASSERT_EQUAL( round_up(14, 7), 14 ); +} + +static void test_iso_lsb_msb() +{ + uint8_t buf[4]; + uint32_t num; + + num = 0x01020304; + iso_lsb(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 ); + + iso_msb(buf, num, 4); + CU_ASSERT_EQUAL( buf[0], 0x01 ); + CU_ASSERT_EQUAL( buf[1], 0x02 ); + CU_ASSERT_EQUAL( buf[2], 0x03 ); + CU_ASSERT_EQUAL( buf[3], 0x04 ); + + iso_lsb(buf, num, 2); + CU_ASSERT_EQUAL( buf[0], 0x04 ); + CU_ASSERT_EQUAL( buf[1], 0x03 ); + + iso_msb(buf, num, 2); + CU_ASSERT_EQUAL( buf[0], 0x03 ); + CU_ASSERT_EQUAL( buf[1], 0x04 ); +} + +static void test_iso_1_dirid() +{ + CU_ASSERT_STRING_EQUAL( iso_1_dirid("dir1", "UTF-8"), "DIR1" ); + CU_ASSERT_STRING_EQUAL( iso_1_dirid("dIR1", "UTF-8"), "DIR1" ); + CU_ASSERT_STRING_EQUAL( iso_1_dirid("DIR1", "UTF-8"), "DIR1" ); + CU_ASSERT_STRING_EQUAL( iso_1_dirid("dirwithbigname", "UTF-8"), "DIRWITHB"); + CU_ASSERT_STRING_EQUAL( iso_1_dirid("dirwith8", "UTF-8"), "DIRWITH8"); + CU_ASSERT_STRING_EQUAL( iso_1_dirid("dir.1", "UTF-8"), "DIR_1"); + CU_ASSERT_STRING_EQUAL( iso_1_dirid("4f<0KmM::xcvf", "UTF-8"), "4F_0KMM_"); +} + +static void test_iso_2_dirid() +{ + CU_ASSERT_STRING_EQUAL( iso_2_dirid("dir1", "UTF-8"), "DIR1" ); + CU_ASSERT_STRING_EQUAL( iso_2_dirid("dIR1", "UTF-8"), "DIR1" ); + CU_ASSERT_STRING_EQUAL( iso_2_dirid("DIR1", "UTF-8"), "DIR1" ); + CU_ASSERT_STRING_EQUAL( iso_2_dirid("dirwithbigname", "UTF-8"), "DIRWITHBIGNAME"); + CU_ASSERT_STRING_EQUAL( iso_2_dirid("dirwith8", "UTF-8"), "DIRWITH8"); + CU_ASSERT_STRING_EQUAL( iso_2_dirid("dir.1", "UTF-8"), "DIR_1"); + CU_ASSERT_STRING_EQUAL( iso_2_dirid("4f<0KmM::xcvf", "UTF-8"), "4F_0KMM__XCVF"); + CU_ASSERT_STRING_EQUAL( iso_2_dirid("directory with 31 characters ok", "UTF-8"), "DIRECTORY_WITH_31_CHARACTERS_OK"); + CU_ASSERT_STRING_EQUAL( iso_2_dirid("directory with more than 31 characters", "UTF-8"), "DIRECTORY_WITH_MORE_THAN_31_CHA"); +} + +static void test_iso_r_dirid() +{ + int flag; + + /* 1. only ECMA119_37_CHAR_FILENAMES */ + flag = ECMA119_37_CHAR_FILENAMES; + CU_ASSERT_STRING_EQUAL( iso_r_dirid("dir1", "UTF-8", flag), "DIR1"); + CU_ASSERT_STRING_EQUAL( iso_r_dirid("dIR1", "UTF-8", flag), "DIR1"); + CU_ASSERT_STRING_EQUAL( iso_r_dirid("DIR1", "UTF-8", flag), "DIR1"); + CU_ASSERT_STRING_EQUAL( iso_r_dirid("dirwithbigname", "UTF-8", flag), "DIRWITHBIGNAME"); + CU_ASSERT_STRING_EQUAL( iso_r_dirid("dirwith8", "UTF-8", flag), "DIRWITH8"); + CU_ASSERT_STRING_EQUAL( iso_r_dirid("dir.1", "UTF-8", flag), "DIR_1"); + CU_ASSERT_STRING_EQUAL( iso_r_dirid("4f<0KmM::xcvf", "UTF-8", flag), "4F_0KMM__XCVF"); + CU_ASSERT_STRING_EQUAL( iso_r_dirid("directory with 31 characters ok", "UTF-8", flag), "DIRECTORY_WITH_31_CHARACTERS_OK"); + CU_ASSERT_STRING_EQUAL( iso_r_dirid("directory with more than 37 characters", "UTF-8", flag), "DIRECTORY_WITH_MORE_THAN_37_CHARACTER"); + CU_ASSERT_STRING_EQUAL( iso_r_dirid("directory with just 37 characters ok", "UTF-8", flag), "DIRECTORY_WITH_JUST_37_CHARACTERS__OK"); + + /* 2. only ECMA119_RELAXED_FILENAMES */ + flag = ECMA119_RELAXED_FILENAMES; + CU_ASSERT_STRING_EQUAL( iso_r_dirid("dir1", "UTF-8", flag), "dir1"); + CU_ASSERT_STRING_EQUAL( iso_r_dirid("dIR1", "UTF-8", flag), "dIR1"); + CU_ASSERT_STRING_EQUAL( iso_r_dirid("DIR1", "UTF-8", flag), "DIR1"); + CU_ASSERT_STRING_EQUAL( iso_r_dirid("dirwithbigname", "UTF-8", flag), "dirwithbigname"); + CU_ASSERT_STRING_EQUAL( iso_r_dirid("dirwith8", "UTF-8", flag), "dirwith8"); + CU_ASSERT_STRING_EQUAL( iso_r_dirid("dir.1", "UTF-8", flag), "dir.1"); + CU_ASSERT_STRING_EQUAL( iso_r_dirid("4f<0KmM::xcvf", "UTF-8", flag), "4f<0KmM::xcvf"); + CU_ASSERT_STRING_EQUAL( iso_r_dirid("directory with 31 characters ok", "UTF-8", flag), "directory with 31 characters ok"); + CU_ASSERT_STRING_EQUAL( iso_r_dirid("directory with more than 37 characters", "UTF-8", flag), "directory with more than 37 cha"); + CU_ASSERT_STRING_EQUAL( iso_r_dirid("directory with just 37 characters ok", "UTF-8", flag), "directory with just 37 characte"); + + /* 3. both ECMA119_RELAXED_FILENAMES and ECMA119_37_CHAR_FILENAMES */ + flag = ECMA119_RELAXED_FILENAMES | ECMA119_37_CHAR_FILENAMES; + CU_ASSERT_STRING_EQUAL( iso_r_dirid("dir1", "UTF-8", flag), "dir1"); + CU_ASSERT_STRING_EQUAL( iso_r_dirid("dIR1", "UTF-8", flag), "dIR1"); + CU_ASSERT_STRING_EQUAL( iso_r_dirid("DIR1", "UTF-8", flag), "DIR1"); + CU_ASSERT_STRING_EQUAL( iso_r_dirid("dirwithbigname", "UTF-8", flag), "dirwithbigname"); + CU_ASSERT_STRING_EQUAL( iso_r_dirid("dirwith8", "UTF-8", flag), "dirwith8"); + CU_ASSERT_STRING_EQUAL( iso_r_dirid("dir.1", "UTF-8", flag), "dir.1"); + CU_ASSERT_STRING_EQUAL( iso_r_dirid("4f<0KmM::xcvf", "UTF-8", flag), "4f<0KmM::xcvf"); + CU_ASSERT_STRING_EQUAL( iso_r_dirid("directory with 31 characters ok", "UTF-8", flag), "directory with 31 characters ok"); + CU_ASSERT_STRING_EQUAL( iso_r_dirid("directory with more than 37 characters", "UTF-8", flag), "directory with more than 37 character"); + CU_ASSERT_STRING_EQUAL( iso_r_dirid("directory with just 37 characters ok", "UTF-8", flag), "directory with just 37 characters ok"); +} + +static void test_iso_1_fileid() +{ + CU_ASSERT_STRING_EQUAL( iso_1_fileid("file1", "UTF-8"), "FILE1.;1"); + CU_ASSERT_STRING_EQUAL( iso_1_fileid("fILe1", "UTF-8"), "FILE1.;1"); + CU_ASSERT_STRING_EQUAL( iso_1_fileid("FILE1", "UTF-8"), "FILE1.;1"); + CU_ASSERT_STRING_EQUAL( iso_1_fileid(".EXT", "UTF-8"), ".EXT;1"); + CU_ASSERT_STRING_EQUAL( iso_1_fileid("file.ext", "UTF-8"), "FILE.EXT;1"); + CU_ASSERT_STRING_EQUAL( iso_1_fileid("fiLE.ext", "UTF-8"), "FILE.EXT;1"); + CU_ASSERT_STRING_EQUAL( iso_1_fileid("file.EXt", "UTF-8"), "FILE.EXT;1"); + CU_ASSERT_STRING_EQUAL( iso_1_fileid("FILE.EXT", "UTF-8"), "FILE.EXT;1"); + CU_ASSERT_STRING_EQUAL( iso_1_fileid("bigfilename", "UTF-8"), "BIGFILEN.;1"); + CU_ASSERT_STRING_EQUAL( iso_1_fileid("bigfilename.ext", "UTF-8"), "BIGFILEN.EXT;1"); + CU_ASSERT_STRING_EQUAL( iso_1_fileid("bigfilename.e", "UTF-8"), "BIGFILEN.E;1"); + CU_ASSERT_STRING_EQUAL( iso_1_fileid("file.bigext", "UTF-8"), "FILE.BIG;1"); + CU_ASSERT_STRING_EQUAL( iso_1_fileid(".bigext", "UTF-8"), ".BIG;1"); + CU_ASSERT_STRING_EQUAL( iso_1_fileid("bigfilename.bigext", "UTF-8"), "BIGFILEN.BIG;1"); + CU_ASSERT_STRING_EQUAL( iso_1_fileid("file<:a.ext", "UTF-8"), "FILE__A.EXT;1"); + CU_ASSERT_STRING_EQUAL( iso_1_fileid("file.<:a", "UTF-8"), "FILE.__A;1"); + CU_ASSERT_STRING_EQUAL( iso_1_fileid("file<:a.--a", "UTF-8"), "FILE__A.__A;1"); + CU_ASSERT_STRING_EQUAL( iso_1_fileid("file.ex1.ex2", "UTF-8"), "FILE_EX1.EX2;1"); + CU_ASSERT_STRING_EQUAL( iso_1_fileid("file.ex1.ex2.ex3", "UTF-8"), "FILE_EX1.EX3;1"); + CU_ASSERT_STRING_EQUAL( iso_1_fileid("fil.ex1.ex2.ex3", "UTF-8"), "FIL_EX1_.EX3;1"); +} + +static void test_iso_2_fileid() +{ + CU_ASSERT_STRING_EQUAL( iso_2_fileid("file1", "UTF-8"), "FILE1.;1"); + CU_ASSERT_STRING_EQUAL( iso_2_fileid("fILe1", "UTF-8"), "FILE1.;1"); + CU_ASSERT_STRING_EQUAL( iso_2_fileid("FILE1", "UTF-8"), "FILE1.;1"); + CU_ASSERT_STRING_EQUAL( iso_2_fileid(".EXT", "UTF-8"), ".EXT;1"); + CU_ASSERT_STRING_EQUAL( iso_2_fileid("file.ext", "UTF-8"), "FILE.EXT;1"); + CU_ASSERT_STRING_EQUAL( iso_2_fileid("fiLE.ext", "UTF-8"), "FILE.EXT;1"); + CU_ASSERT_STRING_EQUAL( iso_2_fileid("file.EXt", "UTF-8"), "FILE.EXT;1"); + CU_ASSERT_STRING_EQUAL( iso_2_fileid("FILE.EXT", "UTF-8"), "FILE.EXT;1"); + CU_ASSERT_STRING_EQUAL( iso_2_fileid("bigfilename", "UTF-8"), "BIGFILENAME.;1"); + CU_ASSERT_STRING_EQUAL( iso_2_fileid("bigfilename.ext", "UTF-8"), "BIGFILENAME.EXT;1"); + CU_ASSERT_STRING_EQUAL( iso_2_fileid("bigfilename.e", "UTF-8"), "BIGFILENAME.E;1"); + CU_ASSERT_STRING_EQUAL( iso_2_fileid("31 characters filename.extensio", "UTF-8"), "31_CHARACTERS_FILENAME.EXTENSIO;1"); + CU_ASSERT_STRING_EQUAL( iso_2_fileid("32 characters filename.extension", "UTF-8"), "32_CHARACTERS_FILENAME.EXTENSIO;1"); + CU_ASSERT_STRING_EQUAL( iso_2_fileid("more than 30 characters filename.extension", "UTF-8"), "MORE_THAN_30_CHARACTERS_FIL.EXT;1"); + CU_ASSERT_STRING_EQUAL( iso_2_fileid("file.bigext", "UTF-8"), "FILE.BIGEXT;1"); + CU_ASSERT_STRING_EQUAL( iso_2_fileid(".bigext", "UTF-8"), ".BIGEXT;1"); + CU_ASSERT_STRING_EQUAL( iso_2_fileid("bigfilename.bigext", "UTF-8"), "BIGFILENAME.BIGEXT;1"); + CU_ASSERT_STRING_EQUAL( iso_2_fileid("file<:a.ext", "UTF-8"), "FILE__A.EXT;1"); + CU_ASSERT_STRING_EQUAL( iso_2_fileid("file.<:a", "UTF-8"), "FILE.__A;1"); + CU_ASSERT_STRING_EQUAL( iso_2_fileid("file<:a.--a", "UTF-8"), "FILE__A.__A;1"); + CU_ASSERT_STRING_EQUAL( iso_2_fileid("file.ex1.ex2", "UTF-8"), "FILE_EX1.EX2;1"); + CU_ASSERT_STRING_EQUAL( iso_2_fileid("file.ex1.ex2.ex3", "UTF-8"), "FILE_EX1_EX2.EX3;1"); + CU_ASSERT_STRING_EQUAL( iso_2_fileid("fil.ex1.ex2.ex3", "UTF-8"), "FIL_EX1_EX2.EX3;1"); + CU_ASSERT_STRING_EQUAL( iso_2_fileid(".file.bigext", "UTF-8"), "_FILE.BIGEXT;1"); +} + +static void test_iso_r_fileid() +{ + int flag; + + /* 1. only ECMA119_OMIT_VERSION_NUMBERS */ + flag = ECMA119_OMIT_VERSION_NUMBERS; + CU_ASSERT_STRING_EQUAL( iso_r_fileid("file1", "UTF-8", flag), "FILE1."); + CU_ASSERT_STRING_EQUAL( iso_r_fileid("fILe1", "UTF-8", flag), "FILE1."); + CU_ASSERT_STRING_EQUAL( iso_r_fileid("31 characters filename.extensio", "UTF-8", flag), "31_CHARACTERS_FILENAME.EXTENSIO"); + CU_ASSERT_STRING_EQUAL( iso_r_fileid("it's 37 characters filename.extension", "UTF-8", flag), "IT_S_37_CHARACTERS_FILENAME.EXT"); + + /* 2. only ECMA119_37_CHAR_FILENAMES */ + flag = ECMA119_37_CHAR_FILENAMES; + CU_ASSERT_STRING_EQUAL( iso_r_fileid("file1", "UTF-8", flag), "FILE1."); + CU_ASSERT_STRING_EQUAL( iso_r_fileid("fILe1", "UTF-8", flag), "FILE1."); + CU_ASSERT_STRING_EQUAL( iso_r_fileid("FILE1", "UTF-8", flag), "FILE1."); + CU_ASSERT_STRING_EQUAL( iso_r_fileid(".EXT", "UTF-8", flag), ".EXT"); + CU_ASSERT_STRING_EQUAL( iso_r_fileid("file.ext", "UTF-8", flag), "FILE.EXT"); + CU_ASSERT_STRING_EQUAL( iso_r_fileid("fiLE.ext", "UTF-8", flag), "FILE.EXT"); + CU_ASSERT_STRING_EQUAL( iso_r_fileid("file.EXt", "UTF-8", flag), "FILE.EXT"); + CU_ASSERT_STRING_EQUAL( iso_r_fileid("FILE.EXT", "UTF-8", flag), "FILE.EXT"); + CU_ASSERT_STRING_EQUAL( iso_r_fileid("bigfilename", "UTF-8", flag), "BIGFILENAME."); + CU_ASSERT_STRING_EQUAL( iso_r_fileid("bigfilename.ext", "UTF-8", flag), "BIGFILENAME.EXT"); + CU_ASSERT_STRING_EQUAL( iso_r_fileid("bigfilename.e", "UTF-8", flag), "BIGFILENAME.E"); + CU_ASSERT_STRING_EQUAL( iso_r_fileid("file.bigext", "UTF-8", flag), "FILE.BIGEXT"); + CU_ASSERT_STRING_EQUAL( iso_r_fileid("31 characters filename.extensio", "UTF-8", flag), "31_CHARACTERS_FILENAME.EXTENSIO"); + CU_ASSERT_STRING_EQUAL( iso_r_fileid("it's 37 characters filename.extension", "UTF-8", flag), "IT_S_37_CHARACTERS_FILENAME.EXTENSION"); + CU_ASSERT_STRING_EQUAL( iso_r_fileid("more than 37 characters filename.extension", "UTF-8", flag), "MORE_THAN_37_CHARACTERS_FILENAME.EXTE"); + CU_ASSERT_STRING_EQUAL( iso_r_fileid("file.this is a 37 chars len extension", "UTF-8", flag), "FILE.THIS_IS_A_37_CHARS_LEN_EXTENSION"); + CU_ASSERT_STRING_EQUAL( iso_r_fileid("file.this is a very very big extension", "UTF-8", flag), "FILE.THIS_IS_A_VERY_VERY_BIG_EXTENSIO"); + CU_ASSERT_STRING_EQUAL( iso_r_fileid("fil.ex1.ex2.ex3", "UTF-8", flag), "FIL_EX1_EX2.EX3"); + + /* 3. only ECMA119_RELAXED_FILENAMES */ + flag = ECMA119_RELAXED_FILENAMES; + CU_ASSERT_STRING_EQUAL( iso_r_fileid("file1", "UTF-8", flag), "file1;1"); + CU_ASSERT_STRING_EQUAL( iso_r_fileid("fILe1", "UTF-8", flag), "fILe1;1"); + CU_ASSERT_STRING_EQUAL( iso_r_fileid("FILE1", "UTF-8", flag), "FILE1;1"); + CU_ASSERT_STRING_EQUAL( iso_r_fileid(".EXT", "UTF-8", flag), ".EXT;1"); + CU_ASSERT_STRING_EQUAL( iso_r_fileid("file.ext", "UTF-8", flag), "file.ext;1"); + CU_ASSERT_STRING_EQUAL( iso_r_fileid("fiLE.ext", "UTF-8", flag), "fiLE.ext;1"); + CU_ASSERT_STRING_EQUAL( iso_r_fileid("file.EXt", "UTF-8", flag), "file.EXt;1"); + CU_ASSERT_STRING_EQUAL( iso_r_fileid("FILE.EXT", "UTF-8", flag), "FILE.EXT;1"); + CU_ASSERT_STRING_EQUAL( iso_r_fileid("bigfilename", "UTF-8", flag), "bigfilename;1"); + CU_ASSERT_STRING_EQUAL( iso_r_fileid("bigfilename.ext", "UTF-8", flag), "bigfilename.ext;1"); + CU_ASSERT_STRING_EQUAL( iso_r_fileid("bigfilename.e", "UTF-8", flag), "bigfilename.e;1"); + CU_ASSERT_STRING_EQUAL( iso_r_fileid("file.bigext", "UTF-8", flag), "file.bigext;1"); + CU_ASSERT_STRING_EQUAL( iso_r_fileid("31 characters filename.extensio", "UTF-8", flag), "31 characters filename.extensio;1"); + CU_ASSERT_STRING_EQUAL( iso_r_fileid("it's 37 characters filename.extension", "UTF-8", flag), "it's 37 characters filename.ext;1"); + CU_ASSERT_STRING_EQUAL( iso_r_fileid("file.this is a 37 chars len extension", "UTF-8", flag), "file.this is a 37 chars len ext;1"); + CU_ASSERT_STRING_EQUAL( iso_r_fileid("fil.ex1.ex2.ex3", "UTF-8", flag), "fil.ex1.ex2.ex3;1"); + CU_ASSERT_STRING_EQUAL( iso_r_fileid("file.<:a", "UTF-8", flag), "file.<:a;1"); + + /* 3. ECMA119_RELAXED_FILENAMES and ECMA119_OMIT_VERSION_NUMBERS*/ + flag = ECMA119_RELAXED_FILENAMES | ECMA119_OMIT_VERSION_NUMBERS; + CU_ASSERT_STRING_EQUAL( iso_r_fileid("file1", "UTF-8", flag), "file1"); + CU_ASSERT_STRING_EQUAL( iso_r_fileid("fILe1", "UTF-8", flag), "fILe1"); + CU_ASSERT_STRING_EQUAL( iso_r_fileid("FILE1", "UTF-8", flag), "FILE1"); + CU_ASSERT_STRING_EQUAL( iso_r_fileid(".EXT", "UTF-8", flag), ".EXT"); + CU_ASSERT_STRING_EQUAL( iso_r_fileid("file.ext", "UTF-8", flag), "file.ext"); + CU_ASSERT_STRING_EQUAL( iso_r_fileid("fiLE.ext", "UTF-8", flag), "fiLE.ext"); + CU_ASSERT_STRING_EQUAL( iso_r_fileid("file.EXt", "UTF-8", flag), "file.EXt"); + CU_ASSERT_STRING_EQUAL( iso_r_fileid("FILE.EXT", "UTF-8", flag), "FILE.EXT"); + CU_ASSERT_STRING_EQUAL( iso_r_fileid("bigfilename", "UTF-8", flag), "bigfilename"); + CU_ASSERT_STRING_EQUAL( iso_r_fileid("bigfilename.ext", "UTF-8", flag), "bigfilename.ext"); + CU_ASSERT_STRING_EQUAL( iso_r_fileid("bigfilename.e", "UTF-8", flag), "bigfilename.e"); + CU_ASSERT_STRING_EQUAL( iso_r_fileid("file.bigext", "UTF-8", flag), "file.bigext"); + CU_ASSERT_STRING_EQUAL( iso_r_fileid("31 characters filename.extensio", "UTF-8", flag), "31 characters filename.extensio"); + CU_ASSERT_STRING_EQUAL( iso_r_fileid("it's 37 characters filename.extension", "UTF-8", flag), "it's 37 characters filename.ext"); + CU_ASSERT_STRING_EQUAL( iso_r_fileid("file.this is a 37 chars len extension", "UTF-8", flag), "file.this is a 37 chars len ext"); + CU_ASSERT_STRING_EQUAL( iso_r_fileid("fil.ex1.ex2.ex3", "UTF-8", flag), "fil.ex1.ex2.ex3"); + CU_ASSERT_STRING_EQUAL( iso_r_fileid("file.<:a", "UTF-8", flag), "file.<:a"); +} + +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); +}