Added tests as part of MS patch
This commit is contained in:
parent
3ea44305b4
commit
170dfe21bf
145
test/iso_add.c
Normal file
145
test/iso_add.c
Normal file
@ -0,0 +1,145 @@
|
||||
/* -*- 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;
|
||||
}
|
||||
|
||||
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;
|
||||
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);
|
||||
|
||||
return 0;
|
||||
}
|
147
test/iso_ms.c
Normal file
147
test/iso_ms.c
Normal file
@ -0,0 +1,147 @@
|
||||
/* -*- 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;
|
||||
}
|
||||
|
||||
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;
|
||||
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);
|
||||
|
||||
return 0;
|
||||
}
|
124
test/iso_read.c
Normal file
124
test/iso_read.c
Normal file
@ -0,0 +1,124 @@
|
||||
/*
|
||||
* 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) );
|
||||
}
|
||||
}
|
||||
iso_tree_iter_free(iter);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
src = data_source_from_file(argv[1]);
|
||||
if (src == NULL) {
|
||||
printf ("Can't open image\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
opts.block = 0;
|
||||
opts.norock = 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));
|
||||
|
||||
printf("\nDIRECTORY TREE\n");
|
||||
printf("==============\n");
|
||||
|
||||
print_dir(iso_volume_get_root(volume), 0);
|
||||
|
||||
printf("\n\n");
|
||||
|
||||
data_source_free(src);
|
||||
iso_volset_free(volset);
|
||||
|
||||
return 0;
|
||||
}
|
75
test/test_data_source.c
Normal file
75
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);
|
||||
}
|
57
test/test_read.c
Normal file
57
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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user