add debugging category use GST_START_TEST now, so we add a debug line
[platform/upstream/gstreamer.git] / tests / check / gst / gstcaps.c
1 /* GStreamer
2  * Copyright (C) 2005 Andy Wingo <wingo@pobox.com>
3  * Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org>
4  *
5  * gstcaps.c: Unit test for GstCaps
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23
24 #include "../gstcheck.h"
25 #include "capslist.h"
26
27 GST_START_TEST (test_from_string)
28 {
29   GstCaps *caps;
30   int i;
31
32   for (i = 0; i < G_N_ELEMENTS (caps_list); i++) {
33     caps = gst_caps_from_string (caps_list[i]);
34     fail_if (caps == NULL,
35         "Could not create caps from string %s\n", caps_list[i]);
36     g_free (caps);
37   }
38 }
39
40 GST_END_TEST;
41
42 GST_START_TEST (test_buffer)
43 {
44   GstCaps *c1;
45   GstBuffer *buffer;
46
47   buffer = gst_buffer_new_and_alloc (1000);
48   c1 = gst_caps_new_simple ("audio/x-raw-int",
49       "buffer", GST_TYPE_BUFFER, buffer, NULL);
50
51   GST_DEBUG ("caps: %" GST_PTR_FORMAT, c1);
52
53   gst_buffer_unref (buffer);
54 }
55
56 GST_END_TEST;
57
58 GST_START_TEST (test_double_append)
59 {
60   GstStructure *s1;
61   GstCaps *c1;
62
63   c1 = gst_caps_new_any ();
64   s1 = gst_structure_from_string ("audio/x-raw-int,rate=44100", NULL);
65   gst_caps_append_structure (c1, s1);
66   ASSERT_CRITICAL (gst_caps_append_structure (c1, s1));
67 }
68
69 GST_END_TEST;
70
71 GST_START_TEST (test_mutability)
72 {
73   GstStructure *s1;
74   GstCaps *c1;
75   gint ret;
76
77   c1 = gst_caps_new_any ();
78   s1 = gst_structure_from_string ("audio/x-raw-int,rate=44100", NULL);
79   gst_structure_set (s1, "rate", G_TYPE_INT, 48000, NULL);
80   gst_caps_append_structure (c1, s1);
81   gst_structure_set (s1, "rate", G_TYPE_INT, 22500, NULL);
82   gst_caps_ref (c1);
83   ASSERT_CRITICAL (gst_structure_set (s1, "rate", G_TYPE_INT, 11250, NULL));
84   fail_unless (gst_structure_get_int (s1, "rate", &ret));
85   fail_unless (ret == 22500);
86   ASSERT_CRITICAL (gst_caps_set_simple (c1, "rate", G_TYPE_INT, 11250, NULL));
87   fail_unless (gst_structure_get_int (s1, "rate", &ret));
88   fail_unless (ret == 22500);
89   gst_caps_unref (c1);
90   gst_structure_set (s1, "rate", G_TYPE_INT, 11250, NULL);
91   fail_unless (gst_structure_get_int (s1, "rate", &ret));
92   fail_unless (ret == 11250);
93   gst_caps_set_simple (c1, "rate", G_TYPE_INT, 1, NULL);
94   fail_unless (gst_structure_get_int (s1, "rate", &ret));
95   fail_unless (ret == 1);
96 }
97
98 GST_END_TEST;
99
100 Suite *
101 gst_caps_suite (void)
102 {
103   Suite *s = suite_create ("GstCaps");
104   TCase *tc_chain = tcase_create ("mutability");
105
106   suite_add_tcase (s, tc_chain);
107   tcase_add_test (tc_chain, test_from_string);
108   tcase_add_test (tc_chain, test_double_append);
109   tcase_add_test (tc_chain, test_mutability);
110   tcase_add_test (tc_chain, test_buffer);
111   return s;
112 }
113
114 int
115 main (int argc, char **argv)
116 {
117   int nf;
118
119   Suite *s = gst_caps_suite ();
120   SRunner *sr = srunner_create (s);
121
122   gst_check_init (&argc, &argv);
123
124   srunner_run_all (sr, CK_NORMAL);
125   nf = srunner_ntests_failed (sr);
126   srunner_free (sr);
127
128   return nf;
129 }