PolicyKit: Branch 'master'

David Zeuthen david at kemper.freedesktop.org
Sat Nov 3 14:36:57 PDT 2007


 polkit/polkit-result.c |   37 +++++++++++++++++++++++++++++++++----
 polkit/polkit-test.c   |    1 +
 polkit/polkit-test.h   |    1 +
 3 files changed, 35 insertions(+), 4 deletions(-)

New commits:
commit 05af4eec1bb980a008f72e687bcf6f7402a74234
Author: David Zeuthen <davidz at redhat.com>
Date:   Sat Nov 3 17:34:33 2007 -0400

    add unit tests for PolKitResult

diff --git a/polkit/polkit-result.c b/polkit/polkit-result.c
index bd12020..eee04c0 100644
--- a/polkit/polkit-result.c
+++ b/polkit/polkit-result.c
@@ -46,12 +46,14 @@
 
 #include <glib.h>
 #include "polkit-result.h"
+#include "polkit-test.h"
+#include "polkit-memory.h"
 
 
 static const struct {
         PolKitResult result;
         const char *str;
-} mapping[] = 
+} mapping[POLKIT_RESULT_N_RESULTS] = 
 {
         {POLKIT_RESULT_UNKNOWN, "unknown"},
         {POLKIT_RESULT_NO, "no"},
@@ -64,7 +66,6 @@ static const struct {
         {POLKIT_RESULT_YES, "yes"},
         {POLKIT_RESULT_ONLY_VIA_ADMIN_AUTH_ONE_SHOT, "auth_admin_one_shot"},
         {POLKIT_RESULT_ONLY_VIA_SELF_AUTH_ONE_SHOT, "auth_self_one_shot"},
-        {0, NULL}
 };
 
 
@@ -109,8 +110,6 @@ polkit_result_from_string_representation (const char *string, PolKitResult *out_
         g_return_val_if_fail (out_result != NULL, FALSE);
 
         for (n = 0; n < POLKIT_RESULT_N_RESULTS; n++) {
-                if (mapping[n].str == NULL)
-                        break;
                 if (strcmp (mapping[n].str, string) == 0) {
                         *out_result = mapping[n].result;
                         goto found;
@@ -121,3 +120,33 @@ polkit_result_from_string_representation (const char *string, PolKitResult *out_
 found:
         return TRUE;
 }
+
+#ifdef POLKIT_BUILD_TESTS
+
+static polkit_bool_t
+_run_test (void)
+{
+        PolKitResult n;
+        PolKitResult m;
+
+        for (n = 0; n < POLKIT_RESULT_N_RESULTS; n++) {
+                g_assert (polkit_result_from_string_representation (polkit_result_to_string_representation (n), &m) && n== m);
+        }
+
+        g_assert (polkit_result_to_string_representation ((PolKitResult) -1) == NULL);
+        g_assert (polkit_result_to_string_representation (POLKIT_RESULT_N_RESULTS) == NULL);
+
+        g_assert (! polkit_result_from_string_representation ("non-exiting-result-id", &m));
+
+
+        return TRUE;
+}
+
+PolKitTest _test_result = {
+        "polkit_result",
+        NULL,
+        NULL,
+        _run_test
+};
+
+#endif /* POLKIT_BUILD_TESTS */
diff --git a/polkit/polkit-test.c b/polkit/polkit-test.c
index 50b3142..ac85456 100644
--- a/polkit/polkit-test.c
+++ b/polkit/polkit-test.c
@@ -33,6 +33,7 @@
 static PolKitTest *tests[] = {
         &_test_action,
         &_test_error,
+        &_test_result,
 };
 
 int 
diff --git a/polkit/polkit-test.h b/polkit/polkit-test.h
index aace39d..2493451 100644
--- a/polkit/polkit-test.h
+++ b/polkit/polkit-test.h
@@ -46,6 +46,7 @@ typedef struct {
 
 extern PolKitTest _test_action;
 extern PolKitTest _test_error;
+extern PolKitTest _test_result;
 
 POLKIT_END_DECLS
 


More information about the hal-commit mailing list