grim/gplate

3ea7d4210672
removed gmakeisms for gpg signing as well
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* HAVE_CONFIG_H */
#include <check.h>
#include <gplate/gplate.h>
#include <glib.h>
#include <glib/gstdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "test.h"
#include "test-collection.h"
#include "test-object.h"
/******************************************************************************
* Globals
*****************************************************************************/
static GPlateVariable *file = NULL;
/******************************************************************************
* Helpers
*****************************************************************************/
static gchar *
create_temp_file(void) {
gint fd = 0;
gchar *filename = NULL;
fd = g_file_open_tmp("gplate-test-XXXXXX", &filename, NULL);
fail_unless(fd >= 0);
/* close the fd, basically we just did a touch ;) */
close(fd);
return filename;
}
static void
test_file(GPlateFileVariable *file, const gchar *filename) {
GPlateCollection *c = GPLATE_COLLECTION(file);
struct stat st;
gint r = 0;
test_collection_lookup(c, "filename", filename);
/* do a g_stat on the file */
r = g_lstat(filename, &st);
fail_unless(r == 0, "Failed to stat '%s'", filename);
/* now run through and compare all of the values */
test_collection_lookup_int(c, "dev", st.st_dev);
test_collection_lookup_int(c, "inode", st.st_ino);
test_collection_lookup_int(c, "mode", st.st_mode);
test_collection_lookup_int(c, "nlink", st.st_nlink);
test_collection_lookup_int(c, "uid", st.st_uid);
test_collection_lookup_int(c, "gid", st.st_gid);
test_collection_lookup_int(c, "rdev", st.st_rdev);
test_collection_lookup_int(c, "size", st.st_size);
test_collection_lookup_int(c, "blocksize", st.st_blksize);
test_collection_lookup_int(c, "blocks", st.st_blocks);
test_collection_lookup_int(c, "atime", st.st_atime);
test_collection_lookup_int(c, "mtime", st.st_mtime);
test_collection_lookup_int(c, "ctime", st.st_ctime);
}
/******************************************************************************
* Fixtures
*****************************************************************************/
static void
object_hierarchy_setup(void) {
gchar *filename = create_temp_file();
file = gplate_file_variable_new("file", filename);
g_free(filename);
}
static void
common_teardown(void) {
if(G_IS_OBJECT(file)) {
GPlateCollection *c = GPLATE_COLLECTION(file);
const gchar *filename = NULL;
filename = gplate_collection_lookup(c, "filename");
if(filename)
g_unlink(filename);
g_object_unref(G_OBJECT(file));
}
file = NULL;
}
/******************************************************************************
* Object Hierarchy Tests
*****************************************************************************/
START_TEST(test_file_hierarchy_type)
test_object_is_a(G_OBJECT(file), GPLATE_TYPE_FILE_VARIABLE);
END_TEST
START_TEST(test_file_hierarchy_parent)
test_object_is_a(G_OBJECT(file), GPLATE_TYPE_DICTIONARY_VARIABLE);
END_TEST
START_TEST(test_file_hierarchy_grandparent)
test_object_is_a(G_OBJECT(file), GPLATE_TYPE_VARIABLE);
END_TEST
START_TEST(test_file_hierarchy_collection)
test_object_is_a(G_OBJECT(file), GPLATE_TYPE_COLLECTION);
END_TEST
/******************************************************************************
* File Tests
*****************************************************************************/
START_TEST(test_file_normal)
gchar *filename = create_temp_file();
file = gplate_file_variable_new("file", filename);
fail_unless(GPLATE_IS_FILE_VARIABLE(file),
"Failed to create a GPlateFileVariable instance for '%s'",
filename);
test_file(GPLATE_FILE_VARIABLE(file), filename);
g_free(filename);
END_TEST
START_TEST(test_file_does_not_exist)
const gchar *filename = "non-existant file";
file = gplate_file_variable_new("file", filename);
fail_unless(file != NULL,
"We should not have been able to create a GPlateFileVariable "
"instance for '%s'\n",
filename);
END_TEST
/******************************************************************************
* API
*****************************************************************************/
Suite *
file_variable_suite(void) {
Suite *s = suite_create("File Variable Suite");
TCase *tc = NULL;
/* object heirarchy */
tc = tcase_create("Object hierarchy");
tcase_add_checked_fixture(tc, object_hierarchy_setup, common_teardown);
tcase_add_test(tc, test_file_hierarchy_type);
tcase_add_test(tc, test_file_hierarchy_parent);
tcase_add_test(tc, test_file_hierarchy_grandparent);
tcase_add_test(tc, test_file_hierarchy_collection);
suite_add_tcase(s, tc);
/* file tests */
tc = tcase_create("File Tests");
tcase_add_checked_fixture(tc, NULL, common_teardown);
tcase_add_test(tc, test_file_normal);
tcase_add_test(tc, test_file_does_not_exist);
suite_add_tcase(s, tc);
return s;
}