Implemented relaxed iso constraints & Cunit based unit-tests

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

View File

@ -48,6 +48,21 @@ test_iso_CPPFLAGS = -Ilibisofs
test_iso_LDADD = $(libisofs_libisofs_la_OBJECTS) $(THREAD_LIBS) test_iso_LDADD = $(libisofs_libisofs_la_OBJECTS) $(THREAD_LIBS)
test_iso_SOURCES = test/iso.c 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
## ========================================================================= ## ## ========================================================================= ##

View File

@ -269,45 +269,62 @@ calc_file_pos(struct ecma119_write_target *t,
t->curfile = 0; 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, ecma119_target_new(struct iso_volset *volset,
int volnum, const struct ecma119_source_opts *opts)
int level,
int flags)
{ {
struct ecma119_write_target *t = struct ecma119_write_target *t =
calloc(1, sizeof(struct ecma119_write_target)); calloc(1, sizeof(struct ecma119_write_target));
size_t i, j, cur; size_t i, j, cur;
struct iso_tree_node *iso_root = 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 = opts->no_cache_inodes ? 0 : 1;
t->cache_inodes = 1; t->replace_mode = opts->default_mode ? 0 : 1;
t->replace_mode = 1; if ( opts->replace_dir_mode )
t->dir_mode = 0555; t->replace_mode |= 0x02;
t->file_mode = 0444; if ( opts->replace_file_mode )
t->gid = 0; t->replace_mode |= 0x04;
t->uid = 0; if ( opts->replace_gid )
t->input_charset = "UTF-8"; t->replace_mode |= 0x08;
t->ouput_charset = "UTF-8"; if ( opts->replace_uid )
t->sort_files = 1; 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); t->file_table = iso_file_table_new(t->cache_inodes);
volset->refcount++; volset->refcount++;
t->iso_level = level; t->iso_level = opts->level;
t->block_size = 2048; t->block_size = 2048;
t->relaxed_constraints = opts->relaxed_constraints;
t->rockridge = (flags & ECMA119_ROCKRIDGE) ? 1 : 0; t->rockridge = (opts->flags & ECMA119_ROCKRIDGE) ? 1 : 0;
t->joliet = (flags & ECMA119_JOLIET) ? 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->eltorito = t->catalog ? 1 : 0;
t->root = ecma119_tree_create(t, iso_root); t->root = ecma119_tree_create(t, iso_root);
if (t->joliet) if (t->joliet)
t->joliet_root = joliet_tree_create(t, iso_root); t->joliet_root = joliet_tree_create(t, iso_root);
t->volset = volset; t->volset = volset;
t->volnum = volnum; t->volnum = opts->volnum;
t->now = time(NULL); t->now = time(NULL);
if (t->rockridge) 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, struct burn_source *iso_source_new_ecma119(struct iso_volset *volset,
int volnum, struct ecma119_source_opts *opts)
int level,
int flags)
{ {
struct burn_source *ret = calloc(1, sizeof(struct burn_source)); struct burn_source *ret = calloc(1, sizeof(struct burn_source));
ret->refcount = 1; ret->refcount = 1;
ret->read = bs_read; ret->read = bs_read;
ret->get_size = bs_get_size; ret->get_size = bs_get_size;
ret->free_data = bs_free_data; ret->free_data = bs_free_data;
ret->data = ecma119_target_new(volset, volnum, level, flags); ret->data = ecma119_target_new(volset, opts);
return ret; return ret;
} }

View File

@ -65,6 +65,8 @@ struct ecma119_write_target
unsigned int iso_level:2; unsigned int iso_level:2;
unsigned int eltorito:1; unsigned int eltorito:1;
int relaxed_constraints; /**< see ecma119_relaxed_constraints_flag */
struct el_torito_boot_catalog *catalog; struct el_torito_boot_catalog *catalog;
int replace_mode; /**< Replace ownership and modes of files int replace_mode; /**< Replace ownership and modes of files
@ -168,19 +170,6 @@ struct ecma119_write_target
} state_files; } 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] #define BP(a,b) [(b) - (a) + 1]
struct ecma119_pri_vol_desc struct ecma119_pri_vol_desc

View File

@ -74,12 +74,23 @@ create_ecma119_node(struct ecma119_write_target *t,
char *(*iso_name)(const char *, const char *) = ISO_ISDIR(iso) ? 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_dirid : iso_2_dirid)
: ((t->iso_level == 1) ? iso_1_fileid : iso_2_fileid); : ((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 ); assert(t && (!parent || parent->type == ECMA119_DIR) && iso );
ret = calloc(1, sizeof(struct ecma119_tree_node)); 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->dirent_len = calc_dirent_len(ret);
ret->attrib = iso->attrib; ret->attrib = iso->attrib;
if ( t->rockridge && t->replace_mode ) if ( t->rockridge && t->replace_mode )
@ -507,7 +518,8 @@ ecma119_tree_create(struct ecma119_write_target *t,
struct iso_tree_node *iso_root) struct iso_tree_node *iso_root)
{ {
t->root = create_tree(t, NULL, 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); sort_tree(t->root);
mangle_all(t->root); mangle_all(t->root);
return t->root; return t->root;

View File

@ -64,6 +64,69 @@ enum eltorito_boot_media_type {
ELTORITO_NO_EMUL 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. * 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); 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 /** 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 * The volume set used to create the libburn_source can _not_ be modified
* until the libburn_source is freed. * until the libburn_source is freed.
* *
* \param volumeset The volume set from which you want to write * \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 opts The options for image generation
* \param level ISO level to write at.
* \param flags Which extensions to support.
* *
* \pre \p volumeset is non-NULL * \pre \p volumeset is non-NULL
* \pre \p volnum is less than \p volset->volset_size. * \pre \p volnum is less than \p volset->volset_size.
* \return A burn_source to be used for the data source for a track * \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, struct burn_source* iso_source_new_ecma119(struct iso_volset *volumeset,
int volnum, struct ecma119_source_opts *opts);
int level,
int flags);
#endif /* LIBISO_LIBISOFS_H */ #endif /* LIBISO_LIBISOFS_H */

View File

@ -20,6 +20,7 @@
#include <limits.h> #include <limits.h>
#include "util.h" #include "util.h"
#include "libisofs.h"
/* avoids warning and names in iso, joliet and rockridge can't be > 255 bytes /* 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, * 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); 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 *iso_1_fileid(const char *src_arg, const char *icharset)
{ {
char *src = str2ascii(src_arg, 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 extension, we need to calculate their new lengths (lnname and
lnext). If the original filename is too long, we start by trimming lnext). If the original filename is too long, we start by trimming
the extension, but keep a minimum extension length of 3. */ 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); lname = strlen(src);
lnname = (lname > 30) ? 30 : lname; lnname = (lname > 30) ? 30 : lname;
lext = lnext = 0; lext = lnext = 0;
@ -511,6 +539,85 @@ char *iso_2_fileid(const char *src_arg, const char *icharset)
return dest; 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 * char *
iso_p_fileid(const char *src, const char *icharset) iso_p_fileid(const char *src, const char *icharset)
{ {

View File

@ -49,6 +49,11 @@ char *iso_1_dirid(const char *src, const char *);
*/ */
char *iso_2_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 * 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 * 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 *); 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, * Create a Joliet file or directory identifier that consists of a name,
* extension and version number. The combined name and extension length will * extension and version number. The combined name and extension length will

30
test.sh
View File

@ -28,33 +28,3 @@ fi
test/test 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

View File

@ -123,7 +123,14 @@ int main(int argc, char **argv)
iso_volume_set_application_id(volume, "Libburnia"); iso_volume_set_application_id(volume, "Libburnia");
iso_volume_set_copyright_file_id(volume, "LICENSE"); 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) { while (src->read(src, buf, 2048) == 2048) {
fwrite(buf, 1, 2048, fd); fwrite(buf, 1, 2048, fd);

View File

@ -1,18 +1,26 @@
#include "test.h" #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) int main(int argc, char **argv)
{ {
test_tree(); CU_pSuite pSuite = NULL;
test_exclude();
test_file_hashtable();
return 0;
}
#include "test.h"
int main(int argc, char **argv) /* initialize the CUnit test registry */
{ if (CUE_SUCCESS != CU_initialize_registry())
test_tree(); return CU_get_error();
test_exclude();
test_file_hashtable(); create_test_suite();
return 0;
/* 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();
} }

View File

@ -3,24 +3,18 @@
#include <sys/types.h> #include <sys/types.h>
#include <stddef.h> #include <stddef.h>
#include <stdio.h>
void test_tree(); #include <CUnit/Basic.h>
void test_exclude(); #include "libisofs.h"
void test_file_hashtable(); void add_tree_suite();
#endif /*TEST_H_*/ void add_exclude_suite();
#ifndef TEST_H_
#define TEST_H_ void add_file_hashtable_suite();
#include <sys/types.h> void add_util_suite();
#include <stddef.h>
void test_tree();
void test_exclude();
void test_file_hashtable();
#endif /*TEST_H_*/ #endif /*TEST_H_*/

View File

@ -9,50 +9,25 @@
#include <assert.h> #include <assert.h>
#include <stdio.h> #include <stdio.h>
void test_exclude() static void test_exclude()
{ {
struct iso_hash_table table = { {0,}, 0}; struct iso_hash_table table = { {0,}, 0};
CU_ASSERT_FALSE( iso_exclude_lookup(&table, "/dir") );
printf("Testing exclude hashtable..."); CU_ASSERT_FALSE( iso_exclude_lookup(&table, "/otherdir") );
assert( !iso_exclude_lookup(&table, "/dir") );
assert( !iso_exclude_lookup(&table, "/otherdir") );
iso_exclude_add_path(&table, "/otherdir"); iso_exclude_add_path(&table, "/otherdir");
assert( iso_exclude_lookup(&table, "/otherdir") ); CU_ASSERT_TRUE( iso_exclude_lookup(&table, "/otherdir") );
assert( !iso_exclude_lookup(&table, "/dir") ); CU_ASSERT_FALSE( iso_exclude_lookup(&table, "/dir") );
iso_exclude_add_path(&table, "/dir"); iso_exclude_add_path(&table, "/dir");
assert( iso_exclude_lookup(&table, "/otherdir") ); CU_ASSERT_TRUE( iso_exclude_lookup(&table, "/otherdir") );
assert( iso_exclude_lookup(&table, "/dir") ); CU_ASSERT_TRUE( iso_exclude_lookup(&table, "/dir") );
iso_exclude_empty(&table); iso_exclude_empty(&table);
assert( !iso_exclude_lookup(&table, "/dir") ); CU_ASSERT_FALSE( iso_exclude_lookup(&table, "/dir") );
assert( !iso_exclude_lookup(&table, "/otherdir") ); CU_ASSERT_FALSE( iso_exclude_lookup(&table, "/otherdir") );
printf("\tOK\n");
} }
/*
* Unit test for exclude.h
*/
void add_exclude_suite()
#include "exclude.h"
#include "test.h"
#include <assert.h>
#include <stdio.h>
void test_exclude()
{ {
struct iso_hash_table table = { {0,}, 0}; CU_pSuite pSuite = CU_add_suite("ExcludeSuite", NULL, NULL);
printf("Testing exclude hashtable..."); CU_add_test(pSuite, "test of exclude", test_exclude);
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");
} }

View File

@ -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_tree_node_file *file3;
struct iso_file *iso1; struct iso_file *iso1;
printf("Testing file hashtable with cache inodes...");
table = iso_file_table_new(1); table = iso_file_table_new(1);
assert( table ); CU_ASSERT_PTR_NOT_NULL( table );
assert( table->cache_inodes ); CU_ASSERT_TRUE( table->cache_inodes );
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";
@ -37,68 +35,16 @@ static void test_cache_inodes()
iso1 = iso_file_new(file1); iso1 = iso_file_new(file1);
assert( !strcmp(iso1->path, "/tmp/filename") ); CU_ASSERT_STRING_EQUAL(iso1->path, "/tmp/filename");
//TODO //TODO
free( file1 ); free( file1 );
printf("\tOK\n");
} }
void test_file_hashtable() void add_file_hashtable_suite()
{ {
test_cache_inodes(); CU_pSuite pSuite = CU_add_suite("FileHashtableSuite", NULL, NULL);
} CU_add_test(pSuite, "test of cache_inodes", test_cache_inodes);
/*
* Unit test for exclude.h
*/
#include "test.h"
#include "file.h"
#include "tree.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
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();
} }

View File

@ -17,242 +17,97 @@
static void test_new_root() { static void test_new_root() {
struct iso_tree_node_dir *root; struct iso_tree_node_dir *root;
printf("Testing iso_tree_new_root()...");
root = iso_tree_new_root(); root = iso_tree_new_root();
assert(root); CU_ASSERT_PTR_NOT_NULL(root);
assert(root->nchildren == 0); CU_ASSERT_EQUAL(root->nchildren, 0);
assert(root->children == NULL); CU_ASSERT_PTR_NULL(root->children);
assert(root->node.parent == NULL); CU_ASSERT_PTR_NULL(root->node.parent);
assert(root->node.name == NULL); CU_ASSERT_PTR_NULL(root->node.name);
assert( S_ISDIR(root->node.attrib.st_mode) ); CU_ASSERT(S_ISDIR(root->node.attrib.st_mode) );
printf("\tOK\n");
} }
static void test_add_dir() { static void test_add_dir() {
struct iso_tree_node_dir *root; struct iso_tree_node_dir *root;
struct iso_tree_node_dir *dir; struct iso_tree_node_dir *dir;
printf("Testing iso_tree_add_dir()...");
root = iso_tree_new_root(); root = iso_tree_new_root();
dir = iso_tree_add_dir(root, "New dir name"); dir = iso_tree_add_dir(root, "New dir name");
assert(root); CU_ASSERT_PTR_NOT_NULL(root);
assert(dir); CU_ASSERT_PTR_NOT_NULL(dir);
assert(dir->node.parent == root); CU_ASSERT_PTR_EQUAL(dir->node.parent, root);
assert(root->nchildren == 1); CU_ASSERT_EQUAL(root->nchildren, 1);
assert(root->children[0] == (struct iso_tree_node *)dir); CU_ASSERT_PTR_EQUAL(root->children[0], (struct iso_tree_node *)dir);
assert( strcmp(dir->node.name, "New dir name") == 0 ); CU_ASSERT_STRING_EQUAL( dir->node.name, "New dir name");
assert( S_ISDIR(dir->node.attrib.st_mode) ); CU_ASSERT( S_ISDIR(dir->node.attrib.st_mode) );
printf("\tOK\n");
} }
static void test_add_file() { static void test_add_file() {
struct iso_tree_node_dir *root; struct iso_tree_node_dir *root;
struct iso_tree_node_file *file; struct iso_tree_node_file *file;
printf("Testing iso_tree_add_file()...");
root = iso_tree_new_root(); root = iso_tree_new_root();
file = (struct iso_tree_node_file *) file = (struct iso_tree_node_file *)
iso_tree_add_file(root, "/tmp/libisofs_test/README"); iso_tree_add_file(root, "/tmp/libisofs_test/README");
assert(root); CU_ASSERT_PTR_NOT_NULL(root);
assert(file); CU_ASSERT_PTR_NOT_NULL(file);
assert(file->node.parent == root); CU_ASSERT_PTR_EQUAL(file->node.parent, root);
assert(root->nchildren == 1); CU_ASSERT_EQUAL(root->nchildren, 1);
assert(root->children[0] == (struct iso_tree_node *)file); CU_ASSERT_PTR_EQUAL(root->children[0], (struct iso_tree_node *)file);
assert( strcmp(file->node.name, "README") == 0 ); CU_ASSERT_STRING_EQUAL( file->node.name, "README" );
assert( strcmp(file->path, "/tmp/libisofs_test/README") == 0 ); CU_ASSERT_STRING_EQUAL( file->path, "/tmp/libisofs_test/README" );
assert( S_ISREG(file->node.attrib.st_mode) ); CU_ASSERT( S_ISREG(file->node.attrib.st_mode) );
printf("\tOK\n");
} }
static void test_add_symlink() { static void test_add_symlink() {
struct iso_tree_node_dir *root; struct iso_tree_node_dir *root;
struct iso_tree_node *lnk; struct iso_tree_node *lnk;
printf("Testing iso_tree_add_symlink()...");
root = iso_tree_new_root(); root = iso_tree_new_root();
lnk = iso_tree_add_symlink(root, "read", "/tmp/libisofs_test/README"); lnk = iso_tree_add_symlink(root, "read", "/tmp/libisofs_test/README");
assert(root); CU_ASSERT_PTR_NOT_NULL(root);
assert(lnk); CU_ASSERT_PTR_NOT_NULL(lnk);
assert(lnk->parent == root); CU_ASSERT_PTR_EQUAL(lnk->parent, root);
assert(root->nchildren == 1); CU_ASSERT_EQUAL(root->nchildren, 1);
assert(root->children[0] == (struct iso_tree_node *)lnk); CU_ASSERT_PTR_EQUAL(root->children[0], (struct iso_tree_node *)lnk);
assert( strcmp(lnk->name, "read") == 0 ); CU_ASSERT_STRING_EQUAL( lnk->name, "read");
assert( strcmp( ((struct iso_tree_node_symlink*)lnk)->dest, CU_ASSERT_STRING_EQUAL( ((struct iso_tree_node_symlink*)lnk)->dest,
"/tmp/libisofs_test/README") == 0 ); "/tmp/libisofs_test/README" );
assert( S_ISLNK(lnk->attrib.st_mode) ); CU_ASSERT( S_ISLNK(lnk->attrib.st_mode) );
printf("\tOK\n");
} }
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 *dir;
struct iso_tree_node_dir *child; struct iso_tree_node_dir *child;
struct iso_tree_radd_dir_behavior behavior = {0,0,0}; struct iso_tree_radd_dir_behavior behavior = {0,0,0};
printf("Testing iso_tree_radd_dir()...");
root = iso_tree_new_root(); root = iso_tree_new_root();
assert(root); CU_ASSERT_PTR_NOT_NULL(root);
dir = iso_tree_radd_dir(root, "/tmp/libisofs_test", &behavior); 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 */ /* test _root_ children */
child = (struct iso_tree_node_dir *)dir->children[0]; child = (struct iso_tree_node_dir *)root->children[0];
assert( S_ISDIR(child->node.attrib.st_mode) ); CU_ASSERT( S_ISDIR(child->node.attrib.st_mode) );
assert( child->nchildren == 2); CU_ASSERT_EQUAL( child->nchildren, 2);
assert( strcmp(child->node.name, "dir1") == 0 ); CU_ASSERT_STRING_EQUAL( child->node.name, "dir1" );
child = (struct iso_tree_node_dir *)dir->children[1]; child = (struct iso_tree_node_dir *)root->children[1];
assert( S_ISDIR(child->node.attrib.st_mode) ); CU_ASSERT( S_ISDIR(child->node.attrib.st_mode) );
assert( child->nchildren == 0); CU_ASSERT_EQUAL( child->nchildren, 0);
assert( strcmp(child->node.name, "dir2") == 0 ); CU_ASSERT_STRING_EQUAL( child->node.name, "dir2" );
//TODO write really full test //TODO write really full test
printf("\tOK\n");
//iso_tree_print( (struct iso_tree_node *)root, 4 ); //iso_tree_print( (struct iso_tree_node *)root, 4 );
} }
void test_tree() void add_tree_suite()
{ {
test_new_root(); CU_pSuite pSuite = CU_add_suite("TreeSuite", NULL, NULL);
test_add_dir();
test_add_file();
test_add_symlink();
test_radd_dir();
}
/*
* Unit test for tree.h
*/
#include "libisofs.h"
#include "tree.h"
#include "test.h"
#include <assert.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
static void test_new_root() {
struct iso_tree_node_dir *root;
printf("Testing iso_tree_new_root()...");
root = iso_tree_new_root();
assert(root);
assert(root->nchildren == 0);
assert(root->children == NULL);
assert(root->node.parent == NULL);
assert(root->node.name == NULL);
assert( S_ISDIR(root->node.attrib.st_mode) );
printf("\tOK\n");
}
static void test_add_dir() {
struct iso_tree_node_dir *root;
struct iso_tree_node_dir *dir;
printf("Testing iso_tree_add_dir()..."); CU_add_test(pSuite, "test of iso_tree_new_root()", test_new_root);
root = iso_tree_new_root(); CU_add_test(pSuite, "test of iso_tree_add_dir()", test_add_dir);
dir = iso_tree_add_dir(root, "New dir name"); CU_add_test(pSuite, "test of iso_tree_add_file()", test_add_file);
assert(root); CU_add_test(pSuite, "test of iso_tree_add_symlink()", test_add_symlink);
assert(dir); CU_add_test(pSuite, "test of iso_tree_radd_dir()", test_radd_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();
}

265
test/test_util.c Normal file
View File

@ -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);
}