X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=tests.c;h=d1bccc5870efbc3a39d2f7508d1e1d15a916e92d;hp=3adf389ab84080a64f3a0a04fecb1d8cfdedeca8;hb=4b382eb8110050cb5b769c6f7d79b0b77eb79719;hpb=8c3b820c2b687345448e3d74a7101b07ff32688e diff --git a/tests.c b/tests.c index 3adf389..d1bccc5 100644 --- a/tests.c +++ b/tests.c @@ -112,6 +112,201 @@ static void no_test_warnings (void) fprintf (stderr, "warning: \"guestfs_get_e2uuid\" has no tests\n"); } +static int test_equal_0 (void) +{ + /* InitBasicFS for equal (0): create ext2 on /dev/sda1 */ + { + int r; + suppress_error = 0; + r = guestfs_umount_all (g); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_lvm_remove_all (g); + if (r == -1) + return -1; + } + { + char *lines[] = { + ",", + NULL + }; + int r; + suppress_error = 0; + r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_mkfs (g, "ext2", "/dev/sda1"); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_mount (g, "/dev/sda1", "/"); + if (r == -1) + return -1; + } + /* TestOutputTrue for equal (0) */ + { + int r; + suppress_error = 0; + r = guestfs_write_file (g, "/file1", "contents of a file", 0); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_cp (g, "/file1", "/file2"); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_equal (g, "/file1", "/file2"); + if (r == -1) + return -1; + if (!r) { + fprintf (stderr, "test_equal_0: expected true, got false\n"); + return -1; + } + } + return 0; +} + +static int test_equal_1 (void) +{ + /* InitBasicFS for equal (1): create ext2 on /dev/sda1 */ + { + int r; + suppress_error = 0; + r = guestfs_umount_all (g); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_lvm_remove_all (g); + if (r == -1) + return -1; + } + { + char *lines[] = { + ",", + NULL + }; + int r; + suppress_error = 0; + r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_mkfs (g, "ext2", "/dev/sda1"); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_mount (g, "/dev/sda1", "/"); + if (r == -1) + return -1; + } + /* TestOutputFalse for equal (1) */ + { + int r; + suppress_error = 0; + r = guestfs_write_file (g, "/file1", "contents of a file", 0); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_write_file (g, "/file2", "contents of another file", 0); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_equal (g, "/file1", "/file2"); + if (r == -1) + return -1; + if (r) { + fprintf (stderr, "test_equal_1: expected false, got true\n"); + return -1; + } + } + return 0; +} + +static int test_equal_2 (void) +{ + /* InitBasicFS for equal (2): create ext2 on /dev/sda1 */ + { + int r; + suppress_error = 0; + r = guestfs_umount_all (g); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_lvm_remove_all (g); + if (r == -1) + return -1; + } + { + char *lines[] = { + ",", + NULL + }; + int r; + suppress_error = 0; + r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_mkfs (g, "ext2", "/dev/sda1"); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_mount (g, "/dev/sda1", "/"); + if (r == -1) + return -1; + } + /* TestLastFail for equal (2) */ + { + int r; + suppress_error = 1; + r = guestfs_equal (g, "/file1", "/file2"); + if (r != -1) + return -1; + } + return 0; +} + static int test_ping_daemon_0 (void) { /* InitEmpty for ping_daemon (0) */ @@ -7320,9 +7515,27 @@ int main (int argc, char *argv[]) exit (1); } - nr_tests = 104; + nr_tests = 107; test_num++; + printf ("%3d/%3d test_equal_0\n", test_num, nr_tests); + if (test_equal_0 () == -1) { + printf ("test_equal_0 FAILED\n"); + failed++; + } + test_num++; + printf ("%3d/%3d test_equal_1\n", test_num, nr_tests); + if (test_equal_1 () == -1) { + printf ("test_equal_1 FAILED\n"); + failed++; + } + test_num++; + printf ("%3d/%3d test_equal_2\n", test_num, nr_tests); + if (test_equal_2 () == -1) { + printf ("test_equal_2 FAILED\n"); + failed++; + } + test_num++; printf ("%3d/%3d test_ping_daemon_0\n", test_num, nr_tests); if (test_ping_daemon_0 () == -1) { printf ("test_ping_daemon_0 FAILED\n");