summaryrefslogtreecommitdiffstats
path: root/tests.c
diff options
context:
space:
mode:
authorRichard Jones <rjones@redhat.com>2009-05-08 14:28:03 +0100
committerRichard Jones <rjones@redhat.com>2009-05-08 14:28:03 +0100
commit0faa5dde7b992ba11bb88f77b3424676c7c492e4 (patch)
tree14948be793fca09223d7ca3022b9ac7e1fbebd81 /tests.c
parentfa7c8bb79b45aecdf65ed93635a42f3fdf301134 (diff)
downloadlibguestfs-0faa5dde7b992ba11bb88f77b3424676c7c492e4.tar.gz
libguestfs-0faa5dde7b992ba11bb88f77b3424676c7c492e4.tar.xz
libguestfs-0faa5dde7b992ba11bb88f77b3424676c7c492e4.zip
Generated code to support previous 2 commits.
Diffstat (limited to 'tests.c')
-rw-r--r--tests.c312
1 files changed, 311 insertions, 1 deletions
diff --git a/tests.c b/tests.c
index a8564e1e..31235135 100644
--- a/tests.c
+++ b/tests.c
@@ -117,6 +117,298 @@ static void no_test_warnings (void)
fprintf (stderr, "warning: \"guestfs_get_e2uuid\" has no tests\n");
}
+static int test_hexdump_0 (void)
+{
+ /* InitBasicFS for hexdump (0): create ext2 on /dev/sda1 */
+ {
+ char device[] = "/dev/sda";
+ device[5] = devchar;
+ int r;
+ suppress_error = 0;
+ r = guestfs_blockdev_setrw (g, device);
+ if (r == -1)
+ return -1;
+ }
+ {
+ 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 device[] = "/dev/sda";
+ device[5] = devchar;
+ char lines_0[] = ",";
+ char *lines[] = {
+ lines_0,
+ NULL
+ };
+ int r;
+ suppress_error = 0;
+ r = guestfs_sfdisk (g, device, 0, 0, 0, lines);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char fstype[] = "ext2";
+ char device[] = "/dev/sda1";
+ device[5] = devchar;
+ int r;
+ suppress_error = 0;
+ r = guestfs_mkfs (g, fstype, device);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char device[] = "/dev/sda1";
+ device[5] = devchar;
+ char mountpoint[] = "/";
+ int r;
+ suppress_error = 0;
+ r = guestfs_mount (g, device, mountpoint);
+ if (r == -1)
+ return -1;
+ }
+ /* TestOutput for hexdump (0) */
+ char expected[] = "00000000 68 65 6c 6c 6f 0a 77 6f 72 6c 64 0a |hello.world.|\n0000000c\n";
+ {
+ char path[] = "/new";
+ char content[] = "hello\nworld\n";
+ int r;
+ suppress_error = 0;
+ r = guestfs_write_file (g, path, content, 12);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char path[] = "/new";
+ char *r;
+ suppress_error = 0;
+ r = guestfs_hexdump (g, path);
+ if (r == NULL)
+ return -1;
+ if (strcmp (r, expected) != 0) {
+ fprintf (stderr, "test_hexdump_0: expected \"%s\" but got \"%s\"\n", expected, r);
+ return -1;
+ }
+ free (r);
+ }
+ return 0;
+}
+
+static int test_strings_e_0 (void)
+{
+ /* InitBasicFS for strings_e (0): create ext2 on /dev/sda1 */
+ {
+ char device[] = "/dev/sda";
+ device[5] = devchar;
+ int r;
+ suppress_error = 0;
+ r = guestfs_blockdev_setrw (g, device);
+ if (r == -1)
+ return -1;
+ }
+ {
+ 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 device[] = "/dev/sda";
+ device[5] = devchar;
+ char lines_0[] = ",";
+ char *lines[] = {
+ lines_0,
+ NULL
+ };
+ int r;
+ suppress_error = 0;
+ r = guestfs_sfdisk (g, device, 0, 0, 0, lines);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char fstype[] = "ext2";
+ char device[] = "/dev/sda1";
+ device[5] = devchar;
+ int r;
+ suppress_error = 0;
+ r = guestfs_mkfs (g, fstype, device);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char device[] = "/dev/sda1";
+ device[5] = devchar;
+ char mountpoint[] = "/";
+ int r;
+ suppress_error = 0;
+ r = guestfs_mount (g, device, mountpoint);
+ if (r == -1)
+ return -1;
+ }
+ /* TestOutputList for strings_e (0) */
+ {
+ char path[] = "/new";
+ char content[] = "hello\nworld\n";
+ int r;
+ suppress_error = 0;
+ r = guestfs_write_file (g, path, content, 0);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char encoding[] = "b";
+ char path[] = "/new";
+ char **r;
+ int i;
+ suppress_error = 0;
+ r = guestfs_strings_e (g, encoding, path);
+ if (r == NULL)
+ return -1;
+ if (r[0] != NULL) {
+ fprintf (stderr, "test_strings_e_0: extra elements returned from command\n");
+ print_strings (r);
+ return -1;
+ }
+ for (i = 0; r[i] != NULL; ++i)
+ free (r[i]);
+ free (r);
+ }
+ return 0;
+}
+
+static int test_strings_0 (void)
+{
+ /* InitBasicFS for strings (0): create ext2 on /dev/sda1 */
+ {
+ char device[] = "/dev/sda";
+ device[5] = devchar;
+ int r;
+ suppress_error = 0;
+ r = guestfs_blockdev_setrw (g, device);
+ if (r == -1)
+ return -1;
+ }
+ {
+ 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 device[] = "/dev/sda";
+ device[5] = devchar;
+ char lines_0[] = ",";
+ char *lines[] = {
+ lines_0,
+ NULL
+ };
+ int r;
+ suppress_error = 0;
+ r = guestfs_sfdisk (g, device, 0, 0, 0, lines);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char fstype[] = "ext2";
+ char device[] = "/dev/sda1";
+ device[5] = devchar;
+ int r;
+ suppress_error = 0;
+ r = guestfs_mkfs (g, fstype, device);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char device[] = "/dev/sda1";
+ device[5] = devchar;
+ char mountpoint[] = "/";
+ int r;
+ suppress_error = 0;
+ r = guestfs_mount (g, device, mountpoint);
+ if (r == -1)
+ return -1;
+ }
+ /* TestOutputList for strings (0) */
+ {
+ char path[] = "/new";
+ char content[] = "hello\nworld\n";
+ int r;
+ suppress_error = 0;
+ r = guestfs_write_file (g, path, content, 0);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char path[] = "/new";
+ char **r;
+ int i;
+ suppress_error = 0;
+ r = guestfs_strings (g, path);
+ if (r == NULL)
+ return -1;
+ if (!r[0]) {
+ fprintf (stderr, "test_strings_0: short list returned from command\n");
+ print_strings (r);
+ return -1;
+ }
+ {
+ char expected[] = "hello";
+ if (strcmp (r[0], expected) != 0) {
+ fprintf (stderr, "test_strings_0: expected \"%s\" but got \"%s\"\n", expected, r[0]);
+ return -1;
+ }
+ }
+ if (!r[1]) {
+ fprintf (stderr, "test_strings_0: short list returned from command\n");
+ print_strings (r);
+ return -1;
+ }
+ {
+ char expected[] = "world";
+ if (strcmp (r[1], expected) != 0) {
+ fprintf (stderr, "test_strings_0: expected \"%s\" but got \"%s\"\n", expected, r[1]);
+ return -1;
+ }
+ }
+ if (r[2] != NULL) {
+ fprintf (stderr, "test_strings_0: extra elements returned from command\n");
+ print_strings (r);
+ return -1;
+ }
+ for (i = 0; r[i] != NULL; ++i)
+ free (r[i]);
+ free (r);
+ }
+ return 0;
+}
+
static int test_equal_0 (void)
{
/* InitBasicFS for equal (0): create ext2 on /dev/sda1 */
@@ -9864,9 +10156,27 @@ int main (int argc, char *argv[])
free (devs[i]);
free (devs);
- nr_tests = 107;
+ nr_tests = 110;
test_num++;
+ printf ("%3d/%3d test_hexdump_0\n", test_num, nr_tests);
+ if (test_hexdump_0 () == -1) {
+ printf ("test_hexdump_0 FAILED\n");
+ failed++;
+ }
+ test_num++;
+ printf ("%3d/%3d test_strings_e_0\n", test_num, nr_tests);
+ if (test_strings_e_0 () == -1) {
+ printf ("test_strings_e_0 FAILED\n");
+ failed++;
+ }
+ test_num++;
+ printf ("%3d/%3d test_strings_0\n", test_num, nr_tests);
+ if (test_strings_0 () == -1) {
+ printf ("test_strings_0 FAILED\n");
+ failed++;
+ }
+ test_num++;
printf ("%3d/%3d test_equal_0\n", test_num, nr_tests);
if (test_equal_0 () == -1) {
printf ("test_equal_0 FAILED\n");