Effective base of libisoburn+xorriso 0.1.1 2008.02.22.124732
This commit is contained in:
378
test/mocked_fsrc.c
Normal file
378
test/mocked_fsrc.c
Normal file
@ -0,0 +1,378 @@
|
||||
/*
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include "fsource.h"
|
||||
#include "mocked_fsrc.h"
|
||||
#include "libisofs.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <libgen.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
static
|
||||
struct mock_file *path_to_node(IsoFilesystem *fs, const char *path);
|
||||
|
||||
static
|
||||
char *get_path_aux(struct mock_file *file)
|
||||
{
|
||||
if (file->parent == NULL) {
|
||||
return strdup("");
|
||||
} else {
|
||||
char *path = get_path_aux(file->parent);
|
||||
int pathlen = strlen(path);
|
||||
path = realloc(path, pathlen + strlen(file->name) + 2);
|
||||
path[pathlen] = '/';
|
||||
path[pathlen + 1] = '\0';
|
||||
return strcat(path, file->name);
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
char* mfs_get_path(IsoFileSource *src)
|
||||
{
|
||||
struct mock_file *data;
|
||||
data = src->data;
|
||||
return get_path_aux(data);
|
||||
}
|
||||
|
||||
static
|
||||
char* mfs_get_name(IsoFileSource *src)
|
||||
{
|
||||
struct mock_file *data;
|
||||
data = src->data;
|
||||
return strdup(data->name);
|
||||
}
|
||||
|
||||
static
|
||||
int mfs_lstat(IsoFileSource *src, struct stat *info)
|
||||
{
|
||||
struct mock_file *data;
|
||||
|
||||
if (src == NULL || info == NULL) {
|
||||
return ISO_NULL_POINTER;
|
||||
}
|
||||
data = src->data;
|
||||
|
||||
*info = data->atts;
|
||||
return ISO_SUCCESS;
|
||||
}
|
||||
|
||||
static
|
||||
int mfs_stat(IsoFileSource *src, struct stat *info)
|
||||
{
|
||||
struct mock_file *node;
|
||||
if (src == NULL || info == NULL) {
|
||||
return ISO_NULL_POINTER;
|
||||
}
|
||||
node = src->data;
|
||||
|
||||
while ( S_ISLNK(node->atts.st_mode) ) {
|
||||
/* the destination is stated */
|
||||
node = path_to_node(node->fs, (char *)node->content);
|
||||
if (node == NULL) {
|
||||
return ISO_FILE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
*info = node->atts;
|
||||
return ISO_SUCCESS;
|
||||
}
|
||||
|
||||
static
|
||||
int mfs_access(IsoFileSource *src)
|
||||
{
|
||||
// TODO not implemented
|
||||
return ISO_ERROR;
|
||||
}
|
||||
|
||||
static
|
||||
int mfs_open(IsoFileSource *src)
|
||||
{
|
||||
// TODO not implemented
|
||||
return ISO_ERROR;
|
||||
}
|
||||
|
||||
static
|
||||
int mfs_close(IsoFileSource *src)
|
||||
{
|
||||
// TODO not implemented
|
||||
return ISO_ERROR;
|
||||
}
|
||||
|
||||
static
|
||||
int mfs_read(IsoFileSource *src, void *buf, size_t count)
|
||||
{
|
||||
// TODO not implemented
|
||||
return ISO_ERROR;
|
||||
}
|
||||
|
||||
static
|
||||
int mfs_readdir(IsoFileSource *src, IsoFileSource **child)
|
||||
{
|
||||
// TODO not implemented
|
||||
return ISO_ERROR;
|
||||
}
|
||||
|
||||
static
|
||||
int mfs_readlink(IsoFileSource *src, char *buf, size_t bufsiz)
|
||||
{
|
||||
struct mock_file *data;
|
||||
|
||||
if (src == NULL || buf == NULL) {
|
||||
return ISO_NULL_POINTER;
|
||||
}
|
||||
|
||||
if (bufsiz <= 0) {
|
||||
return ISO_WRONG_ARG_VALUE;
|
||||
}
|
||||
data = src->data;
|
||||
|
||||
if (!S_ISLNK(data->atts.st_mode)) {
|
||||
return ISO_FILE_IS_NOT_SYMLINK;
|
||||
}
|
||||
strncpy(buf, data->content, bufsiz);
|
||||
buf[bufsiz-1] = '\0';
|
||||
return ISO_SUCCESS;
|
||||
}
|
||||
|
||||
static
|
||||
IsoFilesystem* mfs_get_filesystem(IsoFileSource *src)
|
||||
{
|
||||
struct mock_file *data;
|
||||
data = src->data;
|
||||
return data->fs;
|
||||
}
|
||||
|
||||
static
|
||||
void mfs_free(IsoFileSource *src)
|
||||
{
|
||||
/* nothing to do */
|
||||
}
|
||||
|
||||
IsoFileSourceIface mfs_class = {
|
||||
0,
|
||||
mfs_get_path,
|
||||
mfs_get_name,
|
||||
mfs_lstat,
|
||||
mfs_stat,
|
||||
mfs_access,
|
||||
mfs_open,
|
||||
mfs_close,
|
||||
mfs_read,
|
||||
mfs_readdir,
|
||||
mfs_readlink,
|
||||
mfs_get_filesystem,
|
||||
mfs_free
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
* 1 success, < 0 error
|
||||
*/
|
||||
static
|
||||
int mocked_file_source_new(struct mock_file *data, IsoFileSource **src)
|
||||
{
|
||||
IsoFileSource *mocked_src;
|
||||
|
||||
if (src == NULL || data == NULL) {
|
||||
return ISO_NULL_POINTER;
|
||||
}
|
||||
|
||||
/* allocate memory */
|
||||
mocked_src = malloc(sizeof(IsoFileSource));
|
||||
if (mocked_src == NULL) {
|
||||
free(data);
|
||||
return ISO_OUT_OF_MEM;
|
||||
}
|
||||
|
||||
/* fill struct */
|
||||
mocked_src->refcount = 1;
|
||||
mocked_src->data = data;
|
||||
mocked_src->class = &mfs_class;
|
||||
|
||||
/* take a ref to filesystem */
|
||||
//iso_filesystem_ref(fs);
|
||||
|
||||
/* return */
|
||||
*src = mocked_src;
|
||||
return ISO_SUCCESS;
|
||||
}
|
||||
|
||||
static
|
||||
struct mock_file *path_to_node(IsoFilesystem *fs, const char *path)
|
||||
{
|
||||
struct mock_file *node;
|
||||
struct mock_file *dir;
|
||||
char *ptr, *brk_info, *component;
|
||||
|
||||
/* get the first child at the root of the volume
|
||||
* that is "/" */
|
||||
dir = fs->data;
|
||||
node = dir;
|
||||
if (!strcmp(path, "/"))
|
||||
return node;
|
||||
|
||||
ptr = strdup(path);
|
||||
|
||||
/* get the first component of the path */
|
||||
component = strtok_r(ptr, "/", &brk_info);
|
||||
while (component) {
|
||||
size_t i;
|
||||
|
||||
if ( !S_ISDIR(node->atts.st_mode) ) {
|
||||
node=NULL;
|
||||
break;
|
||||
}
|
||||
dir = node;
|
||||
|
||||
node=NULL;
|
||||
if (!dir->content) {
|
||||
break;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
while (((struct mock_file**)dir->content)[i]) {
|
||||
if (!strcmp(component, ((struct mock_file**)dir->content)[i]->name)) {
|
||||
node = ((struct mock_file**)dir->content)[i];
|
||||
break;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
|
||||
/* see if a node could be found */
|
||||
if (node==NULL) {
|
||||
break;
|
||||
}
|
||||
component = strtok_r(NULL, "/", &brk_info);
|
||||
}
|
||||
free(ptr);
|
||||
return node;
|
||||
}
|
||||
|
||||
static
|
||||
void add_node(struct mock_file *parent, struct mock_file *node)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
if (parent->content) {
|
||||
while (((struct mock_file**)parent->content)[i]) {
|
||||
++i;
|
||||
}
|
||||
}
|
||||
parent->content = realloc(parent->content, (i+2) * sizeof(void*));
|
||||
((struct mock_file**)parent->content)[i] = node;
|
||||
((struct mock_file**)parent->content)[i+1] = NULL;
|
||||
}
|
||||
|
||||
struct mock_file *test_mocked_fs_get_root(IsoFilesystem *fs)
|
||||
{
|
||||
return fs->data;
|
||||
}
|
||||
|
||||
int test_mocked_fs_add_dir(const char *name, struct mock_file *p,
|
||||
struct stat atts, struct mock_file **node)
|
||||
{
|
||||
struct mock_file *dir = calloc(1, sizeof(struct mock_file));
|
||||
dir->fs = p->fs;
|
||||
dir->atts = atts;
|
||||
dir->name = strdup(name);
|
||||
dir->parent = p;
|
||||
add_node(p, dir);
|
||||
|
||||
*node = dir;
|
||||
return ISO_SUCCESS;
|
||||
}
|
||||
|
||||
int test_mocked_fs_add_symlink(const char *name, struct mock_file *p,
|
||||
struct stat atts, const char *dest, struct mock_file **node)
|
||||
{
|
||||
struct mock_file *link = calloc(1, sizeof(struct mock_file));
|
||||
link->fs = p->fs;
|
||||
link->atts = atts;
|
||||
link->name = strdup(name);
|
||||
link->parent = p;
|
||||
add_node(p, link);
|
||||
link->content = strdup(dest);
|
||||
*node = link;
|
||||
return ISO_SUCCESS;
|
||||
}
|
||||
|
||||
static
|
||||
int mocked_get_root(IsoFilesystem *fs, IsoFileSource **root)
|
||||
{
|
||||
if (fs == NULL || root == NULL) {
|
||||
return ISO_NULL_POINTER;
|
||||
}
|
||||
return mocked_file_source_new(fs->data, root);
|
||||
}
|
||||
|
||||
static
|
||||
int mocked_get_by_path(IsoFilesystem *fs, const char *path, IsoFileSource **file)
|
||||
{
|
||||
struct mock_file *f;
|
||||
if (fs == NULL || path == NULL || file == NULL) {
|
||||
return ISO_NULL_POINTER;
|
||||
}
|
||||
f = path_to_node(fs, path);
|
||||
return mocked_file_source_new(f, file);
|
||||
}
|
||||
|
||||
static
|
||||
void free_mocked_file(struct mock_file *file)
|
||||
{
|
||||
if (S_ISDIR(file->atts.st_mode)) {
|
||||
if (file->content) {
|
||||
int i = 0;
|
||||
while (((struct mock_file**)file->content)[i]) {
|
||||
free_mocked_file(((struct mock_file**)file->content)[i]);
|
||||
++i;
|
||||
}
|
||||
}
|
||||
}
|
||||
free(file->content);
|
||||
free(file->name);
|
||||
free(file);
|
||||
}
|
||||
|
||||
static
|
||||
void mocked_fs_free(IsoFilesystem *fs)
|
||||
{
|
||||
free_mocked_file((struct mock_file *)fs->data);
|
||||
}
|
||||
|
||||
int test_mocked_filesystem_new(IsoFilesystem **fs)
|
||||
{
|
||||
struct mock_file *root;
|
||||
IsoFilesystem *filesystem;
|
||||
|
||||
if (fs == NULL) {
|
||||
return ISO_NULL_POINTER;
|
||||
}
|
||||
|
||||
root = calloc(1, sizeof(struct mock_file));
|
||||
root->atts.st_atime = time(NULL);
|
||||
root->atts.st_ctime = time(NULL);
|
||||
root->atts.st_mtime = time(NULL);
|
||||
root->atts.st_uid = 0;
|
||||
root->atts.st_gid = 0;
|
||||
root->atts.st_mode = S_IFDIR | 0777;
|
||||
|
||||
filesystem = malloc(sizeof(IsoFilesystem));
|
||||
filesystem->refcount = 1;
|
||||
root->fs = filesystem;
|
||||
filesystem->data = root;
|
||||
filesystem->get_root = mocked_get_root;
|
||||
filesystem->get_by_path = mocked_get_by_path;
|
||||
filesystem->free = mocked_fs_free;
|
||||
*fs = filesystem;
|
||||
return ISO_SUCCESS;
|
||||
}
|
||||
|
31
test/mocked_fsrc.h
Normal file
31
test/mocked_fsrc.h
Normal file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Mocked objects to simulate an input filesystem.
|
||||
*/
|
||||
|
||||
#ifndef MOCKED_FSRC_H_
|
||||
#define MOCKED_FSRC_H_
|
||||
|
||||
struct mock_file {
|
||||
IsoFilesystem *fs;
|
||||
struct mock_file *parent;
|
||||
struct stat atts;
|
||||
char *name;
|
||||
|
||||
/* for links, link dest. For dirs, children */
|
||||
void *content;
|
||||
};
|
||||
|
||||
/**
|
||||
* A mocked fs.
|
||||
*/
|
||||
int test_mocked_filesystem_new(IsoFilesystem **fs);
|
||||
|
||||
struct mock_file *test_mocked_fs_get_root(IsoFilesystem *fs);
|
||||
|
||||
int test_mocked_fs_add_dir(const char *name, struct mock_file *parent,
|
||||
struct stat atts, struct mock_file **dir);
|
||||
|
||||
int test_mocked_fs_add_symlink(const char *name, struct mock_file *p,
|
||||
struct stat atts, const char *dest, struct mock_file **node);
|
||||
|
||||
#endif /*MOCKED_FSRC_H_*/
|
26
test/test.c
Normal file
26
test/test.c
Normal file
@ -0,0 +1,26 @@
|
||||
#include "test.h"
|
||||
|
||||
static void create_test_suite()
|
||||
{
|
||||
add_node_suite();
|
||||
add_image_suite();
|
||||
add_tree_suite();
|
||||
add_util_suite();
|
||||
add_rockridge_suite();
|
||||
add_stream_suite();
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
/* 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();
|
||||
}
|
14
test/test.h
Normal file
14
test/test.h
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef TEST_H_
|
||||
#define TEST_H_
|
||||
|
||||
#include <CUnit/Basic.h>
|
||||
#include "libisofs.h"
|
||||
|
||||
void add_node_suite();
|
||||
void add_image_suite();
|
||||
void add_tree_suite();
|
||||
void add_util_suite();
|
||||
void add_rockridge_suite();
|
||||
void add_stream_suite();
|
||||
|
||||
#endif /*TEST_H_*/
|
354
test/test_image.c
Normal file
354
test/test_image.c
Normal file
@ -0,0 +1,354 @@
|
||||
/*
|
||||
* Unit test for image.h
|
||||
*/
|
||||
|
||||
|
||||
#include "libisofs.h"
|
||||
#include "test.h"
|
||||
#include "image.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_image_new()
|
||||
{
|
||||
int ret;
|
||||
IsoImage *image;
|
||||
|
||||
ret = iso_image_new("volume_id", &image);
|
||||
CU_ASSERT_EQUAL(ret, 1);
|
||||
CU_ASSERT_PTR_NOT_NULL(image);
|
||||
CU_ASSERT_EQUAL(image->refcount, 1);
|
||||
CU_ASSERT_PTR_NOT_NULL(image->root);
|
||||
|
||||
CU_ASSERT_STRING_EQUAL(image->volume_id, "volume_id");
|
||||
CU_ASSERT_STRING_EQUAL(image->volset_id, "volume_id");
|
||||
|
||||
CU_ASSERT_PTR_NULL(image->publisher_id);
|
||||
CU_ASSERT_PTR_NULL(image->data_preparer_id);
|
||||
CU_ASSERT_PTR_NULL(image->system_id);
|
||||
CU_ASSERT_PTR_NULL(image->application_id);
|
||||
CU_ASSERT_PTR_NULL(image->copyright_file_id);
|
||||
CU_ASSERT_PTR_NULL(image->abstract_file_id);
|
||||
CU_ASSERT_PTR_NULL(image->biblio_file_id);
|
||||
|
||||
//CU_ASSERT_PTR_NULL(image->bootcat);
|
||||
|
||||
iso_image_unref(image);
|
||||
}
|
||||
|
||||
static void test_iso_image_set_volume_id()
|
||||
{
|
||||
int ret;
|
||||
IsoImage *image;
|
||||
char *volid;
|
||||
|
||||
ret = iso_image_new("volume_id", &image);
|
||||
CU_ASSERT_EQUAL(ret, 1);
|
||||
CU_ASSERT_STRING_EQUAL(image->volume_id, "volume_id");
|
||||
|
||||
volid = "new volume id";
|
||||
iso_image_set_volume_id(image, volid);
|
||||
CU_ASSERT_STRING_EQUAL(image->volume_id, "new volume id");
|
||||
|
||||
/* check string was strdup'ed */
|
||||
CU_ASSERT_PTR_NOT_EQUAL(image->volume_id, volid);
|
||||
iso_image_unref(image);
|
||||
}
|
||||
|
||||
static void test_iso_image_get_volume_id()
|
||||
{
|
||||
int ret;
|
||||
IsoImage *image;
|
||||
char *volid;
|
||||
|
||||
ret = iso_image_new("volume_id", &image);
|
||||
CU_ASSERT_EQUAL(ret, 1);
|
||||
CU_ASSERT_STRING_EQUAL(iso_image_get_volume_id(image), "volume_id");
|
||||
|
||||
volid = "new volume id";
|
||||
iso_image_set_volume_id(image, volid);
|
||||
CU_ASSERT_STRING_EQUAL( iso_image_get_volume_id(image), "new volume id" );
|
||||
|
||||
iso_image_unref(image);
|
||||
}
|
||||
|
||||
static void test_iso_image_set_publisher_id()
|
||||
{
|
||||
int ret;
|
||||
IsoImage *image;
|
||||
char *pubid;
|
||||
|
||||
ret = iso_image_new("volume_id", &image);
|
||||
CU_ASSERT_EQUAL(ret, 1);
|
||||
CU_ASSERT_PTR_NULL(image->publisher_id);
|
||||
|
||||
pubid = "new publisher id";
|
||||
iso_image_set_publisher_id(image, pubid);
|
||||
CU_ASSERT_STRING_EQUAL( image->publisher_id, "new publisher id" );
|
||||
|
||||
/* check string was strdup'ed */
|
||||
CU_ASSERT_PTR_NOT_EQUAL( image->publisher_id, pubid );
|
||||
iso_image_unref(image);
|
||||
}
|
||||
|
||||
static void test_iso_image_get_publisher_id()
|
||||
{
|
||||
int ret;
|
||||
IsoImage *image;
|
||||
char *pubid;
|
||||
|
||||
ret = iso_image_new("volume_id", &image);
|
||||
CU_ASSERT_EQUAL(ret, 1);
|
||||
CU_ASSERT_PTR_NULL(image->publisher_id);
|
||||
|
||||
pubid = "new publisher id";
|
||||
iso_image_set_publisher_id(image, pubid);
|
||||
CU_ASSERT_STRING_EQUAL(iso_image_get_publisher_id(image), "new publisher id");
|
||||
|
||||
iso_image_unref(image);
|
||||
}
|
||||
|
||||
static void test_iso_image_set_data_preparer_id()
|
||||
{
|
||||
int ret;
|
||||
IsoImage *image;
|
||||
char *dpid;
|
||||
|
||||
ret = iso_image_new("volume_id", &image);
|
||||
CU_ASSERT_EQUAL(ret, 1);
|
||||
CU_ASSERT_PTR_NULL(image->data_preparer_id);
|
||||
|
||||
dpid = "new data preparer id";
|
||||
iso_image_set_data_preparer_id(image, dpid);
|
||||
CU_ASSERT_STRING_EQUAL(image->data_preparer_id, "new data preparer id");
|
||||
|
||||
/* check string was strdup'ed */
|
||||
CU_ASSERT_PTR_NOT_EQUAL(image->data_preparer_id, dpid);
|
||||
iso_image_unref(image);
|
||||
}
|
||||
|
||||
static void test_iso_image_get_data_preparer_id()
|
||||
{
|
||||
int ret;
|
||||
IsoImage *image;
|
||||
char *dpid;
|
||||
|
||||
ret = iso_image_new("volume_id", &image);
|
||||
CU_ASSERT_EQUAL(ret, 1);
|
||||
CU_ASSERT_PTR_NULL(image->data_preparer_id);
|
||||
|
||||
dpid = "new data preparer id";
|
||||
iso_image_set_data_preparer_id(image, dpid);
|
||||
CU_ASSERT_STRING_EQUAL( iso_image_get_data_preparer_id(image), "new data preparer id" );
|
||||
|
||||
iso_image_unref(image);
|
||||
}
|
||||
|
||||
static void test_iso_image_set_system_id()
|
||||
{
|
||||
int ret;
|
||||
IsoImage *image;
|
||||
char *sysid;
|
||||
|
||||
ret = iso_image_new("volume_id", &image);
|
||||
CU_ASSERT_EQUAL(ret, 1);
|
||||
CU_ASSERT_PTR_NULL(image->system_id);
|
||||
|
||||
sysid = "new system id";
|
||||
iso_image_set_system_id(image, sysid);
|
||||
CU_ASSERT_STRING_EQUAL( image->system_id, "new system id" );
|
||||
|
||||
/* check string was strdup'ed */
|
||||
CU_ASSERT_PTR_NOT_EQUAL( image->system_id, sysid );
|
||||
iso_image_unref(image);
|
||||
}
|
||||
|
||||
static void test_iso_image_get_system_id()
|
||||
{
|
||||
int ret;
|
||||
IsoImage *image;
|
||||
char *sysid;
|
||||
|
||||
ret = iso_image_new("volume_id", &image);
|
||||
CU_ASSERT_EQUAL(ret, 1);
|
||||
CU_ASSERT_PTR_NULL(iso_image_get_system_id(image));
|
||||
|
||||
sysid = "new system id";
|
||||
iso_image_set_system_id(image, sysid);
|
||||
CU_ASSERT_STRING_EQUAL( iso_image_get_system_id(image), "new system id" );
|
||||
|
||||
iso_image_unref(image);
|
||||
}
|
||||
|
||||
static void test_iso_image_set_application_id()
|
||||
{
|
||||
int ret;
|
||||
IsoImage *image;
|
||||
char *appid;
|
||||
|
||||
ret = iso_image_new("volume_id", &image);
|
||||
CU_ASSERT_EQUAL(ret, 1);
|
||||
CU_ASSERT_PTR_NULL(image->application_id);
|
||||
|
||||
appid = "new application id";
|
||||
iso_image_set_application_id(image, appid);
|
||||
CU_ASSERT_STRING_EQUAL( image->application_id, "new application id" );
|
||||
|
||||
/* check string was strdup'ed */
|
||||
CU_ASSERT_PTR_NOT_EQUAL( image->application_id, appid );
|
||||
iso_image_unref(image);
|
||||
}
|
||||
|
||||
static void test_iso_image_get_application_id()
|
||||
{
|
||||
int ret;
|
||||
IsoImage *image;
|
||||
char *appid;
|
||||
|
||||
ret = iso_image_new("volume_id", &image);
|
||||
CU_ASSERT_EQUAL(ret, 1);
|
||||
CU_ASSERT_PTR_NULL(iso_image_get_application_id(image));
|
||||
|
||||
appid = "new application id";
|
||||
iso_image_set_application_id(image, appid);
|
||||
CU_ASSERT_STRING_EQUAL( iso_image_get_application_id(image), "new application id" );
|
||||
|
||||
iso_image_unref(image);
|
||||
}
|
||||
|
||||
static void test_iso_image_set_copyright_file_id()
|
||||
{
|
||||
int ret;
|
||||
IsoImage *image;
|
||||
char *copid;
|
||||
|
||||
ret = iso_image_new("volume_id", &image);
|
||||
CU_ASSERT_EQUAL(ret, 1);
|
||||
CU_ASSERT_PTR_NULL(image->copyright_file_id);
|
||||
|
||||
copid = "new copyright id";
|
||||
iso_image_set_copyright_file_id(image, copid);
|
||||
CU_ASSERT_STRING_EQUAL( image->copyright_file_id, "new copyright id" );
|
||||
|
||||
/* check string was strdup'ed */
|
||||
CU_ASSERT_PTR_NOT_EQUAL( image->copyright_file_id, copid );
|
||||
iso_image_unref(image);
|
||||
}
|
||||
|
||||
static void test_iso_image_get_copyright_file_id()
|
||||
{
|
||||
int ret;
|
||||
IsoImage *image;
|
||||
char *copid;
|
||||
|
||||
ret = iso_image_new("volume_id", &image);
|
||||
CU_ASSERT_EQUAL(ret, 1);
|
||||
CU_ASSERT_PTR_NULL(iso_image_get_copyright_file_id(image));
|
||||
|
||||
copid = "new copyright id";
|
||||
iso_image_set_copyright_file_id(image, copid);
|
||||
CU_ASSERT_STRING_EQUAL( iso_image_get_copyright_file_id(image), "new copyright id" );
|
||||
|
||||
iso_image_unref(image);
|
||||
}
|
||||
|
||||
static void test_iso_image_set_abstract_file_id()
|
||||
{
|
||||
int ret;
|
||||
IsoImage *image;
|
||||
char *absid;
|
||||
|
||||
ret = iso_image_new("volume_id", &image);
|
||||
CU_ASSERT_EQUAL(ret, 1);
|
||||
CU_ASSERT_PTR_NULL(image->abstract_file_id);
|
||||
|
||||
absid = "new abstract id";
|
||||
iso_image_set_abstract_file_id(image, absid);
|
||||
CU_ASSERT_STRING_EQUAL( image->abstract_file_id, "new abstract id" );
|
||||
|
||||
/* check string was strdup'ed */
|
||||
CU_ASSERT_PTR_NOT_EQUAL( image->abstract_file_id, absid );
|
||||
iso_image_unref(image);
|
||||
}
|
||||
|
||||
static void test_iso_image_get_abstract_file_id()
|
||||
{
|
||||
int ret;
|
||||
IsoImage *image;
|
||||
char *absid;
|
||||
|
||||
ret = iso_image_new("volume_id", &image);
|
||||
CU_ASSERT_EQUAL(ret, 1);
|
||||
CU_ASSERT_PTR_NULL(iso_image_get_abstract_file_id(image));
|
||||
|
||||
absid = "new abstract id";
|
||||
iso_image_set_abstract_file_id(image, absid);
|
||||
CU_ASSERT_STRING_EQUAL(iso_image_get_abstract_file_id(image), "new abstract id");
|
||||
|
||||
iso_image_unref(image);
|
||||
}
|
||||
|
||||
static void test_iso_image_set_biblio_file_id()
|
||||
{
|
||||
int ret;
|
||||
IsoImage *image;
|
||||
char *bibid;
|
||||
|
||||
ret = iso_image_new("volume_id", &image);
|
||||
CU_ASSERT_EQUAL(ret, 1);
|
||||
CU_ASSERT_PTR_NULL(image->biblio_file_id);
|
||||
|
||||
bibid = "new biblio id";
|
||||
iso_image_set_biblio_file_id(image, bibid);
|
||||
CU_ASSERT_STRING_EQUAL( image->biblio_file_id, "new biblio id" );
|
||||
|
||||
/* check string was strdup'ed */
|
||||
CU_ASSERT_PTR_NOT_EQUAL( image->biblio_file_id, bibid );
|
||||
iso_image_unref(image);
|
||||
}
|
||||
|
||||
static void test_iso_image_get_biblio_file_id()
|
||||
{
|
||||
int ret;
|
||||
IsoImage *image;
|
||||
char *bibid;
|
||||
|
||||
ret = iso_image_new("volume_id", &image);
|
||||
CU_ASSERT_EQUAL(ret, 1);
|
||||
CU_ASSERT_PTR_NULL(iso_image_get_biblio_file_id(image));
|
||||
|
||||
bibid = "new biblio id";
|
||||
iso_image_set_biblio_file_id(image, bibid);
|
||||
CU_ASSERT_STRING_EQUAL(iso_image_get_biblio_file_id(image), "new biblio id");
|
||||
|
||||
iso_image_unref(image);
|
||||
}
|
||||
|
||||
void add_image_suite()
|
||||
{
|
||||
CU_pSuite pSuite = CU_add_suite("imageSuite", NULL, NULL);
|
||||
|
||||
CU_add_test(pSuite, "iso_image_new()", test_iso_image_new);
|
||||
CU_add_test(pSuite, "iso_image_set_volume_id()", test_iso_image_set_volume_id);
|
||||
CU_add_test(pSuite, "iso_image_get_volume_id()", test_iso_image_get_volume_id);
|
||||
CU_add_test(pSuite, "iso_image_set_publisher_id()", test_iso_image_set_publisher_id);
|
||||
CU_add_test(pSuite, "iso_image_get_publisher_id()", test_iso_image_get_publisher_id);
|
||||
CU_add_test(pSuite, "iso_image_set_data_preparer_id()", test_iso_image_set_data_preparer_id);
|
||||
CU_add_test(pSuite, "iso_image_get_data_preparer_id()", test_iso_image_get_data_preparer_id);
|
||||
CU_add_test(pSuite, "iso_image_set_system_id()", test_iso_image_set_system_id);
|
||||
CU_add_test(pSuite, "iso_image_get_system_id()", test_iso_image_get_system_id);
|
||||
CU_add_test(pSuite, "iso_image_set_application_id()", test_iso_image_set_application_id);
|
||||
CU_add_test(pSuite, "iso_image_get_application_id()", test_iso_image_get_application_id);
|
||||
CU_add_test(pSuite, "iso_image_set_copyright_file_id()", test_iso_image_set_copyright_file_id);
|
||||
CU_add_test(pSuite, "iso_image_get_copyright_file_id()", test_iso_image_get_copyright_file_id);
|
||||
CU_add_test(pSuite, "iso_image_set_abstract_file_id()", test_iso_image_set_abstract_file_id);
|
||||
CU_add_test(pSuite, "iso_image_get_abstract_file_id()", test_iso_image_get_abstract_file_id);
|
||||
CU_add_test(pSuite, "iso_image_set_biblio_file_id()", test_iso_image_set_biblio_file_id);
|
||||
CU_add_test(pSuite, "iso_image_get_biblio_file_id()", test_iso_image_get_biblio_file_id);
|
||||
}
|
690
test/test_node.c
Normal file
690
test/test_node.c
Normal file
@ -0,0 +1,690 @@
|
||||
/*
|
||||
* Unit test for node.h
|
||||
*/
|
||||
|
||||
#include "libisofs.h"
|
||||
#include "node.h"
|
||||
#include "test.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
static
|
||||
void test_iso_node_new_root()
|
||||
{
|
||||
int ret;
|
||||
IsoDir *dir;
|
||||
|
||||
ret = iso_node_new_root(&dir);
|
||||
CU_ASSERT_EQUAL(ret, ISO_SUCCESS);
|
||||
|
||||
CU_ASSERT_EQUAL(dir->node.refcount, 1);
|
||||
CU_ASSERT_EQUAL(dir->node.type, LIBISO_DIR);
|
||||
CU_ASSERT_EQUAL(dir->node.mode, S_IFDIR | 0555);
|
||||
CU_ASSERT_EQUAL(dir->node.uid, 0);
|
||||
CU_ASSERT_EQUAL(dir->node.gid, 0);
|
||||
CU_ASSERT_PTR_NULL(dir->node.name);
|
||||
CU_ASSERT_EQUAL(dir->node.hidden, 0);
|
||||
CU_ASSERT_PTR_EQUAL(dir->node.parent, dir);
|
||||
CU_ASSERT_PTR_NULL(dir->node.next);
|
||||
CU_ASSERT_EQUAL(dir->nchildren, 0);
|
||||
CU_ASSERT_PTR_NULL(dir->children);
|
||||
|
||||
iso_node_unref((IsoNode*)dir);
|
||||
}
|
||||
|
||||
static
|
||||
void test_iso_node_new_dir()
|
||||
{
|
||||
int ret;
|
||||
IsoDir *dir;
|
||||
char *name;
|
||||
|
||||
name = strdup("name1");
|
||||
ret = iso_node_new_dir(name, &dir);
|
||||
CU_ASSERT_EQUAL(ret, ISO_SUCCESS);
|
||||
CU_ASSERT_EQUAL(dir->node.refcount, 1);
|
||||
CU_ASSERT_EQUAL(dir->node.type, LIBISO_DIR);
|
||||
CU_ASSERT_EQUAL(dir->node.mode, S_IFDIR);
|
||||
CU_ASSERT_EQUAL(dir->node.uid, 0);
|
||||
CU_ASSERT_EQUAL(dir->node.gid, 0);
|
||||
CU_ASSERT_EQUAL(dir->node.atime, 0);
|
||||
CU_ASSERT_EQUAL(dir->node.mtime, 0);
|
||||
CU_ASSERT_EQUAL(dir->node.ctime, 0);
|
||||
CU_ASSERT_STRING_EQUAL(dir->node.name, "name1");
|
||||
CU_ASSERT_EQUAL(dir->node.hidden, 0);
|
||||
CU_ASSERT_PTR_NULL(dir->node.parent);
|
||||
CU_ASSERT_PTR_NULL(dir->node.next);
|
||||
CU_ASSERT_EQUAL(dir->nchildren, 0);
|
||||
CU_ASSERT_PTR_NULL(dir->children);
|
||||
|
||||
iso_node_unref((IsoNode*)dir);
|
||||
|
||||
/* try with invalid names */
|
||||
ret = iso_node_new_dir("H/DHS/s", &dir);
|
||||
CU_ASSERT_EQUAL(ret, ISO_WRONG_ARG_VALUE);
|
||||
ret = iso_node_new_dir(".", &dir);
|
||||
CU_ASSERT_EQUAL(ret, ISO_WRONG_ARG_VALUE);
|
||||
ret = iso_node_new_dir("..", &dir);
|
||||
CU_ASSERT_EQUAL(ret, ISO_WRONG_ARG_VALUE);
|
||||
ret = iso_node_new_dir(NULL, &dir);
|
||||
CU_ASSERT_EQUAL(ret, ISO_NULL_POINTER);
|
||||
}
|
||||
|
||||
static
|
||||
void test_iso_node_new_symlink()
|
||||
{
|
||||
int ret;
|
||||
IsoSymlink *link;
|
||||
char *name, *dest;
|
||||
|
||||
name = strdup("name1");
|
||||
dest = strdup("/home");
|
||||
ret = iso_node_new_symlink(name, dest, &link);
|
||||
CU_ASSERT_EQUAL(ret, ISO_SUCCESS);
|
||||
CU_ASSERT_EQUAL(link->node.refcount, 1);
|
||||
CU_ASSERT_EQUAL(link->node.type, LIBISO_SYMLINK);
|
||||
CU_ASSERT_EQUAL(link->node.mode, S_IFLNK);
|
||||
CU_ASSERT_EQUAL(link->node.uid, 0);
|
||||
CU_ASSERT_EQUAL(link->node.gid, 0);
|
||||
CU_ASSERT_EQUAL(link->node.atime, 0);
|
||||
CU_ASSERT_EQUAL(link->node.mtime, 0);
|
||||
CU_ASSERT_EQUAL(link->node.ctime, 0);
|
||||
CU_ASSERT_STRING_EQUAL(link->node.name, "name1");
|
||||
CU_ASSERT_EQUAL(link->node.hidden, 0);
|
||||
CU_ASSERT_PTR_NULL(link->node.parent);
|
||||
CU_ASSERT_PTR_NULL(link->node.next);
|
||||
CU_ASSERT_STRING_EQUAL(link->dest, "/home");
|
||||
|
||||
iso_node_unref((IsoNode*)link);
|
||||
|
||||
/* try with invalid names */
|
||||
ret = iso_node_new_symlink("H/DHS/s", "/home", &link);
|
||||
CU_ASSERT_EQUAL(ret, ISO_WRONG_ARG_VALUE);
|
||||
ret = iso_node_new_symlink(".", "/home", &link);
|
||||
CU_ASSERT_EQUAL(ret, ISO_WRONG_ARG_VALUE);
|
||||
ret = iso_node_new_symlink("..", "/home", &link);
|
||||
CU_ASSERT_EQUAL(ret, ISO_WRONG_ARG_VALUE);
|
||||
}
|
||||
|
||||
static
|
||||
void test_iso_node_set_permissions()
|
||||
{
|
||||
IsoNode *node;
|
||||
node = malloc(sizeof(IsoNode));
|
||||
|
||||
node->mode = S_IFDIR | 0777;
|
||||
|
||||
/* set permissions propertly */
|
||||
iso_node_set_permissions(node, 0555);
|
||||
CU_ASSERT_EQUAL(node->mode, S_IFDIR | 0555);
|
||||
iso_node_set_permissions(node, 0640);
|
||||
CU_ASSERT_EQUAL(node->mode, S_IFDIR | 0640);
|
||||
|
||||
/* try to change file type via this call */
|
||||
iso_node_set_permissions(node, S_IFBLK | 0440);
|
||||
CU_ASSERT_EQUAL(node->mode, S_IFDIR | 0440);
|
||||
|
||||
free(node);
|
||||
}
|
||||
|
||||
static
|
||||
void test_iso_node_get_permissions()
|
||||
{
|
||||
IsoNode *node;
|
||||
mode_t mode;
|
||||
|
||||
node = malloc(sizeof(IsoNode));
|
||||
node->mode = S_IFDIR | 0777;
|
||||
|
||||
mode = iso_node_get_permissions(node);
|
||||
CU_ASSERT_EQUAL(mode, 0777);
|
||||
|
||||
iso_node_set_permissions(node, 0640);
|
||||
mode = iso_node_get_permissions(node);
|
||||
CU_ASSERT_EQUAL(mode, 0640);
|
||||
|
||||
iso_node_set_permissions(node, S_IFBLK | 0440);
|
||||
mode = iso_node_get_permissions(node);
|
||||
CU_ASSERT_EQUAL(mode, 0440);
|
||||
|
||||
free(node);
|
||||
}
|
||||
|
||||
static
|
||||
void test_iso_node_get_mode()
|
||||
{
|
||||
IsoNode *node;
|
||||
mode_t mode;
|
||||
|
||||
node = malloc(sizeof(IsoNode));
|
||||
node->mode = S_IFDIR | 0777;
|
||||
|
||||
mode = iso_node_get_mode(node);
|
||||
CU_ASSERT_EQUAL(mode, S_IFDIR | 0777);
|
||||
|
||||
iso_node_set_permissions(node, 0640);
|
||||
mode = iso_node_get_mode(node);
|
||||
CU_ASSERT_EQUAL(mode, S_IFDIR | 0640);
|
||||
|
||||
iso_node_set_permissions(node, S_IFBLK | 0440);
|
||||
mode = iso_node_get_mode(node);
|
||||
CU_ASSERT_EQUAL(mode, S_IFDIR | 0440);
|
||||
|
||||
free(node);
|
||||
}
|
||||
|
||||
static
|
||||
void test_iso_node_set_uid()
|
||||
{
|
||||
IsoNode *node;
|
||||
node = malloc(sizeof(IsoNode));
|
||||
|
||||
node->uid = 0;
|
||||
|
||||
iso_node_set_uid(node, 23);
|
||||
CU_ASSERT_EQUAL(node->uid, 23);
|
||||
iso_node_set_uid(node, 0);
|
||||
CU_ASSERT_EQUAL(node->uid, 0);
|
||||
|
||||
free(node);
|
||||
}
|
||||
|
||||
static
|
||||
void test_iso_node_get_uid()
|
||||
{
|
||||
IsoNode *node;
|
||||
uid_t uid;
|
||||
|
||||
node = malloc(sizeof(IsoNode));
|
||||
node->uid = 0;
|
||||
|
||||
uid = iso_node_get_uid(node);
|
||||
CU_ASSERT_EQUAL(uid, 0);
|
||||
|
||||
iso_node_set_uid(node, 25);
|
||||
uid = iso_node_get_uid(node);
|
||||
CU_ASSERT_EQUAL(uid, 25);
|
||||
|
||||
free(node);
|
||||
}
|
||||
|
||||
static
|
||||
void test_iso_node_set_gid()
|
||||
{
|
||||
IsoNode *node;
|
||||
node = malloc(sizeof(IsoNode));
|
||||
|
||||
node->gid = 0;
|
||||
|
||||
iso_node_set_gid(node, 23);
|
||||
CU_ASSERT_EQUAL(node->gid, 23);
|
||||
iso_node_set_gid(node, 0);
|
||||
CU_ASSERT_EQUAL(node->gid, 0);
|
||||
|
||||
free(node);
|
||||
}
|
||||
|
||||
static
|
||||
void test_iso_node_get_gid()
|
||||
{
|
||||
IsoNode *node;
|
||||
gid_t gid;
|
||||
|
||||
node = malloc(sizeof(IsoNode));
|
||||
node->gid = 0;
|
||||
|
||||
gid = iso_node_get_gid(node);
|
||||
CU_ASSERT_EQUAL(gid, 0);
|
||||
|
||||
iso_node_set_gid(node, 25);
|
||||
gid = iso_node_get_gid(node);
|
||||
CU_ASSERT_EQUAL(gid, 25);
|
||||
|
||||
free(node);
|
||||
}
|
||||
|
||||
static
|
||||
void test_iso_dir_add_node()
|
||||
{
|
||||
int result;
|
||||
IsoDir *dir;
|
||||
IsoNode *node1, *node2, *node3, *node4, *node5;
|
||||
|
||||
/* init dir with default values, not all field need to be initialized */
|
||||
dir = malloc(sizeof(IsoDir));
|
||||
dir->children = NULL;
|
||||
dir->nchildren = 0;
|
||||
|
||||
/* 1st node to be added */
|
||||
node1 = calloc(1, sizeof(IsoNode));
|
||||
node1->name = "Node1";
|
||||
|
||||
/* addition of node to an empty dir */
|
||||
result = iso_dir_add_node(dir, node1, 0);
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
CU_ASSERT_EQUAL(dir->nchildren, 1);
|
||||
CU_ASSERT_PTR_EQUAL(dir->children, node1);
|
||||
CU_ASSERT_PTR_NULL(node1->next);
|
||||
CU_ASSERT_PTR_EQUAL(node1->parent, dir);
|
||||
|
||||
/* addition of a node, to be inserted before */
|
||||
node2 = calloc(1, sizeof(IsoNode));
|
||||
node2->name = "A node to be added first";
|
||||
|
||||
result = iso_dir_add_node(dir, node2, 0);
|
||||
CU_ASSERT_EQUAL(result, 2);
|
||||
CU_ASSERT_EQUAL(dir->nchildren, 2);
|
||||
CU_ASSERT_PTR_EQUAL(dir->children, node2);
|
||||
CU_ASSERT_PTR_EQUAL(node2->next, node1);
|
||||
CU_ASSERT_PTR_NULL(node1->next);
|
||||
CU_ASSERT_PTR_EQUAL(node2->parent, dir);
|
||||
|
||||
/* addition of a node, to be inserted last */
|
||||
node3 = calloc(1, sizeof(IsoNode));
|
||||
node3->name = "This node will be inserted last";
|
||||
|
||||
result = iso_dir_add_node(dir, node3, 0);
|
||||
CU_ASSERT_EQUAL(result, 3);
|
||||
CU_ASSERT_EQUAL(dir->nchildren, 3);
|
||||
CU_ASSERT_PTR_EQUAL(dir->children, node2);
|
||||
CU_ASSERT_PTR_EQUAL(node2->next, node1);
|
||||
CU_ASSERT_PTR_EQUAL(node1->next, node3);
|
||||
CU_ASSERT_PTR_NULL(node3->next);
|
||||
CU_ASSERT_PTR_EQUAL(node3->parent, dir);
|
||||
|
||||
/* force some failures */
|
||||
result = iso_dir_add_node(NULL, node3, 0);
|
||||
CU_ASSERT_EQUAL(result, ISO_NULL_POINTER);
|
||||
result = iso_dir_add_node(dir, NULL, 0);
|
||||
CU_ASSERT_EQUAL(result, ISO_NULL_POINTER);
|
||||
|
||||
result = iso_dir_add_node(dir, (IsoNode*)dir, 0);
|
||||
CU_ASSERT_EQUAL(result, ISO_WRONG_ARG_VALUE);
|
||||
|
||||
/* a node with same name */
|
||||
node4 = calloc(1, sizeof(IsoNode));
|
||||
node4->name = "This node will be inserted last";
|
||||
result = iso_dir_add_node(dir, node4, 0);
|
||||
CU_ASSERT_EQUAL(result, ISO_NODE_NAME_NOT_UNIQUE);
|
||||
CU_ASSERT_EQUAL(dir->nchildren, 3);
|
||||
CU_ASSERT_PTR_EQUAL(dir->children, node2);
|
||||
CU_ASSERT_PTR_EQUAL(node2->next, node1);
|
||||
CU_ASSERT_PTR_EQUAL(node1->next, node3);
|
||||
CU_ASSERT_PTR_NULL(node3->next);
|
||||
CU_ASSERT_PTR_NULL(node4->parent);
|
||||
|
||||
/* a node already added to another dir should fail */
|
||||
node5 = calloc(1, sizeof(IsoNode));
|
||||
node5->name = "other node";
|
||||
node5->parent = (IsoDir*)node4;
|
||||
result = iso_dir_add_node(dir, node5, 0);
|
||||
CU_ASSERT_EQUAL(result, ISO_NODE_ALREADY_ADDED);
|
||||
|
||||
free(node1);
|
||||
free(node2);
|
||||
free(node3);
|
||||
free(node4);
|
||||
free(node5);
|
||||
free(dir);
|
||||
}
|
||||
|
||||
static
|
||||
void test_iso_dir_get_node()
|
||||
{
|
||||
int result;
|
||||
IsoDir *dir;
|
||||
IsoNode *node1, *node2, *node3;
|
||||
IsoNode *node;
|
||||
|
||||
/* init dir with default values, not all field need to be initialized */
|
||||
dir = malloc(sizeof(IsoDir));
|
||||
dir->children = NULL;
|
||||
dir->nchildren = 0;
|
||||
|
||||
/* try to find a node in an empty dir */
|
||||
result = iso_dir_get_node(dir, "a inexistent name", &node);
|
||||
CU_ASSERT_EQUAL(result, 0);
|
||||
CU_ASSERT_PTR_NULL(node);
|
||||
|
||||
/* add a node */
|
||||
node1 = calloc(1, sizeof(IsoNode));
|
||||
node1->name = "Node1";
|
||||
result = iso_dir_add_node(dir, node1, 0);
|
||||
|
||||
/* try to find a node not existent */
|
||||
result = iso_dir_get_node(dir, "a inexistent name", &node);
|
||||
CU_ASSERT_EQUAL(result, 0);
|
||||
CU_ASSERT_PTR_NULL(node);
|
||||
|
||||
/* and an existing one */
|
||||
result = iso_dir_get_node(dir, "Node1", &node);
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
CU_ASSERT_PTR_EQUAL(node, node1);
|
||||
|
||||
/* add another node */
|
||||
node2 = calloc(1, sizeof(IsoNode));
|
||||
node2->name = "A node to be added first";
|
||||
result = iso_dir_add_node(dir, node2, 0);
|
||||
|
||||
/* try to find a node not existent */
|
||||
result = iso_dir_get_node(dir, "a inexistent name", &node);
|
||||
CU_ASSERT_EQUAL(result, 0);
|
||||
CU_ASSERT_PTR_NULL(node);
|
||||
|
||||
/* and the two existing */
|
||||
result = iso_dir_get_node(dir, "Node1", &node);
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
CU_ASSERT_PTR_EQUAL(node, node1);
|
||||
result = iso_dir_get_node(dir, "A node to be added first", &node);
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
CU_ASSERT_PTR_EQUAL(node, node2);
|
||||
|
||||
/* insert another node */
|
||||
node3 = calloc(1, sizeof(IsoNode));
|
||||
node3->name = "This node will be inserted last";
|
||||
result = iso_dir_add_node(dir, node3, 0);
|
||||
|
||||
/* get again */
|
||||
result = iso_dir_get_node(dir, "a inexistent name", &node);
|
||||
CU_ASSERT_EQUAL(result, 0);
|
||||
CU_ASSERT_PTR_NULL(node);
|
||||
result = iso_dir_get_node(dir, "This node will be inserted last", &node);
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
CU_ASSERT_PTR_EQUAL(node, node3);
|
||||
|
||||
/* force some failures */
|
||||
result = iso_dir_get_node(NULL, "asas", &node);
|
||||
CU_ASSERT_EQUAL(result, ISO_NULL_POINTER);
|
||||
result = iso_dir_get_node(dir, NULL, &node);
|
||||
CU_ASSERT_EQUAL(result, ISO_NULL_POINTER);
|
||||
|
||||
/* and try with null node */
|
||||
result = iso_dir_get_node(dir, "asas", NULL);
|
||||
CU_ASSERT_EQUAL(result, 0);
|
||||
result = iso_dir_get_node(dir, "This node will be inserted last", NULL);
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
|
||||
free(node1);
|
||||
free(node2);
|
||||
free(node3);
|
||||
free(dir);
|
||||
}
|
||||
|
||||
void test_iso_dir_get_children()
|
||||
{
|
||||
int result;
|
||||
IsoDirIter *iter;
|
||||
IsoDir *dir;
|
||||
IsoNode *node, *node1, *node2, *node3;
|
||||
|
||||
/* init dir with default values, not all field need to be initialized */
|
||||
dir = malloc(sizeof(IsoDir));
|
||||
dir->children = NULL;
|
||||
dir->nchildren = 0;
|
||||
|
||||
result = iso_dir_get_children(dir, &iter);
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
|
||||
/* item should have no items */
|
||||
result = iso_dir_iter_has_next(iter);
|
||||
CU_ASSERT_EQUAL(result, 0);
|
||||
result = iso_dir_iter_next(iter, &node);
|
||||
CU_ASSERT_EQUAL(result, 0);
|
||||
CU_ASSERT_PTR_NULL(node);
|
||||
iso_dir_iter_free(iter);
|
||||
|
||||
/* 1st node to be added */
|
||||
node1 = calloc(1, sizeof(IsoNode));
|
||||
node1->name = "Node1";
|
||||
result = iso_dir_add_node(dir, node1, 0);
|
||||
CU_ASSERT_EQUAL(dir->nchildren, 1);
|
||||
|
||||
/* test iteration again */
|
||||
result = iso_dir_get_children(dir, &iter);
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
|
||||
/* iter should have a single item... */
|
||||
result = iso_dir_iter_has_next(iter);
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
result = iso_dir_iter_next(iter, &node);
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
CU_ASSERT_PTR_EQUAL(node, node1);
|
||||
|
||||
/* ...and no more */
|
||||
result = iso_dir_iter_has_next(iter);
|
||||
CU_ASSERT_EQUAL(result, 0);
|
||||
result = iso_dir_iter_next(iter, &node);
|
||||
CU_ASSERT_EQUAL(result, 0);
|
||||
CU_ASSERT_PTR_NULL(node);
|
||||
iso_dir_iter_free(iter);
|
||||
|
||||
/* add another node */
|
||||
node2 = calloc(1, sizeof(IsoNode));
|
||||
node2->name = "A node to be added first";
|
||||
result = iso_dir_add_node(dir, node2, 0);
|
||||
CU_ASSERT_EQUAL(result, 2);
|
||||
|
||||
result = iso_dir_get_children(dir, &iter);
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
|
||||
/* iter should have two items... */
|
||||
result = iso_dir_iter_has_next(iter);
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
result = iso_dir_iter_next(iter, &node);
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
CU_ASSERT_PTR_EQUAL(node, node2);
|
||||
result = iso_dir_iter_has_next(iter);
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
result = iso_dir_iter_next(iter, &node);
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
CU_ASSERT_PTR_EQUAL(node, node1);
|
||||
|
||||
/* ...and no more */
|
||||
result = iso_dir_iter_has_next(iter);
|
||||
CU_ASSERT_EQUAL(result, 0);
|
||||
result = iso_dir_iter_next(iter, &node);
|
||||
CU_ASSERT_EQUAL(result, 0);
|
||||
CU_ASSERT_PTR_NULL(node);
|
||||
iso_dir_iter_free(iter);
|
||||
|
||||
/* addition of a 3rd node, to be inserted last */
|
||||
node3 = calloc(1, sizeof(IsoNode));
|
||||
node3->name = "This node will be inserted last";
|
||||
result = iso_dir_add_node(dir, node3, 0);
|
||||
CU_ASSERT_EQUAL(result, 3);
|
||||
|
||||
result = iso_dir_get_children(dir, &iter);
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
|
||||
/* iter should have 3 items... */
|
||||
result = iso_dir_iter_has_next(iter);
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
result = iso_dir_iter_next(iter, &node);
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
CU_ASSERT_PTR_EQUAL(node, node2);
|
||||
result = iso_dir_iter_has_next(iter);
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
result = iso_dir_iter_next(iter, &node);
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
CU_ASSERT_PTR_EQUAL(node, node1);
|
||||
result = iso_dir_iter_has_next(iter);
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
result = iso_dir_iter_next(iter, &node);
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
CU_ASSERT_PTR_EQUAL(node, node3);
|
||||
|
||||
/* ...and no more */
|
||||
result = iso_dir_iter_has_next(iter);
|
||||
CU_ASSERT_EQUAL(result, 0);
|
||||
result = iso_dir_iter_next(iter, &node);
|
||||
CU_ASSERT_EQUAL(result, 0);
|
||||
CU_ASSERT_PTR_NULL(node);
|
||||
iso_dir_iter_free(iter);
|
||||
|
||||
free(node1);
|
||||
free(node2);
|
||||
free(node3);
|
||||
free(dir);
|
||||
}
|
||||
|
||||
void test_iso_node_take()
|
||||
{
|
||||
int result;
|
||||
IsoDir *dir;
|
||||
IsoNode *node1, *node2, *node3;
|
||||
|
||||
/* init dir with default values, not all field need to be initialized */
|
||||
dir = malloc(sizeof(IsoDir));
|
||||
dir->children = NULL;
|
||||
dir->nchildren = 0;
|
||||
|
||||
/* 1st node to be added */
|
||||
node1 = calloc(1, sizeof(IsoNode));
|
||||
node1->name = "Node1";
|
||||
|
||||
/* addition of node to an empty dir */
|
||||
result = iso_dir_add_node(dir, node1, 0);
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
|
||||
/* and take it */
|
||||
result = iso_node_take(node1);
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
CU_ASSERT_EQUAL(dir->nchildren, 0);
|
||||
CU_ASSERT_PTR_NULL(dir->children);
|
||||
CU_ASSERT_PTR_NULL(node1->next);
|
||||
CU_ASSERT_PTR_NULL(node1->parent);
|
||||
|
||||
/* insert it again */
|
||||
result = iso_dir_add_node(dir, node1, 0);
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
|
||||
/* addition of a 2nd node, to be inserted before */
|
||||
node2 = calloc(1, sizeof(IsoNode));
|
||||
node2->name = "A node to be added first";
|
||||
result = iso_dir_add_node(dir, node2, 0);
|
||||
CU_ASSERT_EQUAL(result, 2);
|
||||
|
||||
/* take first child */
|
||||
result = iso_node_take(node2);
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
CU_ASSERT_EQUAL(dir->nchildren, 1);
|
||||
CU_ASSERT_PTR_EQUAL(dir->children, node1);
|
||||
CU_ASSERT_PTR_NULL(node1->next);
|
||||
CU_ASSERT_PTR_EQUAL(node1->parent, dir);
|
||||
CU_ASSERT_PTR_NULL(node2->next);
|
||||
CU_ASSERT_PTR_NULL(node2->parent);
|
||||
|
||||
/* insert node 2 again */
|
||||
result = iso_dir_add_node(dir, node2, 0);
|
||||
CU_ASSERT_EQUAL(result, 2);
|
||||
|
||||
/* now take last child */
|
||||
result = iso_node_take(node1);
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
CU_ASSERT_EQUAL(dir->nchildren, 1);
|
||||
CU_ASSERT_PTR_EQUAL(dir->children, node2);
|
||||
CU_ASSERT_PTR_NULL(node2->next);
|
||||
CU_ASSERT_PTR_EQUAL(node2->parent, dir);
|
||||
CU_ASSERT_PTR_NULL(node1->next);
|
||||
CU_ASSERT_PTR_NULL(node1->parent);
|
||||
|
||||
/* insert again node1... */
|
||||
result = iso_dir_add_node(dir, node1, 0);
|
||||
CU_ASSERT_EQUAL(result, 2);
|
||||
|
||||
/* ...and a 3rd child, to be inserted last */
|
||||
node3 = calloc(1, sizeof(IsoNode));
|
||||
node3->name = "This node will be inserted last";
|
||||
result = iso_dir_add_node(dir, node3, 0);
|
||||
CU_ASSERT_EQUAL(result, 3);
|
||||
|
||||
/* and take the node in the middle */
|
||||
result = iso_node_take(node1);
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
CU_ASSERT_EQUAL(dir->nchildren, 2);
|
||||
CU_ASSERT_PTR_EQUAL(dir->children, node2);
|
||||
CU_ASSERT_PTR_EQUAL(node2->next, node3);
|
||||
CU_ASSERT_PTR_EQUAL(node2->parent, dir);
|
||||
CU_ASSERT_PTR_NULL(node3->next);
|
||||
CU_ASSERT_PTR_EQUAL(node3->parent, dir);
|
||||
CU_ASSERT_PTR_NULL(node1->next);
|
||||
CU_ASSERT_PTR_NULL(node1->parent);
|
||||
|
||||
free(node1);
|
||||
free(node2);
|
||||
free(node3);
|
||||
free(dir);
|
||||
}
|
||||
|
||||
static
|
||||
void test_iso_node_set_name()
|
||||
{
|
||||
int result;
|
||||
IsoDir *dir;
|
||||
IsoNode *node1, *node2;
|
||||
|
||||
/* init dir with default values, not all field need to be initialized */
|
||||
dir = malloc(sizeof(IsoDir));
|
||||
dir->children = NULL;
|
||||
dir->nchildren = 0;
|
||||
|
||||
/* cretae a node */
|
||||
node1 = calloc(1, sizeof(IsoNode));
|
||||
node1->name = strdup("Node1");
|
||||
|
||||
/* check name change */
|
||||
result = iso_node_set_name(node1, "New name");
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
CU_ASSERT_STRING_EQUAL(node1->name, "New name");
|
||||
|
||||
/* add node dir */
|
||||
result = iso_dir_add_node(dir, node1, 0);
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
|
||||
/* check name change */
|
||||
result = iso_node_set_name(node1, "Another name");
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
CU_ASSERT_STRING_EQUAL(node1->name, "Another name");
|
||||
|
||||
/* addition of a 2nd node */
|
||||
node2 = calloc(1, sizeof(IsoNode));
|
||||
node2->name = strdup("A node to be added first");
|
||||
result = iso_dir_add_node(dir, node2, 0);
|
||||
CU_ASSERT_EQUAL(result, 2);
|
||||
|
||||
result = iso_node_set_name(node2, "New name");
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
CU_ASSERT_STRING_EQUAL(node2->name, "New name");
|
||||
|
||||
/* and now try to give an existing name */
|
||||
result = iso_node_set_name(node2, "Another name");
|
||||
CU_ASSERT_EQUAL(result, ISO_NODE_NAME_NOT_UNIQUE);
|
||||
CU_ASSERT_STRING_EQUAL(node2->name, "New name");
|
||||
|
||||
free(node1->name);
|
||||
free(node2->name);
|
||||
free(node1);
|
||||
free(node2);
|
||||
free(dir);
|
||||
}
|
||||
|
||||
void add_node_suite()
|
||||
{
|
||||
CU_pSuite pSuite = CU_add_suite("Node Test Suite", NULL, NULL);
|
||||
|
||||
CU_add_test(pSuite, "iso_node_new_root()", test_iso_node_new_root);
|
||||
CU_add_test(pSuite, "iso_node_new_dir()", test_iso_node_new_dir);
|
||||
CU_add_test(pSuite, "iso_node_new_symlink()", test_iso_node_new_symlink);
|
||||
CU_add_test(pSuite, "iso_node_set_permissions()", test_iso_node_set_permissions);
|
||||
CU_add_test(pSuite, "iso_node_get_permissions()", test_iso_node_get_permissions);
|
||||
CU_add_test(pSuite, "iso_node_get_mode()", test_iso_node_get_mode);
|
||||
CU_add_test(pSuite, "iso_node_set_uid()", test_iso_node_set_uid);
|
||||
CU_add_test(pSuite, "iso_node_get_uid()", test_iso_node_get_uid);
|
||||
CU_add_test(pSuite, "iso_node_set_gid()", test_iso_node_set_gid);
|
||||
CU_add_test(pSuite, "iso_node_get_gid()", test_iso_node_get_gid);
|
||||
CU_add_test(pSuite, "iso_dir_add_node()", test_iso_dir_add_node);
|
||||
CU_add_test(pSuite, "iso_dir_get_node()", test_iso_dir_get_node);
|
||||
CU_add_test(pSuite, "iso_dir_get_children()", test_iso_dir_get_children);
|
||||
CU_add_test(pSuite, "iso_node_take()", test_iso_node_take);
|
||||
CU_add_test(pSuite, "iso_node_set_name()", test_iso_node_set_name);
|
||||
}
|
1395
test/test_rockridge.c
Normal file
1395
test/test_rockridge.c
Normal file
File diff suppressed because it is too large
Load Diff
155
test/test_stream.c
Normal file
155
test/test_stream.c
Normal file
@ -0,0 +1,155 @@
|
||||
/*
|
||||
* Unit test for util.h
|
||||
*
|
||||
* This test utiliy functions
|
||||
*/
|
||||
#include "test.h"
|
||||
#include "stream.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
static
|
||||
void test_mem_new()
|
||||
{
|
||||
int ret;
|
||||
IsoStream *stream;
|
||||
unsigned char *buf;
|
||||
|
||||
buf = malloc(3000);
|
||||
ret = iso_memory_stream_new(buf, 3000, &stream);
|
||||
CU_ASSERT_EQUAL(ret, 1);
|
||||
iso_stream_unref(stream);
|
||||
|
||||
ret = iso_memory_stream_new(NULL, 3000, &stream);
|
||||
CU_ASSERT_EQUAL(ret, ISO_NULL_POINTER);
|
||||
|
||||
ret = iso_memory_stream_new(buf, 3000, NULL);
|
||||
CU_ASSERT_EQUAL(ret, ISO_NULL_POINTER);
|
||||
}
|
||||
|
||||
static
|
||||
void test_mem_open()
|
||||
{
|
||||
int ret;
|
||||
IsoStream *stream;
|
||||
unsigned char *buf;
|
||||
|
||||
buf = malloc(3000);
|
||||
ret = iso_memory_stream_new(buf, 3000, &stream);
|
||||
CU_ASSERT_EQUAL(ret, 1);
|
||||
|
||||
ret = iso_stream_open(stream);
|
||||
CU_ASSERT_EQUAL(ret, 1);
|
||||
|
||||
/* try to open an already opened stream */
|
||||
ret = iso_stream_open(stream);
|
||||
CU_ASSERT_EQUAL(ret, ISO_FILE_ALREADY_OPENNED);
|
||||
|
||||
ret = iso_stream_close(stream);
|
||||
CU_ASSERT_EQUAL(ret, 1);
|
||||
|
||||
ret = iso_stream_close(stream);
|
||||
CU_ASSERT_EQUAL(ret, ISO_FILE_NOT_OPENNED);
|
||||
|
||||
iso_stream_unref(stream);
|
||||
}
|
||||
|
||||
static
|
||||
void test_mem_read()
|
||||
{
|
||||
int ret;
|
||||
IsoStream *stream;
|
||||
unsigned char *buf;
|
||||
unsigned char rbuf[3000];
|
||||
|
||||
buf = malloc(3000);
|
||||
memset(buf, 2, 200);
|
||||
memset(buf + 200, 3, 300);
|
||||
memset(buf + 500, 5, 500);
|
||||
memset(buf + 1000, 10, 1000);
|
||||
memset(buf + 2000, 56, 48);
|
||||
memset(buf + 2048, 137, 22);
|
||||
memset(buf + 2070, 13, 130);
|
||||
memset(buf + 2200, 88, 800);
|
||||
|
||||
ret = iso_memory_stream_new(buf, 3000, &stream);
|
||||
CU_ASSERT_EQUAL(ret, 1);
|
||||
|
||||
/* test 1: read full buf */
|
||||
ret = iso_stream_open(stream);
|
||||
CU_ASSERT_EQUAL(ret, 1);
|
||||
|
||||
ret = iso_stream_read(stream, rbuf, 3000);
|
||||
CU_ASSERT_EQUAL(ret, 3000);
|
||||
CU_ASSERT_NSTRING_EQUAL(rbuf, buf, 3000);
|
||||
|
||||
/* read again is EOF */
|
||||
ret = iso_stream_read(stream, rbuf, 20);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
ret = iso_stream_close(stream);
|
||||
CU_ASSERT_EQUAL(ret, 1);
|
||||
|
||||
/* test 2: read more than available bytes */
|
||||
ret = iso_stream_open(stream);
|
||||
CU_ASSERT_EQUAL(ret, 1);
|
||||
|
||||
ret = iso_stream_read(stream, rbuf, 3050);
|
||||
CU_ASSERT_EQUAL(ret, 3000);
|
||||
CU_ASSERT_NSTRING_EQUAL(rbuf, buf, 3000);
|
||||
|
||||
/* read again is EOF */
|
||||
ret = iso_stream_read(stream, rbuf, 20);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
ret = iso_stream_close(stream);
|
||||
CU_ASSERT_EQUAL(ret, 1);
|
||||
|
||||
/* test 3: read in block size */
|
||||
ret = iso_stream_open(stream);
|
||||
CU_ASSERT_EQUAL(ret, 1);
|
||||
|
||||
ret = iso_stream_read(stream, rbuf, 2048);
|
||||
CU_ASSERT_EQUAL(ret, 2048);
|
||||
CU_ASSERT_NSTRING_EQUAL(rbuf, buf, 2048);
|
||||
|
||||
ret = iso_stream_read(stream, rbuf, 2048);
|
||||
CU_ASSERT_EQUAL(ret, 3000 - 2048);
|
||||
CU_ASSERT_NSTRING_EQUAL(rbuf, buf + 2048, 3000 - 2048);
|
||||
|
||||
ret = iso_stream_read(stream, rbuf, 20);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
ret = iso_stream_close(stream);
|
||||
CU_ASSERT_EQUAL(ret, 1);
|
||||
|
||||
iso_stream_unref(stream);
|
||||
}
|
||||
|
||||
static
|
||||
void test_mem_size()
|
||||
{
|
||||
int ret;
|
||||
off_t size;
|
||||
IsoStream *stream;
|
||||
unsigned char *buf;
|
||||
|
||||
buf = malloc(3000);
|
||||
ret = iso_memory_stream_new(buf, 3000, &stream);
|
||||
CU_ASSERT_EQUAL(ret, 1);
|
||||
|
||||
size = iso_stream_get_size(stream);
|
||||
CU_ASSERT_EQUAL(size, 3000);
|
||||
|
||||
iso_stream_unref(stream);
|
||||
}
|
||||
|
||||
void add_stream_suite()
|
||||
{
|
||||
CU_pSuite pSuite = CU_add_suite("IsoStreamSuite", NULL, NULL);
|
||||
|
||||
CU_add_test(pSuite, "iso_memory_stream_new()", test_mem_new);
|
||||
CU_add_test(pSuite, "MemoryStream->open()", test_mem_open);
|
||||
CU_add_test(pSuite, "MemoryStream->read()", test_mem_read);
|
||||
CU_add_test(pSuite, "MemoryStream->get_size()", test_mem_size);
|
||||
}
|
566
test/test_tree.c
Normal file
566
test/test_tree.c
Normal file
@ -0,0 +1,566 @@
|
||||
/*
|
||||
* Unit test for node.h
|
||||
*/
|
||||
|
||||
#include "libisofs.h"
|
||||
#include "node.h"
|
||||
#include "image.h"
|
||||
|
||||
#include "test.h"
|
||||
#include "mocked_fsrc.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
static
|
||||
void test_iso_tree_add_new_dir()
|
||||
{
|
||||
int result;
|
||||
IsoDir *root;
|
||||
IsoDir *node1, *node2, *node3, *node4;
|
||||
IsoImage *image;
|
||||
|
||||
result = iso_image_new("volume_id", &image);
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
root = iso_image_get_root(image);
|
||||
CU_ASSERT_PTR_NOT_NULL(root);
|
||||
|
||||
result = iso_tree_add_new_dir(root, "Dir1", &node1);
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
CU_ASSERT_EQUAL(root->nchildren, 1);
|
||||
CU_ASSERT_PTR_EQUAL(root->children, node1);
|
||||
CU_ASSERT_PTR_NULL(node1->node.next);
|
||||
CU_ASSERT_PTR_EQUAL(node1->node.parent, root);
|
||||
CU_ASSERT_EQUAL(node1->node.type, LIBISO_DIR);
|
||||
CU_ASSERT_STRING_EQUAL(node1->node.name, "Dir1");
|
||||
|
||||
/* creation of a second dir, to be inserted before */
|
||||
result = iso_tree_add_new_dir(root, "A node to be added first", &node2);
|
||||
CU_ASSERT_EQUAL(result, 2);
|
||||
CU_ASSERT_EQUAL(root->nchildren, 2);
|
||||
CU_ASSERT_PTR_EQUAL(root->children, node2);
|
||||
CU_ASSERT_PTR_EQUAL(node2->node.next, node1);
|
||||
CU_ASSERT_PTR_NULL(node1->node.next);
|
||||
CU_ASSERT_PTR_EQUAL(node2->node.parent, root);
|
||||
CU_ASSERT_EQUAL(node2->node.type, LIBISO_DIR);
|
||||
CU_ASSERT_STRING_EQUAL(node2->node.name, "A node to be added first");
|
||||
|
||||
/* creation of a 3rd node, to be inserted last */
|
||||
result = iso_tree_add_new_dir(root, "This node will be inserted last", &node3);
|
||||
CU_ASSERT_EQUAL(result, 3);
|
||||
CU_ASSERT_EQUAL(root->nchildren, 3);
|
||||
CU_ASSERT_PTR_EQUAL(root->children, node2);
|
||||
CU_ASSERT_PTR_EQUAL(node2->node.next, node1);
|
||||
CU_ASSERT_PTR_EQUAL(node1->node.next, node3);
|
||||
CU_ASSERT_PTR_NULL(node3->node.next);
|
||||
CU_ASSERT_PTR_EQUAL(node3->node.parent, root);
|
||||
CU_ASSERT_EQUAL(node3->node.type, LIBISO_DIR);
|
||||
CU_ASSERT_STRING_EQUAL(node3->node.name, "This node will be inserted last");
|
||||
|
||||
/* force some failures */
|
||||
result = iso_tree_add_new_dir(NULL, "dsadas", &node4);
|
||||
CU_ASSERT_EQUAL(result, ISO_NULL_POINTER);
|
||||
result = iso_tree_add_new_dir(root, NULL, &node4);
|
||||
CU_ASSERT_EQUAL(result, ISO_NULL_POINTER);
|
||||
|
||||
/* try to insert a new dir with same name */
|
||||
result = iso_tree_add_new_dir(root, "This node will be inserted last", &node4);
|
||||
CU_ASSERT_EQUAL(result, ISO_NODE_NAME_NOT_UNIQUE);
|
||||
CU_ASSERT_EQUAL(root->nchildren, 3);
|
||||
CU_ASSERT_PTR_EQUAL(root->children, node2);
|
||||
CU_ASSERT_PTR_EQUAL(node2->node.next, node1);
|
||||
CU_ASSERT_PTR_EQUAL(node1->node.next, node3);
|
||||
CU_ASSERT_PTR_NULL(node3->node.next);
|
||||
CU_ASSERT_PTR_NULL(node4);
|
||||
|
||||
/* but pointer to new dir can be null */
|
||||
result = iso_tree_add_new_dir(root, "Another node", NULL);
|
||||
CU_ASSERT_EQUAL(result, 4);
|
||||
CU_ASSERT_EQUAL(root->nchildren, 4);
|
||||
CU_ASSERT_PTR_EQUAL(node2->node.next->next, node1);
|
||||
CU_ASSERT_STRING_EQUAL(node2->node.next->name, "Another node");
|
||||
|
||||
iso_image_unref(image);
|
||||
}
|
||||
|
||||
static
|
||||
void test_iso_tree_add_new_symlink()
|
||||
{
|
||||
int result;
|
||||
IsoDir *root;
|
||||
IsoSymlink *node1, *node2, *node3, *node4;
|
||||
IsoImage *image;
|
||||
|
||||
result = iso_image_new("volume_id", &image);
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
root = iso_image_get_root(image);
|
||||
CU_ASSERT_PTR_NOT_NULL(root);
|
||||
|
||||
result = iso_tree_add_new_symlink(root, "Link1", "/path/to/dest", &node1);
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
CU_ASSERT_EQUAL(root->nchildren, 1);
|
||||
CU_ASSERT_PTR_EQUAL(root->children, node1);
|
||||
CU_ASSERT_PTR_NULL(node1->node.next);
|
||||
CU_ASSERT_PTR_EQUAL(node1->node.parent, root);
|
||||
CU_ASSERT_EQUAL(node1->node.type, LIBISO_SYMLINK);
|
||||
CU_ASSERT_STRING_EQUAL(node1->node.name, "Link1");
|
||||
CU_ASSERT_STRING_EQUAL(node1->dest, "/path/to/dest");
|
||||
|
||||
/* creation of a second link, to be inserted before */
|
||||
result = iso_tree_add_new_symlink(root, "A node to be added first", "/home/me", &node2);
|
||||
CU_ASSERT_EQUAL(result, 2);
|
||||
CU_ASSERT_EQUAL(root->nchildren, 2);
|
||||
CU_ASSERT_PTR_EQUAL(root->children, node2);
|
||||
CU_ASSERT_PTR_EQUAL(node2->node.next, node1);
|
||||
CU_ASSERT_PTR_NULL(node1->node.next);
|
||||
CU_ASSERT_PTR_EQUAL(node2->node.parent, root);
|
||||
CU_ASSERT_EQUAL(node2->node.type, LIBISO_SYMLINK);
|
||||
CU_ASSERT_STRING_EQUAL(node2->node.name, "A node to be added first");
|
||||
CU_ASSERT_STRING_EQUAL(node2->dest, "/home/me");
|
||||
|
||||
/* creation of a 3rd node, to be inserted last */
|
||||
result = iso_tree_add_new_symlink(root, "This node will be inserted last",
|
||||
"/path/to/dest", &node3);
|
||||
CU_ASSERT_EQUAL(result, 3);
|
||||
CU_ASSERT_EQUAL(root->nchildren, 3);
|
||||
CU_ASSERT_PTR_EQUAL(root->children, node2);
|
||||
CU_ASSERT_PTR_EQUAL(node2->node.next, node1);
|
||||
CU_ASSERT_PTR_EQUAL(node1->node.next, node3);
|
||||
CU_ASSERT_PTR_NULL(node3->node.next);
|
||||
CU_ASSERT_PTR_EQUAL(node3->node.parent, root);
|
||||
CU_ASSERT_EQUAL(node3->node.type, LIBISO_SYMLINK);
|
||||
CU_ASSERT_STRING_EQUAL(node3->node.name, "This node will be inserted last");
|
||||
CU_ASSERT_STRING_EQUAL(node3->dest, "/path/to/dest");
|
||||
|
||||
/* force some failures */
|
||||
result = iso_tree_add_new_symlink(NULL, "dsadas", "/path/to/dest", &node4);
|
||||
CU_ASSERT_EQUAL(result, ISO_NULL_POINTER);
|
||||
result = iso_tree_add_new_symlink(root, NULL, "/path/to/dest", &node4);
|
||||
CU_ASSERT_EQUAL(result, ISO_NULL_POINTER);
|
||||
result = iso_tree_add_new_symlink(root, "dsadas", NULL, &node4);
|
||||
CU_ASSERT_EQUAL(result, ISO_NULL_POINTER);
|
||||
|
||||
/* try to insert a new link with same name */
|
||||
result = iso_tree_add_new_symlink(root, "This node will be inserted last", "/", &node4);
|
||||
CU_ASSERT_EQUAL(result, ISO_NODE_NAME_NOT_UNIQUE);
|
||||
CU_ASSERT_EQUAL(root->nchildren, 3);
|
||||
CU_ASSERT_PTR_EQUAL(root->children, node2);
|
||||
CU_ASSERT_PTR_EQUAL(node2->node.next, node1);
|
||||
CU_ASSERT_PTR_EQUAL(node1->node.next, node3);
|
||||
CU_ASSERT_PTR_NULL(node3->node.next);
|
||||
CU_ASSERT_PTR_NULL(node4);
|
||||
|
||||
/* but pointer to new link can be null */
|
||||
result = iso_tree_add_new_symlink(root, "Another node", ".", NULL);
|
||||
CU_ASSERT_EQUAL(result, 4);
|
||||
CU_ASSERT_EQUAL(root->nchildren, 4);
|
||||
CU_ASSERT_PTR_EQUAL(node2->node.next->next, node1);
|
||||
CU_ASSERT_EQUAL(node2->node.next->type, LIBISO_SYMLINK);
|
||||
CU_ASSERT_STRING_EQUAL(((IsoSymlink*)(node2->node.next))->dest, ".");
|
||||
CU_ASSERT_STRING_EQUAL(node2->node.next->name, "Another node");
|
||||
|
||||
iso_image_unref(image);
|
||||
}
|
||||
|
||||
static
|
||||
void test_iso_tree_add_new_special()
|
||||
{
|
||||
int result;
|
||||
IsoDir *root;
|
||||
IsoSpecial *node1, *node2, *node3, *node4;
|
||||
IsoImage *image;
|
||||
|
||||
result = iso_image_new("volume_id", &image);
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
root = iso_image_get_root(image);
|
||||
CU_ASSERT_PTR_NOT_NULL(root);
|
||||
|
||||
result = iso_tree_add_new_special(root, "Special1", S_IFSOCK | 0644, 0, &node1);
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
CU_ASSERT_EQUAL(root->nchildren, 1);
|
||||
CU_ASSERT_PTR_EQUAL(root->children, node1);
|
||||
CU_ASSERT_PTR_NULL(node1->node.next);
|
||||
CU_ASSERT_PTR_EQUAL(node1->node.parent, root);
|
||||
CU_ASSERT_EQUAL(node1->node.type, LIBISO_SPECIAL);
|
||||
CU_ASSERT_STRING_EQUAL(node1->node.name, "Special1");
|
||||
CU_ASSERT_EQUAL(node1->dev, 0);
|
||||
CU_ASSERT_EQUAL(node1->node.mode, S_IFSOCK | 0644);
|
||||
|
||||
/* creation of a block dev, to be inserted before */
|
||||
result = iso_tree_add_new_special(root, "A node to be added first", S_IFBLK | 0640, 34, &node2);
|
||||
CU_ASSERT_EQUAL(result, 2);
|
||||
CU_ASSERT_EQUAL(root->nchildren, 2);
|
||||
CU_ASSERT_PTR_EQUAL(root->children, node2);
|
||||
CU_ASSERT_PTR_EQUAL(node2->node.next, node1);
|
||||
CU_ASSERT_PTR_NULL(node1->node.next);
|
||||
CU_ASSERT_PTR_EQUAL(node2->node.parent, root);
|
||||
CU_ASSERT_EQUAL(node2->node.type, LIBISO_SPECIAL);
|
||||
CU_ASSERT_STRING_EQUAL(node2->node.name, "A node to be added first");
|
||||
CU_ASSERT_EQUAL(node2->dev, 34);
|
||||
CU_ASSERT_EQUAL(node2->node.mode, S_IFBLK | 0640);
|
||||
|
||||
/* creation of a 3rd node, to be inserted last */
|
||||
result = iso_tree_add_new_special(root, "This node will be inserted last",
|
||||
S_IFCHR | 0440, 345, &node3);
|
||||
CU_ASSERT_EQUAL(result, 3);
|
||||
CU_ASSERT_EQUAL(root->nchildren, 3);
|
||||
CU_ASSERT_PTR_EQUAL(root->children, node2);
|
||||
CU_ASSERT_PTR_EQUAL(node2->node.next, node1);
|
||||
CU_ASSERT_PTR_EQUAL(node1->node.next, node3);
|
||||
CU_ASSERT_PTR_NULL(node3->node.next);
|
||||
CU_ASSERT_PTR_EQUAL(node3->node.parent, root);
|
||||
CU_ASSERT_EQUAL(node3->node.type, LIBISO_SPECIAL);
|
||||
CU_ASSERT_STRING_EQUAL(node3->node.name, "This node will be inserted last");
|
||||
CU_ASSERT_EQUAL(node3->dev, 345);
|
||||
CU_ASSERT_EQUAL(node3->node.mode, S_IFCHR | 0440);
|
||||
|
||||
/* force some failures */
|
||||
result = iso_tree_add_new_special(NULL, "dsadas", S_IFBLK | 0440, 345, &node4);
|
||||
CU_ASSERT_EQUAL(result, ISO_NULL_POINTER);
|
||||
result = iso_tree_add_new_special(root, NULL, S_IFBLK | 0440, 345, &node4);
|
||||
CU_ASSERT_EQUAL(result, ISO_NULL_POINTER);
|
||||
result = iso_tree_add_new_special(root, "dsadas", S_IFDIR | 0666, 0, &node4);
|
||||
CU_ASSERT_EQUAL(result, ISO_WRONG_ARG_VALUE);
|
||||
result = iso_tree_add_new_special(root, "dsadas", S_IFREG | 0666, 0, &node4);
|
||||
CU_ASSERT_EQUAL(result, ISO_WRONG_ARG_VALUE);
|
||||
result = iso_tree_add_new_special(root, "dsadas", S_IFLNK | 0666, 0, &node4);
|
||||
CU_ASSERT_EQUAL(result, ISO_WRONG_ARG_VALUE);
|
||||
|
||||
/* try to insert a new special file with same name */
|
||||
result = iso_tree_add_new_special(root, "This node will be inserted last", S_IFIFO | 0666, 0, &node4);
|
||||
CU_ASSERT_EQUAL(result, ISO_NODE_NAME_NOT_UNIQUE);
|
||||
CU_ASSERT_EQUAL(root->nchildren, 3);
|
||||
CU_ASSERT_PTR_EQUAL(root->children, node2);
|
||||
CU_ASSERT_PTR_EQUAL(node2->node.next, node1);
|
||||
CU_ASSERT_PTR_EQUAL(node1->node.next, node3);
|
||||
CU_ASSERT_PTR_NULL(node3->node.next);
|
||||
CU_ASSERT_PTR_NULL(node4);
|
||||
|
||||
/* but pointer to new special can be null */
|
||||
result = iso_tree_add_new_special(root, "Another node", S_IFIFO | 0666, 0, NULL);
|
||||
CU_ASSERT_EQUAL(result, 4);
|
||||
CU_ASSERT_EQUAL(root->nchildren, 4);
|
||||
CU_ASSERT_PTR_EQUAL(node2->node.next->next, node1);
|
||||
CU_ASSERT_EQUAL(node2->node.next->type, LIBISO_SPECIAL);
|
||||
CU_ASSERT_EQUAL(((IsoSpecial*)(node2->node.next))->dev, 0);
|
||||
CU_ASSERT_EQUAL(node2->node.next->mode, S_IFIFO | 0666);
|
||||
CU_ASSERT_STRING_EQUAL(node2->node.next->name, "Another node");
|
||||
|
||||
iso_image_unref(image);
|
||||
}
|
||||
|
||||
static
|
||||
void test_iso_tree_add_node_dir()
|
||||
{
|
||||
int result;
|
||||
IsoDir *root;
|
||||
IsoNode *node1, *node2, *node3, *node4;
|
||||
IsoImage *image;
|
||||
IsoFilesystem *fs;
|
||||
struct stat info;
|
||||
struct mock_file *mroot, *dir1, *dir2;
|
||||
|
||||
result = iso_image_new("volume_id", &image);
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
root = iso_image_get_root(image);
|
||||
CU_ASSERT_PTR_NOT_NULL(root);
|
||||
|
||||
/* replace image filesystem with out mockep one */
|
||||
iso_filesystem_unref(image->fs);
|
||||
result = test_mocked_filesystem_new(&fs);
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
image->fs = fs;
|
||||
mroot = test_mocked_fs_get_root(fs);
|
||||
|
||||
/* add some files to the filesystem */
|
||||
info.st_mode = S_IFDIR | 0550;
|
||||
info.st_uid = 20;
|
||||
info.st_gid = 21;
|
||||
info.st_atime = 234523;
|
||||
info.st_ctime = 23432432;
|
||||
info.st_mtime = 1111123;
|
||||
result = test_mocked_fs_add_dir("dir", mroot, info, &dir1);
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
|
||||
info.st_mode = S_IFDIR | 0555;
|
||||
info.st_uid = 30;
|
||||
info.st_gid = 31;
|
||||
info.st_atime = 3234523;
|
||||
info.st_ctime = 3234432;
|
||||
info.st_mtime = 3111123;
|
||||
result = test_mocked_fs_add_dir("a child node", dir1, info, &dir2);
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
|
||||
info.st_mode = S_IFDIR | 0750;
|
||||
info.st_uid = 40;
|
||||
info.st_gid = 41;
|
||||
info.st_atime = 4234523;
|
||||
info.st_ctime = 4234432;
|
||||
info.st_mtime = 4111123;
|
||||
result = test_mocked_fs_add_dir("another one", dir1, info, &dir2);
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
|
||||
info.st_mode = S_IFDIR | 0755;
|
||||
info.st_uid = 50;
|
||||
info.st_gid = 51;
|
||||
info.st_atime = 5234523;
|
||||
info.st_ctime = 5234432;
|
||||
info.st_mtime = 5111123;
|
||||
result = test_mocked_fs_add_dir("zzzz", mroot, info, &dir2);
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
|
||||
/* and now insert those files to the image */
|
||||
result = iso_tree_add_node(image, root, "/dir", &node1);
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
CU_ASSERT_EQUAL(root->nchildren, 1);
|
||||
CU_ASSERT_PTR_EQUAL(root->children, node1);
|
||||
CU_ASSERT_PTR_NULL(node1->next);
|
||||
CU_ASSERT_PTR_EQUAL(node1->parent, root);
|
||||
CU_ASSERT_EQUAL(node1->type, LIBISO_DIR);
|
||||
CU_ASSERT_STRING_EQUAL(node1->name, "dir");
|
||||
CU_ASSERT_EQUAL(node1->mode, S_IFDIR | 0550);
|
||||
CU_ASSERT_EQUAL(node1->uid, 20);
|
||||
CU_ASSERT_EQUAL(node1->gid, 21);
|
||||
CU_ASSERT_EQUAL(node1->atime, 234523);
|
||||
CU_ASSERT_EQUAL(node1->ctime, 23432432);
|
||||
CU_ASSERT_EQUAL(node1->mtime, 1111123);
|
||||
CU_ASSERT_PTR_NULL(((IsoDir*)node1)->children);
|
||||
CU_ASSERT_EQUAL(((IsoDir*)node1)->nchildren, 0);
|
||||
|
||||
result = iso_tree_add_node(image, root, "/dir/a child node", &node2);
|
||||
CU_ASSERT_EQUAL(result, 2);
|
||||
CU_ASSERT_EQUAL(root->nchildren, 2);
|
||||
CU_ASSERT_PTR_EQUAL(root->children, node2);
|
||||
CU_ASSERT_PTR_EQUAL(node2->next, node1);
|
||||
CU_ASSERT_PTR_NULL(node1->next);
|
||||
CU_ASSERT_PTR_EQUAL(node1->parent, root);
|
||||
CU_ASSERT_PTR_EQUAL(node2->parent, root);
|
||||
CU_ASSERT_EQUAL(node2->type, LIBISO_DIR);
|
||||
CU_ASSERT_STRING_EQUAL(node2->name, "a child node");
|
||||
CU_ASSERT_EQUAL(node2->mode, S_IFDIR | 0555);
|
||||
CU_ASSERT_EQUAL(node2->uid, 30);
|
||||
CU_ASSERT_EQUAL(node2->gid, 31);
|
||||
CU_ASSERT_EQUAL(node2->atime, 3234523);
|
||||
CU_ASSERT_EQUAL(node2->ctime, 3234432);
|
||||
CU_ASSERT_EQUAL(node2->mtime, 3111123);
|
||||
CU_ASSERT_PTR_NULL(((IsoDir*)node2)->children);
|
||||
CU_ASSERT_EQUAL(((IsoDir*)node2)->nchildren, 0);
|
||||
|
||||
result = iso_tree_add_node(image, root, "/dir/another one", &node3);
|
||||
CU_ASSERT_EQUAL(result, 3);
|
||||
CU_ASSERT_EQUAL(root->nchildren, 3);
|
||||
CU_ASSERT_PTR_EQUAL(root->children, node2);
|
||||
CU_ASSERT_PTR_EQUAL(node2->next, node3);
|
||||
CU_ASSERT_PTR_EQUAL(node3->next, node1);
|
||||
CU_ASSERT_PTR_NULL(node1->next);
|
||||
CU_ASSERT_PTR_EQUAL(node1->parent, root);
|
||||
CU_ASSERT_PTR_EQUAL(node2->parent, root);
|
||||
CU_ASSERT_PTR_EQUAL(node3->parent, root);
|
||||
CU_ASSERT_EQUAL(node3->type, LIBISO_DIR);
|
||||
CU_ASSERT_STRING_EQUAL(node3->name, "another one");
|
||||
CU_ASSERT_EQUAL(node3->mode, S_IFDIR | 0750);
|
||||
CU_ASSERT_EQUAL(node3->uid, 40);
|
||||
CU_ASSERT_EQUAL(node3->gid, 41);
|
||||
CU_ASSERT_EQUAL(node3->atime, 4234523);
|
||||
CU_ASSERT_EQUAL(node3->ctime, 4234432);
|
||||
CU_ASSERT_EQUAL(node3->mtime, 4111123);
|
||||
CU_ASSERT_PTR_NULL(((IsoDir*)node3)->children);
|
||||
CU_ASSERT_EQUAL(((IsoDir*)node3)->nchildren, 0);
|
||||
|
||||
result = iso_tree_add_node(image, root, "/zzzz", &node4);
|
||||
CU_ASSERT_EQUAL(result, 4);
|
||||
CU_ASSERT_EQUAL(root->nchildren, 4);
|
||||
CU_ASSERT_PTR_EQUAL(root->children, node2);
|
||||
CU_ASSERT_PTR_EQUAL(node2->next, node3);
|
||||
CU_ASSERT_PTR_EQUAL(node3->next, node1);
|
||||
CU_ASSERT_PTR_EQUAL(node1->next, node4);
|
||||
CU_ASSERT_PTR_NULL(node4->next);
|
||||
CU_ASSERT_PTR_EQUAL(node1->parent, root);
|
||||
CU_ASSERT_PTR_EQUAL(node2->parent, root);
|
||||
CU_ASSERT_PTR_EQUAL(node3->parent, root);
|
||||
CU_ASSERT_PTR_EQUAL(node4->parent, root);
|
||||
CU_ASSERT_EQUAL(node4->type, LIBISO_DIR);
|
||||
CU_ASSERT_STRING_EQUAL(node4->name, "zzzz");
|
||||
CU_ASSERT_EQUAL(node4->mode, S_IFDIR | 0755);
|
||||
CU_ASSERT_EQUAL(node4->uid, 50);
|
||||
CU_ASSERT_EQUAL(node4->gid, 51);
|
||||
CU_ASSERT_EQUAL(node4->atime, 5234523);
|
||||
CU_ASSERT_EQUAL(node4->ctime, 5234432);
|
||||
CU_ASSERT_EQUAL(node4->mtime, 5111123);
|
||||
CU_ASSERT_PTR_NULL(((IsoDir*)node4)->children);
|
||||
CU_ASSERT_EQUAL(((IsoDir*)node4)->nchildren, 0);
|
||||
|
||||
iso_image_unref(image);
|
||||
}
|
||||
|
||||
static
|
||||
void test_iso_tree_add_node_link()
|
||||
{
|
||||
int result;
|
||||
IsoDir *root;
|
||||
IsoNode *node1, *node2, *node3;
|
||||
IsoImage *image;
|
||||
IsoFilesystem *fs;
|
||||
struct stat info;
|
||||
struct mock_file *mroot, *link;
|
||||
|
||||
result = iso_image_new("volume_id", &image);
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
root = iso_image_get_root(image);
|
||||
CU_ASSERT_PTR_NOT_NULL(root);
|
||||
|
||||
/* replace image filesystem with out mockep one */
|
||||
iso_filesystem_unref(image->fs);
|
||||
result = test_mocked_filesystem_new(&fs);
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
image->fs = fs;
|
||||
mroot = test_mocked_fs_get_root(fs);
|
||||
|
||||
/* add some files to the filesystem */
|
||||
info.st_mode = S_IFLNK | 0777;
|
||||
info.st_uid = 12;
|
||||
info.st_gid = 13;
|
||||
info.st_atime = 123444;
|
||||
info.st_ctime = 123555;
|
||||
info.st_mtime = 123666;
|
||||
result = test_mocked_fs_add_symlink("link1", mroot, info, "/home/me", &link);
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
|
||||
info.st_mode = S_IFLNK | 0555;
|
||||
info.st_uid = 22;
|
||||
info.st_gid = 23;
|
||||
info.st_atime = 223444;
|
||||
info.st_ctime = 223555;
|
||||
info.st_mtime = 223666;
|
||||
result = test_mocked_fs_add_symlink("another link", mroot, info, "/", &link);
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
|
||||
info.st_mode = S_IFLNK | 0750;
|
||||
info.st_uid = 32;
|
||||
info.st_gid = 33;
|
||||
info.st_atime = 323444;
|
||||
info.st_ctime = 323555;
|
||||
info.st_mtime = 323666;
|
||||
result = test_mocked_fs_add_symlink("this will be the last", mroot, info, "/etc", &link);
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
|
||||
/* and now insert those files to the image */
|
||||
result = iso_tree_add_node(image, root, "/link1", &node1);
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
CU_ASSERT_EQUAL(root->nchildren, 1);
|
||||
CU_ASSERT_PTR_EQUAL(root->children, node1);
|
||||
CU_ASSERT_PTR_NULL(node1->next);
|
||||
CU_ASSERT_PTR_EQUAL(node1->parent, root);
|
||||
CU_ASSERT_EQUAL(node1->type, LIBISO_SYMLINK);
|
||||
CU_ASSERT_STRING_EQUAL(node1->name, "link1");
|
||||
CU_ASSERT_EQUAL(node1->mode, S_IFLNK | 0777);
|
||||
CU_ASSERT_EQUAL(node1->uid, 12);
|
||||
CU_ASSERT_EQUAL(node1->gid, 13);
|
||||
CU_ASSERT_EQUAL(node1->atime, 123444);
|
||||
CU_ASSERT_EQUAL(node1->ctime, 123555);
|
||||
CU_ASSERT_EQUAL(node1->mtime, 123666);
|
||||
CU_ASSERT_STRING_EQUAL(((IsoSymlink*)node1)->dest, "/home/me");
|
||||
|
||||
result = iso_tree_add_node(image, root, "/another link", &node2);
|
||||
CU_ASSERT_EQUAL(result, 2);
|
||||
CU_ASSERT_EQUAL(root->nchildren, 2);
|
||||
CU_ASSERT_PTR_EQUAL(root->children, node2);
|
||||
CU_ASSERT_PTR_EQUAL(node2->next, node1);
|
||||
CU_ASSERT_PTR_NULL(node1->next);
|
||||
CU_ASSERT_PTR_EQUAL(node1->parent, root);
|
||||
CU_ASSERT_PTR_EQUAL(node2->parent, root);
|
||||
CU_ASSERT_EQUAL(node2->type, LIBISO_SYMLINK);
|
||||
CU_ASSERT_STRING_EQUAL(node2->name, "another link");
|
||||
CU_ASSERT_EQUAL(node2->mode, S_IFLNK | 0555);
|
||||
CU_ASSERT_EQUAL(node2->uid, 22);
|
||||
CU_ASSERT_EQUAL(node2->gid, 23);
|
||||
CU_ASSERT_EQUAL(node2->atime, 223444);
|
||||
CU_ASSERT_EQUAL(node2->ctime, 223555);
|
||||
CU_ASSERT_EQUAL(node2->mtime, 223666);
|
||||
CU_ASSERT_STRING_EQUAL(((IsoSymlink*)node2)->dest, "/");
|
||||
|
||||
result = iso_tree_add_node(image, root, "/this will be the last", &node3);
|
||||
CU_ASSERT_EQUAL(result, 3);
|
||||
CU_ASSERT_EQUAL(root->nchildren, 3);
|
||||
CU_ASSERT_PTR_EQUAL(root->children, node2);
|
||||
CU_ASSERT_PTR_EQUAL(node2->next, node1);
|
||||
CU_ASSERT_PTR_EQUAL(node1->next, node3);
|
||||
CU_ASSERT_PTR_NULL(node3->next);
|
||||
CU_ASSERT_PTR_EQUAL(node1->parent, root);
|
||||
CU_ASSERT_PTR_EQUAL(node2->parent, root);
|
||||
CU_ASSERT_PTR_EQUAL(node3->parent, root);
|
||||
CU_ASSERT_EQUAL(node3->type, LIBISO_SYMLINK);
|
||||
CU_ASSERT_STRING_EQUAL(node3->name, "this will be the last");
|
||||
CU_ASSERT_EQUAL(node3->mode, S_IFLNK | 0750);
|
||||
CU_ASSERT_EQUAL(node3->uid, 32);
|
||||
CU_ASSERT_EQUAL(node3->gid, 33);
|
||||
CU_ASSERT_EQUAL(node3->atime, 323444);
|
||||
CU_ASSERT_EQUAL(node3->ctime, 323555);
|
||||
CU_ASSERT_EQUAL(node3->mtime, 323666);
|
||||
CU_ASSERT_STRING_EQUAL(((IsoSymlink*)node3)->dest, "/etc");
|
||||
|
||||
iso_image_unref(image);
|
||||
}
|
||||
|
||||
static
|
||||
void test_iso_tree_path_to_node()
|
||||
{
|
||||
int result;
|
||||
IsoDir *root;
|
||||
IsoDir *node1, *node2, *node11;
|
||||
IsoNode *node;
|
||||
IsoImage *image;
|
||||
IsoFilesystem *fs;
|
||||
|
||||
result = iso_image_new("volume_id", &image);
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
root = iso_image_get_root(image);
|
||||
CU_ASSERT_PTR_NOT_NULL(root);
|
||||
|
||||
/* replace image filesystem with out mockep one */
|
||||
iso_filesystem_unref(image->fs);
|
||||
result = test_mocked_filesystem_new(&fs);
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
image->fs = fs;
|
||||
|
||||
/* add some files */
|
||||
result = iso_tree_add_new_dir(root, "Dir1", &node1);
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
result = iso_tree_add_new_dir(root, "Dir2", (IsoDir**)&node2);
|
||||
CU_ASSERT_EQUAL(result, 2);
|
||||
result = iso_tree_add_new_dir((IsoDir*)node1, "Dir11", (IsoDir**)&node11);
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
|
||||
/* retrive some items */
|
||||
result = iso_tree_path_to_node(image, "/", &node);
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
CU_ASSERT_PTR_EQUAL(node, root);
|
||||
result = iso_tree_path_to_node(image, "/Dir1", &node);
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
CU_ASSERT_PTR_EQUAL(node, node1);
|
||||
result = iso_tree_path_to_node(image, "/Dir2", &node);
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
CU_ASSERT_PTR_EQUAL(node, node2);
|
||||
result = iso_tree_path_to_node(image, "/Dir1/Dir11", &node);
|
||||
CU_ASSERT_EQUAL(result, 1);
|
||||
CU_ASSERT_PTR_EQUAL(node, node11);
|
||||
|
||||
/* some failtures */
|
||||
result = iso_tree_path_to_node(image, "/Dir2/Dir11", &node);
|
||||
CU_ASSERT_EQUAL(result, 0);
|
||||
CU_ASSERT_PTR_NULL(node);
|
||||
|
||||
iso_image_unref(image);
|
||||
}
|
||||
|
||||
void add_tree_suite()
|
||||
{
|
||||
CU_pSuite pSuite = CU_add_suite("Iso Tree Suite", NULL, NULL);
|
||||
|
||||
CU_add_test(pSuite, "iso_tree_add_new_dir()", test_iso_tree_add_new_dir);
|
||||
CU_add_test(pSuite, "iso_tree_add_new_symlink()", test_iso_tree_add_new_symlink);
|
||||
CU_add_test(pSuite, "iso_tree_add_new_special()", test_iso_tree_add_new_special);
|
||||
CU_add_test(pSuite, "iso_tree_add_node() [1. dir]", test_iso_tree_add_node_dir);
|
||||
CU_add_test(pSuite, "iso_tree_add_node() [2. symlink]", test_iso_tree_add_node_link);
|
||||
CU_add_test(pSuite, "iso_tree_path_to_node()", test_iso_tree_path_to_node);
|
||||
|
||||
}
|
1072
test/test_util.c
Normal file
1072
test/test_util.c
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user