PolicyKit: Branch 'master'

David Zeuthen david at kemper.freedesktop.org
Sat Nov 3 14:52:59 PDT 2007


 polkit/polkit-seat.c |   63 ++++++++++++++++++++++++++++++++++++++++++++++-----
 polkit/polkit-test.c |    1 
 polkit/polkit-test.h |    1 
 3 files changed, 59 insertions(+), 6 deletions(-)

New commits:
commit ed968d50f1c31849219adff04369d5aeb7082fb2
Author: David Zeuthen <davidz at redhat.com>
Date:   Sat Nov 3 17:50:35 2007 -0400

    add unit tests for PolKitSeat

diff --git a/polkit/polkit-seat.c b/polkit/polkit-seat.c
index b6e3269..0056da9 100644
--- a/polkit/polkit-seat.c
+++ b/polkit/polkit-seat.c
@@ -40,6 +40,8 @@
 #include "polkit-debug.h"
 #include "polkit-seat.h"
 #include "polkit-utils.h"
+#include "polkit-test.h"
+#include "polkit-memory.h"
 
 /**
  * SECTION:polkit-seat
@@ -72,8 +74,11 @@ PolKitSeat *
 polkit_seat_new (void)
 {
         PolKitSeat *seat;
-        seat = g_new0 (PolKitSeat, 1);
+        seat = p_new0 (PolKitSeat, 1);
+        if (seat == NULL)
+                goto out;
         seat->refcount = 1;
+out:
         return seat;
 }
 
@@ -108,8 +113,8 @@ polkit_seat_unref (PolKitSeat *seat)
         seat->refcount--;
         if (seat->refcount > 0) 
                 return;
-        g_free (seat->ck_objref);
-        g_free (seat);
+        p_free (seat->ck_objref);
+        p_free (seat);
 }
 
 /**
@@ -127,9 +132,12 @@ polkit_seat_set_ck_objref (PolKitSeat *seat, const char *ck_objref)
         g_return_val_if_fail (seat != NULL, FALSE);
         g_return_val_if_fail (_pk_validate_identifier (ck_objref), FALSE);
         if (seat->ck_objref != NULL)
-                g_free (seat->ck_objref);
-        seat->ck_objref = g_strdup (ck_objref);
-        return TRUE;
+                p_free (seat->ck_objref);
+        seat->ck_objref = p_strdup (ck_objref);
+        if (seat->ck_objref == NULL)
+                return FALSE;
+        else
+                return TRUE;
 }
 
 /**
@@ -178,3 +186,46 @@ polkit_seat_validate (PolKitSeat *seat)
         g_return_val_if_fail (seat->ck_objref != NULL, FALSE);
         return TRUE;
 }
+
+#ifdef POLKIT_BUILD_TESTS
+
+static polkit_bool_t
+_run_test (void)
+{
+        char *str;
+        PolKitSeat *s;
+
+        s = polkit_seat_new ();
+        if (s == NULL) {
+                /* OOM */
+        } else {
+                if (! polkit_seat_set_ck_objref (s, "/someseat")) {
+                        /* OOM */
+                } else {
+                        g_assert (polkit_seat_get_ck_objref (s, &str) && strcmp (str, "/someseat") == 0);
+                        g_assert (polkit_seat_validate (s));
+                        polkit_seat_ref (s);
+                        g_assert (polkit_seat_validate (s));
+                        polkit_seat_unref (s);
+                        g_assert (polkit_seat_validate (s));
+                        polkit_seat_debug (s);
+                        if (! polkit_seat_set_ck_objref (s, "/someseat2")) {
+                                /* OOM */
+                        } else {
+                                g_assert (polkit_seat_get_ck_objref (s, &str) && strcmp (str, "/someseat2") == 0);
+                        }
+                }
+                polkit_seat_unref (s);
+        }
+
+        return TRUE;
+}
+
+PolKitTest _test_seat = {
+        "polkit_seat",
+        NULL,
+        NULL,
+        _run_test
+};
+
+#endif /* POLKIT_BUILD_TESTS */
diff --git a/polkit/polkit-test.c b/polkit/polkit-test.c
index ac85456..c2008ae 100644
--- a/polkit/polkit-test.c
+++ b/polkit/polkit-test.c
@@ -34,6 +34,7 @@ static PolKitTest *tests[] = {
         &_test_action,
         &_test_error,
         &_test_result,
+        &_test_seat,
 };
 
 int 
diff --git a/polkit/polkit-test.h b/polkit/polkit-test.h
index 2493451..59116cb 100644
--- a/polkit/polkit-test.h
+++ b/polkit/polkit-test.h
@@ -47,6 +47,7 @@ typedef struct {
 extern PolKitTest _test_action;
 extern PolKitTest _test_error;
 extern PolKitTest _test_result;
+extern PolKitTest _test_seat;
 
 POLKIT_END_DECLS
 


More information about the hal-commit mailing list