2009-07-24 Jeffrey Stedfast <fejj@novell.com>
[moon.git] / test / cpp / utils.cpp
blob03ab091446e1984d8c6da810bac4df978f9e77a5
1 /*
2 * Native unit tests
4 * Contact:
5 * Moonlight List (moonlight-list@lists.ximian.com)
7 * Copyright 2009 Novell, Inc. (http://www.novell.com)
9 * See the LICENSE file included with the distribution for details.
13 #include "config.h"
14 #include "main.h"
16 #include "utils.h"
18 TEST(Utils, parse_rfc_1945_token_test)
20 char *input, *free;
22 char *result;
23 char c;
24 char *end;
26 input = g_strdup_printf ("asd");
27 result = parse_rfc_1945_token (input, &c, &end);
28 EXPECT_EQ (result, input);
29 EXPECT_EQ (c, '\0');
30 EXPECT_EQ (end, (void*) NULL);
31 g_free (input);
33 result = parse_rfc_1945_token (NULL, NULL, NULL);
34 EXPECT_EQ (result, (void*) NULL);
36 free = input = g_strdup_printf ("LI(H\"ñoIH\"");
37 result = parse_rfc_1945_token (input, &c, &end);
38 EXPECT_EQ (result, input);
39 EXPECT_STREQ (result, "LI");
40 EXPECT_EQ (c, '(');
41 EXPECT_EQ (end, result + 3);
42 input = end;
43 result = parse_rfc_1945_token (input, &c, &end);
44 EXPECT_EQ (result, input);
45 EXPECT_STREQ (result, "H");
46 EXPECT_EQ (c, '\"');
47 EXPECT_EQ (end, result + 2);
48 input = end;
49 result = parse_rfc_1945_token (input, &c, &end);
50 EXPECT_EQ (result, input);
51 EXPECT_STREQ (result, "ñoIH");
52 EXPECT_EQ (c, '\"');
53 EXPECT_EQ (end, result + 6);
54 g_free (free);
56 free = input = g_strdup_printf ("packet-pair-experiment=1, no-cache, client-id=1089364828, xResetStrm=1, features=\"seekable,stridable,playlist,skipforward\", timeout=60000");
57 result = parse_rfc_1945_token (input, &c, &end);
58 EXPECT_EQ (result, input);
59 EXPECT_STREQ (result, "packet-pair-experiment");
60 EXPECT_EQ (c, '=');
61 EXPECT_EQ (end, result + 23);
62 input = end; // ----
63 result = parse_rfc_1945_token (input, &c, &end);
64 EXPECT_EQ (result, input);
65 EXPECT_STREQ (result, "1");
66 EXPECT_EQ (c, ',');
67 EXPECT_EQ (end, result + 2);
68 input = end; // ----
69 result = parse_rfc_1945_token (input, &c, &end);
70 EXPECT_EQ (result, input + 1);
71 EXPECT_STREQ (result, "no-cache");
72 EXPECT_EQ (c, ',');
73 EXPECT_EQ (end, result + 9);
74 input = end; // ----
75 result = parse_rfc_1945_token (input, &c, &end);
76 EXPECT_EQ (result, input + 1);
77 EXPECT_STREQ (result, "client-id");
78 EXPECT_EQ (c, '=');
79 EXPECT_EQ (end, result + 10);
80 input = end; // ----
81 result = parse_rfc_1945_token (input, &c, &end);
82 EXPECT_EQ (result, input );
83 EXPECT_STREQ (result, "1089364828");
84 EXPECT_EQ (c, ',');
85 EXPECT_EQ (end, result + 11);
86 input = end; // ----
87 result = parse_rfc_1945_token (input, &c, &end);
88 EXPECT_EQ (result, input + 1);
89 EXPECT_STREQ (result, "xResetStrm");
90 EXPECT_EQ (c, '=');
91 EXPECT_EQ (end, result + 11);
92 input = end; // ----
93 result = parse_rfc_1945_token (input, &c, &end);
94 EXPECT_EQ (result, input);
95 EXPECT_STREQ (result, "1");
96 EXPECT_EQ (c, ',');
97 EXPECT_EQ (end, result + 2);
98 input = end; // ----
99 result = parse_rfc_1945_token (input, &c, &end);
100 EXPECT_EQ (result, input + 1);
101 EXPECT_STREQ (result, "features");
102 EXPECT_EQ (c, '=');
103 EXPECT_EQ (end, result + 9);
104 input = end; // ----
105 result = parse_rfc_1945_token (input, &c, &end);
106 EXPECT_EQ (result, input + 1);
107 EXPECT_STREQ (result, "seekable");
108 EXPECT_EQ (c, ',');
109 EXPECT_EQ (end, result + 9);
110 input = end; // ----
111 result = parse_rfc_1945_token (input, &c, &end);
112 EXPECT_EQ (result, input);
113 EXPECT_STREQ (result, "stridable");
114 EXPECT_EQ (c, ',');
115 EXPECT_EQ (end, result + 10);
116 input = end; // ----
117 result = parse_rfc_1945_token (input, &c, &end);
118 EXPECT_EQ (result, input);
119 EXPECT_STREQ (result, "playlist");
120 EXPECT_EQ (c, ',');
121 EXPECT_EQ (end, result + 9);
122 input = end; // ----
123 result = parse_rfc_1945_token (input, &c, &end);
124 EXPECT_EQ (result, input);
125 EXPECT_STREQ (result, "skipforward");
126 EXPECT_EQ (c, '\"');
127 EXPECT_EQ (end, result + 12);
128 input = end; // ----
129 result = parse_rfc_1945_token (input, &c, &end);
130 EXPECT_EQ (result, input + 2);
131 EXPECT_STREQ (result, "timeout");
132 EXPECT_EQ (c, '=');
133 EXPECT_EQ (end, result + 8);
134 input = end; // ----
135 result = parse_rfc_1945_token (input, &c, &end);
136 EXPECT_EQ (result, input);
137 EXPECT_STREQ (result, "60000");
138 EXPECT_EQ (c, '\0');
139 EXPECT_EQ (end, (void*) NULL);
140 g_free (free);
145 TEST(Utils, parse_rfc_1945_quoted_string_test)
147 char *input, *free;
149 char *result;
150 char c;
151 char *end;
153 input = g_strdup_printf ("\"asd");
154 result = parse_rfc_1945_quoted_string (input, &c, &end);
155 EXPECT_EQ (result, input + 1);
156 EXPECT_STREQ (result, "asd");
157 EXPECT_EQ (c, '\0');
158 EXPECT_EQ (end, (void*) NULL);
159 g_free (input);
161 result = parse_rfc_1945_quoted_string (NULL, NULL, NULL);
162 EXPECT_EQ (result, (void*) NULL);
164 free = input = g_strdup_printf ("LI(H\"ñoIH\"");
165 result = parse_rfc_1945_quoted_string (input, &c, &end);
166 EXPECT_EQ (result, (void*) NULL);
167 g_free (free);
169 free = input = g_strdup_printf ("\"seekable,stridable,playlist,skipforward\"");
170 result = parse_rfc_1945_quoted_string (input, &c, &end);
171 EXPECT_EQ (result, input + 1);
172 EXPECT_STREQ (result, "seekable,stridable,playlist,skipforward");
173 EXPECT_EQ (c, '\"');
174 EXPECT_EQ (end, result + 40);
175 g_free (free);