Add getters and setters for image properties, together with unit tests.

This commit is contained in:
Vreixo Formoso 2007-12-02 19:49:11 +01:00
parent c83bac7d9e
commit d916b60172
6 changed files with 588 additions and 1 deletions

View File

@ -51,7 +51,8 @@ test_test_LDFLAGS = -L.. -lm
test_test_SOURCES = \ test_test_SOURCES = \
test/test.h \ test/test.h \
test/test.c \ test/test.c \
test/test_node.c test/test_node.c \
test/test_image.c
## ========================================================================= ## ## ========================================================================= ##

View File

@ -84,3 +84,111 @@ void iso_image_unref(IsoImage *image)
free(image->biblio_file_id); free(image->biblio_file_id);
} }
} }
IsoDir *iso_image_get_root(const IsoImage *image)
{
return image->root;
}
void iso_image_set_volset_id(IsoImage *image, const char *volset_id)
{
free(image->volset_id);
image->volset_id = strdup(volset_id);
}
const char *iso_image_get_volset_id(const IsoImage *image)
{
return image->volset_id;
}
void iso_image_set_volume_id(IsoImage *image, const char *volume_id)
{
free(image->volume_id);
image->volume_id = strdup(volume_id);
}
const char *iso_image_get_volume_id(const IsoImage *image)
{
return image->volume_id;
}
void iso_image_set_publisher_id(IsoImage *image, const char *publisher_id)
{
free(image->publisher_id);
image->publisher_id = strdup(publisher_id);
}
const char *iso_image_get_publisher_id(const IsoImage *image)
{
return image->publisher_id;
}
void iso_image_set_data_preparer_id(IsoImage *image,
const char *data_preparer_id)
{
free(image->data_preparer_id);
image->data_preparer_id = strdup(data_preparer_id);
}
const char *iso_image_get_data_preparer_id(const IsoImage *image)
{
return image->data_preparer_id;
}
void iso_image_set_system_id(IsoImage *image, const char *system_id)
{
free(image->system_id);
image->system_id = strdup(system_id);
}
const char *iso_image_get_system_id(const IsoImage *image)
{
return image->system_id;
}
void iso_image_set_application_id(IsoImage *image, const char *application_id)
{
free(image->application_id);
image->application_id = strdup(application_id);
}
const char *iso_image_get_application_id(const IsoImage *image)
{
return image->application_id;
}
void iso_image_set_copyright_file_id(IsoImage *image,
const char *copyright_file_id)
{
free(image->copyright_file_id);
image->copyright_file_id = strdup(copyright_file_id);
}
const char *iso_image_get_copyright_file_id(const IsoImage *image)
{
return image->copyright_file_id;
}
void iso_image_set_abstract_file_id(IsoImage *image,
const char *abstract_file_id)
{
free(image->abstract_file_id);
image->abstract_file_id = strdup(abstract_file_id);
}
const char *iso_image_get_abstract_file_id(const IsoImage *image)
{
return image->abstract_file_id;
}
void iso_image_set_biblio_file_id(IsoImage *image,
const char *biblio_file_id)
{
free(image->biblio_file_id);
image->biblio_file_id = strdup(biblio_file_id);
}
const char *iso_image_get_biblio_file_id(const IsoImage *image)
{
return image->biblio_file_id;
}

View File

@ -45,6 +45,128 @@ void iso_image_ref(IsoImage *image);
*/ */
void iso_image_unref(IsoImage *image); void iso_image_unref(IsoImage *image);
/**
* Get the root directory of the image.
* No extra ref is added to it, so you musn't unref it. Use iso_node_ref()
* if you want to get your own reference.
*/
IsoDir *iso_image_get_root(const IsoImage *image);
/**
* Fill in the volset identifier for a image.
*/
void iso_image_set_volset_id(IsoImage *image, const char *volset_id);
/**
* Get the volset identifier.
* The returned string is owned by the image and should not be freed nor
* changed.
*/
const char *iso_image_get_volset_id(const IsoImage *image);
/**
* Fill in the volume identifier for a image.
*/
void iso_image_set_volume_id(IsoImage *image, const char *volume_id);
/**
* Get the volume identifier.
* The returned string is owned by the image and should not be freed nor
* changed.
*/
const char *iso_image_get_volume_id(const IsoImage *image);
/**
* Fill in the publisher for a image.
*/
void iso_image_set_publisher_id(IsoImage *image, const char *publisher_id);
/**
* Get the publisher of a image.
* The returned string is owned by the image and should not be freed nor
* changed.
*/
const char *iso_image_get_publisher_id(const IsoImage *image);
/**
* Fill in the data preparer for a image.
*/
void iso_image_set_data_preparer_id(IsoImage *image,
const char *data_preparer_id);
/**
* Get the data preparer of a image.
* The returned string is owned by the image and should not be freed nor
* changed.
*/
const char *iso_image_get_data_preparer_id(const IsoImage *image);
/**
* Fill in the system id for a image. Up to 32 characters.
*/
void iso_image_set_system_id(IsoImage *image, const char *system_id);
/**
* Get the system id of a image.
* The returned string is owned by the image and should not be freed nor
* changed.
*/
const char *iso_image_get_system_id(const IsoImage *image);
/**
* Fill in the application id for a image. Up to 128 chars.
*/
void iso_image_set_application_id(IsoImage *image, const char *application_id);
/**
* Get the application id of a image.
* The returned string is owned by the image and should not be freed nor
* changed.
*/
const char *iso_image_get_application_id(const IsoImage *image);
/**
* Fill copyright information for the image. Usually this refers
* to a file on disc. Up to 37 characters.
*/
void iso_image_set_copyright_file_id(IsoImage *image,
const char *copyright_file_id);
/**
* Get the copyright information of a image.
* The returned string is owned by the image and should not be freed nor
* changed.
*/
const char *iso_image_get_copyright_file_id(const IsoImage *image);
/**
* Fill abstract information for the image. Usually this refers
* to a file on disc. Up to 37 characters.
*/
void iso_image_set_abstract_file_id(IsoImage *image,
const char *abstract_file_id);
/**
* Get the abstract information of a image.
* The returned string is owned by the image and should not be freed nor
* changed.
*/
const char *iso_image_get_abstract_file_id(const IsoImage *image);
/**
* Fill biblio information for the image. Usually this refers
* to a file on disc. Up to 37 characters.
*/
void iso_image_set_biblio_file_id(IsoImage *image,
const char *biblio_file_id);
/**
* Get the biblio information of a image.
* The returned string is owned by the image and should not be freed nor
* changed.
*/
const char *iso_image_get_biblio_file_id(const IsoImage *image);
/** /**
* Increments the reference counting of the given node. * Increments the reference counting of the given node.
*/ */

View File

@ -3,6 +3,7 @@
static void create_test_suite() static void create_test_suite()
{ {
add_node_suite(); add_node_suite();
add_image_suite();
} }
int main(int argc, char **argv) int main(int argc, char **argv)

View File

@ -5,5 +5,6 @@
#include "libisofs.h" #include "libisofs.h"
void add_node_suite(); void add_node_suite();
void add_image_suite();
#endif /*TEST_H_*/ #endif /*TEST_H_*/

354
test/test_image.c Normal file
View 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);
}