Please find attached a patch introducing a new test for ped_disk_probe.

+                probed = ped_disk_probe (dev);
+                fail_if (!probed,
+                         "Failed to probe the just created label of type: %s",
+                         type->name);
+                fail_if (strcmp (probed->name, type->name) != 0,
+                         "Probe returned label of type: %s as type: %s",
+                         type->name, probed->name);

I have added the second fail_if to make sure that ped_disk_probe
actually detects the correct disk label type. A failure would indicate
a mismatch in ped_disk_new_fresh and ped_disk_probe.

What do you think?

Happy hacking,
Debarshi
--
GPG key ID: 63D4A5A7
Key server: pgp.mit.edu
diff --git a/libparted/tests/label.c b/libparted/tests/label.c
index 9338de5..898dbe3 100644
--- a/libparted/tests/label.c
+++ b/libparted/tests/label.c
@@ -52,6 +52,38 @@ START_TEST (test_create_label)
 }
 END_TEST
 
+/* TEST: Probe the disk label of a loop device. */
+START_TEST (test_probe_label)
+{
+        PedDevice* dev = ped_device_get (temporary_disk);
+        if (dev == NULL)
+                return;
+
+        PedDiskType* probed;
+        PedDiskType* type;
+        PedDisk* disk;
+
+        for (type = ped_disk_type_get_next (NULL); type;
+             type = ped_disk_type_get_next (type)) {
+                if (!_implemented_disk_label (type->name))
+                        continue;
+
+                disk = _create_disk_label (dev, type);
+                ped_disk_destroy (disk);
+
+                /* Try to probe the disk label. */
+                probed = ped_disk_probe (dev);
+                fail_if (!probed,
+                         "Failed to probe the just created label of type: %s",
+                         type->name);
+                fail_if (strcmp (probed->name, type->name) != 0,
+                         "Probe returned label of type: %s as type: %s",
+                         type->name, probed->name);
+        }
+        ped_device_destroy (dev);
+}
+END_TEST
+
 /* TEST: Clone the disk label of a loop device. */
 START_TEST (test_clone_label)
 {
@@ -89,6 +121,7 @@ main (void)
         int number_failed;
         Suite* suite = suite_create ("Disk Label");
         TCase* tcase_basic = tcase_create ("Create");
+        TCase* tcase_probe = tcase_create ("Probe");
         TCase* tcase_clone = tcase_create ("Clone");
 
         /* Fail when an exception is raised */
@@ -100,6 +133,12 @@ main (void)
         tcase_set_timeout (tcase_basic, 0);
         suite_add_tcase (suite, tcase_basic);
 
+        tcase_add_checked_fixture (tcase_probe, create_disk, destroy_disk);
+        tcase_add_test (tcase_probe, test_probe_label);
+        /* Disable timeout for this test. */
+        tcase_set_timeout (tcase_probe, 0);
+        suite_add_tcase (suite, tcase_probe);
+
         tcase_add_checked_fixture (tcase_clone, create_disk, destroy_disk);
         tcase_add_test (tcase_clone, test_clone_label);
         /* Disable timeout for this test. */
_______________________________________________
parted-devel mailing list
[email protected]
http://lists.alioth.debian.org/mailman/listinfo/parted-devel

Reply via email to