[parted-devel] [PATCH 3/3] Include a disk probing test
Otavio Salvador
otavio at ossystems.com.br
Thu Dec 7 17:54:51 CET 2006
From: Otavio Salvador <otavio at ossystems.com.br>
---
libparted/tests/Makefile.am | 11 ++++++++
libparted/tests/common.c | 22 ++++++++++++++++
libparted/tests/common.h | 6 ++++
libparted/tests/label.c | 61 +++++++++++++++++++++++++++++++++++++++++++
4 files changed, 100 insertions(+), 0 deletions(-)
diff --git a/libparted/tests/Makefile.am b/libparted/tests/Makefile.am
new file mode 100644
index 0000000..79c7b69
--- /dev/null
+++ b/libparted/tests/Makefile.am
@@ -0,0 +1,11 @@
+# This file is part of GNU Parted
+# Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
+#
+# This file may be modified and/or distributed without restriction.
+
+TESTS = label
+bin_PROGRAMS = label
+label_CFLAGS = @CHECK_CFLAGS@ -I$(top_srcdir)/include
+label_LDADD = @CHECK_LIBS@ $(top_builddir)/libparted/libparted.la
+label_SOURCES = common.h common.c label.c
+
diff --git a/libparted/tests/common.c b/libparted/tests/common.c
new file mode 100644
index 0000000..9a4aeb5
--- /dev/null
+++ b/libparted/tests/common.c
@@ -0,0 +1,22 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <string.h>
+
+#include "common.h"
+
+
+char *_create_disk(const off_t size)
+{
+ char filename[] = "parted-test-XXXXXX";
+ mktemp(filename);
+
+ FILE *disk = fopen(filename, "w");
+ off_t total_size = size * 1024 * 1024; /* Mb */
+
+ fseek(disk, total_size, SEEK_SET);
+ fwrite("", sizeof(char), sizeof(char), disk);
+ fclose(disk);
+
+ return strdup(filename);
+}
diff --git a/libparted/tests/common.h b/libparted/tests/common.h
new file mode 100644
index 0000000..466c218
--- /dev/null
+++ b/libparted/tests/common.h
@@ -0,0 +1,6 @@
+/* Create an empty disk image
+ *
+ * filename: file (with full path) where to write the disk image
+ * size: size of disk image (megabytes)
+ */
+char *_create_disk(const off_t size);
diff --git a/libparted/tests/label.c b/libparted/tests/label.c
new file mode 100644
index 0000000..2fd9a5a
--- /dev/null
+++ b/libparted/tests/label.c
@@ -0,0 +1,61 @@
+#include <string.h>
+#include <unistd.h>
+
+#include <check.h>
+
+#include <parted/parted.h>
+
+#include "common.h"
+
+char *temporary_disk;
+
+void create_disk(void)
+{
+ temporary_disk = _create_disk(20);
+}
+
+void destroy_disk(void)
+{
+ unlink(temporary_disk);
+ free(temporary_disk);
+}
+
+/* TEST: Create a disklabel on a simple disk image */
+START_TEST (test_create_label)
+{
+ PedDevice *dev = ped_device_get(temporary_disk);
+ PedDiskType *type;
+ PedDisk *disk;
+
+ for (type = ped_disk_type_get_next(NULL); type;
+ type = ped_disk_type_get_next(type)) {
+
+ /* Not implemented yet */
+ if (strncmp(type->name, "aix", 3) == 0)
+ continue;
+
+ disk = ped_disk_new_fresh(dev, type);
+ fail_if(!disk, "Failed to create a label of type: %s",
+ type->name);
+ }
+}
+END_TEST
+
+int main(void)
+{
+ int number_failed;
+ Suite *suite = suite_create("Disk Label");
+ TCase *tcase_basic = tcase_create("Create");
+
+ tcase_add_checked_fixture(tcase_basic, create_disk, destroy_disk);
+ tcase_add_test(tcase_basic, test_create_label);
+ suite_add_tcase(suite, tcase_basic);
+
+ SRunner *srunner = srunner_create(suite);
+ srunner_run_all(srunner, CK_VERBOSE);
+
+ number_failed = srunner_ntests_failed(srunner);
+ srunner_free(srunner);
+
+ return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
+}
More information about the parted-devel
mailing list