Moved libisofs trunk to attic, due to libisofs-ng
This commit is contained in:
4
libisofs/attic/test/Makefile
Normal file
4
libisofs/attic/test/Makefile
Normal file
@ -0,0 +1,4 @@
|
||||
all clean:
|
||||
$(MAKE) -C .. -$(MAKEFLAGS) $@
|
||||
|
||||
.PHONY: all clean
|
164
libisofs/attic/test/iso.c
Normal file
164
libisofs/attic/test/iso.c
Normal file
@ -0,0 +1,164 @@
|
||||
/* -*- 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:hV:";
|
||||
extern char *optarg;
|
||||
extern int optind;
|
||||
|
||||
void usage(char **argv)
|
||||
{
|
||||
printf("%s [OPTIONS] DIRECTORY OUTPUT\n", argv[0]);
|
||||
help();
|
||||
}
|
||||
|
||||
void help()
|
||||
{
|
||||
printf(
|
||||
"Options:\n"
|
||||
" -J Add Joliet support\n"
|
||||
" -R Add Rock Ridge support\n"
|
||||
" -V label Volume Label\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 ecma119_source_opts opts;
|
||||
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;
|
||||
int constraints;
|
||||
struct iso_tree_radd_dir_behavior behav = {0,0,0};
|
||||
int level=1, flags=0;
|
||||
char *boot_img = NULL;
|
||||
char *volid = "VOLID";
|
||||
|
||||
while ((c = getopt(argc, argv, optstring)) != -1) {
|
||||
switch(c) {
|
||||
case 'h':
|
||||
usage(argv);
|
||||
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 'V':
|
||||
volid = optarg;
|
||||
break;
|
||||
case '?':
|
||||
usage(argv);
|
||||
exit(1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (argc < 2) {
|
||||
printf ("Please pass directory from which to build ISO\n");
|
||||
usage(argv);
|
||||
return 1;
|
||||
}
|
||||
if (argc < 3) {
|
||||
printf ("Please supply output file\n");
|
||||
usage(argv);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!iso_init()) {
|
||||
err(1, "Can't init libisofs");
|
||||
}
|
||||
iso_msgs_set_severities("NEVER", "ALL", "");
|
||||
|
||||
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 el_torito_boot_image *bootimg;
|
||||
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");
|
||||
}
|
||||
bootimg = iso_volume_set_boot_image(volume, img, ELTORITO_NO_EMUL,
|
||||
boot, "boot.cat");
|
||||
el_torito_set_load_size(bootimg, 4);
|
||||
el_torito_patch_isolinux_image(bootimg);
|
||||
|
||||
/* Or just this for hidden img
|
||||
* iso_volume_set_boot_image_hidden(volume, boot_img, ELTORITO_NO_EMUL);
|
||||
*/
|
||||
}
|
||||
|
||||
volset = iso_volset_new( volume, "VOLSETID" );
|
||||
|
||||
/* some tests */
|
||||
iso_volume_set_application_id(volume, "Libburnia");
|
||||
iso_volume_set_copyright_file_id(volume, "LICENSE");
|
||||
|
||||
constraints = ECMA119_OMIT_VERSION_NUMBERS |
|
||||
ECMA119_37_CHAR_FILENAMES | ECMA119_NO_DIR_REALOCATION |
|
||||
ECMA119_RELAXED_FILENAMES;
|
||||
|
||||
memset(&opts, 0, sizeof(struct ecma119_source_opts));
|
||||
opts.level = level;
|
||||
opts.flags = flags;
|
||||
opts.relaxed_constraints = 0;
|
||||
opts.input_charset = NULL;
|
||||
opts.ouput_charset = "UTF-8";
|
||||
|
||||
src = iso_source_new_ecma119(volset, &opts);
|
||||
|
||||
while (src->read(src, buf, 2048) == 2048) {
|
||||
fwrite(buf, 1, 2048, fd);
|
||||
}
|
||||
fclose(fd);
|
||||
|
||||
iso_finish();
|
||||
return 0;
|
||||
}
|
297
libisofs/attic/test/iso.py
Normal file
297
libisofs/attic/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
|
157
libisofs/attic/test/iso_add.c
Normal file
157
libisofs/attic/test/iso_add.c
Normal file
@ -0,0 +1,157 @@
|
||||
/* -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 8; -*- */
|
||||
/* vim: set ts=8 sts=8 sw=8 noet : */
|
||||
|
||||
/*
|
||||
* Little program that appends a dir to an existing image
|
||||
*/
|
||||
|
||||
#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:h";
|
||||
extern char *optarg;
|
||||
extern int optind;
|
||||
|
||||
void usage()
|
||||
{
|
||||
printf("test [OPTIONS] IMAGE 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"
|
||||
" -h Print this message\n"
|
||||
);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
struct ecma119_source_opts wopts;
|
||||
struct ecma119_read_opts ropts;
|
||||
struct data_source *rsrc;
|
||||
struct iso_volset *volset;
|
||||
struct iso_tree_node_dir *root;
|
||||
struct burn_source *wsrc;
|
||||
unsigned char buf[2048];
|
||||
FILE *fd;
|
||||
int c;
|
||||
int constraints;
|
||||
struct iso_tree_radd_dir_behavior behav = {0,0,0};
|
||||
int level=1, flags=0;
|
||||
|
||||
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 '?':
|
||||
usage();
|
||||
exit(1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (argc < optind + 1) {
|
||||
printf ("Please supply old image file\n");
|
||||
usage();
|
||||
return 1;
|
||||
}
|
||||
if (argc < optind + 2) {
|
||||
printf ("Please supply directory to add to image\n");
|
||||
usage();
|
||||
return 1;
|
||||
}
|
||||
if (argc < optind + 3) {
|
||||
printf ("Please supply output file\n");
|
||||
usage();
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!iso_init()) {
|
||||
err(1, "Can't init libisofs");
|
||||
}
|
||||
iso_msgs_set_severities("NEVER", "ALL", "");
|
||||
|
||||
rsrc = data_source_from_file(argv[optind]);
|
||||
if (rsrc == NULL) {
|
||||
printf ("Can't open device\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
fd = fopen(argv[optind+2], "w");
|
||||
if (!fd) {
|
||||
err(1, "error opening output file");
|
||||
}
|
||||
|
||||
ropts.block = 0;
|
||||
ropts.norock = 0;
|
||||
ropts.nojoliet = 0;
|
||||
ropts.preferjoliet = 0;
|
||||
ropts.mode = 0555;
|
||||
ropts.uid = 0;
|
||||
ropts.gid = 0;
|
||||
volset = iso_volset_read(rsrc, &ropts);
|
||||
|
||||
if (volset == NULL) {
|
||||
printf ("Error reading image\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
root = iso_volume_get_root(iso_volset_get_volume(volset, 0));
|
||||
iso_tree_radd_dir(root, argv[optind+1], &behav);
|
||||
|
||||
constraints = ECMA119_OMIT_VERSION_NUMBERS |
|
||||
ECMA119_37_CHAR_FILENAMES | ECMA119_NO_DIR_REALOCATION |
|
||||
ECMA119_RELAXED_FILENAMES;
|
||||
|
||||
memset(&wopts, 0, sizeof(struct ecma119_source_opts));
|
||||
wopts.level = level;
|
||||
wopts.flags = flags;
|
||||
wopts.relaxed_constraints = 0;//constraints;
|
||||
wopts.input_charset = "UTF-8";
|
||||
wopts.ouput_charset = "UTF-8";
|
||||
wopts.ms_block = 0;
|
||||
wopts.src = rsrc;
|
||||
|
||||
wsrc = iso_source_new_ecma119(volset, &wopts);
|
||||
|
||||
while (wsrc->read(wsrc, buf, 2048) == 2048) {
|
||||
fwrite(buf, 1, 2048, fd);
|
||||
}
|
||||
fclose(fd);
|
||||
|
||||
iso_finish();
|
||||
|
||||
return 0;
|
||||
}
|
302
libisofs/attic/test/iso_grow.c
Normal file
302
libisofs/attic/test/iso_grow.c
Normal file
@ -0,0 +1,302 @@
|
||||
/* -*- 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:h";
|
||||
extern char *optarg;
|
||||
extern int optind;
|
||||
|
||||
static struct data_source *libburn_data_source_new(struct burn_drive *d);
|
||||
|
||||
void usage()
|
||||
{
|
||||
printf("test [OPTIONS] DISC DIRECTORY\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"
|
||||
" -h Print this message\n"
|
||||
);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
struct burn_drive_info *drives;
|
||||
struct burn_drive *drive;
|
||||
struct ecma119_source_opts wopts;
|
||||
struct ecma119_read_opts ropts;
|
||||
struct data_source *rsrc;
|
||||
struct iso_volset *volset;
|
||||
struct iso_tree_node_dir *root;
|
||||
struct burn_source *wsrc;
|
||||
int c;
|
||||
struct iso_tree_radd_dir_behavior behav = {0,0,0};
|
||||
int level=1, flags=0;
|
||||
int ret = 0;
|
||||
|
||||
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 '?':
|
||||
usage();
|
||||
exit(1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (argc < optind + 1) {
|
||||
printf ("Please supply device name\n");
|
||||
usage();
|
||||
return 1;
|
||||
}
|
||||
if (argc < optind + 2) {
|
||||
printf ("Please supply directory to add to disc\n");
|
||||
usage();
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!iso_init()) {
|
||||
err(1, "Can't init libisofs");
|
||||
}
|
||||
if (!burn_initialize()) {
|
||||
err(1, "Can't init libburn");
|
||||
}
|
||||
iso_msgs_set_severities("NEVER", "ALL", "");
|
||||
burn_msgs_set_severities("NEVER", "SORRY", "libburner : ");
|
||||
|
||||
printf("Reading from %s\n", argv[optind]);
|
||||
|
||||
if (burn_drive_scan_and_grab(&drives, argv[optind], 0) != 1) {
|
||||
err(1, "Can't open device. Are you sure it is a valid drive?\n");
|
||||
}
|
||||
|
||||
drive = drives[0].drive;
|
||||
|
||||
{
|
||||
/* some check before going on */
|
||||
enum burn_disc_status state;
|
||||
int pno;
|
||||
char name[80];
|
||||
|
||||
state = burn_disc_get_status(drive);
|
||||
burn_disc_get_profile(drive, &pno, name);
|
||||
|
||||
// my drives report BURN_DISC_BLANK on a DVD+RW with data.
|
||||
// is that correct?
|
||||
if ( (pno != 0x1a) /*|| (state != BURN_DISC_FULL)*/ ) {
|
||||
printf("You need to insert a DVD+RW with some data.\n");
|
||||
printf("Profile: %x, state: %d.\n", pno, state);
|
||||
ret = 1;
|
||||
goto exit_cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
rsrc = libburn_data_source_new(drive);
|
||||
if (rsrc == NULL) {
|
||||
printf ("Can't create data source.\n");
|
||||
ret = 1;
|
||||
goto exit_cleanup;
|
||||
}
|
||||
|
||||
ropts.block = 0; /* image always start on first block */
|
||||
ropts.norock = 0;
|
||||
ropts.nojoliet = 0;
|
||||
ropts.preferjoliet = 0;
|
||||
ropts.mode = 0555;
|
||||
ropts.uid = 0;
|
||||
ropts.gid = 0;
|
||||
volset = iso_volset_read(rsrc, &ropts);
|
||||
|
||||
if (volset == NULL) {
|
||||
printf ("Error reading image\n");
|
||||
ret = 1;
|
||||
goto exit_cleanup;
|
||||
}
|
||||
|
||||
printf("Image size: %d blocks.\n", ropts.size);
|
||||
|
||||
/* close source, no more needed */
|
||||
data_source_free(rsrc);
|
||||
|
||||
root = iso_volume_get_root(iso_volset_get_volume(volset, 0));
|
||||
|
||||
/* add a new dir */
|
||||
iso_tree_radd_dir(root, argv[optind+1], &behav);
|
||||
|
||||
memset(&wopts, 0, sizeof(struct ecma119_source_opts));
|
||||
wopts.level = level;
|
||||
wopts.flags = flags;
|
||||
wopts.relaxed_constraints = 0;
|
||||
wopts.input_charset = "UTF-8";
|
||||
wopts.ouput_charset = "UTF-8";
|
||||
/* round up to 32kb aligment = 16 block*/
|
||||
wopts.ms_block = ((ropts.size + 15) / 16 ) * 16;
|
||||
wopts.overwrite = calloc(32, 2048);
|
||||
|
||||
wsrc = iso_source_new_ecma119(volset, &wopts);
|
||||
|
||||
/* a. write the new image */
|
||||
printf("Adding new data...\n");
|
||||
{
|
||||
struct burn_disc *target_disc;
|
||||
struct burn_session *session;
|
||||
struct burn_write_opts *burn_options;
|
||||
struct burn_track *track;
|
||||
struct burn_progress progress;
|
||||
char reasons[BURN_REASONS_LEN];
|
||||
|
||||
target_disc = burn_disc_create();
|
||||
session = burn_session_create();
|
||||
burn_disc_add_session(target_disc, session, BURN_POS_END);
|
||||
|
||||
track = burn_track_create();
|
||||
burn_track_set_source(track, wsrc);
|
||||
burn_session_add_track(session, track, BURN_POS_END);
|
||||
|
||||
burn_options = burn_write_opts_new(drive);
|
||||
burn_drive_set_speed(drive, 0, 0);
|
||||
burn_write_opts_set_underrun_proof(burn_options, 1);
|
||||
|
||||
//mmm, check for 32K alignment?
|
||||
burn_write_opts_set_start_byte(burn_options, wopts.ms_block * 2048);
|
||||
|
||||
if (burn_write_opts_auto_write_type(burn_options, target_disc,
|
||||
reasons, 0) == BURN_WRITE_NONE) {
|
||||
printf("Failed to find a suitable write mode:\n%s\n", reasons);
|
||||
ret = 1;
|
||||
goto exit_cleanup;
|
||||
}
|
||||
|
||||
/* ok, write the new track */
|
||||
burn_disc_write(burn_options, target_disc);
|
||||
burn_write_opts_free(burn_options);
|
||||
|
||||
while (burn_drive_get_status(drive, NULL) == BURN_DRIVE_SPAWNING)
|
||||
usleep(1002);
|
||||
|
||||
while (burn_drive_get_status(drive, &progress) != BURN_DRIVE_IDLE) {
|
||||
printf("Writing: sector %d of %d\n", progress.sector, progress.sectors);
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* b. write the new vol desc */
|
||||
printf("Writing the new vol desc...\n");
|
||||
if ( burn_random_access_write(drive, 0, wopts.overwrite, 32*2048, 0) != 1) {
|
||||
printf("Ups, new vol desc write failed\n");
|
||||
}
|
||||
|
||||
free(wopts.overwrite);
|
||||
iso_volset_free(volset);
|
||||
|
||||
exit_cleanup:;
|
||||
burn_drive_release(drives[0].drive, 0);
|
||||
burn_finish();
|
||||
iso_finish();
|
||||
|
||||
exit(ret);
|
||||
}
|
||||
|
||||
struct disc_data_src {
|
||||
struct burn_drive *d;
|
||||
int nblocks;
|
||||
};
|
||||
|
||||
static int
|
||||
libburn_ds_read_block(struct data_source *src, int lba, unsigned char *buffer)
|
||||
{
|
||||
struct disc_data_src *data;
|
||||
off_t data_count;
|
||||
|
||||
assert(src && buffer);
|
||||
|
||||
data = (struct disc_data_src*)src->data;
|
||||
|
||||
/* if (lba >= data->nblocks)
|
||||
* return BLOCK_OUT_OF_FILE;
|
||||
*/
|
||||
|
||||
if ( burn_read_data(data->d, (off_t) lba * (off_t) 2048, buffer, 2048,
|
||||
&data_count, 0) < 0 ) {
|
||||
return -1; //error
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
libburn_ds_get_size(struct data_source *src)
|
||||
{
|
||||
struct disc_data_src *data;
|
||||
|
||||
assert(src);
|
||||
|
||||
data = (struct disc_data_src*)src->data;
|
||||
return data->nblocks;
|
||||
}
|
||||
|
||||
static void
|
||||
libburn_ds_free_data(struct data_source *src)
|
||||
{
|
||||
free(src->data);
|
||||
}
|
||||
|
||||
static struct data_source *
|
||||
libburn_data_source_new(struct burn_drive *d)
|
||||
{
|
||||
struct disc_data_src *data;
|
||||
struct data_source *ret;
|
||||
|
||||
assert(d);
|
||||
|
||||
data = malloc(sizeof(struct disc_data_src));
|
||||
data->d = d;
|
||||
|
||||
//should be filled with the size of disc (or track?)
|
||||
data->nblocks = 0;
|
||||
|
||||
ret = malloc(sizeof(struct data_source));
|
||||
ret->refcount = 1;
|
||||
ret->read_block = libburn_ds_read_block;
|
||||
ret->get_size = libburn_ds_get_size;
|
||||
ret->free_data = libburn_ds_free_data;
|
||||
ret->data = data;
|
||||
return ret;
|
||||
}
|
159
libisofs/attic/test/iso_ms.c
Normal file
159
libisofs/attic/test/iso_ms.c
Normal file
@ -0,0 +1,159 @@
|
||||
/* -*- 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:h";
|
||||
extern char *optarg;
|
||||
extern int optind;
|
||||
|
||||
void usage()
|
||||
{
|
||||
printf("test [OPTIONS] LSS NWA DISC 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"
|
||||
" -h Print this message\n"
|
||||
);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
struct ecma119_source_opts wopts;
|
||||
struct ecma119_read_opts ropts;
|
||||
struct data_source *rsrc;
|
||||
struct iso_volset *volset;
|
||||
struct iso_volume *volume;
|
||||
struct iso_tree_node_dir *root;
|
||||
struct burn_source *wsrc;
|
||||
unsigned char buf[2048];
|
||||
FILE *fd;
|
||||
int c;
|
||||
int constraints;
|
||||
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 '?':
|
||||
usage();
|
||||
exit(1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (argc < optind + 2) {
|
||||
printf ("Please supply last_sess_start next_sess_start\n");
|
||||
usage();
|
||||
return 1;
|
||||
}
|
||||
if (argc < optind + 3) {
|
||||
printf ("Please supply device name\n");
|
||||
usage();
|
||||
return 1;
|
||||
}
|
||||
if (argc < optind + 4) {
|
||||
printf ("Please supply directory to add to disc\n");
|
||||
usage();
|
||||
return 1;
|
||||
}
|
||||
if (argc < optind + 5) {
|
||||
printf ("Please supply output file\n");
|
||||
usage();
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!iso_init()) {
|
||||
err(1, "Can't init libisofs");
|
||||
}
|
||||
iso_msgs_set_severities("NEVER", "ALL", "");
|
||||
|
||||
rsrc = data_source_from_file(argv[optind+2]);
|
||||
if (rsrc == NULL) {
|
||||
printf ("Can't open device\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
fd = fopen(argv[optind+4], "w");
|
||||
if (!fd) {
|
||||
err(1, "error opening output file");
|
||||
}
|
||||
|
||||
ropts.block = atoi(argv[optind]);
|
||||
ropts.norock = 0;
|
||||
ropts.nojoliet = 0;
|
||||
ropts.preferjoliet = 0;
|
||||
ropts.mode = 0555;
|
||||
ropts.uid = 0;
|
||||
ropts.gid = 0;
|
||||
volset = iso_volset_read(rsrc, &ropts);
|
||||
|
||||
if (volset == NULL) {
|
||||
printf ("Error reading image\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
root = iso_volume_get_root(iso_volset_get_volume(volset, 0));
|
||||
iso_tree_radd_dir(root, argv[optind+3], &behav);
|
||||
|
||||
constraints = ECMA119_OMIT_VERSION_NUMBERS |
|
||||
ECMA119_37_CHAR_FILENAMES | ECMA119_NO_DIR_REALOCATION |
|
||||
ECMA119_RELAXED_FILENAMES;
|
||||
|
||||
memset(&wopts, 0, sizeof(struct ecma119_source_opts));
|
||||
wopts.level = level;
|
||||
wopts.flags = flags;
|
||||
wopts.relaxed_constraints = 0;//constraints;
|
||||
wopts.input_charset = "UTF-8";
|
||||
wopts.ouput_charset = "UTF-8";
|
||||
wopts.ms_block = atoi(argv[optind+1]);
|
||||
|
||||
wsrc = iso_source_new_ecma119(volset, &wopts);
|
||||
|
||||
while (wsrc->read(wsrc, buf, 2048) == 2048) {
|
||||
fwrite(buf, 1, 2048, fd);
|
||||
}
|
||||
fclose(fd);
|
||||
|
||||
iso_finish();
|
||||
|
||||
return 0;
|
||||
}
|
163
libisofs/attic/test/iso_read.c
Normal file
163
libisofs/attic/test/iso_read.c
Normal file
@ -0,0 +1,163 @@
|
||||
/*
|
||||
* Little program that reads an existing ISO image and prints its
|
||||
* contents to stdout.
|
||||
*/
|
||||
|
||||
#include "libisofs.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static void
|
||||
print_permissions(mode_t mode)
|
||||
{
|
||||
char perm[10];
|
||||
|
||||
//TODO suid, sticky...
|
||||
|
||||
perm[9] = '\0';
|
||||
perm[8] = mode & S_IXOTH ? 'x' : '-';
|
||||
perm[7] = mode & S_IWOTH ? 'w' : '-';
|
||||
perm[6] = mode & S_IROTH ? 'r' : '-';
|
||||
perm[5] = mode & S_IXGRP ? 'x' : '-';
|
||||
perm[4] = mode & S_IWGRP ? 'w' : '-';
|
||||
perm[3] = mode & S_IRGRP ? 'r' : '-';
|
||||
perm[2] = mode & S_IXUSR ? 'x' : '-';
|
||||
perm[1] = mode & S_IWUSR ? 'w' : '-';
|
||||
perm[0] = mode & S_IRUSR ? 'r' : '-';
|
||||
printf("[%s]",perm);
|
||||
}
|
||||
|
||||
static void
|
||||
print_dir(struct iso_tree_node_dir *dir, int level)
|
||||
{
|
||||
int i;
|
||||
struct iso_tree_iter *iter;
|
||||
struct iso_tree_node *node;
|
||||
char sp[level * 2 + 1];
|
||||
|
||||
for (i = 0; i < level * 2; i += 2) {
|
||||
sp[i] = '|';
|
||||
sp[i+1] = ' ';
|
||||
}
|
||||
|
||||
sp[level * 2-1] = '-';
|
||||
sp[level * 2] = '\0';
|
||||
|
||||
iter = iso_tree_node_children(dir);
|
||||
while ( (node = iso_tree_iter_next(iter)) != NULL ) {
|
||||
|
||||
|
||||
if (LIBISO_ISDIR(node)) {
|
||||
printf("%s+[D] ", sp);
|
||||
print_permissions(iso_tree_node_get_permissions(node));
|
||||
printf(" %s\n", iso_tree_node_get_name(node) );
|
||||
print_dir((struct iso_tree_node_dir*)node, level+1);
|
||||
} else if (LIBISO_ISREG(node)) {
|
||||
printf("%s-[F] ", sp);
|
||||
print_permissions(iso_tree_node_get_permissions(node));
|
||||
printf(" %s\n", iso_tree_node_get_name(node) );
|
||||
} else if (LIBISO_ISLNK(node)) {
|
||||
printf("%s-[L] ", sp);
|
||||
print_permissions(iso_tree_node_get_permissions(node));
|
||||
printf(" %s -> %s \n", iso_tree_node_get_name(node),
|
||||
iso_tree_node_symlink_get_dest((struct iso_tree_node_symlink*)node) );
|
||||
} else {
|
||||
/* boot catalog */
|
||||
printf("%s-[C] ", sp);
|
||||
print_permissions(iso_tree_node_get_permissions(node));
|
||||
printf(" %s\n", iso_tree_node_get_name(node) );
|
||||
}
|
||||
}
|
||||
iso_tree_iter_free(iter);
|
||||
}
|
||||
|
||||
static void
|
||||
check_el_torito(struct iso_volume *volume)
|
||||
{
|
||||
struct iso_tree_node *cat, *img;
|
||||
|
||||
if (iso_volume_get_boot_image(volume, &img, &cat)) {
|
||||
|
||||
printf("\nEL-TORITO INFORMATION\n");
|
||||
printf("=====================\n\n");
|
||||
printf("Catalog: %s\n", iso_tree_node_get_name(cat) );
|
||||
printf("Image: %s\n", iso_tree_node_get_name(img) );
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
struct ecma119_read_opts opts;
|
||||
struct data_source *src;
|
||||
struct iso_volset *volset;
|
||||
struct iso_volume *volume;
|
||||
|
||||
if (argc != 2) {
|
||||
printf ("You need to specify a valid ISO image\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!iso_init()) {
|
||||
err(1, "Can't init libisofs");
|
||||
}
|
||||
iso_msgs_set_severities("NEVER", "ALL", "");
|
||||
|
||||
src = data_source_from_file(argv[1]);
|
||||
if (src == NULL) {
|
||||
printf ("Can't open image\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
opts.block = 0;
|
||||
opts.norock = 0;
|
||||
opts.nojoliet = 0;
|
||||
opts.preferjoliet = 1;
|
||||
opts.mode = 0555;
|
||||
opts.uid = 0;
|
||||
opts.gid = 0;
|
||||
|
||||
volset = iso_volset_read(src, &opts);
|
||||
|
||||
if (volset == NULL) {
|
||||
printf ("Error reading image\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
volume = iso_volset_get_volume(volset, 0);
|
||||
|
||||
printf("\nVOLUME INFORMATION\n");
|
||||
printf("==================\n\n");
|
||||
|
||||
printf("Vol. id: %s\n", iso_volume_get_volume_id(volume));
|
||||
printf("Publisher: %s\n", iso_volume_get_publisher_id(volume));
|
||||
printf("Data preparer: %s\n", iso_volume_get_data_preparer_id(volume));
|
||||
printf("System: %s\n", iso_volume_get_system_id(volume));
|
||||
printf("Application: %s\n", iso_volume_get_application_id(volume));
|
||||
printf("Copyright: %s\n", iso_volume_get_copyright_file_id(volume));
|
||||
printf("Abstract: %s\n", iso_volume_get_abstract_file_id(volume));
|
||||
printf("Biblio: %s\n", iso_volume_get_biblio_file_id(volume));
|
||||
|
||||
if (opts.hasRR)
|
||||
printf("Rock Ridge Extensions are available.\n");
|
||||
if (opts.hasJoliet)
|
||||
printf("Joliet Extensions are available.\n");
|
||||
|
||||
printf("\nDIRECTORY TREE\n");
|
||||
printf("==============\n");
|
||||
|
||||
print_dir(iso_volume_get_root(volume), 0);
|
||||
|
||||
check_el_torito(volume);
|
||||
|
||||
printf("\n\n");
|
||||
|
||||
data_source_free(src);
|
||||
iso_volset_free(volset);
|
||||
|
||||
iso_finish();
|
||||
|
||||
return 0;
|
||||
}
|
30
libisofs/attic/test/test.c
Normal file
30
libisofs/attic/test/test.c
Normal file
@ -0,0 +1,30 @@
|
||||
#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();
|
||||
add_data_source_suite();
|
||||
add_isoread_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();
|
||||
}
|
28
libisofs/attic/test/test.h
Normal file
28
libisofs/attic/test/test.h
Normal file
@ -0,0 +1,28 @@
|
||||
#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();
|
||||
|
||||
void add_data_source_suite();
|
||||
|
||||
void add_isoread_suite();
|
||||
|
||||
#endif /*TEST_H_*/
|
75
libisofs/attic/test/test_data_source.c
Normal file
75
libisofs/attic/test/test_data_source.c
Normal file
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Unit test for data_source implementation
|
||||
*/
|
||||
|
||||
#include "test.h"
|
||||
#include "libisofs.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
void test_data_source_from_file()
|
||||
{
|
||||
int res;
|
||||
struct data_source *ds;
|
||||
unsigned char buffer[2048];
|
||||
unsigned char rbuff[2048];
|
||||
char filename[] = "/tmp/temp.iso.XXXXXX";
|
||||
int fd = mkstemp(filename);
|
||||
|
||||
/* actually a failure here means that we couldn't test */
|
||||
CU_ASSERT_NOT_EQUAL(fd, -1);
|
||||
|
||||
memset(buffer, 0x35, 2048);
|
||||
write(fd, buffer, 2048);
|
||||
memset(buffer, 0x20, 2048);
|
||||
write(fd, buffer, 2048);
|
||||
memset(buffer, 0xF2, 2048);
|
||||
write(fd, buffer, 2048);
|
||||
memset(buffer, 0x11, 2048);
|
||||
write(fd, buffer, 2048);
|
||||
memset(buffer, 0xAB, 2048);
|
||||
write(fd, buffer, 2048);
|
||||
close(fd);
|
||||
|
||||
ds = data_source_from_file(filename);
|
||||
CU_ASSERT_PTR_NOT_NULL(ds);
|
||||
|
||||
/* check correct size reported */
|
||||
CU_ASSERT_EQUAL(ds->get_size(ds), 5);
|
||||
|
||||
/* check reading */
|
||||
res = ds->read_block(ds, 4, rbuff);
|
||||
CU_ASSERT_EQUAL(res, 0);
|
||||
CU_ASSERT_NSTRING_EQUAL(rbuff, buffer, 2048);
|
||||
|
||||
res = ds->read_block(ds, 1, rbuff);
|
||||
CU_ASSERT_EQUAL(res, 0);
|
||||
memset(buffer, 0x20, 2048);
|
||||
CU_ASSERT_NSTRING_EQUAL(rbuff, buffer, 2048);
|
||||
|
||||
res = ds->read_block(ds, 0, rbuff);
|
||||
CU_ASSERT_EQUAL(res, 0);
|
||||
memset(buffer, 0x35, 2048);
|
||||
CU_ASSERT_NSTRING_EQUAL(rbuff, buffer, 2048);
|
||||
|
||||
res = ds->read_block(ds, 3, rbuff);
|
||||
CU_ASSERT_EQUAL(res, 0);
|
||||
memset(buffer, 0x11, 2048);
|
||||
CU_ASSERT_NSTRING_EQUAL(rbuff, buffer, 2048);
|
||||
|
||||
/* and a block outside file */
|
||||
res = ds->read_block(ds, 5, rbuff);
|
||||
CU_ASSERT_TRUE(res < 0);
|
||||
|
||||
data_source_free(ds);
|
||||
unlink(filename);
|
||||
}
|
||||
|
||||
void add_data_source_suite()
|
||||
{
|
||||
CU_pSuite pSuite = CU_add_suite("DataSourceSuite", NULL, NULL);
|
||||
|
||||
CU_add_test(pSuite, "test of data_source_from_file()", test_data_source_from_file);
|
||||
}
|
122
libisofs/attic/test/test_ecma119_tree.c
Normal file
122
libisofs/attic/test/test_ecma119_tree.c
Normal file
@ -0,0 +1,122 @@
|
||||
/*
|
||||
* Unit test for ecma119_tree.h
|
||||
*/
|
||||
|
||||
#include "libisofs.h"
|
||||
#include "tree.h"
|
||||
#include "test.h"
|
||||
#include "ecma119.h"
|
||||
#include "ecma119_tree.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
struct ecma119_write_target t;
|
||||
|
||||
|
||||
static void reset_write_target()
|
||||
{
|
||||
/* inititalize t with default values */
|
||||
t.root = NULL;
|
||||
t.joliet_root = NULL;
|
||||
t.volset = NULL;
|
||||
t.volnum = time(NULL);
|
||||
|
||||
t.now;
|
||||
t.total_size = 0;
|
||||
t.vol_space_size = 0;
|
||||
|
||||
t.rockridge = 0;
|
||||
t.joliet = 0;
|
||||
t.iso_level = 1;
|
||||
t.eltorito = 0;
|
||||
t.relaxed_constraints = 0;
|
||||
|
||||
t.catalog = NULL;
|
||||
|
||||
t.replace_mode = 0;
|
||||
t.dir_mode = 0777;
|
||||
t.file_mode = 0777;
|
||||
t.gid = 0;
|
||||
t.uid = 0;
|
||||
|
||||
t.input_charset = "UTF-8";
|
||||
t.ouput_charset = "UTF-8";
|
||||
|
||||
t.cache_inodes = 0;
|
||||
t.sort_files = 0;
|
||||
t.ino = 0;
|
||||
|
||||
t.curblock = 0;
|
||||
t.block_size = 2048;
|
||||
t.path_table_size = 0;
|
||||
t.path_table_size_joliet = 0;
|
||||
t.l_path_table_pos = 0;
|
||||
t.m_path_table_pos = 0;
|
||||
t.l_path_table_pos_joliet = 0;
|
||||
t.m_path_table_pos_joliet = 0;
|
||||
t.total_dir_size = 0;
|
||||
t.total_dir_size_joliet = 0;
|
||||
|
||||
t.dirlist = NULL;
|
||||
t.pathlist = NULL;
|
||||
t.dirlist_len = 0;
|
||||
t.file_table = NULL;
|
||||
t.filelist = NULL;
|
||||
t.filelist_len = 0;
|
||||
t.curfile = 0;
|
||||
|
||||
t.dirlist_joliet = NULL;
|
||||
t.pathlist_joliet = NULL;
|
||||
t.dirlist_len_joliet = 0;
|
||||
|
||||
t.state = ECMA119_WRITE_SYSTEM_AREA;
|
||||
}
|
||||
|
||||
void test_create_tree_only_root()
|
||||
{
|
||||
struct iso_tree_node *root;
|
||||
struct ecma119_tree_node *node;
|
||||
|
||||
reset_write_target();
|
||||
|
||||
root = (struct iso_tree_node*) iso_tree_new_root();
|
||||
|
||||
node = ecma119_tree_create(&t, root);
|
||||
CU_ASSERT_PTR_NOT_NULL(node);
|
||||
|
||||
/* root has no name */
|
||||
CU_ASSERT_PTR_NULL(node->iso_name);
|
||||
CU_ASSERT_PTR_NULL(node->full_name);
|
||||
|
||||
/* target root has been set */
|
||||
CU_ASSERT_PTR_EQUAL(t.root, node);
|
||||
CU_ASSERT_PTR_EQUAL(node->target, &t);
|
||||
|
||||
CU_ASSERT_PTR_NULL(node->parent);
|
||||
CU_ASSERT_EQUAL(node->attrib.st_mode, root->attrib.st_mode);
|
||||
CU_ASSERT_EQUAL(node->attrib.st_uid, root->attrib.st_uid);
|
||||
CU_ASSERT_EQUAL(node->attrib.st_gid, root->attrib.st_gid);
|
||||
|
||||
/* the node is a directory */
|
||||
CU_ASSERT_EQUAL(node->type, ECMA119_DIR);
|
||||
|
||||
CU_ASSERT_EQUAL(node->info.dir.nchildren, 0);
|
||||
|
||||
|
||||
iso_tree_free((struct iso_tree_node *)root);
|
||||
ecma119_tree_free(node);
|
||||
}
|
||||
|
||||
void add_ecma119_tree_suite()
|
||||
{
|
||||
CU_pSuite pSuite = CU_add_suite("Ecma119TreeSuite", NULL, NULL);
|
||||
|
||||
CU_add_test(pSuite, "test of ecma119_tree_create() with only root dir", test_create_tree_only_root);
|
||||
//CU_add_test(pSuite, "test of create_dir()", test_create_dir);
|
||||
}
|
33
libisofs/attic/test/test_exclude.c
Normal file
33
libisofs/attic/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);
|
||||
}
|
314
libisofs/attic/test/test_file_hashtable.c
Normal file
314
libisofs/attic/test/test_file_hashtable.c
Normal file
@ -0,0 +1,314 @@
|
||||
/*
|
||||
* 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->loc.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->loc.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->loc.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->loc.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->loc.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->loc.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->loc.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->loc.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->loc.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);
|
||||
}
|
||||
|
||||
static void test_prev_img_files()
|
||||
{
|
||||
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.procedence = LIBISO_PREVIMG;
|
||||
file1->node.attrib.st_dev = 0;
|
||||
file1->node.attrib.st_ino = 204;
|
||||
file1->loc.block = 567;
|
||||
|
||||
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.procedence = LIBISO_PREVIMG;
|
||||
file2->node.attrib.st_dev = 0;
|
||||
file2->node.attrib.st_ino = 204;
|
||||
file2->loc.block = 567;
|
||||
iso2 = iso_file_new(file2);
|
||||
|
||||
/* ensure is not added */
|
||||
r = iso_file_table_add_file(table, iso2);
|
||||
CU_ASSERT_EQUAL(r, 0);
|
||||
|
||||
iso3 = iso_file_table_lookup(table, file2);
|
||||
CU_ASSERT_PTR_EQUAL(iso3, iso1);
|
||||
|
||||
/* and now a file added new */
|
||||
file3 = calloc(1, sizeof(struct iso_tree_node_file) );
|
||||
file3->node.name = "different file";
|
||||
file3->node.attrib.st_dev = 0;
|
||||
file3->node.attrib.st_ino = 204;
|
||||
file3->loc.path = "/tmp/filename";
|
||||
iso3 = iso_file_new(file3);
|
||||
|
||||
/* assert it's added */
|
||||
r = iso_file_table_add_file(table, iso3);
|
||||
CU_ASSERT_EQUAL(r, 1);
|
||||
iso1 = iso_file_table_lookup(table, file3);
|
||||
CU_ASSERT_PTR_EQUAL(iso1, iso3);
|
||||
|
||||
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, "iso_file_new()", test_iso_file_new);
|
||||
CU_add_test(pSuite, "add and lookup", test_add_lookup);
|
||||
CU_add_test(pSuite, "with cache_inodes", test_cache_inodes);
|
||||
CU_add_test(pSuite, "with files from previous img", test_prev_img_files);
|
||||
}
|
57
libisofs/attic/test/test_read.c
Normal file
57
libisofs/attic/test/test_read.c
Normal file
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Unit test iso reading functions
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "test.h"
|
||||
#include "ecma119_read_rr.h"
|
||||
#include "util.h"
|
||||
|
||||
static void
|
||||
test_read_rr_PX()
|
||||
{
|
||||
struct iso_read_info info;
|
||||
struct susp_sys_user_entry px;
|
||||
struct stat atts;
|
||||
int res;
|
||||
|
||||
info.src = NULL; /* data source is not needed */
|
||||
info.error = 0;
|
||||
info.ino = 0;
|
||||
|
||||
memset(&atts, 0, sizeof(atts));
|
||||
|
||||
/* fill px struct */
|
||||
px.sig[0] = 'P';
|
||||
px.sig[1] = 'X';
|
||||
px.version[0] = 1;
|
||||
iso_bb(px.data.PX.uid, 33, 4);
|
||||
iso_bb(px.data.PX.gid, 22, 4);
|
||||
iso_bb(px.data.PX.links, 7, 4);
|
||||
iso_bb(px.data.PX.mode, S_IFREG | 0555, 4);
|
||||
|
||||
/* a) test with RRIP 1.12 */
|
||||
info.rr = RR_EXT_112;
|
||||
px.len_sue[0] = 44;
|
||||
iso_bb(px.data.PX.serial, 678, 4);
|
||||
|
||||
res = read_rr_PX(&info, &px, &atts);
|
||||
CU_ASSERT_EQUAL(res, 0);
|
||||
CU_ASSERT_EQUAL(atts.st_uid, 33);
|
||||
CU_ASSERT_EQUAL(atts.st_gid, 22);
|
||||
CU_ASSERT_EQUAL(atts.st_mode, (mode_t) S_IFREG | 0555);
|
||||
CU_ASSERT_EQUAL(atts.st_nlink, 7);
|
||||
CU_ASSERT_EQUAL(atts.st_ino, 678);
|
||||
//TODO
|
||||
|
||||
}
|
||||
|
||||
void add_isoread_suite()
|
||||
{
|
||||
CU_pSuite pSuite = CU_add_suite("IsoReadSuite", NULL, NULL);
|
||||
|
||||
CU_add_test(pSuite, "test of read_rr_PX()", test_read_rr_PX);
|
||||
}
|
1051
libisofs/attic/test/test_tree.c
Normal file
1051
libisofs/attic/test/test_tree.c
Normal file
File diff suppressed because it is too large
Load Diff
387
libisofs/attic/test/test_util.c
Normal file
387
libisofs/attic/test/test_util.c
Normal file
@ -0,0 +1,387 @@
|
||||
/*
|
||||
* Unit test for util.h
|
||||
*
|
||||
* This test utiliy functions
|
||||
*
|
||||
*/
|
||||
#include <time.h>
|
||||
#include <locale.h>
|
||||
|
||||
#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_read_lsb_msb()
|
||||
{
|
||||
uint8_t buf[4];
|
||||
uint32_t num;
|
||||
|
||||
buf[0] = 0x04;
|
||||
buf[1] = 0x03;
|
||||
buf[2] = 0x02;
|
||||
buf[3] = 0x01;
|
||||
|
||||
num = iso_read_lsb(buf, 4);
|
||||
CU_ASSERT_EQUAL(num, 0x01020304);
|
||||
|
||||
num = iso_read_msb(buf, 4);
|
||||
CU_ASSERT_EQUAL(num, 0x04030201);
|
||||
|
||||
num = iso_read_lsb(buf, 2);
|
||||
CU_ASSERT_EQUAL(num, 0x0304);
|
||||
|
||||
num = iso_read_msb(buf, 2);
|
||||
CU_ASSERT_EQUAL(num, 0x0403);
|
||||
}
|
||||
|
||||
static void test_iso_bb()
|
||||
{
|
||||
uint8_t buf[8];
|
||||
uint32_t num;
|
||||
|
||||
num = 0x01020304;
|
||||
iso_bb(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 );
|
||||
CU_ASSERT_EQUAL( buf[4], 0x01 );
|
||||
CU_ASSERT_EQUAL( buf[5], 0x02 );
|
||||
CU_ASSERT_EQUAL( buf[6], 0x03 );
|
||||
CU_ASSERT_EQUAL( buf[7], 0x04 );
|
||||
|
||||
iso_bb(buf, num, 2);
|
||||
CU_ASSERT_EQUAL( buf[0], 0x04 );
|
||||
CU_ASSERT_EQUAL( buf[1], 0x03 );
|
||||
CU_ASSERT_EQUAL( buf[2], 0x03 );
|
||||
CU_ASSERT_EQUAL( buf[3], 0x04 );
|
||||
}
|
||||
|
||||
static void test_iso_read_bb()
|
||||
{
|
||||
uint8_t buf[8];
|
||||
uint32_t num;
|
||||
int error = 0;
|
||||
|
||||
buf[0] = 0x04;
|
||||
buf[1] = 0x03;
|
||||
buf[2] = 0x02;
|
||||
buf[3] = 0x01;
|
||||
buf[4] = 0x01;
|
||||
buf[5] = 0x02;
|
||||
buf[6] = 0x03;
|
||||
buf[7] = 0x04;
|
||||
|
||||
num = iso_read_bb(buf, 4, &error);
|
||||
CU_ASSERT_EQUAL( num, 0x01020304 );
|
||||
CU_ASSERT_FALSE(error);
|
||||
|
||||
num = iso_read_bb(buf, 4, NULL);
|
||||
CU_ASSERT_EQUAL( num, 0x01020304 );
|
||||
|
||||
buf[2] = 3;
|
||||
num = iso_read_bb(buf, 4, &error);
|
||||
/* return the LSB */
|
||||
CU_ASSERT_EQUAL( num, 0x01030304 );
|
||||
CU_ASSERT_TRUE(error);
|
||||
|
||||
num = iso_read_bb(buf, 4, NULL);
|
||||
/* return the LSB */
|
||||
CU_ASSERT_EQUAL( num, 0x01030304 );
|
||||
|
||||
error = 0;
|
||||
buf[3] = 0x04;
|
||||
|
||||
num = iso_read_bb(buf, 2, &error);
|
||||
CU_ASSERT_EQUAL( num, 0x0304 );
|
||||
CU_ASSERT_FALSE(error);
|
||||
|
||||
num = iso_read_bb(buf, 2, NULL);
|
||||
CU_ASSERT_EQUAL( num, 0x0304 );
|
||||
}
|
||||
|
||||
static void test_iso_datetime_7()
|
||||
{
|
||||
uint8_t buf[7];
|
||||
time_t t, t2;
|
||||
struct tm tp;
|
||||
|
||||
strptime("01-03-1976 13:27:45", "%d-%m-%Y %T", &tp);
|
||||
t = mktime(&tp);
|
||||
|
||||
iso_datetime_7(buf, t);
|
||||
CU_ASSERT_EQUAL( buf[0], 76 ); /* year since 1900 */
|
||||
CU_ASSERT_EQUAL( buf[1], 3 ); /* month */
|
||||
CU_ASSERT_EQUAL( buf[2], 1 ); /* day */
|
||||
CU_ASSERT_EQUAL( buf[3], 13 ); /* hour */
|
||||
CU_ASSERT_EQUAL( buf[4], 27 ); /* minute */
|
||||
CU_ASSERT_EQUAL( buf[5], 45 ); /* second */
|
||||
/* the offset depends on current timezone and it's not easy to test */
|
||||
//CU_ASSERT_EQUAL( buf[6], 4 ); /* 15 min offset */
|
||||
|
||||
/* check that reading returns the same time */
|
||||
t2 = iso_datetime_read_7(buf);
|
||||
CU_ASSERT_EQUAL(t2, t);
|
||||
|
||||
//TODO check with differnt timezones for reading and writting
|
||||
|
||||
}
|
||||
|
||||
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, "div_up()", test_div_up);
|
||||
CU_add_test(pSuite, "round_up()", test_round_up);
|
||||
CU_add_test(pSuite, "iso_lsb() and iso_msb()", test_iso_lsb_msb);
|
||||
CU_add_test(pSuite, "iso_read_lsb() and iso_read_msb()", test_iso_read_lsb_msb);
|
||||
CU_add_test(pSuite, "iso_bb()", test_iso_bb);
|
||||
CU_add_test(pSuite, "iso_read_bb()", test_iso_read_bb);
|
||||
CU_add_test(pSuite, "iso_datetime_7()", test_iso_datetime_7);
|
||||
CU_add_test(pSuite, "iso_1_dirid()", test_iso_1_dirid);
|
||||
CU_add_test(pSuite, "iso_2_dirid()", test_iso_2_dirid);
|
||||
CU_add_test(pSuite, "iso_r_dirid()", test_iso_r_dirid);
|
||||
CU_add_test(pSuite, "iso_1_fileid()", test_iso_1_fileid);
|
||||
CU_add_test(pSuite, "iso_2_fileid()", test_iso_2_fileid);
|
||||
CU_add_test(pSuite, "iso_r_fileid()", test_iso_r_fileid);
|
||||
}
|
375
libisofs/attic/test/test_volume.c
Normal file
375
libisofs/attic/test/test_volume.c
Normal file
@ -0,0 +1,375 @@
|
||||
/*
|
||||
* 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_get_volume_id()
|
||||
{
|
||||
struct iso_volume *volume;
|
||||
|
||||
volume = iso_volume_new("volume_id", "publisher_id", "data_preparer_id");
|
||||
CU_ASSERT_STRING_EQUAL( iso_volume_get_volume_id(volume), "volume_id" );
|
||||
|
||||
char *volid = "new volume id";
|
||||
iso_volume_set_volume_id(volume, volid);
|
||||
CU_ASSERT_STRING_EQUAL( iso_volume_get_volume_id(volume), "new volume id" );
|
||||
|
||||
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_get_publisher_id()
|
||||
{
|
||||
struct iso_volume *volume;
|
||||
|
||||
volume = iso_volume_new("volume_id", "publisher_id", "data_preparer_id");
|
||||
CU_ASSERT_STRING_EQUAL( iso_volume_get_publisher_id(volume), "publisher_id" );
|
||||
|
||||
char *pubid = "new publisher id";
|
||||
iso_volume_set_publisher_id(volume, pubid);
|
||||
CU_ASSERT_STRING_EQUAL( iso_volume_get_publisher_id(volume), "new publisher id" );
|
||||
|
||||
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_get_data_preparer_id()
|
||||
{
|
||||
struct iso_volume *volume;
|
||||
|
||||
volume = iso_volume_new("volume_id", "publisher_id", "data_preparer_id");
|
||||
CU_ASSERT_STRING_EQUAL( iso_volume_get_data_preparer_id(volume), "data_preparer_id" );
|
||||
|
||||
char *dpid = "new data preparer id";
|
||||
iso_volume_set_data_preparer_id(volume, dpid);
|
||||
CU_ASSERT_STRING_EQUAL( iso_volume_get_data_preparer_id(volume), "new data preparer id" );
|
||||
|
||||
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_get_system_id()
|
||||
{
|
||||
struct iso_volume *volume;
|
||||
|
||||
volume = iso_volume_new("volume_id", "publisher_id", "data_preparer_id");
|
||||
CU_ASSERT_PTR_NULL(iso_volume_get_system_id(volume));
|
||||
|
||||
char *sysid = "new system id";
|
||||
iso_volume_set_system_id(volume, sysid);
|
||||
CU_ASSERT_STRING_EQUAL( iso_volume_get_system_id(volume), "new system id" );
|
||||
|
||||
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_get_application_id()
|
||||
{
|
||||
struct iso_volume *volume;
|
||||
|
||||
volume = iso_volume_new("volume_id", "publisher_id", "data_preparer_id");
|
||||
CU_ASSERT_PTR_NULL(iso_volume_get_application_id(volume));
|
||||
|
||||
char *appid = "new application id";
|
||||
iso_volume_set_application_id(volume, appid);
|
||||
CU_ASSERT_STRING_EQUAL( iso_volume_get_application_id(volume), "new application id" );
|
||||
|
||||
iso_volume_free(volume);
|
||||
}
|
||||
|
||||
static void test_iso_volume_set_copyright_file_id()
|
||||
{
|
||||
struct iso_volume *volume;
|
||||
|
||||
volume = iso_volume_new("volume_id", "publisher_id", "data_preparer_id");
|
||||
CU_ASSERT_PTR_NULL(volume->copyright_file_id);
|
||||
|
||||
char *copid = "new copyright id";
|
||||
iso_volume_set_copyright_file_id(volume, copid);
|
||||
CU_ASSERT_STRING_EQUAL( volume->copyright_file_id, "new copyright id" );
|
||||
|
||||
/* check string was strdup'ed */
|
||||
CU_ASSERT_PTR_NOT_EQUAL( volume->copyright_file_id, copid );
|
||||
iso_volume_free(volume);
|
||||
}
|
||||
|
||||
static void test_iso_volume_get_copyright_file_id()
|
||||
{
|
||||
struct iso_volume *volume;
|
||||
|
||||
volume = iso_volume_new("volume_id", "publisher_id", "data_preparer_id");
|
||||
CU_ASSERT_PTR_NULL(iso_volume_get_copyright_file_id(volume));
|
||||
|
||||
char *copid = "new copyright id";
|
||||
iso_volume_set_copyright_file_id(volume, copid);
|
||||
CU_ASSERT_STRING_EQUAL( iso_volume_get_copyright_file_id(volume), "new copyright id" );
|
||||
|
||||
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_get_abstract_file_id()
|
||||
{
|
||||
struct iso_volume *volume;
|
||||
|
||||
volume = iso_volume_new("volume_id", "publisher_id", "data_preparer_id");
|
||||
CU_ASSERT_PTR_NULL(iso_volume_get_abstract_file_id(volume));
|
||||
|
||||
char *absid = "new abstract id";
|
||||
iso_volume_set_abstract_file_id(volume, absid);
|
||||
CU_ASSERT_STRING_EQUAL(iso_volume_get_abstract_file_id(volume), "new abstract id");
|
||||
|
||||
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_volume_get_biblio_file_id()
|
||||
{
|
||||
struct iso_volume *volume;
|
||||
|
||||
volume = iso_volume_new("volume_id", "publisher_id", "data_preparer_id");
|
||||
CU_ASSERT_PTR_NULL(iso_volume_get_biblio_file_id(volume));
|
||||
|
||||
char *bibid = "new biblio id";
|
||||
iso_volume_set_biblio_file_id(volume, bibid);
|
||||
CU_ASSERT_STRING_EQUAL(iso_volume_get_biblio_file_id(volume), "new biblio id");
|
||||
|
||||
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_get_volume_id()", test_iso_volume_get_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_get_publisher_id()", test_iso_volume_get_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_get_data_preparer_id()", test_iso_volume_get_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_get_system_id()", test_iso_volume_get_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_get_application_id()", test_iso_volume_get_application_id);
|
||||
CU_add_test(pSuite, "test of iso_volume_set_copyright_file_id()", test_iso_volume_set_copyright_file_id);
|
||||
CU_add_test(pSuite, "test of iso_volume_get_copyright_file_id()", test_iso_volume_get_copyright_file_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_get_abstract_file_id()", test_iso_volume_get_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_volume_get_biblio_file_id()", test_iso_volume_get_biblio_file_id);
|
||||
CU_add_test(pSuite, "test of iso_volset_new()", test_iso_volset_new);
|
||||
}
|
77
libisofs/attic/test/tree.py
Normal file
77
libisofs/attic/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