1 /* GStreamer
2 *
3 * unit test for PNM encoder / decoder
4 *
5 * Copyright (C) <2016> Jan Schmidt <jan@centricular.com>
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., 51 Franklin St, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 */
22 #include <gst/check/gstcheck.h>
23 #include <gst/app/gstappsink.h>
24
25 /* Create a pnmenc ! pnmdec and push in
26 * frames, checking that what comes out is what
27 * went in */
GST_START_TEST(test_pnm_enc_dec)28 GST_START_TEST (test_pnm_enc_dec)
29 {
30 GstElement *pipeline;
31 GstElement *incf, *outcf, *enc;
32 GstElement *sink;
33 GstSample *sample;
34 GstBuffer *buffer;
35 gint i, n;
36
37 struct
38 {
39 const gchar *in_fmt;
40 const gchar *out_fmt;
41 } test_formats[] = {
42 {
43 "RGB", "RGB"}, {
44 "GRAY8", "GRAY8"}, {
45 "GRAY16_BE", "GRAY16_BE"}, {
46 "GRAY16_BE", "GRAY16_LE"}, {
47 "GRAY16_LE", "GRAY16_BE"}, {
48 "GRAY16_LE", "GRAY16_LE"}
49 };
50
51 pipeline =
52 gst_parse_launch
53 ("videotestsrc num-buffers=1 ! capsfilter name=incf ! pnmenc name=enc ! pnmdec ! capsfilter name=outcf ! appsink name=sink",
54 NULL);
55 g_assert (pipeline != NULL);
56
57 incf = gst_bin_get_by_name (GST_BIN (pipeline), "incf");
58 enc = gst_bin_get_by_name (GST_BIN (pipeline), "enc");
59 outcf = gst_bin_get_by_name (GST_BIN (pipeline), "outcf");
60 sink = gst_bin_get_by_name (GST_BIN (pipeline), "sink");
61
62 for (n = 0; n < 2; n++) {
63 for (i = 0; i < G_N_ELEMENTS (test_formats); i++) {
64 GstCaps *incaps = gst_caps_new_simple ("video/x-raw", "width", G_TYPE_INT,
65 320, "height", G_TYPE_INT, 240, "framerate",
66 GST_TYPE_FRACTION, 1, 1, "format", G_TYPE_STRING,
67 test_formats[i].in_fmt, NULL);
68 GstCaps *outcaps =
69 gst_caps_new_simple ("video/x-raw", "width", G_TYPE_INT,
70 320, "height", G_TYPE_INT, 240, "framerate",
71 GST_TYPE_FRACTION, 1, 1, "format", G_TYPE_STRING,
72 test_formats[i].out_fmt, NULL);
73
74 GST_DEBUG ("Setting in caps %" GST_PTR_FORMAT, incaps);
75 g_object_set (G_OBJECT (incf), "caps", incaps, NULL);
76 GST_DEBUG ("Setting out caps %" GST_PTR_FORMAT, outcaps);
77 g_object_set (G_OBJECT (outcf), "caps", outcaps, NULL);
78
79 gst_caps_unref (incaps);
80 gst_caps_unref (outcaps);
81
82 gst_element_set_state (pipeline, GST_STATE_PLAYING);
83
84 sample = gst_app_sink_pull_sample (GST_APP_SINK (sink));
85
86 fail_unless (sample != NULL);
87 buffer = gst_sample_get_buffer (sample);
88 fail_unless (buffer != NULL);
89 gst_sample_unref (sample);
90
91 gst_element_set_state (pipeline, GST_STATE_NULL);
92 }
93
94 g_object_set (enc, "ascii", TRUE, NULL);
95 }
96
97 gst_object_unref (pipeline);
98 gst_object_unref (sink);
99 gst_object_unref (outcf);
100 gst_object_unref (enc);
101 gst_object_unref (incf);
102
103 }
104
105 GST_END_TEST;
106
107 static Suite *
pnm_suite(void)108 pnm_suite (void)
109 {
110 Suite *s = suite_create ("pnm");
111 TCase *tc_chain = tcase_create ("general");
112
113 suite_add_tcase (s, tc_chain);
114 tcase_add_test (tc_chain, test_pnm_enc_dec);
115
116 return s;
117 }
118
119 GST_CHECK_MAIN (pnm);
120