tests: Add unit tests for permissions
authorSebastian Rasmussen <sebras@hotmail.com>
Sat, 19 Oct 2013 15:36:05 +0000 (17:36 +0200)
committerWim Taymans <wim.taymans@gmail.com>
Tue, 12 Nov 2013 08:54:46 +0000 (09:54 +0100)
Fixes https://bugzilla.gnome.org/show_bug.cgi?id=710202

tests/check/Makefile.am
tests/check/gst/permissions.c [new file with mode: 0644]

index 54aa0df..49675bd 100644 (file)
@@ -33,6 +33,7 @@ check_PROGRAMS = \
        gst/media \
        gst/addresspool \
        gst/threadpool
+       gst/permissions
 
 # these tests don't even pass
 noinst_PROGRAMS =
diff --git a/tests/check/gst/permissions.c b/tests/check/gst/permissions.c
new file mode 100644 (file)
index 0000000..0dcf770
--- /dev/null
@@ -0,0 +1,107 @@
+/* GStreamer
+ * Copyright (C) 2013 Sebastian Rasmussen <sebras@hotmail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include <gst/check/gstcheck.h>
+
+#include <rtsp-permissions.h>
+
+GST_START_TEST (test_permissions)
+{
+  GstRTSPPermissions *perms;
+  GstRTSPPermissions *copy;
+
+  perms = gst_rtsp_permissions_new ();
+  fail_if (gst_rtsp_permissions_is_allowed (perms, "missing", "permission1"));
+  gst_rtsp_permissions_unref (perms);
+
+  perms = gst_rtsp_permissions_new ();
+  gst_rtsp_permissions_add_role (perms, "user",
+      "permission1", G_TYPE_BOOLEAN, TRUE,
+      "permission2", G_TYPE_BOOLEAN, FALSE, NULL);
+  fail_unless (gst_rtsp_permissions_is_allowed (perms, "user", "permission1"));
+  fail_if (gst_rtsp_permissions_is_allowed (perms, "user", "permission2"));
+  fail_if (gst_rtsp_permissions_is_allowed (perms, "user", "missing"));
+  fail_if (gst_rtsp_permissions_is_allowed (perms, "missing", "permission1"));
+  copy = GST_RTSP_PERMISSIONS (gst_mini_object_copy (GST_MINI_OBJECT (perms)));
+  gst_rtsp_permissions_unref (perms);
+  fail_unless (gst_rtsp_permissions_is_allowed (copy, "user", "permission1"));
+  fail_if (gst_rtsp_permissions_is_allowed (copy, "user", "permission2"));
+  gst_rtsp_permissions_unref (copy);
+
+  perms = gst_rtsp_permissions_new ();
+  gst_rtsp_permissions_add_role (perms, "admin",
+      "permission1", G_TYPE_BOOLEAN, TRUE,
+      "permission2", G_TYPE_BOOLEAN, TRUE, NULL);
+  gst_rtsp_permissions_add_role (perms, "user",
+      "permission1", G_TYPE_BOOLEAN, TRUE,
+      "permission2", G_TYPE_BOOLEAN, FALSE, NULL);
+  fail_unless (gst_rtsp_permissions_is_allowed (perms, "admin", "permission1"));
+  fail_unless (gst_rtsp_permissions_is_allowed (perms, "admin", "permission2"));
+  fail_unless (gst_rtsp_permissions_is_allowed (perms, "user", "permission1"));
+  fail_if (gst_rtsp_permissions_is_allowed (perms, "user", "permission2"));
+  gst_rtsp_permissions_unref (perms);
+
+  perms = gst_rtsp_permissions_new ();
+  gst_rtsp_permissions_add_role (perms, "user",
+      "permission1", G_TYPE_BOOLEAN, TRUE,
+      "permission2", G_TYPE_BOOLEAN, FALSE, NULL);
+  fail_unless (gst_rtsp_permissions_is_allowed (perms, "user", "permission1"));
+  fail_if (gst_rtsp_permissions_is_allowed (perms, "user", "permission2"));
+  gst_rtsp_permissions_add_role (perms, "user",
+      "permission1", G_TYPE_BOOLEAN, FALSE,
+      "permission2", G_TYPE_BOOLEAN, TRUE, NULL);
+  fail_if (gst_rtsp_permissions_is_allowed (perms, "user", "permission1"));
+  fail_unless (gst_rtsp_permissions_is_allowed (perms, "user", "permission2"));
+  gst_rtsp_permissions_unref (perms);
+
+  perms = gst_rtsp_permissions_new ();
+  gst_rtsp_permissions_add_role (perms, "admin",
+      "permission1", G_TYPE_BOOLEAN, TRUE,
+      "permission2", G_TYPE_BOOLEAN, TRUE, NULL);
+  gst_rtsp_permissions_add_role (perms, "user",
+      "permission1", G_TYPE_BOOLEAN, TRUE,
+      "permission2", G_TYPE_BOOLEAN, FALSE, NULL);
+  fail_unless (gst_rtsp_permissions_is_allowed (perms, "admin", "permission1"));
+  fail_unless (gst_rtsp_permissions_is_allowed (perms, "admin", "permission2"));
+  fail_unless (gst_rtsp_permissions_is_allowed (perms, "user", "permission1"));
+  fail_if (gst_rtsp_permissions_is_allowed (perms, "user", "permission2"));
+  gst_rtsp_permissions_remove_role (perms, "user");
+  fail_unless (gst_rtsp_permissions_is_allowed (perms, "admin", "permission1"));
+  fail_unless (gst_rtsp_permissions_is_allowed (perms, "admin", "permission2"));
+  fail_if (gst_rtsp_permissions_is_allowed (perms, "user", "permission1"));
+  fail_if (gst_rtsp_permissions_is_allowed (perms, "user", "permission2"));
+  gst_rtsp_permissions_unref (perms);
+}
+
+GST_END_TEST;
+
+static Suite *
+rtsppermissions_suite (void)
+{
+  Suite *s = suite_create ("rtsppermissions");
+  TCase *tc = tcase_create ("general");
+
+  suite_add_tcase (s, tc);
+  tcase_set_timeout (tc, 20);
+  tcase_add_test (tc, test_permissions);
+
+  return s;
+}
+
+GST_CHECK_MAIN (rtsppermissions);