Anonymous avatar Anonymous committed 1db1847

Comments (0)

Files changed (6)

 VERSION = @VERSION@
 
 SUBDIRS = po src doc
+if MAKE_TESTS
+SUBDIRS += tests
+endif MAKE_TESTS
+
 EXTRA_DIST = autotools/config.rpath autotools/mkinstalldirs m4/ChangeLog \
 	     ABOUT-NLS AUTHORS THANKS ChangeLog NEWS README fdisk.spec
 
 		[AC_CHECK_HEADER(curses.h, 
 		have_ncurses_h=false
 		AC_DEFINE(HAVE_CURSES_H, 1, [We have the curses.h header.]),
-		[AC_MSG_FAILURE([ncurses.h or curses.h not found])]
 		$2)])
 if test x$have_ncurses_h == xtrue; then
-	AC_CHECK_LIB(ncurses, getch, ,
-		[AC_MSG_FAILURE([libncurses not found])]
+	AC_CHECK_LIB(ncurses, getch, LIBS="-lncurses"
+		$1 ,
 		$2)
 else
-	AC_CHECK_LIB(curses, getch, ,
-		[AC_MSG_FAILURE([libcurses not found])]
+	AC_CHECK_LIB(curses, getch, LIBS="-lcurses"
+		$1 ,
 		$2)
 fi
 
 LIBS="$saved_LIBS"
 AC_SUBST(CURSES_LIBS)
 
-dnl Execute ACTION-IF-FOUND
-$1
 
-])
-
-
+])
 AC_DEFINE_UNQUOTED(BUILD_DATE, "$BUILD_DATE", [The date of the build.])
 
 # Check for programs.
+AC_PROG_AWK
 AC_LANG_C
 AC_PROG_CC
 AC_PROG_INSTALL
+AC_PROG_LN_S
 
 # Check headers.
 AC_CHECK_HEADERS([ctype.h errno.h stdio.h getopt.h stdarg.h string.h \
 
 
 dnl ncurses
-CHECK_CURSES( , AC_MSG_ERROR([ncurses not installed; please install it first]))
+CHECK_CURSES(have_curses=true , have_curses=false)
 AC_SUBST(CURSES_LIBS)
 
-AC_CONFIG_FILES([Makefile src/Makefile doc/Makefile po/Makefile.in])
+dnl Check if we have check... FIXME: Running autogen requires check installed
+
+AM_PATH_CHECK(, have_check=true, have_check=false)
+AM_CONDITIONAL(MAKE_TESTS, test x$have_check = xtrue)
+AM_CONDITIONAL(MAKE_CFDISK, test x$have_curses = xtrue)
+
+AC_CONFIG_FILES([Makefile src/Makefile doc/Makefile tests/Makefile po/Makefile.in])
 AC_OUTPUT
 
 DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@
 LIBS = @LIBINTL@ @LIBS@
 
-sbin_PROGRAMS = cfdisk fdisk
+sbin_PROGRAMS =  fdisk
 
 fdisk_SOURCES = main.c		\
 		command.c	\
 
 fdisk_LDADD = $(PARTED_LIBS)
 
+if MAKE_CFDISK
+sbin_PROGRAMS += cfdisk
 
 cfdisk_SOURCES = cfdisk.c	\
 		common.c	\
 
 cfdisk_LDADD = $(PARTED_LIBS) $(CURSES_LIBS)
 
+endif MAKE_CFDISK

tests/Makefile.am

+if MAKE_TESTS
+TESTS = \
+	check_common
+
+noinst_PROGRAMS = \
+	check_common
+
+check_common_SOURCES = \
+	check_common.c \
+	../src/common.h \
+	../src/common.c \
+	../src/strlist.h \
+	../src/strlist.c
+
+check_common_LDADD = $(PARTED_LIBS) $(CHECK_LIBS)
+endif MAKE_TESTS

tests/check_common.c

+#include <stdlib.h>
+#include <check.h>
+#include <stdio.h>
+#include "../src/strlist.h"
+#include "../src/common.h"
+
+#define SIZE 2000000000LL
+#define BUFSIZE 4096
+
+/* No chance someone else decides to call this file this way, I hope */
+char tempfile[] = "/tmp/check_cfdisk_temporary_disk_drive";
+
+PedDevice *dev = NULL;
+PedDisk *disk = NULL;
+UICalls uiquery;
+
+
+/* This functions will return what's needed */
+char string[BUFSIZE];
+int getstring (const char* prompt, char** value, const StrList* str_list, 
+               const StrList* loc_str_list, int multi_word)
+{
+	if (str_list || loc_str_list) {
+		int found = 0;
+		char *temp = NULL;
+		const StrList *c;
+		/* Check if the test string is not found in the string list */
+		for (c = str_list; !found && c != NULL; c = c->next) {
+			temp = str_list_convert_node(c);
+			if (!strcmp(temp,string)) found = 1;
+			if (temp) free(temp);
+		}
+		for (c = loc_str_list; !found && c != NULL; c = c->next) {
+			temp = str_list_convert_node(c);
+			if (!strcmp(temp,string)) found = 1;
+			if (temp) free(temp);
+		}
+		if (!found) return 0;
+	}
+	if (*value) ped_free (*value);
+	*value = strdup(string);
+	return 1;
+}
+
+int integer = 0;
+int getint (const char* prompt, int *value)
+{
+	*value = integer;
+	return 1;
+}
+
+int bool = 1;
+int getbool (const char* prompt, int *value)
+{
+	*value = bool;
+	return 1;
+}
+
+PedDevice *device = NULL;
+int getdev (const char* prompt, PedDevice** value)
+{
+	*value = device;
+	return 1;
+}
+
+PedPartition *partition;
+int getpart (const char* prompt, PedPartition** value)
+{
+	*value = partition;
+	return 1;
+}
+
+PedDiskType *disk_type;
+int getdisktype (const char* prompt, PedDiskType **value)
+{
+	*value = disk_type;
+	return 1;
+}
+
+PedFileSystemType *fs_type;
+int getfstype (const char* prompt, PedFileSystemType **value)
+{
+	*value = fs_type;
+	return 1;
+}
+
+int
+init_tempfile() {
+	FILE *fp;
+	fp = fopen(tempfile,"w");
+	if (!fp) return 0;
+	fseek (fp, SIZE, SEEK_SET);
+	fwrite ("", 1, 1, fp);
+	fclose (fp);
+	return 1;
+	
+}
+
+int
+init_device() {
+	dev = ped_device_get(tempfile);
+	return ped_device_open(dev);
+}
+
+
+
+START_TEST (test_null)
+{
+	fail_unless(1 == 1, "Your computer is insane");
+}
+END_TEST
+
+START_TEST (test_mklabel)
+{
+	strncpy(string,"msdos", BUFSIZE);
+	disk_type = ped_disk_type_get(string);
+	/* First we will test with giving it the string */
+	uiquery.getstring = getstring;
+	uiquery.getdisktype = NULL;
+	fail_unless (do_mklabel(dev, &disk, NULL, &uiquery), 
+	             "Failed to create a label with a getstring query");
+	fail_unless (disk != NULL, "mklabel reported success, but failed");
+	fail_unless (!strcmp(string,disk->type->name),
+	             "mklabel created wrong disk type");
+	/* Then we do it the other way */
+	uiquery.getstring = NULL;
+	uiquery.getdisktype = getdisktype;
+	fail_unless (do_mklabel(dev,&disk, NULL, &uiquery),
+	             "Failed to create a label with a getdisktype query");
+	fail_unless (disk != NULL,
+	             "mklabel reported success, but failed, getdisktype");
+	fail_unless (!strcmp(string,disk->type->name),
+	             "mklabel created wrong disk type, using getdisktype");
+	if (disk) ped_disk_destroy(disk);
+	disk = NULL;
+	/* Then we do it the third way */	
+	uiquery.getdisktype = NULL;
+	fail_unless (do_mklabel(dev,&disk,disk_type,&uiquery),
+	             "Failed to create a label with a specified type");
+	fail_unless (disk != NULL,
+	             "mklabel reported success, but failed, specified");
+	fail_unless (!strcmp(string,disk->type->name),
+	             "mklabel created wrong disk type when we specified it");
+	
+}
+END_TEST
+
+Suite *common_suite(void)
+{
+	Suite *s = suite_create("Common functions");
+	TCase *tc_core = tcase_create("Core");
+	suite_add_tcase (s, tc_core);
+	tcase_add_test(tc_core, test_null);
+	tcase_add_test(tc_core, test_mklabel);
+	return s;
+}
+
+
+int main (void)
+{
+	int nf;
+	if (!init_tempfile()) return 1;
+	if (!init_device()) {
+		unlink(tempfile);
+		return 1;
+	}
+	Suite *s = common_suite();
+	SRunner *sr = srunner_create(s);
+	srunner_run_all (sr, CK_NORMAL);
+	nf = srunner_ntests_failed(sr);
+	srunner_free(sr);
+	return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
+}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.