Commited unit tests

This commit is contained in:
Mario Danic 2007-07-12 14:25:29 +00:00
parent aac7bfdff0
commit 812e701e72
2 changed files with 272 additions and 0 deletions

View File

@ -0,0 +1,34 @@
/*
* Unit test for ecma119_tree.h
*/
//FIXME not implemented yet!!
#include "libisofs.h"
#include "tree.h"
#include "test.h"
//#include "ecma119_tree.h"
/*
* Also including C file, testing internal functions
*/
//#include "ecma119_tree.c"
#include <assert.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
static void test_calc_dirent_len()
{
}
void add_ecma119_tree_suite()
{
CU_pSuite pSuite = CU_add_suite("Ecma119TreeSuite", NULL, NULL);
//CU_add_test(pSuite, "test of calc_dirent_len()", test_calc_dirent_len);
}

View File

@ -0,0 +1,238 @@
/*
* Unit test for volume.h
*/
#include "libisofs.h"
#include "tree.h"
#include "test.h"
#include "volume.h"
#include <assert.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
static void test_iso_volume_new()
{
struct iso_volume *volume;
volume = iso_volume_new("volume_id", "publisher_id", "data_preparer_id");
CU_ASSERT_PTR_NOT_NULL(volume);
CU_ASSERT_EQUAL(volume->refcount, 1);
/* a new root must be created */
CU_ASSERT_PTR_NOT_NULL(volume->root);
CU_ASSERT_STRING_EQUAL( volume->volume_id, "volume_id" );
CU_ASSERT_STRING_EQUAL( volume->publisher_id, "publisher_id" );
CU_ASSERT_STRING_EQUAL( volume->data_preparer_id, "data_preparer_id" );
CU_ASSERT_PTR_NULL(volume->system_id);
CU_ASSERT_PTR_NULL(volume->application_id);
CU_ASSERT_PTR_NULL(volume->copyright_file_id);
CU_ASSERT_PTR_NULL(volume->abstract_file_id);
CU_ASSERT_PTR_NULL(volume->biblio_file_id);
CU_ASSERT_PTR_NULL(volume->bootcat);
iso_volume_free(volume);
}
static void test_iso_volume_new_with_root()
{
struct iso_volume *volume;
struct iso_tree_node_dir *root;
root = iso_tree_new_root();
volume = iso_volume_new_with_root("volume_id", "publisher_id",
"data_preparer_id", root);
CU_ASSERT_PTR_NOT_NULL(volume);
CU_ASSERT_EQUAL(volume->refcount, 1);
CU_ASSERT_PTR_NOT_NULL(volume->root);
CU_ASSERT_PTR_EQUAL(volume->root, root);
CU_ASSERT_STRING_EQUAL( volume->volume_id, "volume_id" );
CU_ASSERT_STRING_EQUAL( volume->publisher_id, "publisher_id" );
CU_ASSERT_STRING_EQUAL( volume->data_preparer_id, "data_preparer_id" );
CU_ASSERT_PTR_NULL(volume->system_id);
CU_ASSERT_PTR_NULL(volume->application_id);
CU_ASSERT_PTR_NULL(volume->copyright_file_id);
CU_ASSERT_PTR_NULL(volume->abstract_file_id);
CU_ASSERT_PTR_NULL(volume->biblio_file_id);
CU_ASSERT_PTR_NULL(volume->bootcat);
iso_volume_free(volume);
}
static void test_iso_volume_get_root()
{
struct iso_volume *volume;
struct iso_tree_node_dir *root;
struct iso_tree_node_dir *root2;
root = iso_tree_new_root();
volume = iso_volume_new_with_root("volume_id", "publisher_id",
"data_preparer_id", root);
root2 = iso_volume_get_root(volume);
CU_ASSERT_PTR_NOT_NULL(root2);
CU_ASSERT_PTR_EQUAL(root2, volume->root);
CU_ASSERT_PTR_EQUAL(root2, root);
iso_volume_free(volume);
}
static void test_iso_volume_set_volume_id()
{
struct iso_volume *volume;
volume = iso_volume_new("volume_id", "publisher_id", "data_preparer_id");
CU_ASSERT_STRING_EQUAL( volume->volume_id, "volume_id" );
char *volid = "new volume id";
iso_volume_set_volume_id(volume, volid);
CU_ASSERT_STRING_EQUAL( volume->volume_id, "new volume id" );
/* check string was strdup'ed */
CU_ASSERT_PTR_NOT_EQUAL( volume->volume_id, volid );
iso_volume_free(volume);
}
static void test_iso_volume_set_publisher_id()
{
struct iso_volume *volume;
volume = iso_volume_new("volume_id", "publisher_id", "data_preparer_id");
CU_ASSERT_STRING_EQUAL( volume->publisher_id, "publisher_id" );
char *pubid = "new publisher id";
iso_volume_set_publisher_id(volume, pubid);
CU_ASSERT_STRING_EQUAL( volume->publisher_id, "new publisher id" );
/* check string was strdup'ed */
CU_ASSERT_PTR_NOT_EQUAL( volume->publisher_id, pubid );
iso_volume_free(volume);
}
static void test_iso_volume_set_data_preparer_id()
{
struct iso_volume *volume;
volume = iso_volume_new("volume_id", "publisher_id", "data_preparer_id");
CU_ASSERT_STRING_EQUAL( volume->data_preparer_id, "data_preparer_id" );
char *dpid = "new data preparer id";
iso_volume_set_data_preparer_id(volume, dpid);
CU_ASSERT_STRING_EQUAL( volume->data_preparer_id, "new data preparer id" );
/* check string was strdup'ed */
CU_ASSERT_PTR_NOT_EQUAL( volume->data_preparer_id, dpid );
iso_volume_free(volume);
}
static void test_iso_volume_set_system_id()
{
struct iso_volume *volume;
volume = iso_volume_new("volume_id", "publisher_id", "data_preparer_id");
CU_ASSERT_PTR_NULL(volume->system_id);
char *sysid = "new system id";
iso_volume_set_system_id(volume, sysid);
CU_ASSERT_STRING_EQUAL( volume->system_id, "new system id" );
/* check string was strdup'ed */
CU_ASSERT_PTR_NOT_EQUAL( volume->system_id, sysid );
iso_volume_free(volume);
}
static void test_iso_volume_set_application_id()
{
struct iso_volume *volume;
volume = iso_volume_new("volume_id", "publisher_id", "data_preparer_id");
CU_ASSERT_PTR_NULL(volume->application_id);
char *appid = "new application id";
iso_volume_set_application_id(volume, appid);
CU_ASSERT_STRING_EQUAL( volume->application_id, "new application id" );
/* check string was strdup'ed */
CU_ASSERT_PTR_NOT_EQUAL( volume->application_id, appid );
iso_volume_free(volume);
}
static void test_iso_volume_set_abstract_file_id()
{
struct iso_volume *volume;
volume = iso_volume_new("volume_id", "publisher_id", "data_preparer_id");
CU_ASSERT_PTR_NULL(volume->abstract_file_id);
char *absid = "new abstract id";
iso_volume_set_abstract_file_id(volume, absid);
CU_ASSERT_STRING_EQUAL( volume->abstract_file_id, "new abstract id" );
/* check string was strdup'ed */
CU_ASSERT_PTR_NOT_EQUAL( volume->abstract_file_id, absid );
iso_volume_free(volume);
}
static void test_iso_volume_set_biblio_file_id()
{
struct iso_volume *volume;
volume = iso_volume_new("volume_id", "publisher_id", "data_preparer_id");
CU_ASSERT_PTR_NULL(volume->biblio_file_id);
char *bibid = "new biblio id";
iso_volume_set_biblio_file_id(volume, bibid);
CU_ASSERT_STRING_EQUAL( volume->biblio_file_id, "new biblio id" );
/* check string was strdup'ed */
CU_ASSERT_PTR_NOT_EQUAL( volume->biblio_file_id, bibid );
iso_volume_free(volume);
}
static void test_iso_volset_new()
{
struct iso_volume *volume;
struct iso_volset *volset;
volume = iso_volume_new("volume_id", "publisher_id", "data_preparer_id");
volset = iso_volset_new(volume, "volset_id");
CU_ASSERT_PTR_NOT_NULL(volset);
CU_ASSERT_EQUAL(volset->refcount, 1);
CU_ASSERT_EQUAL(volset->volset_size, 1);
CU_ASSERT_PTR_NOT_NULL(volset->volume);
CU_ASSERT_PTR_NOT_NULL(volset->volume[0]);
CU_ASSERT_PTR_EQUAL(volset->volume[0], volume);
CU_ASSERT_STRING_EQUAL( volset->volset_id, "volset_id" );
iso_volset_free(volset);
}
void add_volume_suite()
{
CU_pSuite pSuite = CU_add_suite("VolumeSuite", NULL, NULL);
CU_add_test(pSuite, "test of iso_volume_new()", test_iso_volume_new);
CU_add_test(pSuite, "test of iso_volume_new_with_root()", test_iso_volume_new_with_root);
CU_add_test(pSuite, "test of iso_volume_get_root()", test_iso_volume_get_root);
CU_add_test(pSuite, "test of iso_volume_set_volume_id()", test_iso_volume_set_volume_id);
CU_add_test(pSuite, "test of iso_volume_set_publisher_id()", test_iso_volume_set_publisher_id);
CU_add_test(pSuite, "test of iso_volume_set_data_preparer_id()", test_iso_volume_set_data_preparer_id);
CU_add_test(pSuite, "test of iso_volume_set_system_id()", test_iso_volume_set_system_id);
CU_add_test(pSuite, "test of iso_volume_set_application_id()", test_iso_volume_set_application_id);
CU_add_test(pSuite, "test of iso_volume_set_abstract_file_id()", test_iso_volume_set_abstract_file_id);
CU_add_test(pSuite, "test of iso_volume_set_biblio_file_id()", test_iso_volume_set_biblio_file_id);
CU_add_test(pSuite, "test of iso_volset_new()", test_iso_volset_new);
}