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

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

View File

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

View File

@ -3,24 +3,18 @@
#include <sys/types.h>
#include <stddef.h>
#include <stdio.h>
void test_tree();
#include <CUnit/Basic.h>
void test_exclude();
#include "libisofs.h"
void test_file_hashtable();
#endif /*TEST_H_*/
#ifndef TEST_H_
#define TEST_H_
#include <sys/types.h>
#include <stddef.h>
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_*/

View File

@ -9,50 +9,25 @@
#include <assert.h>
#include <stdio.h>
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 <assert.h>
#include <stdio.h>
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);
}

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_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 <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();
CU_pSuite pSuite = CU_add_suite("FileHashtableSuite", NULL, NULL);
CU_add_test(pSuite, "test of cache_inodes", test_cache_inodes);
}

View File

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

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