source: trunk/third/gstreamer/testsuite/caps/value_serialize.c @ 21448

Revision 21448, 2.7 KB checked in by ghudson, 20 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r21447, which included commits to RCS files with non-trunk default branches.
Line 
1#include <gst/gst.h>
2
3static void
4test1 (void)
5{
6  GValue value = { 0 };
7  gboolean ret;
8
9  g_value_init (&value, GST_TYPE_BUFFER);
10  ret = gst_value_deserialize (&value, "1234567890abcdef");
11  g_assert (ret);
12}
13
14static gboolean
15test_string_serialization (void)
16{
17  gchar *try[] = {
18    "Dude",
19    "Hi, I'm a string",
20    "tüüüt!"
21  };
22  gchar *tmp;
23  GValue v = { 0, };
24  guint i;
25  gboolean ret = TRUE;
26
27  g_value_init (&v, G_TYPE_STRING);
28  for (i = 0; i < G_N_ELEMENTS (try); i++) {
29    g_value_set_string (&v, try[i]);
30    tmp = gst_value_serialize (&v);
31    if (!tmp) {
32      g_print ("couldn't serialize: %s\n", try[i]);
33      ret = FALSE;
34      continue;
35    }
36    if (!gst_value_deserialize (&v, tmp)) {
37      g_print ("couldn't deserialize: %s\n", tmp);
38      g_free (tmp);
39      ret = FALSE;
40      continue;
41    }
42    g_free (tmp);
43    if (!g_str_equal (g_value_get_string (&v), try[i])) {
44      g_print ("serialized  : %s\n", try[i]);
45      g_print ("deserialized: %s\n", g_value_get_string (&v));
46      ret = FALSE;
47      continue;
48    }
49  }
50  g_value_unset (&v);
51  return ret;
52
53}
54
55static gboolean
56test_string_deserialization (void)
57{
58  struct
59  {
60    gchar *from;
61    gchar *to;
62  } tests[] = {
63    {
64    "", ""}, {
65    "\"\"", ""},
66        /* FAILURES */
67    {
68    "\"", NULL},                /* missing second quote */
69    {
70    "\"Hello\\ World", NULL},   /* missing second quote */
71    {
72    "\"\\", NULL},              /* quote at end, missing second quote */
73    {
74    "\"\\0", NULL},             /* missing second quote */
75    {
76    "\"\\0\"", NULL},           /* unfinished escaped character */
77    {
78    "\" \"", NULL},             /* spaces must be escaped */
79#if 0
80        /* FIXME 0.9: this test should fail, but it doesn't */
81    {
82    "tüüt", NULL}             /* string with special chars must be escaped */
83#endif
84  };
85  guint i;
86  GValue v = { 0, };
87  gboolean ret = TRUE;
88
89  g_value_init (&v, G_TYPE_STRING);
90  for (i = 0; i < G_N_ELEMENTS (tests); i++) {
91    if (gst_value_deserialize (&v, tests[i].from)) {
92      if (tests[i].to == NULL) {
93        g_print ("should fail\n");
94        g_print ("but got: %s\n", g_value_get_string (&v));
95        ret = FALSE;
96      } else if (!g_str_equal (g_value_get_string (&v), tests[i].to)) {
97        g_print ("wanted: %s\n", tests[i].to);
98        g_print ("got   : %s\n", g_value_get_string (&v));
99        ret = FALSE;
100      }
101    } else {
102      if (tests[i].to != NULL) {
103        g_print ("failed\n");
104        g_print ("but wanted: %s\n", tests[i].to);
105        ret = FALSE;
106      }
107    }
108  }
109  g_value_unset (&v);
110  return ret;
111}
112
113int
114main (int argc, char *argv[])
115{
116  gboolean ret = TRUE;
117
118  gst_init (&argc, &argv);
119
120  test1 ();
121  ret &= test_string_serialization ();
122  ret &= test_string_deserialization ();
123
124  return ret ? 0 : 1;
125}
Note: See TracBrowser for help on using the repository browser.