Improved docs, and created 0.3.8 branch
This commit is contained in:
4
libisofs/branches/ZeroTwoEight/test/Makefile
Normal file
4
libisofs/branches/ZeroTwoEight/test/Makefile
Normal file
@ -0,0 +1,4 @@
|
||||
all clean:
|
||||
$(MAKE) -C .. -$(MAKEFLAGS) $@
|
||||
|
||||
.PHONY: all clean
|
141
libisofs/branches/ZeroTwoEight/test/iso.c
Normal file
141
libisofs/branches/ZeroTwoEight/test/iso.c
Normal file
@ -0,0 +1,141 @@
|
||||
/* -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 8; -*- */
|
||||
/* vim: set ts=8 sts=8 sw=8 noet : */
|
||||
|
||||
#define _GNU_SOURCE
|
||||
|
||||
#include "libisofs.h"
|
||||
#include "libburn/libburn.h"
|
||||
#include <getopt.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <assert.h>
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
#include <string.h>
|
||||
#include <err.h>
|
||||
|
||||
#define SECSIZE 2048
|
||||
|
||||
const char * const optstring = "JRL:b:h";
|
||||
extern char *optarg;
|
||||
extern int optind;
|
||||
|
||||
void usage()
|
||||
{
|
||||
printf("test [OPTIONS] DIRECTORY OUTPUT\n");
|
||||
}
|
||||
|
||||
void help()
|
||||
{
|
||||
printf(
|
||||
"Options:\n"
|
||||
" -J Add Joliet support\n"
|
||||
" -R Add Rock Ridge support\n"
|
||||
" -L <num> Set the ISO level (1 or 2)\n"
|
||||
" -b file Specifies a boot image to add to image\n"
|
||||
" -h Print this message\n"
|
||||
);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
struct iso_volset *volset;
|
||||
struct iso_volume *volume;
|
||||
struct iso_tree_node_dir *root;
|
||||
struct burn_source *src;
|
||||
unsigned char buf[2048];
|
||||
FILE *fd;
|
||||
int c;
|
||||
struct iso_tree_radd_dir_behavior behav = {0,0,0};
|
||||
int level=1, flags=0;
|
||||
char *boot_img = NULL;
|
||||
|
||||
while ((c = getopt(argc, argv, optstring)) != -1) {
|
||||
switch(c) {
|
||||
case 'h':
|
||||
usage();
|
||||
help();
|
||||
exit(0);
|
||||
break;
|
||||
case 'J':
|
||||
flags |= ECMA119_JOLIET;
|
||||
break;
|
||||
case 'R':
|
||||
flags |= ECMA119_ROCKRIDGE;
|
||||
break;
|
||||
case 'L':
|
||||
level = atoi(optarg);
|
||||
break;
|
||||
case 'b':
|
||||
boot_img = optarg;
|
||||
break;
|
||||
case '?':
|
||||
usage();
|
||||
exit(1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (argc < 2) {
|
||||
printf ("Please pass directory from which to build ISO\n");
|
||||
usage();
|
||||
return 1;
|
||||
}
|
||||
if (argc < 3) {
|
||||
printf ("Please supply output file\n");
|
||||
usage();
|
||||
return 1;
|
||||
}
|
||||
fd = fopen(argv[optind+1], "w");
|
||||
if (!fd) {
|
||||
err(1, "error opening output file");
|
||||
}
|
||||
|
||||
root = iso_tree_new_root();
|
||||
iso_tree_radd_dir(root, argv[optind], &behav);
|
||||
if (!root) {
|
||||
err(1, "error opening input directory");
|
||||
}
|
||||
volume = iso_volume_new_with_root( "VOLID", "PUBID", "PREPID", root );
|
||||
|
||||
if ( boot_img ) {
|
||||
/* adds El-Torito boot info. Tunned for isolinux */
|
||||
struct iso_tree_node_dir *boot = (struct iso_tree_node_dir *)
|
||||
iso_tree_volume_path_to_node(volume, "isolinux");
|
||||
struct iso_tree_node *img = iso_tree_volume_path_to_node(volume, boot_img);
|
||||
if (!img) {
|
||||
err(1, "boot image patch is not valid");
|
||||
}
|
||||
struct el_torito_boot_image *bootimg =
|
||||
iso_volume_create_boot_catalog(volume, img, ELTORITO_NO_EMUL,
|
||||
boot, "boot.cat");
|
||||
el_torito_set_load_size(bootimg, 4);
|
||||
el_torito_set_write_boot_info(bootimg);
|
||||
}
|
||||
|
||||
volset = iso_volset_new( volume, "VOLSETID" );
|
||||
|
||||
/* some tests */
|
||||
iso_volume_set_application_id(volume, "Libburnia");
|
||||
iso_volume_set_copyright_file_id(volume, "LICENSE");
|
||||
|
||||
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);
|
||||
}
|
||||
fclose(fd);
|
||||
|
||||
return 0;
|
||||
}
|
297
libisofs/branches/ZeroTwoEight/test/iso.py
Normal file
297
libisofs/branches/ZeroTwoEight/test/iso.py
Normal file
@ -0,0 +1,297 @@
|
||||
|
||||
import struct
|
||||
import tree
|
||||
import sys
|
||||
|
||||
voldesc_fmt = "B" "5s" "B" "2041x"
|
||||
|
||||
# all these fields are common between the pri and sec voldescs
|
||||
privoldesc_fmt = "B" "5s" "B" "x" "32s" "32s" "8x" "8s" "32x" "4s" "4s" "4s" "8s" "4s4s" "4s4s" "34s" "128s" \
|
||||
"128s" "128s" "128s" "37s" "37s" "37s" "17s" "17s" "17s" "17s" "B" "x" "512s" "653x"
|
||||
|
||||
# the fields unique to the sec_vol_desc
|
||||
secvoldesc_fmt = "x" "5x" "x" "B" "32x" "32x" "8x" "8x" "32s" "4x" "4x" "4x" "8x" "4x4x" "4x4x" "34x" "128x" \
|
||||
"128x" "128x" "128x" "37x" "37x" "37x" "17x" "17x" "17x" "17x" "x" "x" "512x" "653x"
|
||||
|
||||
dirrecord_fmt = "B" "B" "8s" "8s" "7s" "B" "B" "B" "4s" "B" # + file identifier, padding field and SU area
|
||||
|
||||
pathrecord_fmt = "B" "B" "4s" "2s" # + directory identifier and padding field
|
||||
|
||||
def read_bb(str, le, be):
|
||||
val1, = struct.unpack(le, str)
|
||||
val2, = struct.unpack(be, str)
|
||||
if val1 != val2:
|
||||
print "val1=%d, val2=%d" % (val1, val2)
|
||||
raise AssertionError, "values are not equal in dual byte-order field"
|
||||
return val1
|
||||
|
||||
def read_bb4(str):
|
||||
return read_bb(str, "<I4x", ">4xI")
|
||||
|
||||
def read_bb2(str):
|
||||
return read_bb(str, "<H2x", ">2xH")
|
||||
|
||||
def read_lsb4(str):
|
||||
return struct.unpack("<I", str)[0]
|
||||
|
||||
def read_lsb2(str):
|
||||
return struct.unpack("<H", str)[0]
|
||||
|
||||
def read_msb4(str):
|
||||
return struct.unpack(">I", str)[0]
|
||||
|
||||
def read_msb2(str):
|
||||
return struct.unpack(">H", str)[0]
|
||||
|
||||
class VolDesc(object):
|
||||
def __init__(self, data):
|
||||
print "fmt len=%d, data len=%d" % ( struct.calcsize(voldesc_fmt), len(data) )
|
||||
self.vol_desc_type, self.standard_id, self.vol_desc_version = struct.unpack(voldesc_fmt, data)
|
||||
|
||||
class PriVolDesc(VolDesc):
|
||||
def __init__(self, data):
|
||||
self.vol_desc_type, \
|
||||
self.standard_id, \
|
||||
self.vol_desc_version, \
|
||||
self.system_id, \
|
||||
self.volume_id, \
|
||||
self.vol_space_size, \
|
||||
self.vol_set_size, \
|
||||
self.vol_seq_num, \
|
||||
self.block_size, \
|
||||
self.path_table_size, \
|
||||
self.l_table_pos, \
|
||||
self.l_table2_pos, \
|
||||
self.m_table_pos, \
|
||||
self.m_table2_pos, \
|
||||
self.root_record, \
|
||||
self.volset_id, \
|
||||
self.publisher_id, \
|
||||
self.preparer_id, \
|
||||
self.application_id, \
|
||||
self.copyright_file, \
|
||||
self.abstract_file, \
|
||||
self.bibliographic_file, \
|
||||
self.creation_timestamp, \
|
||||
self.modification_timestamp, \
|
||||
self.expiration_timestamp, \
|
||||
self.effective_timestamp, \
|
||||
self.file_struct_version, \
|
||||
self.application_use = struct.unpack(privoldesc_fmt, data)
|
||||
|
||||
# take care of reading the integer types
|
||||
self.vol_space_size = read_bb4(self.vol_space_size)
|
||||
self.vol_set_size = read_bb2(self.vol_set_size)
|
||||
self.vol_seq_num = read_bb2(self.vol_seq_num)
|
||||
self.block_size = read_bb2(self.block_size)
|
||||
self.path_table_size = read_bb4(self.path_table_size)
|
||||
self.l_table_pos = read_lsb4(self.l_table_pos)
|
||||
self.l_table2_pos = read_lsb4(self.l_table2_pos)
|
||||
self.m_table_pos = read_msb4(self.m_table_pos)
|
||||
self.m_table2_pos = read_msb4(self.m_table2_pos)
|
||||
|
||||
# parse the root directory record
|
||||
self.root_record = DirRecord(self.root_record)
|
||||
|
||||
def readPathTables(self, file):
|
||||
file.seek( self.block_size * self.l_table_pos )
|
||||
self.l_table = PathTable( file.read(self.path_table_size), 0 )
|
||||
file.seek( self.block_size * self.m_table_pos )
|
||||
self.m_table = PathTable( file.read(self.path_table_size), 1 )
|
||||
|
||||
if self.l_table2_pos:
|
||||
file.seek( self.block_size * self.l_table2_pos )
|
||||
self.l_table2 = PathTable( file.read(self.path_table_size), 0 )
|
||||
else:
|
||||
self.l_table2 = None
|
||||
|
||||
if self.m_table2_pos:
|
||||
file.seek( self.block_size * self.m_table2_pos )
|
||||
self.m_table2 = PathTable( file.read(self.path_table_size), 1 )
|
||||
else:
|
||||
self.m_table2 = None
|
||||
|
||||
def toTree(self, isofile):
|
||||
ret = tree.Tree(isofile=isofile.name)
|
||||
ret.root = self.root_record.toTreeNode(parent=None, isofile=isofile)
|
||||
return ret
|
||||
|
||||
class SecVolDesc(PriVolDesc):
|
||||
def __init__(self, data):
|
||||
super(SecVolDesc,self).__init__(data)
|
||||
self.flags, self.escape_sequences = struct.unpack(secvoldesc_fmt, data)
|
||||
|
||||
# return a single volume descriptor of the appropriate type
|
||||
def readVolDesc(data):
|
||||
desc = VolDesc(data)
|
||||
if desc.standard_id != "CD001":
|
||||
print "Unexpected standard_id " +desc.standard_id
|
||||
return None
|
||||
if desc.vol_desc_type == 1:
|
||||
return PriVolDesc(data)
|
||||
elif desc.vol_desc_type == 2:
|
||||
return SecVolDesc(data)
|
||||
elif desc.vol_desc_type == 3:
|
||||
print "I don't know about partitions yet!"
|
||||
return None
|
||||
elif desc.vol_desc_type == 255:
|
||||
return desc
|
||||
else:
|
||||
print "Unknown volume descriptor type %d" % (desc.vol_desc_type,)
|
||||
return None
|
||||
|
||||
def readVolDescSet(file):
|
||||
ret = [ readVolDesc(file.read(2048)) ]
|
||||
while ret[-1].vol_desc_type != 255:
|
||||
ret.append( readVolDesc(file.read(2048)) )
|
||||
|
||||
for vol in ret:
|
||||
if vol.vol_desc_type == 1 or vol.vol_desc_type == 2:
|
||||
vol.readPathTables(file)
|
||||
|
||||
return ret
|
||||
|
||||
class DirRecord:
|
||||
def __init__(self, data):
|
||||
self.len_dr, \
|
||||
self.len_xa, \
|
||||
self.block, \
|
||||
self.len_data, \
|
||||
self.timestamp, \
|
||||
self.flags, \
|
||||
self.unit_size, \
|
||||
self.gap_size, \
|
||||
self.vol_seq_number, \
|
||||
self.len_fi = struct.unpack(dirrecord_fmt, data[:33])
|
||||
self.children = []
|
||||
|
||||
if self.len_dr > len(data):
|
||||
raise AssertionError, "Error: not enough data to read in DirRecord()"
|
||||
elif self.len_dr < 34:
|
||||
raise AssertionError, "Error: directory record too short"
|
||||
|
||||
fmt = str(self.len_fi) + "s"
|
||||
if self.len_fi % 2 == 0:
|
||||
fmt += "1x"
|
||||
len_su = self.len_dr - (33 + self.len_fi + 1 - (self.len_fi % 2))
|
||||
fmt += str(len_su) + "s"
|
||||
|
||||
if len(data) >= self.len_dr:
|
||||
self.file_id, self.su = struct.unpack(fmt, data[33 : self.len_dr])
|
||||
else:
|
||||
print "Error: couldn't read file_id: not enough data"
|
||||
self.file_id = "BLANK"
|
||||
self.su = ""
|
||||
|
||||
# convert to integers
|
||||
self.block = read_bb4(self.block)
|
||||
self.len_data = read_bb4(self.len_data)
|
||||
self.vol_seq_number = read_bb2(self.vol_seq_number)
|
||||
|
||||
def toTreeNode(self, parent, isofile, path=""):
|
||||
ret = tree.TreeNode(parent=parent, isofile=isofile.name)
|
||||
if len(path) > 0:
|
||||
path += "/"
|
||||
path += self.file_id
|
||||
ret.path = path
|
||||
|
||||
if self.flags & 2: # we are a directory, recurse
|
||||
isofile.seek( 2048 * self.block )
|
||||
data = isofile.read( self.len_data )
|
||||
pos = 0
|
||||
while pos < self.len_data:
|
||||
try:
|
||||
child = DirRecord( data[pos:] )
|
||||
pos += child.len_dr
|
||||
if child.len_fi == 1 and (child.file_id == "\x00" or child.file_id == "\x01"):
|
||||
continue
|
||||
print "read child named " +child.file_id
|
||||
self.children.append( child )
|
||||
ret.children.append( child.toTreeNode(ret, isofile, path) )
|
||||
except AssertionError:
|
||||
print "Couldn't read child of directory %s, position is %d, len is %d" % \
|
||||
(path, pos, self.len_data)
|
||||
raise
|
||||
|
||||
return ret
|
||||
|
||||
class PathTableRecord:
|
||||
def __init__(self, data, readint2, readint4):
|
||||
self.len_di, self.len_xa, self.block, self.parent_number = struct.unpack(pathrecord_fmt, data[:8])
|
||||
|
||||
if len(data) < self.len_di + 8:
|
||||
raise AssertionError, "Error: not enough data to read path table record"
|
||||
|
||||
fmt = str(self.len_di) + "s"
|
||||
self.dir_id, = struct.unpack(fmt, data[8:8+self.len_di])
|
||||
|
||||
self.block = readint4(self.block)
|
||||
self.parent_number = readint2(self.parent_number)
|
||||
|
||||
class PathTable:
|
||||
def __init__(self, data, m_type):
|
||||
if m_type:
|
||||
readint2 = read_msb2
|
||||
readint4 = read_msb4
|
||||
else:
|
||||
readint2 = read_lsb2
|
||||
readint4 = read_lsb4
|
||||
pos = 0
|
||||
self.records = []
|
||||
while pos < len(data):
|
||||
try:
|
||||
self.records.append( PathTableRecord(data[pos:], readint2, readint4) )
|
||||
print "Read path record %d: dir_id %s, block %d, parent_number %d" %\
|
||||
(len(self.records), self.records[-1].dir_id, self.records[-1].block, self.records[-1].parent_number)
|
||||
pos += self.records[-1].len_di + 8
|
||||
pos += pos % 2
|
||||
except AssertionError:
|
||||
print "Last successfully read path table record had dir_id %s, block %d, parent_number %d" % \
|
||||
(self.records[-1].dir_id, self.records[-1].block, self.records[-1].parent_number)
|
||||
print "Error was near offset %x" % (pos,)
|
||||
raise
|
||||
|
||||
def findRecord(self, dir_id, block, parent_number):
|
||||
number=1
|
||||
for record in self.records:
|
||||
if record.dir_id == dir_id and record.block == block and record.parent_number == parent_number:
|
||||
return number, record
|
||||
number += 1
|
||||
|
||||
return None, None
|
||||
|
||||
# check this path table for consistency against the actual directory heirarchy
|
||||
def crossCheckDirRecords(self, root, parent_number=1):
|
||||
number, rec = self.findRecord(root.file_id, root.block, parent_number)
|
||||
|
||||
if not rec:
|
||||
print "Error: directory record parent_number %d, dir_id %s, block %d doesn't match a path table record" % \
|
||||
(parent_number, root.file_id, root.block)
|
||||
parent = self.records[parent_number]
|
||||
print "Parent has parent_number %d, dir_id %s, block %d" % (parent.parent_number, parent.dir_id, parent.block)
|
||||
return 0
|
||||
|
||||
for child in root.children:
|
||||
if child.flags & 2:
|
||||
self.crossCheckDirRecords(child, number)
|
||||
|
||||
|
||||
if len(sys.argv) != 2:
|
||||
print "Please enter the name of the .iso file to open"
|
||||
sys.exit(1)
|
||||
|
||||
f = file(sys.argv[1])
|
||||
f.seek(2048 * 16) # system area
|
||||
volumes = readVolDescSet(f)
|
||||
vol = volumes[0]
|
||||
t = vol.toTree(f)
|
||||
vol.l_table.crossCheckDirRecords(vol.root_record)
|
||||
vol.m_table.crossCheckDirRecords(vol.root_record)
|
||||
|
||||
vol = volumes[1]
|
||||
try:
|
||||
t = vol.toTree(f)
|
||||
vol.l_table.crossCheckDirRecords(vol.root_record)
|
||||
vol.m_table.crossCheckDirRecords(vol.root_record)
|
||||
except AttributeError:
|
||||
pass
|
28
libisofs/branches/ZeroTwoEight/test/test.c
Normal file
28
libisofs/branches/ZeroTwoEight/test/test.c
Normal file
@ -0,0 +1,28 @@
|
||||
#include "test.h"
|
||||
|
||||
static void create_test_suite()
|
||||
{
|
||||
add_util_suite();
|
||||
add_tree_suite();
|
||||
add_exclude_suite();
|
||||
add_file_hashtable_suite();
|
||||
add_ecma119_tree_suite();
|
||||
add_volume_suite();
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
CU_pSuite pSuite = NULL;
|
||||
|
||||
/* 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();
|
||||
}
|
24
libisofs/branches/ZeroTwoEight/test/test.h
Normal file
24
libisofs/branches/ZeroTwoEight/test/test.h
Normal file
@ -0,0 +1,24 @@
|
||||
#ifndef TEST_H_
|
||||
#define TEST_H_
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <CUnit/Basic.h>
|
||||
|
||||
#include "libisofs.h"
|
||||
|
||||
void add_tree_suite();
|
||||
|
||||
void add_exclude_suite();
|
||||
|
||||
void add_file_hashtable_suite();
|
||||
|
||||
void add_util_suite();
|
||||
|
||||
void add_ecma119_tree_suite();
|
||||
|
||||
void add_volume_suite();
|
||||
|
||||
#endif /*TEST_H_*/
|
34
libisofs/branches/ZeroTwoEight/test/test_ecma119_tree.c
Normal file
34
libisofs/branches/ZeroTwoEight/test/test_ecma119_tree.c
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Unit test for ecma119_tree.h
|
||||
*/
|
||||
//FIXME not implemented yet!!
|
||||
|
||||
#include "libisofs.h"
|
||||
#include "tree.h"
|
||||
#include "test.h"
|
||||
//#include "ecma119_tree.h"
|
||||
|
||||
/*
|
||||
* Also including C file, testing internal functions
|
||||
*/
|
||||
//#include "ecma119_tree.c"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
static void test_calc_dirent_len()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void add_ecma119_tree_suite()
|
||||
{
|
||||
CU_pSuite pSuite = CU_add_suite("Ecma119TreeSuite", NULL, NULL);
|
||||
|
||||
//CU_add_test(pSuite, "test of calc_dirent_len()", test_calc_dirent_len);
|
||||
}
|
33
libisofs/branches/ZeroTwoEight/test/test_exclude.c
Normal file
33
libisofs/branches/ZeroTwoEight/test/test_exclude.c
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Unit test for exclude.h
|
||||
*/
|
||||
|
||||
|
||||
#include "exclude.h"
|
||||
#include "test.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
static void test_exclude()
|
||||
{
|
||||
struct iso_hash_table table = { {0,}, 0};
|
||||
CU_ASSERT_FALSE( iso_exclude_lookup(&table, "/dir") );
|
||||
CU_ASSERT_FALSE( iso_exclude_lookup(&table, "/otherdir") );
|
||||
iso_exclude_add_path(&table, "/otherdir");
|
||||
CU_ASSERT_TRUE( iso_exclude_lookup(&table, "/otherdir") );
|
||||
CU_ASSERT_FALSE( iso_exclude_lookup(&table, "/dir") );
|
||||
iso_exclude_add_path(&table, "/dir");
|
||||
CU_ASSERT_TRUE( iso_exclude_lookup(&table, "/otherdir") );
|
||||
CU_ASSERT_TRUE( iso_exclude_lookup(&table, "/dir") );
|
||||
iso_exclude_empty(&table);
|
||||
CU_ASSERT_FALSE( iso_exclude_lookup(&table, "/dir") );
|
||||
CU_ASSERT_FALSE( iso_exclude_lookup(&table, "/otherdir") );
|
||||
}
|
||||
|
||||
void add_exclude_suite()
|
||||
{
|
||||
CU_pSuite pSuite = CU_add_suite("ExcludeSuite", NULL, NULL);
|
||||
|
||||
CU_add_test(pSuite, "test of exclude", test_exclude);
|
||||
}
|
248
libisofs/branches/ZeroTwoEight/test/test_file_hashtable.c
Normal file
248
libisofs/branches/ZeroTwoEight/test/test_file_hashtable.c
Normal file
@ -0,0 +1,248 @@
|
||||
/*
|
||||
* Unit test for file.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_iso_file_new()
|
||||
{
|
||||
struct iso_tree_node_file *file;
|
||||
struct iso_file *iso;
|
||||
|
||||
file = calloc(1, sizeof(struct iso_tree_node_file) );
|
||||
file->node.name = "fileName";
|
||||
file->node.attrib.st_size = 12;
|
||||
file->node.attrib.st_dev = 15;
|
||||
file->node.attrib.st_ino = 204;
|
||||
file->path = "/tmp/filename";
|
||||
file->sort_weight = 1;
|
||||
|
||||
iso = iso_file_new(file);
|
||||
|
||||
CU_ASSERT_PTR_NOT_NULL(iso);
|
||||
CU_ASSERT_STRING_EQUAL(iso->path, "/tmp/filename");
|
||||
CU_ASSERT_EQUAL(iso->size, 12);
|
||||
CU_ASSERT_EQUAL(iso->ino, 0);
|
||||
CU_ASSERT_EQUAL(iso->nlink, 1);
|
||||
CU_ASSERT_EQUAL(iso->sort_weight, 1);
|
||||
CU_ASSERT_EQUAL(iso->real_dev, 15);
|
||||
CU_ASSERT_EQUAL(iso->real_ino, 204);
|
||||
}
|
||||
|
||||
static void test_add_lookup()
|
||||
{
|
||||
struct iso_file_table *table;
|
||||
struct iso_tree_node_file *file1;
|
||||
struct iso_tree_node_file *file2;
|
||||
struct iso_file *iso1;
|
||||
struct iso_file *iso2;
|
||||
struct iso_file *iso3;
|
||||
int r;
|
||||
|
||||
table = iso_file_table_new(1);
|
||||
|
||||
CU_ASSERT_PTR_NOT_NULL( table );
|
||||
CU_ASSERT_TRUE( table->cache_inodes );
|
||||
CU_ASSERT_EQUAL(table->count, 0);
|
||||
|
||||
file1 = calloc(1, sizeof(struct iso_tree_node_file) );
|
||||
file1->node.name = "fileName";
|
||||
file1->node.attrib.st_dev = 15;
|
||||
file1->node.attrib.st_ino = 204;
|
||||
file1->path = "/tmp/filename";
|
||||
|
||||
iso1 = iso_file_new(file1);
|
||||
|
||||
r = iso_file_table_add_file(table, iso1);
|
||||
CU_ASSERT_EQUAL(r, 1);
|
||||
CU_ASSERT_EQUAL(table->count, 1);
|
||||
|
||||
iso2 = iso_file_table_lookup(table, file1);
|
||||
CU_ASSERT_PTR_NOT_NULL(iso2);
|
||||
CU_ASSERT_PTR_EQUAL(iso2, iso1);
|
||||
|
||||
file2 = calloc(1, sizeof(struct iso_tree_node_file) );
|
||||
file2->node.name = "fileName2";
|
||||
file2->node.attrib.st_dev = 152;
|
||||
file2->node.attrib.st_ino = 2042;
|
||||
file2->path = "/tmp/filename2";
|
||||
|
||||
iso3 = iso_file_new(file2);
|
||||
r = iso_file_table_add_file(table, iso3);
|
||||
CU_ASSERT_EQUAL(r, 1);
|
||||
CU_ASSERT_EQUAL(table->count, 2);
|
||||
|
||||
/* treat to add the same file again */
|
||||
r = iso_file_table_add_file(table, iso3);
|
||||
CU_ASSERT_EQUAL(r, 0);
|
||||
CU_ASSERT_EQUAL(table->count, 2);
|
||||
|
||||
iso2 = iso_file_table_lookup(table, file1);
|
||||
CU_ASSERT_PTR_NOT_NULL(iso2);
|
||||
CU_ASSERT_PTR_EQUAL(iso2, iso1);
|
||||
|
||||
iso2 = iso_file_table_lookup(table, file2);
|
||||
CU_ASSERT_PTR_NOT_NULL(iso2);
|
||||
CU_ASSERT_PTR_EQUAL(iso2, iso3);
|
||||
|
||||
iso3 = iso_file_new(file2);
|
||||
r = iso_file_table_add_file(table, iso3);
|
||||
CU_ASSERT_EQUAL(r, 0);
|
||||
CU_ASSERT_EQUAL(table->count, 2);
|
||||
|
||||
iso_file_table_clear(table);
|
||||
CU_ASSERT_EQUAL(table->count, 0);
|
||||
|
||||
iso2 = iso_file_table_lookup(table, file2);
|
||||
CU_ASSERT_PTR_NULL(iso2);
|
||||
|
||||
free( file1 );
|
||||
free( file2 );
|
||||
free( table );
|
||||
}
|
||||
|
||||
static void test_cache_inodes()
|
||||
{
|
||||
struct iso_file_table *table;
|
||||
struct iso_tree_node_file *file1;
|
||||
struct iso_tree_node_file *file2;
|
||||
struct iso_file *iso1;
|
||||
struct iso_file *iso2;
|
||||
struct iso_file *iso3;
|
||||
int r;
|
||||
|
||||
table = iso_file_table_new(1);
|
||||
|
||||
CU_ASSERT_PTR_NOT_NULL( table );
|
||||
CU_ASSERT_TRUE( table->cache_inodes );
|
||||
CU_ASSERT_EQUAL(table->count, 0);
|
||||
|
||||
file1 = calloc(1, sizeof(struct iso_tree_node_file) );
|
||||
file1->node.name = "fileName";
|
||||
file1->node.attrib.st_dev = 15;
|
||||
file1->node.attrib.st_ino = 204;
|
||||
file1->path = "/tmp/filename";
|
||||
|
||||
iso1 = iso_file_new(file1);
|
||||
|
||||
r = iso_file_table_add_file(table, iso1);
|
||||
CU_ASSERT_EQUAL(r, 1);
|
||||
|
||||
/* another file, different but with the same inode id */
|
||||
file2 = calloc(1, sizeof(struct iso_tree_node_file) );
|
||||
file2->node.name = "another file";
|
||||
file2->node.attrib.st_dev = 15;
|
||||
file2->node.attrib.st_ino = 204;
|
||||
file2->path = "/tmp/another";
|
||||
iso2 = iso_file_new(file2);
|
||||
|
||||
/* ensure it's not added again... */
|
||||
r = iso_file_table_add_file(table, iso2);
|
||||
CU_ASSERT_EQUAL(r, 0);
|
||||
|
||||
/* ...and the lookup returns the first */
|
||||
iso3 = iso_file_table_lookup(table, file2);
|
||||
CU_ASSERT_PTR_EQUAL(iso1, iso3);
|
||||
|
||||
free(iso2);
|
||||
free(file2);
|
||||
|
||||
/* and now a file with same inode but different device */
|
||||
file2 = calloc(1, sizeof(struct iso_tree_node_file) );
|
||||
file2->node.name = "different file";
|
||||
file2->node.attrib.st_dev = 16; /* different dev id */
|
||||
file2->node.attrib.st_ino = 204;
|
||||
file2->path = "/tmp/different";
|
||||
iso2 = iso_file_new(file2);
|
||||
|
||||
r = iso_file_table_add_file(table, iso2);
|
||||
CU_ASSERT_EQUAL(r, 1);
|
||||
iso3 = iso_file_table_lookup(table, file2);
|
||||
CU_ASSERT_PTR_NOT_EQUAL(iso3, iso1);
|
||||
CU_ASSERT_PTR_EQUAL(iso3, iso2);
|
||||
|
||||
iso_file_table_clear(table);
|
||||
free( file1 );
|
||||
free( file2 );
|
||||
free( table );
|
||||
}
|
||||
|
||||
static void test_no_cache_inodes()
|
||||
{
|
||||
struct iso_file_table *table;
|
||||
struct iso_tree_node_file *file1;
|
||||
struct iso_tree_node_file *file2;
|
||||
struct iso_tree_node_file *file3;
|
||||
struct iso_file *iso1;
|
||||
struct iso_file *iso2;
|
||||
struct iso_file *iso3;
|
||||
int r;
|
||||
|
||||
table = iso_file_table_new(0);
|
||||
|
||||
CU_ASSERT_PTR_NOT_NULL( table );
|
||||
CU_ASSERT_FALSE( table->cache_inodes );
|
||||
CU_ASSERT_EQUAL(table->count, 0);
|
||||
|
||||
file1 = calloc(1, sizeof(struct iso_tree_node_file) );
|
||||
file1->node.name = "fileName";
|
||||
file1->node.attrib.st_dev = 15;
|
||||
file1->node.attrib.st_ino = 204;
|
||||
file1->path = "/tmp/filename";
|
||||
|
||||
iso1 = iso_file_new(file1);
|
||||
|
||||
r = iso_file_table_add_file(table, iso1);
|
||||
CU_ASSERT_EQUAL(r, 1);
|
||||
|
||||
/* another file, different but with the same inode id */
|
||||
file2 = calloc(1, sizeof(struct iso_tree_node_file) );
|
||||
file2->node.name = "another file";
|
||||
file2->node.attrib.st_dev = 15;
|
||||
file2->node.attrib.st_ino = 204;
|
||||
file2->path = "/tmp/another";
|
||||
iso2 = iso_file_new(file2);
|
||||
|
||||
/* ensure is added */
|
||||
r = iso_file_table_add_file(table, iso2);
|
||||
CU_ASSERT_EQUAL(r, 1);
|
||||
|
||||
iso3 = iso_file_table_lookup(table, file2);
|
||||
CU_ASSERT_PTR_EQUAL(iso3, iso2);
|
||||
|
||||
/* and now a file with same inode and path */
|
||||
file3 = calloc(1, sizeof(struct iso_tree_node_file) );
|
||||
file3->node.name = "different file";
|
||||
file3->node.attrib.st_dev = 15;
|
||||
file3->node.attrib.st_ino = 204;
|
||||
file3->path = "/tmp/filename";
|
||||
iso3 = iso_file_new(file3);
|
||||
|
||||
r = iso_file_table_add_file(table, iso3);
|
||||
CU_ASSERT_EQUAL(r, 0);
|
||||
iso3 = iso_file_table_lookup(table, file3);
|
||||
CU_ASSERT_PTR_EQUAL(iso3, iso1);
|
||||
|
||||
iso_file_table_clear(table);
|
||||
free(file1);
|
||||
free(file2);
|
||||
free(file3);
|
||||
free(table);
|
||||
}
|
||||
|
||||
|
||||
void add_file_hashtable_suite()
|
||||
{
|
||||
CU_pSuite pSuite = CU_add_suite("FileHashtableSuite", NULL, NULL);
|
||||
CU_add_test(pSuite, "test of iso_file_new()", test_iso_file_new);
|
||||
CU_add_test(pSuite, "test of add and lookup", test_add_lookup);
|
||||
CU_add_test(pSuite, "test with cache_inodes", test_cache_inodes);
|
||||
CU_add_test(pSuite, "test without cache_inodes", test_no_cache_inodes);
|
||||
}
|
395
libisofs/branches/ZeroTwoEight/test/test_tree.c
Normal file
395
libisofs/branches/ZeroTwoEight/test/test_tree.c
Normal file
@ -0,0 +1,395 @@
|
||||
/*
|
||||
* 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;
|
||||
root = iso_tree_new_root();
|
||||
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;
|
||||
|
||||
root = iso_tree_new_root();
|
||||
CU_ASSERT_PTR_NOT_NULL(root);
|
||||
dir = iso_tree_add_dir(root, "New dir name");
|
||||
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) );
|
||||
iso_tree_free((struct iso_tree_node *)root);
|
||||
}
|
||||
|
||||
static void test_add_file() {
|
||||
struct iso_tree_node_dir *root;
|
||||
struct iso_tree_node_file *file;
|
||||
|
||||
root = iso_tree_new_root();
|
||||
file = (struct iso_tree_node_file *)
|
||||
iso_tree_add_file(root, "/tmp/libisofs_test/README");
|
||||
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) );
|
||||
iso_tree_free((struct iso_tree_node *)root);
|
||||
}
|
||||
|
||||
static void test_add_symlink() {
|
||||
struct iso_tree_node_dir *root;
|
||||
struct iso_tree_node *lnk;
|
||||
|
||||
root = iso_tree_new_root();
|
||||
lnk = iso_tree_add_symlink(root, "read", "/tmp/libisofs_test/README");
|
||||
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) );
|
||||
iso_tree_free((struct iso_tree_node *)root);
|
||||
}
|
||||
|
||||
static void test_add_node() {
|
||||
struct iso_tree_node_dir *root;
|
||||
struct iso_tree_node *node;
|
||||
|
||||
root = iso_tree_new_root();
|
||||
|
||||
/* test addition of a dir */
|
||||
node = iso_tree_add_node(root, "/tmp/libisofs_test/dir1");
|
||||
CU_ASSERT_PTR_NOT_NULL(node);
|
||||
CU_ASSERT_PTR_EQUAL(node->parent, root);
|
||||
CU_ASSERT_EQUAL(root->nchildren, 1);
|
||||
CU_ASSERT_PTR_EQUAL(root->children[0], node);
|
||||
CU_ASSERT_STRING_EQUAL( node->name, "dir1");
|
||||
CU_ASSERT( ISO_ISDIR(node) );
|
||||
CU_ASSERT( S_ISDIR(node->attrib.st_mode) );
|
||||
|
||||
/* test addition of a link */
|
||||
node = iso_tree_add_node(root, "/tmp/libisofs_test/link to readme");
|
||||
CU_ASSERT_PTR_NOT_NULL(node);
|
||||
CU_ASSERT_PTR_EQUAL(node->parent, root);
|
||||
CU_ASSERT_EQUAL(root->nchildren, 2);
|
||||
CU_ASSERT_PTR_EQUAL(root->children[1], node);
|
||||
CU_ASSERT( ISO_ISLNK(node) );
|
||||
CU_ASSERT( S_ISLNK(node->attrib.st_mode) );
|
||||
CU_ASSERT_STRING_EQUAL( node->name, "link to readme");
|
||||
CU_ASSERT_STRING_EQUAL( ((struct iso_tree_node_symlink*)node)->dest,
|
||||
"/tmp/libisofs_test/README" );
|
||||
|
||||
/* test addition of a file */
|
||||
node = iso_tree_add_node(root, "/tmp/libisofs_test/README");
|
||||
CU_ASSERT_PTR_NOT_NULL(node);
|
||||
CU_ASSERT_PTR_EQUAL(node->parent, root);
|
||||
CU_ASSERT_EQUAL(root->nchildren, 3);
|
||||
CU_ASSERT_PTR_EQUAL(root->children[2], node);
|
||||
CU_ASSERT( S_ISREG(node->attrib.st_mode) );
|
||||
CU_ASSERT( ISO_ISREG(node) );
|
||||
CU_ASSERT_STRING_EQUAL( node->name, "README" );
|
||||
CU_ASSERT_STRING_EQUAL( ((struct iso_tree_node_file *) node)->path,
|
||||
"/tmp/libisofs_test/README" );
|
||||
|
||||
/* test no exiting file */
|
||||
node = iso_tree_add_node(root, "/tmp/libisofs_test/THISNOTEXIST");
|
||||
CU_ASSERT_PTR_NULL(node);
|
||||
CU_ASSERT_EQUAL(libisofs_errno, NO_FILE);
|
||||
CU_ASSERT_EQUAL(root->nchildren, 3);
|
||||
|
||||
/* test no valid file */
|
||||
node = iso_tree_add_node(root, "/dev/zero");
|
||||
CU_ASSERT_PTR_NULL(node);
|
||||
CU_ASSERT_EQUAL(libisofs_errno, UNEXPECTED_FILE_TYPE);
|
||||
CU_ASSERT_EQUAL(root->nchildren, 3);
|
||||
|
||||
/* test no read perm file */
|
||||
node = iso_tree_add_node(root, "/tmp/libisofs_test/no_read");
|
||||
CU_ASSERT_PTR_NULL(node);
|
||||
CU_ASSERT_EQUAL(libisofs_errno, NO_READ_ACCESS);
|
||||
CU_ASSERT_EQUAL(root->nchildren, 3);
|
||||
|
||||
iso_tree_free((struct iso_tree_node *)root);
|
||||
}
|
||||
|
||||
static void test_radd_dir() {
|
||||
struct iso_tree_node_dir *root;
|
||||
struct iso_tree_node_dir *child;
|
||||
struct iso_tree_node_file *file;
|
||||
struct iso_tree_radd_dir_behavior behavior = {0,0,0};
|
||||
|
||||
//TODO write really full test
|
||||
|
||||
root = iso_tree_new_root();
|
||||
CU_ASSERT_PTR_NOT_NULL(root);
|
||||
|
||||
iso_tree_radd_dir(root, "/tmp/libisofs_test", &behavior);
|
||||
|
||||
/* test _root_ children */
|
||||
/*
|
||||
child = (struct iso_tree_node_dir *)root->children[0];
|
||||
CU_ASSERT( S_ISDIR(child->node.attrib.st_mode) );
|
||||
CU_ASSERT_EQUAL( child->nchildren, 2);
|
||||
CU_ASSERT_STRING_EQUAL( child->node.name, "dir1" );
|
||||
|
||||
child = (struct iso_tree_node_dir *)root->children[1];
|
||||
CU_ASSERT( S_ISDIR(child->node.attrib.st_mode) );
|
||||
CU_ASSERT_EQUAL( child->nchildren, 0);
|
||||
CU_ASSERT_STRING_EQUAL( child->node.name, "dir2" );
|
||||
|
||||
file = (struct iso_tree_node_file *)root->children[2];
|
||||
CU_ASSERT( S_ISREG(file->node.attrib.st_mode) );
|
||||
CU_ASSERT_STRING_EQUAL( file->node.name, "README" );
|
||||
*/
|
||||
//iso_tree_print( (struct iso_tree_node *)root, 4 );
|
||||
}
|
||||
|
||||
static void test_set_name() {
|
||||
struct iso_tree_node_dir *root;
|
||||
struct iso_tree_node *node;
|
||||
|
||||
root = iso_tree_new_root();
|
||||
|
||||
/* test on a dir */
|
||||
node = iso_tree_add_node(root, "/tmp/libisofs_test/dir1");
|
||||
CU_ASSERT_PTR_NOT_NULL(node);
|
||||
CU_ASSERT_STRING_EQUAL( node->name, "dir1");
|
||||
iso_tree_node_set_name(node, "newname");
|
||||
CU_ASSERT_STRING_EQUAL( node->name, "newname");
|
||||
|
||||
/* test on a link */
|
||||
node = iso_tree_add_node(root, "/tmp/libisofs_test/link to readme");
|
||||
CU_ASSERT_PTR_NOT_NULL(node);
|
||||
CU_ASSERT_STRING_EQUAL( node->name, "link to readme");
|
||||
iso_tree_node_set_name(node, "new link name");
|
||||
CU_ASSERT_STRING_EQUAL( node->name, "new link name");
|
||||
|
||||
/* test on a file */
|
||||
node = iso_tree_add_node(root, "/tmp/libisofs_test/README");
|
||||
CU_ASSERT_PTR_NOT_NULL(node);
|
||||
CU_ASSERT_STRING_EQUAL( node->name, "README" );
|
||||
iso_tree_node_set_name(node, "new file name");
|
||||
CU_ASSERT_STRING_EQUAL( node->name, "new file name");
|
||||
|
||||
iso_tree_free((struct iso_tree_node *)root);
|
||||
}
|
||||
|
||||
static void test_set_hidden() {
|
||||
struct iso_tree_node_dir *root;
|
||||
struct iso_tree_node *node;
|
||||
|
||||
root = iso_tree_new_root();
|
||||
|
||||
/* test on a dir */
|
||||
node = iso_tree_add_node(root, "/tmp/libisofs_test/dir1");
|
||||
CU_ASSERT_PTR_NOT_NULL(node);
|
||||
CU_ASSERT_EQUAL(node->hide_flags, 0);
|
||||
iso_tree_node_set_hidden(node, LIBISO_HIDE_ON_RR);
|
||||
CU_ASSERT_EQUAL(node->hide_flags, LIBISO_HIDE_ON_RR);
|
||||
iso_tree_node_set_hidden(node, LIBISO_HIDE_ON_JOLIET);
|
||||
CU_ASSERT_EQUAL(node->hide_flags, LIBISO_HIDE_ON_JOLIET);
|
||||
iso_tree_node_set_hidden(node, LIBISO_HIDE_ON_RR|LIBISO_HIDE_ON_JOLIET);
|
||||
CU_ASSERT_EQUAL(node->hide_flags, LIBISO_HIDE_ON_RR|LIBISO_HIDE_ON_JOLIET);
|
||||
|
||||
/* test on a link */
|
||||
node = iso_tree_add_node(root, "/tmp/libisofs_test/link to readme");
|
||||
CU_ASSERT_PTR_NOT_NULL(node);
|
||||
CU_ASSERT_EQUAL(node->hide_flags, 0);
|
||||
iso_tree_node_set_hidden(node, LIBISO_HIDE_ON_RR);
|
||||
CU_ASSERT_EQUAL(node->hide_flags, LIBISO_HIDE_ON_RR);
|
||||
iso_tree_node_set_hidden(node, LIBISO_HIDE_ON_JOLIET);
|
||||
CU_ASSERT_EQUAL(node->hide_flags, LIBISO_HIDE_ON_JOLIET);
|
||||
iso_tree_node_set_hidden(node, LIBISO_HIDE_ON_RR|LIBISO_HIDE_ON_JOLIET);
|
||||
CU_ASSERT_EQUAL(node->hide_flags, LIBISO_HIDE_ON_RR|LIBISO_HIDE_ON_JOLIET);
|
||||
|
||||
/* test on a file */
|
||||
node = iso_tree_add_node(root, "/tmp/libisofs_test/README");
|
||||
CU_ASSERT_PTR_NOT_NULL(node);
|
||||
CU_ASSERT_EQUAL(node->hide_flags, 0);
|
||||
iso_tree_node_set_hidden(node, LIBISO_HIDE_ON_RR);
|
||||
CU_ASSERT_EQUAL(node->hide_flags, LIBISO_HIDE_ON_RR);
|
||||
iso_tree_node_set_hidden(node, LIBISO_HIDE_ON_JOLIET);
|
||||
CU_ASSERT_EQUAL(node->hide_flags, LIBISO_HIDE_ON_JOLIET);
|
||||
iso_tree_node_set_hidden(node, LIBISO_HIDE_ON_RR|LIBISO_HIDE_ON_JOLIET);
|
||||
CU_ASSERT_EQUAL(node->hide_flags, LIBISO_HIDE_ON_RR|LIBISO_HIDE_ON_JOLIET);
|
||||
|
||||
iso_tree_free((struct iso_tree_node *)root);
|
||||
}
|
||||
|
||||
static void test_set_gid() {
|
||||
struct iso_tree_node_dir *root;
|
||||
struct iso_tree_node *node;
|
||||
gid_t mygid = getgid();
|
||||
|
||||
root = iso_tree_new_root();
|
||||
|
||||
/* test on a dir */
|
||||
node = iso_tree_add_node(root, "/tmp/libisofs_test/dir1");
|
||||
CU_ASSERT_PTR_NOT_NULL(node);
|
||||
CU_ASSERT_EQUAL(node->attrib.st_gid, mygid);
|
||||
iso_tree_node_set_gid(node, 1234);
|
||||
CU_ASSERT_EQUAL(node->attrib.st_gid, 1234);
|
||||
|
||||
/* test on a link */
|
||||
node = iso_tree_add_node(root, "/tmp/libisofs_test/link to readme");
|
||||
CU_ASSERT_PTR_NOT_NULL(node);
|
||||
CU_ASSERT_EQUAL(node->attrib.st_gid, mygid);
|
||||
iso_tree_node_set_gid(node, 1234);
|
||||
CU_ASSERT_EQUAL(node->attrib.st_gid, 1234);
|
||||
|
||||
/* test on a file */
|
||||
node = iso_tree_add_node(root, "/tmp/libisofs_test/README");
|
||||
CU_ASSERT_PTR_NOT_NULL(node);
|
||||
CU_ASSERT_EQUAL(node->attrib.st_gid, mygid);
|
||||
iso_tree_node_set_gid(node, 1234);
|
||||
CU_ASSERT_EQUAL(node->attrib.st_gid, 1234);
|
||||
|
||||
iso_tree_free((struct iso_tree_node *)root);
|
||||
}
|
||||
|
||||
static void test_set_uid() {
|
||||
struct iso_tree_node_dir *root;
|
||||
struct iso_tree_node *node;
|
||||
uid_t myuid = getuid();
|
||||
|
||||
root = iso_tree_new_root();
|
||||
|
||||
/* test on a dir */
|
||||
node = iso_tree_add_node(root, "/tmp/libisofs_test/dir1");
|
||||
CU_ASSERT_PTR_NOT_NULL(node);
|
||||
CU_ASSERT_EQUAL(node->attrib.st_uid, myuid);
|
||||
iso_tree_node_set_uid(node, 1234);
|
||||
CU_ASSERT_EQUAL(node->attrib.st_uid, 1234);
|
||||
|
||||
/* test on a link */
|
||||
node = iso_tree_add_node(root, "/tmp/libisofs_test/link to readme");
|
||||
CU_ASSERT_PTR_NOT_NULL(node);
|
||||
CU_ASSERT_EQUAL(node->attrib.st_uid, myuid);
|
||||
iso_tree_node_set_uid(node, 1234);
|
||||
CU_ASSERT_EQUAL(node->attrib.st_uid, 1234);
|
||||
|
||||
/* test on a file */
|
||||
node = iso_tree_add_node(root, "/tmp/libisofs_test/README");
|
||||
CU_ASSERT_PTR_NOT_NULL(node);
|
||||
CU_ASSERT_EQUAL(node->attrib.st_uid, myuid);
|
||||
iso_tree_node_set_uid(node, 1234);
|
||||
CU_ASSERT_EQUAL(node->attrib.st_uid, 1234);
|
||||
|
||||
//TODO
|
||||
|
||||
iso_tree_free((struct iso_tree_node *)root);
|
||||
}
|
||||
|
||||
static void test_set_permissions() {
|
||||
struct iso_tree_node_dir *root;
|
||||
struct iso_tree_node *node;
|
||||
|
||||
root = iso_tree_new_root();
|
||||
|
||||
/* test on a dir */
|
||||
node = iso_tree_add_node(root, "/tmp/libisofs_test/dir1");
|
||||
CU_ASSERT_PTR_NOT_NULL(node);
|
||||
CU_ASSERT_EQUAL(node->attrib.st_mode, S_IFDIR | 0755);
|
||||
iso_tree_node_set_permissions(node, 0777);
|
||||
CU_ASSERT_EQUAL(node->attrib.st_mode, S_IFDIR | 0777);
|
||||
iso_tree_node_set_permissions(node, 0744);
|
||||
CU_ASSERT_EQUAL(node->attrib.st_mode, S_IFDIR | 0744);
|
||||
iso_tree_node_set_permissions(node, 0411);
|
||||
CU_ASSERT_EQUAL(node->attrib.st_mode, S_IFDIR | 0411);
|
||||
|
||||
/* test on a link */
|
||||
node = iso_tree_add_node(root, "/tmp/libisofs_test/link to readme");
|
||||
CU_ASSERT_PTR_NOT_NULL(node);
|
||||
CU_ASSERT_EQUAL(node->attrib.st_mode, S_IFLNK | 0777);
|
||||
iso_tree_node_set_permissions(node, 0555);
|
||||
CU_ASSERT_EQUAL(node->attrib.st_mode, S_IFLNK | 0555);
|
||||
iso_tree_node_set_permissions(node, 0744);
|
||||
CU_ASSERT_EQUAL(node->attrib.st_mode, S_IFLNK | 0744);
|
||||
iso_tree_node_set_permissions(node, 0411);
|
||||
CU_ASSERT_EQUAL(node->attrib.st_mode, S_IFLNK | 0411);
|
||||
|
||||
/* test on a file */
|
||||
node = iso_tree_add_node(root, "/tmp/libisofs_test/README");
|
||||
CU_ASSERT_PTR_NOT_NULL(node);
|
||||
CU_ASSERT_EQUAL(node->attrib.st_mode, S_IFREG | 0555);
|
||||
iso_tree_node_set_permissions(node, 0777);
|
||||
CU_ASSERT_EQUAL(node->attrib.st_mode, S_IFREG | 0777);
|
||||
iso_tree_node_set_permissions(node, 0744);
|
||||
CU_ASSERT_EQUAL(node->attrib.st_mode, S_IFREG | 0744);
|
||||
iso_tree_node_set_permissions(node, 0411);
|
||||
CU_ASSERT_EQUAL(node->attrib.st_mode, S_IFREG | 0411);
|
||||
|
||||
iso_tree_free((struct iso_tree_node *)root);
|
||||
}
|
||||
|
||||
static void test_set_sort_weight() {
|
||||
struct iso_tree_node_dir *root;
|
||||
struct iso_tree_node_dir *dir;
|
||||
struct iso_tree_node_file *file;
|
||||
|
||||
root = iso_tree_new_root();
|
||||
|
||||
dir = iso_tree_add_dir(root, "New dir name");
|
||||
CU_ASSERT_PTR_NOT_NULL(dir);
|
||||
|
||||
file = (struct iso_tree_node_file *)
|
||||
iso_tree_add_file(dir, "/tmp/libisofs_test/README");
|
||||
CU_ASSERT_EQUAL(file->sort_weight, 0);
|
||||
iso_tree_node_set_sort_weight((struct iso_tree_node *) file, 15);
|
||||
CU_ASSERT_EQUAL(file->sort_weight, 15);
|
||||
iso_tree_node_set_sort_weight((struct iso_tree_node *) file, -15);
|
||||
CU_ASSERT_EQUAL(file->sort_weight, -15);
|
||||
|
||||
/* changes to dir involve update files inside it */
|
||||
iso_tree_node_set_sort_weight((struct iso_tree_node *) dir, 28);
|
||||
CU_ASSERT_EQUAL(file->sort_weight, 28);
|
||||
|
||||
iso_tree_free((struct iso_tree_node *)root);
|
||||
}
|
||||
|
||||
void add_tree_suite()
|
||||
{
|
||||
CU_pSuite pSuite = CU_add_suite("TreeSuite", NULL, NULL);
|
||||
|
||||
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_add_node()", test_add_node);
|
||||
CU_add_test(pSuite, "test of iso_tree_radd_dir()", test_radd_dir);
|
||||
|
||||
CU_add_test(pSuite, "test of iso_tree_node_set_name()", test_set_name);
|
||||
CU_add_test(pSuite, "test of iso_tree_node_set_hidden()", test_set_hidden);
|
||||
CU_add_test(pSuite, "test of iso_tree_node_set_gid()", test_set_gid);
|
||||
CU_add_test(pSuite, "test of iso_tree_node_set_uid()", test_set_uid);
|
||||
CU_add_test(pSuite, "test of iso_tree_node_set_permissions()", test_set_permissions);
|
||||
CU_add_test(pSuite, "test of iso_tree_node_set_sort_weight()", test_set_sort_weight);
|
||||
}
|
265
libisofs/branches/ZeroTwoEight/test/test_util.c
Normal file
265
libisofs/branches/ZeroTwoEight/test/test_util.c
Normal 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);
|
||||
}
|
238
libisofs/branches/ZeroTwoEight/test/test_volume.c
Normal file
238
libisofs/branches/ZeroTwoEight/test/test_volume.c
Normal file
@ -0,0 +1,238 @@
|
||||
/*
|
||||
* Unit test for volume.h
|
||||
*/
|
||||
|
||||
|
||||
#include "libisofs.h"
|
||||
#include "tree.h"
|
||||
#include "test.h"
|
||||
#include "volume.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
static void test_iso_volume_new()
|
||||
{
|
||||
struct iso_volume *volume;
|
||||
|
||||
volume = iso_volume_new("volume_id", "publisher_id", "data_preparer_id");
|
||||
CU_ASSERT_PTR_NOT_NULL(volume);
|
||||
CU_ASSERT_EQUAL(volume->refcount, 1);
|
||||
/* a new root must be created */
|
||||
CU_ASSERT_PTR_NOT_NULL(volume->root);
|
||||
|
||||
CU_ASSERT_STRING_EQUAL( volume->volume_id, "volume_id" );
|
||||
CU_ASSERT_STRING_EQUAL( volume->publisher_id, "publisher_id" );
|
||||
CU_ASSERT_STRING_EQUAL( volume->data_preparer_id, "data_preparer_id" );
|
||||
|
||||
CU_ASSERT_PTR_NULL(volume->system_id);
|
||||
CU_ASSERT_PTR_NULL(volume->application_id);
|
||||
CU_ASSERT_PTR_NULL(volume->copyright_file_id);
|
||||
CU_ASSERT_PTR_NULL(volume->abstract_file_id);
|
||||
CU_ASSERT_PTR_NULL(volume->biblio_file_id);
|
||||
|
||||
CU_ASSERT_PTR_NULL(volume->bootcat);
|
||||
|
||||
iso_volume_free(volume);
|
||||
}
|
||||
|
||||
static void test_iso_volume_new_with_root()
|
||||
{
|
||||
struct iso_volume *volume;
|
||||
struct iso_tree_node_dir *root;
|
||||
|
||||
root = iso_tree_new_root();
|
||||
volume = iso_volume_new_with_root("volume_id", "publisher_id",
|
||||
"data_preparer_id", root);
|
||||
|
||||
CU_ASSERT_PTR_NOT_NULL(volume);
|
||||
CU_ASSERT_EQUAL(volume->refcount, 1);
|
||||
CU_ASSERT_PTR_NOT_NULL(volume->root);
|
||||
CU_ASSERT_PTR_EQUAL(volume->root, root);
|
||||
|
||||
CU_ASSERT_STRING_EQUAL( volume->volume_id, "volume_id" );
|
||||
CU_ASSERT_STRING_EQUAL( volume->publisher_id, "publisher_id" );
|
||||
CU_ASSERT_STRING_EQUAL( volume->data_preparer_id, "data_preparer_id" );
|
||||
|
||||
CU_ASSERT_PTR_NULL(volume->system_id);
|
||||
CU_ASSERT_PTR_NULL(volume->application_id);
|
||||
CU_ASSERT_PTR_NULL(volume->copyright_file_id);
|
||||
CU_ASSERT_PTR_NULL(volume->abstract_file_id);
|
||||
CU_ASSERT_PTR_NULL(volume->biblio_file_id);
|
||||
|
||||
CU_ASSERT_PTR_NULL(volume->bootcat);
|
||||
|
||||
iso_volume_free(volume);
|
||||
}
|
||||
|
||||
static void test_iso_volume_get_root()
|
||||
{
|
||||
struct iso_volume *volume;
|
||||
struct iso_tree_node_dir *root;
|
||||
struct iso_tree_node_dir *root2;
|
||||
|
||||
root = iso_tree_new_root();
|
||||
volume = iso_volume_new_with_root("volume_id", "publisher_id",
|
||||
"data_preparer_id", root);
|
||||
|
||||
root2 = iso_volume_get_root(volume);
|
||||
|
||||
CU_ASSERT_PTR_NOT_NULL(root2);
|
||||
CU_ASSERT_PTR_EQUAL(root2, volume->root);
|
||||
CU_ASSERT_PTR_EQUAL(root2, root);
|
||||
|
||||
iso_volume_free(volume);
|
||||
}
|
||||
|
||||
static void test_iso_volume_set_volume_id()
|
||||
{
|
||||
struct iso_volume *volume;
|
||||
|
||||
volume = iso_volume_new("volume_id", "publisher_id", "data_preparer_id");
|
||||
CU_ASSERT_STRING_EQUAL( volume->volume_id, "volume_id" );
|
||||
|
||||
char *volid = "new volume id";
|
||||
iso_volume_set_volume_id(volume, volid);
|
||||
CU_ASSERT_STRING_EQUAL( volume->volume_id, "new volume id" );
|
||||
|
||||
/* check string was strdup'ed */
|
||||
CU_ASSERT_PTR_NOT_EQUAL( volume->volume_id, volid );
|
||||
iso_volume_free(volume);
|
||||
}
|
||||
|
||||
static void test_iso_volume_set_publisher_id()
|
||||
{
|
||||
struct iso_volume *volume;
|
||||
|
||||
volume = iso_volume_new("volume_id", "publisher_id", "data_preparer_id");
|
||||
CU_ASSERT_STRING_EQUAL( volume->publisher_id, "publisher_id" );
|
||||
|
||||
char *pubid = "new publisher id";
|
||||
iso_volume_set_publisher_id(volume, pubid);
|
||||
CU_ASSERT_STRING_EQUAL( volume->publisher_id, "new publisher id" );
|
||||
|
||||
/* check string was strdup'ed */
|
||||
CU_ASSERT_PTR_NOT_EQUAL( volume->publisher_id, pubid );
|
||||
iso_volume_free(volume);
|
||||
}
|
||||
|
||||
static void test_iso_volume_set_data_preparer_id()
|
||||
{
|
||||
struct iso_volume *volume;
|
||||
|
||||
volume = iso_volume_new("volume_id", "publisher_id", "data_preparer_id");
|
||||
CU_ASSERT_STRING_EQUAL( volume->data_preparer_id, "data_preparer_id" );
|
||||
|
||||
char *dpid = "new data preparer id";
|
||||
iso_volume_set_data_preparer_id(volume, dpid);
|
||||
CU_ASSERT_STRING_EQUAL( volume->data_preparer_id, "new data preparer id" );
|
||||
|
||||
/* check string was strdup'ed */
|
||||
CU_ASSERT_PTR_NOT_EQUAL( volume->data_preparer_id, dpid );
|
||||
iso_volume_free(volume);
|
||||
}
|
||||
|
||||
static void test_iso_volume_set_system_id()
|
||||
{
|
||||
struct iso_volume *volume;
|
||||
|
||||
volume = iso_volume_new("volume_id", "publisher_id", "data_preparer_id");
|
||||
CU_ASSERT_PTR_NULL(volume->system_id);
|
||||
|
||||
char *sysid = "new system id";
|
||||
iso_volume_set_system_id(volume, sysid);
|
||||
CU_ASSERT_STRING_EQUAL( volume->system_id, "new system id" );
|
||||
|
||||
/* check string was strdup'ed */
|
||||
CU_ASSERT_PTR_NOT_EQUAL( volume->system_id, sysid );
|
||||
iso_volume_free(volume);
|
||||
}
|
||||
|
||||
static void test_iso_volume_set_application_id()
|
||||
{
|
||||
struct iso_volume *volume;
|
||||
|
||||
volume = iso_volume_new("volume_id", "publisher_id", "data_preparer_id");
|
||||
CU_ASSERT_PTR_NULL(volume->application_id);
|
||||
|
||||
char *appid = "new application id";
|
||||
iso_volume_set_application_id(volume, appid);
|
||||
CU_ASSERT_STRING_EQUAL( volume->application_id, "new application id" );
|
||||
|
||||
/* check string was strdup'ed */
|
||||
CU_ASSERT_PTR_NOT_EQUAL( volume->application_id, appid );
|
||||
iso_volume_free(volume);
|
||||
}
|
||||
|
||||
static void test_iso_volume_set_abstract_file_id()
|
||||
{
|
||||
struct iso_volume *volume;
|
||||
|
||||
volume = iso_volume_new("volume_id", "publisher_id", "data_preparer_id");
|
||||
CU_ASSERT_PTR_NULL(volume->abstract_file_id);
|
||||
|
||||
char *absid = "new abstract id";
|
||||
iso_volume_set_abstract_file_id(volume, absid);
|
||||
CU_ASSERT_STRING_EQUAL( volume->abstract_file_id, "new abstract id" );
|
||||
|
||||
/* check string was strdup'ed */
|
||||
CU_ASSERT_PTR_NOT_EQUAL( volume->abstract_file_id, absid );
|
||||
iso_volume_free(volume);
|
||||
}
|
||||
|
||||
static void test_iso_volume_set_biblio_file_id()
|
||||
{
|
||||
struct iso_volume *volume;
|
||||
|
||||
volume = iso_volume_new("volume_id", "publisher_id", "data_preparer_id");
|
||||
CU_ASSERT_PTR_NULL(volume->biblio_file_id);
|
||||
|
||||
char *bibid = "new biblio id";
|
||||
iso_volume_set_biblio_file_id(volume, bibid);
|
||||
CU_ASSERT_STRING_EQUAL( volume->biblio_file_id, "new biblio id" );
|
||||
|
||||
/* check string was strdup'ed */
|
||||
CU_ASSERT_PTR_NOT_EQUAL( volume->biblio_file_id, bibid );
|
||||
iso_volume_free(volume);
|
||||
}
|
||||
|
||||
static void test_iso_volset_new()
|
||||
{
|
||||
struct iso_volume *volume;
|
||||
struct iso_volset *volset;
|
||||
|
||||
volume = iso_volume_new("volume_id", "publisher_id", "data_preparer_id");
|
||||
|
||||
volset = iso_volset_new(volume, "volset_id");
|
||||
CU_ASSERT_PTR_NOT_NULL(volset);
|
||||
CU_ASSERT_EQUAL(volset->refcount, 1);
|
||||
CU_ASSERT_EQUAL(volset->volset_size, 1);
|
||||
CU_ASSERT_PTR_NOT_NULL(volset->volume);
|
||||
CU_ASSERT_PTR_NOT_NULL(volset->volume[0]);
|
||||
CU_ASSERT_PTR_EQUAL(volset->volume[0], volume);
|
||||
CU_ASSERT_STRING_EQUAL( volset->volset_id, "volset_id" );
|
||||
|
||||
iso_volset_free(volset);
|
||||
}
|
||||
|
||||
void add_volume_suite()
|
||||
{
|
||||
CU_pSuite pSuite = CU_add_suite("VolumeSuite", NULL, NULL);
|
||||
|
||||
CU_add_test(pSuite, "test of iso_volume_new()", test_iso_volume_new);
|
||||
CU_add_test(pSuite, "test of iso_volume_new_with_root()", test_iso_volume_new_with_root);
|
||||
CU_add_test(pSuite, "test of iso_volume_get_root()", test_iso_volume_get_root);
|
||||
CU_add_test(pSuite, "test of iso_volume_set_volume_id()", test_iso_volume_set_volume_id);
|
||||
CU_add_test(pSuite, "test of iso_volume_set_publisher_id()", test_iso_volume_set_publisher_id);
|
||||
CU_add_test(pSuite, "test of iso_volume_set_data_preparer_id()", test_iso_volume_set_data_preparer_id);
|
||||
CU_add_test(pSuite, "test of iso_volume_set_system_id()", test_iso_volume_set_system_id);
|
||||
CU_add_test(pSuite, "test of iso_volume_set_application_id()", test_iso_volume_set_application_id);
|
||||
CU_add_test(pSuite, "test of iso_volume_set_abstract_file_id()", test_iso_volume_set_abstract_file_id);
|
||||
CU_add_test(pSuite, "test of iso_volume_set_biblio_file_id()", test_iso_volume_set_biblio_file_id);
|
||||
CU_add_test(pSuite, "test of iso_volset_new()", test_iso_volset_new);
|
||||
}
|
77
libisofs/branches/ZeroTwoEight/test/tree.py
Normal file
77
libisofs/branches/ZeroTwoEight/test/tree.py
Normal file
@ -0,0 +1,77 @@
|
||||
# a module to help with handling of filenames, directory trees, etc.
|
||||
|
||||
import os
|
||||
import os.path
|
||||
import stat
|
||||
|
||||
def pathsubtract(a, b):
|
||||
index = a.find(b)
|
||||
if index == -1:
|
||||
return None
|
||||
res = a[ (index + len(b)): ]
|
||||
|
||||
if res.find("/") == 0:
|
||||
res = res[1:]
|
||||
return res
|
||||
|
||||
# same as C strcmp()
|
||||
def strcmp(a, b):
|
||||
if a < b:
|
||||
return -1
|
||||
if a > b:
|
||||
return 1
|
||||
return 0
|
||||
|
||||
class TreeNode:
|
||||
|
||||
# path is the location of the file/directory. It is either a full path or
|
||||
# a path relative to $PWD
|
||||
def __init__(self, parent, path=".", root=".", isofile=None):
|
||||
if isofile:
|
||||
self.root = os.path.abspath(isofile)
|
||||
self.path = ""
|
||||
else:
|
||||
fullpath = os.path.abspath( path )
|
||||
fullroot = os.path.abspath( root )
|
||||
self.root = fullroot
|
||||
self.path = pathsubtract( fullpath, fullroot )
|
||||
self.parent = parent
|
||||
self.children = []
|
||||
|
||||
if self.path == None:
|
||||
raise NameError, "Invalid paths %s and %s" % (fullpath, fullroot)
|
||||
|
||||
# if this is a directory, add its children recursively
|
||||
def addchildren(self):
|
||||
if not stat.S_ISDIR( os.lstat(self.root + "/" + self.path).st_mode ):
|
||||
return
|
||||
|
||||
children = os.listdir( self.root + "/" + self.path )
|
||||
for child in children:
|
||||
if self.path:
|
||||
child = self.path + "/" + child
|
||||
self.children.append( TreeNode(self, child, self.root) )
|
||||
for child in self.children:
|
||||
child.addchildren()
|
||||
|
||||
def printAll(self, spaces=0):
|
||||
print " "*spaces + self.root + "/" + self.path
|
||||
for child in self.children:
|
||||
child.printAll(spaces + 2)
|
||||
|
||||
def isValidISO1(self):
|
||||
pass
|
||||
|
||||
class Tree:
|
||||
def __init__(self, root=None, isofile=None):
|
||||
if isofile:
|
||||
self.root = TreeNode(parent=None, isofile=isofile)
|
||||
else:
|
||||
self.root = TreeNode(parent=None, path=root, root=root)
|
||||
self.root.addchildren()
|
||||
|
||||
def isValidISO1(self):
|
||||
return root.isValidISO1();
|
||||
|
||||
#t = Tree(root=".")
|
||||
#t.root.printAll()
|
Reference in New Issue
Block a user