tests: add mediafactory test
[platform/upstream/gstreamer.git] / tests / check / gst / mediafactory.c
1 /* GStreamer
2  * Copyright (C) 2012 Wim Taymans <wim.taymans@gmail.com>
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., 51 Franklin St, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19
20 #include <gst/check/gstcheck.h>
21
22 #include <rtsp-media-factory.h>
23
24 GST_START_TEST (test_parse_error)
25 {
26   GstRTSPMediaFactory *factory;
27   GstRTSPUrl *url;
28
29   factory = gst_rtsp_media_factory_new ();
30
31   gst_rtsp_media_factory_set_launch (factory, "foo");
32   gst_rtsp_url_parse ("rtsp://localhost:8554/test", &url);
33   ASSERT_CRITICAL (gst_rtsp_media_factory_create_element (factory, url));
34   ASSERT_CRITICAL (gst_rtsp_media_factory_construct (factory, url));
35
36   gst_rtsp_url_free (url);
37   g_object_unref (factory);
38 }
39
40 GST_END_TEST;
41
42 GST_START_TEST (test_launch)
43 {
44   GstRTSPMediaFactory *factory;
45   GstElement *element;
46   GstRTSPUrl *url;
47
48   factory = gst_rtsp_media_factory_new ();
49   fail_if (gst_rtsp_media_factory_is_shared (factory));
50   gst_rtsp_url_parse ("rtsp://localhost:8554/test", &url);
51
52   gst_rtsp_media_factory_set_launch (factory,
53       "( videotestsrc ! rtpvrawpay pt=96 name=pay0 )");
54
55   element = gst_rtsp_media_factory_create_element (factory, url);
56   fail_unless (GST_IS_BIN (element));
57   fail_if (GST_IS_PIPELINE (element));
58   gst_object_unref (element);
59
60   gst_rtsp_url_free (url);
61   g_object_unref (factory);
62 }
63
64 GST_END_TEST;
65
66 GST_START_TEST (test_launch_construct)
67 {
68   GstRTSPMediaFactory *factory;
69   GstRTSPMedia *media, *media2;
70   GstRTSPUrl *url;
71
72   factory = gst_rtsp_media_factory_new ();
73   fail_if (gst_rtsp_media_factory_is_shared (factory));
74   gst_rtsp_url_parse ("rtsp://localhost:8554/test", &url);
75
76   gst_rtsp_media_factory_set_launch (factory,
77       "( videotestsrc ! rtpvrawpay pt=96 name=pay0 )");
78
79   media = gst_rtsp_media_factory_construct (factory, url);
80   fail_unless (GST_IS_RTSP_MEDIA (media));
81   g_object_unref (media);
82
83   media2 = gst_rtsp_media_factory_construct (factory, url);
84   fail_unless (GST_IS_RTSP_MEDIA (media2));
85   fail_if (media == media2);
86   g_object_unref (media2);
87
88   gst_rtsp_url_free (url);
89   g_object_unref (factory);
90 }
91
92 GST_END_TEST;
93
94 GST_START_TEST (test_shared)
95 {
96   GstRTSPMediaFactory *factory;
97   GstElement *element;
98   GstRTSPMedia *media, *media2;
99   GstRTSPUrl *url;
100
101   factory = gst_rtsp_media_factory_new ();
102   gst_rtsp_media_factory_set_shared (factory, TRUE);
103   fail_unless (gst_rtsp_media_factory_is_shared (factory));
104
105   gst_rtsp_url_parse ("rtsp://localhost:8554/test", &url);
106
107   gst_rtsp_media_factory_set_launch (factory,
108       "( videotestsrc ! rtpvrawpay pt=96 name=pay0 )");
109
110   element = gst_rtsp_media_factory_create_element (factory, url);
111   fail_unless (GST_IS_BIN (element));
112   fail_if (GST_IS_PIPELINE (element));
113   gst_object_unref (element);
114
115   media = gst_rtsp_media_factory_construct (factory, url);
116   fail_unless (GST_IS_RTSP_MEDIA (media));
117
118   media2 = gst_rtsp_media_factory_construct (factory, url);
119   fail_unless (GST_IS_RTSP_MEDIA (media2));
120   fail_unless (media == media2);
121
122   g_object_unref (media);
123   g_object_unref (media2);
124
125   gst_rtsp_url_free (url);
126   g_object_unref (factory);
127 }
128
129 GST_END_TEST;
130
131 static Suite *
132 rtspmediafactory_suite (void)
133 {
134   Suite *s = suite_create ("rtspmediafactory");
135   TCase *tc = tcase_create ("general");
136
137   suite_add_tcase (s, tc);
138   tcase_set_timeout (tc, 20);
139   tcase_add_test (tc, test_parse_error);
140   tcase_add_test (tc, test_launch);
141   tcase_add_test (tc, test_launch_construct);
142   tcase_add_test (tc, test_shared);
143
144   return s;
145 }
146
147 GST_CHECK_MAIN (rtspmediafactory);