Policy element integration
[profile/ivi/gst-plugins-base.git] / tests / check / elements / policy.c
1 /* GStreamer
2  * Copyright (C) <2012> Intel Corporation
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #include <gst/check/gstcheck.h>
21 #include <gst/policy/gstpolicy.h>
22
23
24 static void
25 test_pads (GstElement * policy)
26 {
27   GstPad *sinkpad1;
28   GstPad *sinkpad2;
29
30   sinkpad1 = gst_element_get_request_pad (policy, "sink_%d");
31  
32   assert_equals_int (policy->numpads, 2);
33   assert_equals_int (policy->numsinkpads, 1);
34   assert_equals_int (policy->numsrcpads, 1);
35
36   sinkpad2 = gst_element_get_request_pad (policy, "sink_%d");
37
38   assert_equals_int (policy->numpads, 4);
39   assert_equals_int (policy->numsinkpads, 2);
40   assert_equals_int (policy->numsrcpads, 2);
41
42   gst_element_release_request_pad (policy, sinkpad2);
43   g_object_unref (sinkpad2);
44   assert_equals_int (policy->numpads, 2);
45   assert_equals_int (policy->numsinkpads, 1);
46   assert_equals_int (policy->numsrcpads, 1);
47
48   gst_element_release_request_pad (policy, sinkpad1);
49   g_object_unref (sinkpad1);
50   assert_equals_int (policy->numpads, 0);
51   assert_equals_int (policy->numsinkpads, 0);
52   assert_equals_int (policy->numsrcpads, 0);
53 }
54
55 GST_START_TEST (test_autopolicy)
56 {
57   GstElement *policy;
58   const gchar *role1;
59   gchar *role2;
60
61   policy = gst_check_setup_element ("autopolicy");
62
63   test_pads (policy);
64
65   role1 = "megarole";
66   gst_child_proxy_set (GST_OBJECT (policy), "actual-policy::role", role1,
67       NULL);
68   gst_child_proxy_get (GST_OBJECT (policy), "actual-policy::role", &role2,
69       NULL);
70   assert_equals_string (role1, role2);
71   g_free (role2);
72
73   gst_check_teardown_element (policy);
74 }
75
76 GST_END_TEST;
77
78
79 GST_START_TEST (test_defaultpolicy)
80 {
81   GstElement *policy;
82   const gchar *role1;
83   gchar *role2;
84
85   policy = gst_check_setup_element ("defaultpolicy");
86
87   test_pads (policy);
88
89   role1 = "megarole";
90   g_object_set (policy, "role", role1, NULL);
91   g_object_get (policy, "role", &role2, NULL);
92   assert_equals_string (role1, role2);
93   g_free (role2);
94
95   gst_check_teardown_element (policy);
96 }
97
98 GST_END_TEST;
99
100 static Suite *
101 policy_suite (void)
102 {
103   Suite *s = suite_create ("policy");
104   TCase *tc_chain = tcase_create ("general");
105
106   suite_add_tcase (s, tc_chain);
107   tcase_add_test (tc_chain, test_defaultpolicy);
108   tcase_add_test (tc_chain, test_autopolicy);
109
110   return s;
111 }
112
113 GST_CHECK_MAIN (policy);