[Parted-commits] GNU Parted Official Repository: Changes to 'stable-1.8.x'

Otavio Salvador otavio at alioth.debian.org
Fri Apr 20 15:02:05 UTC 2007


 libparted/tests/common.c |   44 ++++++++++++++++-
 libparted/tests/common.h |   22 ++++++++
 libparted/tests/label.c  |  115 +++++++++++++++++++++++++++++++----------------
 parted/parted.c          |   42 ++++++++++++-----
 4 files changed, 170 insertions(+), 53 deletions(-)

New commits:
commit 4263c3a15f39d0dca01b35d671b44c60f4110db5
Author: Otavio Salvador <otavio at ossystems.com.br>
Date:   Fri Apr 20 03:53:18 2007 -0300

    [tests] Simplify test_clone_label removing the label reading test
    
    Since the test_create_label already tests the label reading we
    shouldn't redo it. It's always better to have simple tests so is much
    easier to find the bugs.
    
    Signed-off-by: Otavio Salvador <otavio at ossystems.com.br>
    (cherry picked from commit 5650695a9abf63c3930b0f5f44352b4e2a5469dc)

diff --git a/libparted/tests/label.c b/libparted/tests/label.c
index fe3b971..9338de5 100644
--- a/libparted/tests/label.c
+++ b/libparted/tests/label.c
@@ -69,13 +69,6 @@ START_TEST (test_clone_label)
                         continue;
 
                 disk = _create_disk_label (dev, type);
-                ped_disk_destroy (disk);
-
-                /* Try to read the disk label. */
-                disk = ped_disk_new (dev);
-                fail_if (!disk,
-                         "Failed to read the just created label of type: %s",
-                         type->name);
 
                 /* Try to clone the disk label. */
                 clone = ped_disk_duplicate (disk);

commit 9b1ad1dc13f5f427c03b77d07a024e830c977a17
Author: Otavio Salvador <otavio at ossystems.com.br>
Date:   Fri Apr 20 00:37:07 2007 -0300

    [tests] Trivial coding style fixes around the tests code
    
    Signed-off-by: Otavio Salvador <otavio at ossystems.com.br>
    (cherry picked from commit 5c438aee9b6fc699b5e4bb9adcbe2ed13c87f202)

diff --git a/libparted/tests/label.c b/libparted/tests/label.c
index 4d04753..fe3b971 100644
--- a/libparted/tests/label.c
+++ b/libparted/tests/label.c
@@ -44,7 +44,7 @@ START_TEST (test_create_label)
                 /* Try to read the label */
                 disk = ped_disk_new (dev);
                 fail_if (!disk,
-			 "Failed to read the just created label of type: %s",
+                         "Failed to read the just created label of type: %s",
                          type->name);
                 ped_disk_destroy (disk);
         }

commit 9365c83cf57ca287a481f44b9a1e907994bb9b41
Author: Debarshi Ray <rishi at gnu.org>
Date:   Fri Apr 20 05:49:44 2007 +0530

    [tests] New test for cloning of disk labels.
    (cherry picked from commit a46cc7578fd2ff478b6e83850e06b73fe42911b1)

diff --git a/libparted/tests/label.c b/libparted/tests/label.c
index 7417324..4d04753 100644
--- a/libparted/tests/label.c
+++ b/libparted/tests/label.c
@@ -52,12 +52,51 @@ START_TEST (test_create_label)
 }
 END_TEST
 
+/* TEST: Clone the disk label of a loop device. */
+START_TEST (test_clone_label)
+{
+        PedDevice* dev = ped_device_get (temporary_disk);
+        if (dev == NULL)
+                return;
+
+        PedDiskType* type;
+        PedDisk* clone;
+        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 read the disk label. */
+                disk = ped_disk_new (dev);
+                fail_if (!disk,
+                         "Failed to read the just created label of type: %s",
+                         type->name);
+
+                /* Try to clone the disk label. */
+                clone = ped_disk_duplicate (disk);
+                fail_if (!clone,
+                         "Failed to clone the just created label of type: %s",
+                         type->name);
+
+                ped_disk_destroy (clone);
+                ped_disk_destroy (disk);
+        }
+        ped_device_destroy (dev);
+}
+END_TEST
+
 int
 main (void)
 {
         int number_failed;
         Suite* suite = suite_create ("Disk Label");
         TCase* tcase_basic = tcase_create ("Create");
+        TCase* tcase_clone = tcase_create ("Clone");
 
         /* Fail when an exception is raised */
         ped_exception_set_handler (_test_exception_handler);
@@ -68,6 +107,12 @@ main (void)
         tcase_set_timeout (tcase_basic, 0);
         suite_add_tcase (suite, tcase_basic);
 
+        tcase_add_checked_fixture (tcase_clone, create_disk, destroy_disk);
+        tcase_add_test (tcase_clone, test_clone_label);
+        /* Disable timeout for this test. */
+        tcase_set_timeout (tcase_clone, 0);
+        suite_add_tcase (suite, tcase_clone);
+
         SRunner* srunner = srunner_create (suite);
         srunner_run_all (srunner, CK_VERBOSE);
 

commit bc19c56aad86d4eb7b8bb200b38ee77ff8e4bc29
Author: Otavio Salvador <otavio at ossystems.com.br>
Date:   Thu Apr 19 21:30:53 2007 -0300

    [tests] Add _test_exception_handler to fail every time an exception is raised
    
    Sometimes parts of code raises exceptions and this shouldn't happen on
    tests. To ensure we catch them a specific exception handler has been
    implemented.
    
    The handler usage is very easy. You just need to put the following
    code at testsuite main method:
    
    ...
            /* Fail when an exception is raised */
            ped_exception_set_handler (_test_exception_handler);
    ...
    
    Signed-off-by: Otavio Salvador <otavio at ossystems.com.br>
    (cherry picked from commit cba3a64fb1744f545c373594c8795a4da30558c4)

diff --git a/libparted/tests/common.c b/libparted/tests/common.c
index ab2c0ac..e7ce56f 100644
--- a/libparted/tests/common.c
+++ b/libparted/tests/common.c
@@ -8,6 +8,16 @@
 
 #include "common.h"
 
+PedExceptionOption
+_test_exception_handler (PedException* e)
+{
+        fail ("Exception of type %s has been raised: %s",
+              ped_exception_get_type_string (e->type),
+              e->message);
+
+        return PED_EXCEPTION_UNHANDLED;
+}
+
 char*
 _create_disk (const off_t size)
 {
diff --git a/libparted/tests/common.h b/libparted/tests/common.h
index 91230b1..3fbad73 100644
--- a/libparted/tests/common.h
+++ b/libparted/tests/common.h
@@ -19,3 +19,9 @@ PedDisk* _create_disk_label (PedDevice* dev, PedDiskType* type);
  * label: disk label name
  */
 int _implemented_disk_label (const char* label);
+
+/* Test specific exception handler
+ *
+ */
+PedExceptionOption _test_exception_handler (PedException* e);
+
diff --git a/libparted/tests/label.c b/libparted/tests/label.c
index 563c4eb..7417324 100644
--- a/libparted/tests/label.c
+++ b/libparted/tests/label.c
@@ -59,6 +59,9 @@ main (void)
         Suite* suite = suite_create ("Disk Label");
         TCase* tcase_basic = tcase_create ("Create");
 
+        /* Fail when an exception is raised */
+        ped_exception_set_handler (_test_exception_handler);
+
         tcase_add_checked_fixture (tcase_basic, create_disk, destroy_disk);
         tcase_add_test (tcase_basic, test_create_label);
         /* Disable timeout for this test */

commit dff847674fe48a08dc9ab5c6793d3dd4c8da3a8e
Author: Debarshi Ray <rishi at gnu.org>
Date:   Fri Apr 20 01:00:50 2007 +0530

    [tests] Fix spacing around brackets and asterisks.
    
    Signed-off-by: Otavio Salvador <otavio at ossystems.com.br>
    (cherry picked from commit a1ae8809d111795dcc977e693668bcfaf776fbbe)

diff --git a/libparted/tests/common.c b/libparted/tests/common.c
index 07f716f..ab2c0ac 100644
--- a/libparted/tests/common.c
+++ b/libparted/tests/common.c
@@ -8,9 +8,10 @@
 
 #include "common.h"
 
-char *_create_disk (const off_t size)
+char*
+_create_disk (const off_t size)
 {
-        char *filename = strdup ("parted-test-XXXXXX");
+        char* filename = strdup ("parted-test-XXXXXX");
 
         if (filename == NULL)
                 return NULL;
@@ -22,7 +23,7 @@ char *_create_disk (const off_t size)
                 return NULL;
         }
 
-        FILE *disk = fdopen (fd, "w");
+        FILE* disk = fdopen (fd, "w");
         if (disk == NULL)
                 goto free_filename;
 
@@ -37,24 +38,26 @@ char *_create_disk (const off_t size)
         return filename;
 }
 
-PedDisk *_create_disk_label(PedDevice *dev, PedDiskType *type)
+PedDisk*
+_create_disk_label (PedDevice *dev, PedDiskType *type)
 {
-        PedDisk *disk = NULL;
+        PedDisk* disk = NULL;
 
         /* Create the label */
-        disk = ped_disk_new_fresh(dev, type);
-        fail_if(!disk, "Failed to create a label of type: %s",
-                type->name);
-        fail_if(!ped_disk_commit(disk),
-                "Failed to commit label to device");
+        disk = ped_disk_new_fresh (dev, type);
+        fail_if (!disk, "Failed to create a label of type: %s",
+                 type->name);
+        fail_if (!ped_disk_commit(disk),
+		 "Failed to commit label to device");
 
         return disk;
 }
 
-int _implemented_disk_label (const char *label)
+int
+_implemented_disk_label (const char *label)
 {
         /* Not implemented yet */
-        if (strncmp(label, "aix", 3) == 0)
+        if (strncmp (label, "aix", 3) == 0)
                 return 0;
         
         return 1;
diff --git a/libparted/tests/common.h b/libparted/tests/common.h
index b2b5d3b..91230b1 100644
--- a/libparted/tests/common.h
+++ b/libparted/tests/common.h
@@ -5,17 +5,17 @@
  * filename: file (with full path) where to write the disk image
  *     size: size of disk image (megabytes)
  */
-char *_create_disk(const off_t size);
+char* _create_disk (const off_t size);
 
 /* Create a disk label
  *
  *  dev: device to use when creating the label
  * type: label type
  */
-PedDisk *_create_disk_label(PedDevice *dev, PedDiskType *type);
+PedDisk* _create_disk_label (PedDevice* dev, PedDiskType* type);
 
 /* Return if a disk label is implemented
  *
  * label: disk label name
  */
-int _implemented_disk_label(const char *label);
+int _implemented_disk_label (const char* label);
diff --git a/libparted/tests/label.c b/libparted/tests/label.c
index 244dd5d..563c4eb 100644
--- a/libparted/tests/label.c
+++ b/libparted/tests/label.c
@@ -7,65 +7,69 @@
 
 #include "common.h"
 
-static char *temporary_disk;
+static char* temporary_disk;
 
-static void create_disk(void)
+static void
+create_disk (void)
 {
-        temporary_disk = _create_disk(20);
-        fail_if(temporary_disk == NULL, "Failed to create temporary disk");
+        temporary_disk = _create_disk (20);
+        fail_if (temporary_disk == NULL, "Failed to create temporary disk");
 }
 
-static void destroy_disk(void)
+static void
+destroy_disk (void)
 {
-        unlink(temporary_disk);
-        free(temporary_disk);
+        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);
+        PedDevice* dev = ped_device_get (temporary_disk);
         if (dev == NULL)
                 return;
 
-        PedDiskType *type;
-        PedDisk *disk;
+        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))
+        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 read the label */
-                disk = ped_disk_new(dev);
-                fail_if(!disk,
-                        "Failed to read the just created label of type: %s",
-                        type->name);
-                ped_disk_destroy(disk);
+                disk = ped_disk_new (dev);
+                fail_if (!disk,
+			 "Failed to read the just created label of type: %s",
+                         type->name);
+                ped_disk_destroy (disk);
         }
         ped_device_destroy (dev);
 }
 END_TEST
 
-int main(void)
+int
+main (void)
 {
         int number_failed;
-        Suite *suite = suite_create("Disk Label");
-        TCase *tcase_basic = tcase_create("Create");
+        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);
-        tcase_set_timeout(tcase_basic, 0); /* disable timeout for this tests */
-        suite_add_tcase(suite, tcase_basic);
+        tcase_add_checked_fixture (tcase_basic, create_disk, destroy_disk);
+        tcase_add_test (tcase_basic, test_create_label);
+        /* Disable timeout for this test */
+        tcase_set_timeout (tcase_basic, 0);
+        suite_add_tcase (suite, tcase_basic);
 
-        SRunner *srunner = srunner_create(suite);
-        srunner_run_all(srunner, CK_VERBOSE);
+        SRunner* srunner = srunner_create (suite);
+        srunner_run_all (srunner, CK_VERBOSE);
 
-        number_failed = srunner_ntests_failed(srunner);
-        srunner_free(srunner);
+        number_failed = srunner_ntests_failed (srunner);
+        srunner_free (srunner);
 
         return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
 }

commit 319a886cc97fc1aa11054d839a0da80c3ee1777f
Author: Benno Schulenberg <bensberg at justemail.net>
Date:   Mon Apr 9 23:34:15 2007 +0200

    Handle options independent of their order.
    
    Abort on any invalid option, and handle -v and -h first.
    
    Signed-off-by: Otavio Salvador <otavio at ossystems.com.br>
    (cherry picked from commit b60e2a0cb24272cc9d5af043ab69aa2fba546f93)

diff --git a/parted/parted.c b/parted/parted.c
index 954876a..c4adde0 100644
--- a/parted/parted.c
+++ b/parted/parted.c
@@ -97,6 +97,9 @@ int     opt_machine_mode = 0;
 int     disk_is_modified = 0;
 int     is_toggle_mode = 0;
 
+static char* short_usage_msg =  N_(
+"Usage: parted [-hlmsv] [DEVICE [COMMAND [PARAMETERS]]...]\n");
+
 static char* number_msg = N_(
 "NUMBER is the partition number used by Linux.  On MS-DOS disk labels, the "
 "primary partitions number from 1 to 4, logical partitions from 5 onwards.\n");
@@ -137,7 +140,7 @@ static Command* commands [256] = {NULL};
 static PedTimer* g_timer;
 static TimerContext timer_context;
 
-static int _print_list (int cli);
+static int _print_list ();
 static void _done (PedDevice* dev);
 
 static void
@@ -1314,7 +1317,7 @@ do_print (PedDevice** dev)
         }
 
         else if (has_list_arg) 
-                return _print_list (0);
+                return _print_list ();
 
         else if (has_num_arg) {
                 PedPartition*   part = NULL;
@@ -1533,7 +1536,7 @@ error:
 }
 
 static int
-_print_list (int cli)
+_print_list ()
 {
         PedDevice *current_dev = NULL;
 
@@ -1544,9 +1547,6 @@ _print_list (int cli)
                 putchar ('\n');
         }    
 
-        if(cli)
-                exit(0);
-
         return 1;
 }
 
@@ -2292,13 +2292,12 @@ _version ()
 {
   version_etc (stdout, PROGRAM_NAME, PACKAGE_NAME, VERSION, AUTHORS,
                (char *) NULL);
-  exit (EXIT_SUCCESS);
 }
 
 static int
 _parse_options (int* argc_ptr, char*** argv_ptr)
 {
-int     opt;
+int     opt, help = 0, list = 0, version = 0, wrong = 0;
 
 while (1)
 {
@@ -2308,14 +2307,35 @@ while (1)
                 break;
 
         switch (opt) {
-                case 'h': help_msg (); break;
-                case 'l': _print_list(1); break;
+                case 'h': help = 1; break;
+                case 'l': list = 1; break;
                 case 'm': opt_machine_mode = 1; break;
                 case 's': opt_script_mode = 1; break;
-                case 'v': _version (); break;
+                case 'v': version = 1; break;
+                default:  wrong = 1; break;
         }
 }
 
+if (wrong == 1) {
+        printf (_(short_usage_msg));
+        return 0;
+}
+
+if (version == 1) {
+        _version ();
+        exit (EXIT_SUCCESS);
+}
+
+if (help == 1) {
+        help_msg ();
+        exit (EXIT_SUCCESS);
+}
+
+if (list == 1) {
+        _print_list ();
+        exit (EXIT_SUCCESS);
+}
+
 *argc_ptr -= optind;
 *argv_ptr += optind;
 return 1;

commit 55098d9d232ce7b15280afd5cb5e90673f5615a1
Author: Otavio Salvador <otavio at ossystems.com.br>
Date:   Wed Apr 18 19:37:11 2007 -0300

    [tests] Small refactoring on test_create_label
    
     - Destroy the temporary device once the test has been finished,
     - Use the _implemented_disk_label and _create_disk_label methods
       to avoid code duplication.
    
    Signed-off-by: Otavio Salvador <otavio at ossystems.com.br>
    (cherry picked from commit 0b3cdc7425a3b8d6095c1d0dd4e0d53851c52236)

diff --git a/libparted/tests/common.c b/libparted/tests/common.c
index e22b2ef..07f716f 100644
--- a/libparted/tests/common.c
+++ b/libparted/tests/common.c
@@ -59,5 +59,3 @@ int _implemented_disk_label (const char *label)
         
         return 1;
 }
-
- 
diff --git a/libparted/tests/label.c b/libparted/tests/label.c
index 6accb91..244dd5d 100644
--- a/libparted/tests/label.c
+++ b/libparted/tests/label.c
@@ -33,17 +33,10 @@ START_TEST (test_create_label)
 
         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)
+                if (!_implemented_disk_label(type->name))
                         continue;
 
-                /* Create the label */
-                disk = ped_disk_new_fresh(dev, type);
-                fail_if(!disk, "Failed to create a label of type: %s",
-                        type->name);
-                fail_if(!ped_disk_commit(disk),
-                        "Failed to commit label to device");
+                disk = _create_disk_label (dev, type);
                 ped_disk_destroy (disk);
 
                 /* Try to read the label */
@@ -53,6 +46,7 @@ START_TEST (test_create_label)
                         type->name);
                 ped_disk_destroy(disk);
         }
+        ped_device_destroy (dev);
 }
 END_TEST
 

commit bc00d3be97e5ca55f7028e9ecd05de07fc841d79
Author: Otavio Salvador <otavio at ossystems.com.br>
Date:   Wed Apr 18 19:35:57 2007 -0300

    [tests] Implements _implemented_disk_label and _create_disk_label on common.[hc]
    
     - _implemented_disk_label: returns 0 when we haven't yet implemented
       this specific label and 1 otherwise;
    
     - _create_disk_label: creates a disk label of a specific type on a
       specific device;
    
    Signed-off-by: Otavio Salvador <otavio at ossystems.com.br>
    (cherry picked from commit c70ef4439cc5ea80db950f404ccdc2fef92bd488)

diff --git a/libparted/tests/common.c b/libparted/tests/common.c
index 409f031..e22b2ef 100644
--- a/libparted/tests/common.c
+++ b/libparted/tests/common.c
@@ -4,6 +4,8 @@
 #include <sys/types.h>
 #include <string.h>
 
+#include <check.h>
+
 #include "common.h"
 
 char *_create_disk (const off_t size)
@@ -34,3 +36,28 @@ char *_create_disk (const off_t size)
 
         return filename;
 }
+
+PedDisk *_create_disk_label(PedDevice *dev, PedDiskType *type)
+{
+        PedDisk *disk = NULL;
+
+        /* Create the label */
+        disk = ped_disk_new_fresh(dev, type);
+        fail_if(!disk, "Failed to create a label of type: %s",
+                type->name);
+        fail_if(!ped_disk_commit(disk),
+                "Failed to commit label to device");
+
+        return disk;
+}
+
+int _implemented_disk_label (const char *label)
+{
+        /* Not implemented yet */
+        if (strncmp(label, "aix", 3) == 0)
+                return 0;
+        
+        return 1;
+}
+
+ 
diff --git a/libparted/tests/common.h b/libparted/tests/common.h
index 168175c..b2b5d3b 100644
--- a/libparted/tests/common.h
+++ b/libparted/tests/common.h
@@ -1,7 +1,21 @@
+#include <parted/parted.h>
+
 /* 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);
+
+/* Create a disk label
+ *
+ *  dev: device to use when creating the label
+ * type: label type
+ */
+PedDisk *_create_disk_label(PedDevice *dev, PedDiskType *type);
+
+/* Return if a disk label is implemented
+ *
+ * label: disk label name
+ */
+int _implemented_disk_label(const char *label);



More information about the Parted-commits mailing list