1 | /* GStreamer test |
---|
2 | * (c) 2004 Ronald Bultje <rbultje@ronald.bitfreak.net> |
---|
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 | #ifdef HAVE_CONFIG_H |
---|
21 | #include <config.h> |
---|
22 | #endif |
---|
23 | |
---|
24 | #include <gst/gst.h> |
---|
25 | |
---|
26 | typedef enum |
---|
27 | { |
---|
28 | TEST_YES, |
---|
29 | TEST_NO |
---|
30 | } |
---|
31 | TestBool; |
---|
32 | |
---|
33 | #define TEST_BOOL_TYPE (test_bool_get_type ()) |
---|
34 | GType |
---|
35 | test_bool_get_type (void) |
---|
36 | { |
---|
37 | static GType etype = 0; |
---|
38 | |
---|
39 | if (etype == 0) { |
---|
40 | static const GEnumValue values[] = { |
---|
41 | {TEST_YES, "TEST_YES", "yes"}, |
---|
42 | {TEST_NO, "TEST_NO", "no"}, |
---|
43 | {0, NULL, NULL} |
---|
44 | }; |
---|
45 | |
---|
46 | etype = g_enum_register_static ("TestBool", values); |
---|
47 | } |
---|
48 | return etype; |
---|
49 | } |
---|
50 | |
---|
51 | gint |
---|
52 | main (gint argc, gchar * argv[]) |
---|
53 | { |
---|
54 | gchar *str; |
---|
55 | GstCaps *caps, *res_caps; |
---|
56 | GstStructure *strc; |
---|
57 | GValue value = { 0 }; |
---|
58 | TestBool yes, no; |
---|
59 | |
---|
60 | /* register multichannel type */ |
---|
61 | gst_init (&argc, &argv); |
---|
62 | test_bool_get_type (); |
---|
63 | |
---|
64 | /* test some caps */ |
---|
65 | caps = gst_caps_new_simple ("application/x-gst-test", NULL); |
---|
66 | str = gst_caps_to_string (caps); |
---|
67 | g_assert (str); |
---|
68 | g_free (str); |
---|
69 | |
---|
70 | /* set enums in list */ |
---|
71 | strc = gst_caps_get_structure (caps, 0); |
---|
72 | g_value_init (&value, TEST_BOOL_TYPE); |
---|
73 | g_value_set_enum (&value, TEST_YES); |
---|
74 | gst_structure_set_value (strc, "yes", &value); |
---|
75 | g_value_set_enum (&value, TEST_NO); |
---|
76 | gst_structure_set_value (strc, "no", &value); |
---|
77 | g_value_unset (&value); |
---|
78 | |
---|
79 | /* test to-/from-string conversions for enums */ |
---|
80 | str = gst_caps_to_string (caps); |
---|
81 | g_assert (str); |
---|
82 | res_caps = gst_caps_from_string (str); |
---|
83 | g_free (str); |
---|
84 | |
---|
85 | /* see if all worked */ |
---|
86 | strc = gst_caps_get_structure (res_caps, 0); |
---|
87 | yes = g_value_get_enum (gst_structure_get_value (strc, "yes")); |
---|
88 | no = g_value_get_enum (gst_structure_get_value (strc, "no")); |
---|
89 | g_assert (yes == TEST_YES && no == TEST_NO); |
---|
90 | gst_caps_free (caps); |
---|
91 | gst_caps_free (res_caps); |
---|
92 | |
---|
93 | /* yes */ |
---|
94 | return 0; |
---|
95 | } |
---|