cppu_unourl.cxx (9d7e27ac) cppu_unourl.cxx (5c0ee992)
1/**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance

--- 7 unchanged lines hidden (view full) ---

16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
1/**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance

--- 7 unchanged lines hidden (view full) ---

16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24#include <testshl/simpleheader.hxx>
25
26#include "cppuhelper/unourl.hxx"
27#include "rtl/malformeduriexception.hxx"
28#include "rtl/strbuf.hxx"
29#include "rtl/string.h"
30#include "rtl/textenc.h"
31#include "rtl/ustring.hxx"
32#include "sal/types.h"
24#include "cppuhelper/unourl.hxx"
25#include "rtl/malformeduriexception.hxx"
26#include "rtl/strbuf.hxx"
27#include "rtl/string.h"
28#include "rtl/textenc.h"
29#include "rtl/ustring.hxx"
30#include "sal/types.h"
31#include "gtest/gtest.h"
33
34namespace cppu_unourl
35{
32
33namespace cppu_unourl
34{
36 class UrlTest : public CppUnit::TestFixture
35 class UrlTest : public ::testing::Test
37 {
38 public:
36 {
37 public:
39 void testDescriptorParsing()
38 };
39
40 TEST_F(UrlTest, testDescriptorParsing)
41 {
42 struct Test
40 {
43 {
41 struct Test
44 char const * pInput;
45 bool bValid;
46 };
47 static Test const aTests[]
48 = { { "", false },
49 { "abc", true },
50 { "Abc", true },
51 { "aBC", true },
52 { "ABC", true },
53 { "1abc", true },
54 { "123", true },
55 { "abc-1", false },
56 { "ab%63", false },
57 { "abc,", false },
58 { "abc,def=", true },
59 { "abc,Def=", true },
60 { "abc,DEF=", true },
61 { "abc,1def=", true },
62 { "abc,123=", true },
63 { "abc,def-1=", false },
64 { "abc,def", false },
65 { "abc,def=xxx,def=xxx", false },
66 { "abc,def=xxx,ghi=xxx", true },
67 { "abc,,def=xxx", false },
68 { "abc,def=xxx,,ghi=xxx", false },
69 { "abc,def=xxx,ghi=xxx,", false },
70 { "abc,def=%", true },
71 { "abc,def=%1", true },
72 { "abc,def=%00", true },
73 { "abc,def=%22", true },
74 { "abc,def=\"", true },
75 { "abc,def=%ed%a0%80", true } };
76 for (int i = 0; i < sizeof aTests / sizeof (Test); ++i)
77 {
78 bool bValid = false;
79 try
42 {
80 {
43 char const * pInput;
44 bool bValid;
45 };
46 static Test const aTests[]
47 = { { "", false },
48 { "abc", true },
49 { "Abc", true },
50 { "aBC", true },
51 { "ABC", true },
52 { "1abc", true },
53 { "123", true },
54 { "abc-1", false },
55 { "ab%63", false },
56 { "abc,", false },
57 { "abc,def=", true },
58 { "abc,Def=", true },
59 { "abc,DEF=", true },
60 { "abc,1def=", true },
61 { "abc,123=", true },
62 { "abc,def-1=", false },
63 { "abc,def", false },
64 { "abc,def=xxx,def=xxx", false },
65 { "abc,def=xxx,ghi=xxx", true },
66 { "abc,,def=xxx", false },
67 { "abc,def=xxx,,ghi=xxx", false },
68 { "abc,def=xxx,ghi=xxx,", false },
69 { "abc,def=%", true },
70 { "abc,def=%1", true },
71 { "abc,def=%00", true },
72 { "abc,def=%22", true },
73 { "abc,def=\"", true },
74 { "abc,def=%ed%a0%80", true } };
75 for (int i = 0; i < sizeof aTests / sizeof (Test); ++i)
76 {
77 bool bValid = false;
78 try
79 {
80 cppu::UnoUrlDescriptor aDescriptor(rtl::OUString::createFromAscii(
81 aTests[i].pInput));
82 bValid = true;
83 }
84 catch (rtl::MalformedUriException &)
85 {}
81 cppu::UnoUrlDescriptor aDescriptor(rtl::OUString::createFromAscii(
82 aTests[i].pInput));
83 bValid = true;
84 }
85 catch (rtl::MalformedUriException &)
86 {}
86
87
87 if (aTests[i].bValid)
88 {
89 CPPUNIT_ASSERT_MESSAGE("Valid uri parsed as invalid", bValid);
90 }
91 else
92 {
93 CPPUNIT_ASSERT_MESSAGE("Invalid uri parsed as valid", !bValid);
94 }
88 if (aTests[i].bValid)
89 {
90 ASSERT_TRUE(bValid) << "Valid uri parsed as invalid";
95 }
91 }
92 else
93 {
94 ASSERT_TRUE(!bValid) << "Invalid uri parsed as valid";
95 }
96 }
96 }
97 }
97
98
98 void testDescriptorDescriptor()
99 TEST_F(UrlTest, testDescriptorDescriptor)
100 {
101 struct Test
99 {
102 {
100 struct Test
103 char const * pInput;
104 char const * pDescriptor;
105 };
106 static Test const aTests[]
107 = {{ "abc", "abc" },
108 { "Abc", "Abc" },
109 { "aBC", "aBC" },
110 { "ABC", "ABC" },
111 { "1abc", "1abc" },
112 { "123", "123" },
113 { "abc,def=", "abc,def=" },
114 { "abc,Def=", "abc,Def=" },
115 { "abc,DEF=", "abc,DEF=" },
116 { "abc,1def=", "abc,1def=" },
117 { "abc,123=", "abc,123=" },
118 { "abc,def=xxx,ghi=xxx", "abc,def=xxx,ghi=xxx" },
119 { "abc,def=%", "abc,def=%" },
120 { "abc,def=%1", "abc,def=%1" },
121 { "abc,def=%00", "abc,def=%00" },
122 { "abc,def=%22", "abc,def=%22" },
123 { "abc,def=\"", "abc,def=\"" },
124 { "abc,def=%ed%a0%80", "abc,def=%ed%a0%80" } };
125 bool bResult = true;
126 for (int i = 0; i < sizeof aTests / sizeof (Test); ++i)
127 {
128 bool bValid = false;
129 rtl::OUString aDescriptor;
130 try
101 {
131 {
102 char const * pInput;
103 char const * pDescriptor;
104 };
105 static Test const aTests[]
106 = {{ "abc", "abc" },
107 { "Abc", "Abc" },
108 { "aBC", "aBC" },
109 { "ABC", "ABC" },
110 { "1abc", "1abc" },
111 { "123", "123" },
112 { "abc,def=", "abc,def=" },
113 { "abc,Def=", "abc,Def=" },
114 { "abc,DEF=", "abc,DEF=" },
115 { "abc,1def=", "abc,1def=" },
116 { "abc,123=", "abc,123=" },
117 { "abc,def=xxx,ghi=xxx", "abc,def=xxx,ghi=xxx" },
118 { "abc,def=%", "abc,def=%" },
119 { "abc,def=%1", "abc,def=%1" },
120 { "abc,def=%00", "abc,def=%00" },
121 { "abc,def=%22", "abc,def=%22" },
122 { "abc,def=\"", "abc,def=\"" },
123 { "abc,def=%ed%a0%80", "abc,def=%ed%a0%80" } };
124 bool bResult = true;
125 for (int i = 0; i < sizeof aTests / sizeof (Test); ++i)
126 {
127 bool bValid = false;
128 rtl::OUString aDescriptor;
129 try
130 {
131 aDescriptor = cppu::UnoUrlDescriptor(rtl::OUString::createFromAscii(
132 aTests[i].pInput)).
133 getDescriptor();
134 bValid = true;
135 }
136 catch (rtl::MalformedUriException &)
137 {}
138
139 CPPUNIT_ASSERT_MESSAGE("Failed to parse URI", bValid);
140 CPPUNIT_ASSERT_MESSAGE("Failed to parse URI correctly",
141 aDescriptor.equalsAscii(
142 aTests[i].pDescriptor));
132 aDescriptor = cppu::UnoUrlDescriptor(rtl::OUString::createFromAscii(
133 aTests[i].pInput)).
134 getDescriptor();
135 bValid = true;
143 }
136 }
137 catch (rtl::MalformedUriException &)
138 {}
139
140 ASSERT_TRUE(bValid) << "Failed to parse URI";
141 ASSERT_TRUE(aDescriptor.equalsAscii(aTests[i].pDescriptor)) << "Failed to parse URI correctly";
144 }
142 }
143 }
145
146
144
145
147 void testDescriptorName()
146 TEST_F(UrlTest, testDescriptorName)
147 {
148 struct Test
148 {
149 {
149 struct Test
150 char const * pInput;
151 char const * pName;
152 };
153 static Test const aTests[]
154 = { { "abc", "abc" },
155 { "Abc", "abc" },
156 { "aBC", "abc" },
157 { "ABC", "abc" },
158 { "1abc", "1abc" },
159 { "123", "123" },
160 { "abc,def=", "abc" },
161 { "abc,Def=", "abc" },
162 { "abc,DEF=", "abc" },
163 { "abc,1def=", "abc" },
164 { "abc,123=", "abc" },
165 { "abc,def=xxx,ghi=xxx", "abc" },
166 { "abc,def=%", "abc" },
167 { "abc,def=%1", "abc" },
168 { "abc,def=%00", "abc" },
169 { "abc,def=%22", "abc" },
170 { "abc,def=\"", "abc" },
171 { "abc,def=%ed%a0%80", "abc" } };
172 for (int i = 0; i < sizeof aTests / sizeof (Test); ++i)
173 {
174 bool bValid = false;
175 rtl::OUString aName;
176 try
150 {
177 {
151 char const * pInput;
152 char const * pName;
153 };
154 static Test const aTests[]
155 = { { "abc", "abc" },
156 { "Abc", "abc" },
157 { "aBC", "abc" },
158 { "ABC", "abc" },
159 { "1abc", "1abc" },
160 { "123", "123" },
161 { "abc,def=", "abc" },
162 { "abc,Def=", "abc" },
163 { "abc,DEF=", "abc" },
164 { "abc,1def=", "abc" },
165 { "abc,123=", "abc" },
166 { "abc,def=xxx,ghi=xxx", "abc" },
167 { "abc,def=%", "abc" },
168 { "abc,def=%1", "abc" },
169 { "abc,def=%00", "abc" },
170 { "abc,def=%22", "abc" },
171 { "abc,def=\"", "abc" },
172 { "abc,def=%ed%a0%80", "abc" } };
173 for (int i = 0; i < sizeof aTests / sizeof (Test); ++i)
174 {
175 bool bValid = false;
176 rtl::OUString aName;
177 try
178 {
179 aName = cppu::UnoUrlDescriptor(rtl::OUString::createFromAscii(
180 aTests[i].pInput)).getName();
181 bValid = true;
182 }
183 catch (rtl::MalformedUriException &)
184 {}
185
186 CPPUNIT_ASSERT_MESSAGE("Failed to parse URI", bValid);
187 CPPUNIT_ASSERT_MESSAGE("Failed to parse URI correctly",
188 aName.equalsAscii(aTests[i].pName));
178 aName = cppu::UnoUrlDescriptor(rtl::OUString::createFromAscii(
179 aTests[i].pInput)).getName();
180 bValid = true;
189 }
181 }
182 catch (rtl::MalformedUriException &)
183 {}
184
185 ASSERT_TRUE(bValid) << "Failed to parse URI";
186 ASSERT_TRUE(aName.equalsAscii(aTests[i].pName)) << "Failed to parse URI correctly";
190 }
187 }
188 }
191
189
192 void testDescriptorKey(void)
190 TEST_F(UrlTest, testDescriptorKey)
191 {
192 struct Test
193 {
193 {
194 struct Test
194 char const * pInput;
195 char const * pKey;
196 bool bPresent;
197 };
198 static Test const aTests[]
199 = { { "abc", "abc", false },
200 { "abc", "def", false },
201 { "1abc", "def", false },
202 { "123", "def", false },
203 { "abc,def=", "abc", false },
204 { "abc,def=", "def", true },
205 { "abc,def=", "defg", false },
206 { "abc,def=", "de", false },
207 { "abc,def=", "ghi", false },
208 { "abc,Def=", "def", true },
209 { "abc,Def=", "Def", true },
210 { "abc,Def=", "dEF", true },
211 { "abc,Def=", "DEF", true },
212 { "abc,def=xxx,ghi=xxx", "abc", false },
213 { "abc,def=xxx,ghi=xxx", "def", true },
214 { "abc,def=xxx,ghi=xxx", "ghi", true },
215 { "abc,def=xxx,ghi=xxx", "jkl", false } };
216 for (int i = 0; i < sizeof aTests / sizeof (Test); ++i)
217 {
218 bool bValid = false;
219 bool bPresent = false;
220 try
195 {
221 {
196 char const * pInput;
197 char const * pKey;
198 bool bPresent;
199 };
200 static Test const aTests[]
201 = { { "abc", "abc", false },
202 { "abc", "def", false },
203 { "1abc", "def", false },
204 { "123", "def", false },
205 { "abc,def=", "abc", false },
206 { "abc,def=", "def", true },
207 { "abc,def=", "defg", false },
208 { "abc,def=", "de", false },
209 { "abc,def=", "ghi", false },
210 { "abc,Def=", "def", true },
211 { "abc,Def=", "Def", true },
212 { "abc,Def=", "dEF", true },
213 { "abc,Def=", "DEF", true },
214 { "abc,def=xxx,ghi=xxx", "abc", false },
215 { "abc,def=xxx,ghi=xxx", "def", true },
216 { "abc,def=xxx,ghi=xxx", "ghi", true },
217 { "abc,def=xxx,ghi=xxx", "jkl", false } };
218 for (int i = 0; i < sizeof aTests / sizeof (Test); ++i)
219 {
220 bool bValid = false;
221 bool bPresent = false;
222 try
223 {
224 bPresent = cppu::UnoUrlDescriptor(rtl::OUString::createFromAscii(
225 aTests[i].pInput)).
226 hasParameter(rtl::OUString::createFromAscii(aTests[i].pKey));
227 bValid = true;
228 }
229 catch (rtl::MalformedUriException &)
230 {}
231
232 CPPUNIT_ASSERT_MESSAGE("Failed to parse URI", bValid);
233 CPPUNIT_ASSERT_MESSAGE("Failed to detect parameter correctly",
234 bPresent == aTests[i].bPresent);
222 bPresent = cppu::UnoUrlDescriptor(rtl::OUString::createFromAscii(
223 aTests[i].pInput)).
224 hasParameter(rtl::OUString::createFromAscii(aTests[i].pKey));
225 bValid = true;
235 }
226 }
227 catch (rtl::MalformedUriException &)
228 {}
229
230 ASSERT_TRUE(bValid) << "Failed to parse URI";
231 ASSERT_TRUE(bPresent == aTests[i].bPresent) << "Failed to detect parameter correctly";
236 }
232 }
233 }
237
234
238 void testDescriptorValue()
235 TEST_F(UrlTest, testDescriptorValue)
236 {
237 struct Test
239 {
238 {
240 struct Test
239 char const * pInput;
240 char const * pKey;
241 char const * pValue;
242 };
243 static Test const aTests[]
244 = { { "abc", "abc", "" },
245 { "abc", "def", "" },
246 { "1abc", "def", "" },
247 { "123", "def", "" },
248 { "abc,def=", "abc", "" },
249 { "abc,def=", "def", "" },
250 { "abc,def=", "defg", "" },
251 { "abc,def=", "de", "" },
252 { "abc,def=", "ghi", "" },
253 { "abc,Def=", "def", "" },
254 { "abc,Def=", "Def", "" },
255 { "abc,Def=", "dEF", "" },
256 { "abc,Def=", "DEF", "" },
257 { "abc,def=xxx,ghi=xxx", "abc", "" },
258 { "abc,def=xxx,ghi=xxx", "def", "xxx" },
259 { "abc,def=xxx,ghi=xxx", "ghi", "xxx" },
260 { "abc,def=xxx,ghi=xxx", "jkl", "" },
261 { "abc,def=%", "def", "%" },
262 { "abc,def=%1", "def", "%1" },
263 { "abc,def=%22", "def", "\"" },
264 { "abc,def=\"", "def", "\"" },
265 { "abc,def=abc", "def", "abc" },
266 { "abc,def=Abc", "def", "Abc" },
267 { "abc,def=aBC", "def", "aBC" },
268 { "abc,def=ABC", "def", "ABC" },
269 { "abc,def=%,ghi=", "def", "%" },
270 { "abc,def=%1,ghi=", "def", "%1" },
271 { "abc,def=%22,ghi=", "def", "\"" },
272 { "abc,def=\",ghi=", "def", "\"" },
273 { "abc,def=abc,ghi=", "def", "abc" },
274 { "abc,def=Abc,ghi=", "def", "Abc" },
275 { "abc,def=aBC,ghi=", "def", "aBC" },
276 { "abc,def=ABC,ghi=", "def", "ABC" },
277 { "abc,abc=,def=%", "def", "%" },
278 { "abc,abc=,def=%1", "def", "%1" },
279 { "abc,abc=,def=%22", "def", "\"" },
280 { "abc,abc=,def=\"", "def", "\"" },
281 { "abc,abc=,def=abc", "def", "abc" },
282 { "abc,abc=,def=Abc", "def", "Abc" },
283 { "abc,abc=,def=aBC", "def", "aBC" },
284 { "abc,abc=,def=ABC", "def", "ABC" } };
285 for (int i = 0; i < sizeof aTests / sizeof (Test); ++i)
286 {
287 bool bValid = false;
288 rtl::OUString aValue;
289 try
241 {
290 {
242 char const * pInput;
243 char const * pKey;
244 char const * pValue;
245 };
246 static Test const aTests[]
247 = { { "abc", "abc", "" },
248 { "abc", "def", "" },
249 { "1abc", "def", "" },
250 { "123", "def", "" },
251 { "abc,def=", "abc", "" },
252 { "abc,def=", "def", "" },
253 { "abc,def=", "defg", "" },
254 { "abc,def=", "de", "" },
255 { "abc,def=", "ghi", "" },
256 { "abc,Def=", "def", "" },
257 { "abc,Def=", "Def", "" },
258 { "abc,Def=", "dEF", "" },
259 { "abc,Def=", "DEF", "" },
260 { "abc,def=xxx,ghi=xxx", "abc", "" },
261 { "abc,def=xxx,ghi=xxx", "def", "xxx" },
262 { "abc,def=xxx,ghi=xxx", "ghi", "xxx" },
263 { "abc,def=xxx,ghi=xxx", "jkl", "" },
264 { "abc,def=%", "def", "%" },
265 { "abc,def=%1", "def", "%1" },
266 { "abc,def=%22", "def", "\"" },
267 { "abc,def=\"", "def", "\"" },
268 { "abc,def=abc", "def", "abc" },
269 { "abc,def=Abc", "def", "Abc" },
270 { "abc,def=aBC", "def", "aBC" },
271 { "abc,def=ABC", "def", "ABC" },
272 { "abc,def=%,ghi=", "def", "%" },
273 { "abc,def=%1,ghi=", "def", "%1" },
274 { "abc,def=%22,ghi=", "def", "\"" },
275 { "abc,def=\",ghi=", "def", "\"" },
276 { "abc,def=abc,ghi=", "def", "abc" },
277 { "abc,def=Abc,ghi=", "def", "Abc" },
278 { "abc,def=aBC,ghi=", "def", "aBC" },
279 { "abc,def=ABC,ghi=", "def", "ABC" },
280 { "abc,abc=,def=%", "def", "%" },
281 { "abc,abc=,def=%1", "def", "%1" },
282 { "abc,abc=,def=%22", "def", "\"" },
283 { "abc,abc=,def=\"", "def", "\"" },
284 { "abc,abc=,def=abc", "def", "abc" },
285 { "abc,abc=,def=Abc", "def", "Abc" },
286 { "abc,abc=,def=aBC", "def", "aBC" },
287 { "abc,abc=,def=ABC", "def", "ABC" } };
288 for (int i = 0; i < sizeof aTests / sizeof (Test); ++i)
289 {
290 bool bValid = false;
291 rtl::OUString aValue;
292 try
293 {
294 aValue = cppu::UnoUrlDescriptor(rtl::OUString::createFromAscii(
295 aTests[i].pInput)).
296 getParameter(rtl::OUString::createFromAscii(aTests[i].pKey));
297 bValid = true;
298 }
299 catch (rtl::MalformedUriException &)
300 {}
301 CPPUNIT_ASSERT_MESSAGE("Failed to parse URI", bValid);
302 CPPUNIT_ASSERT_MESSAGE("Failed to get param correctly",
303 aValue.equalsAscii(aTests[i].pValue));
291 aValue = cppu::UnoUrlDescriptor(rtl::OUString::createFromAscii(
292 aTests[i].pInput)).
293 getParameter(rtl::OUString::createFromAscii(aTests[i].pKey));
294 bValid = true;
304 }
295 }
296 catch (rtl::MalformedUriException &)
297 {}
298 ASSERT_TRUE(bValid) << "Failed to parse URI";
299 ASSERT_TRUE(aValue.equalsAscii(aTests[i].pValue)) << "Failed to get param correctly";
305 }
300 }
301 }
306
302
307 void testUrlParsing()
303 TEST_F(UrlTest, testUrlParsing)
304 {
305 struct Test
308 {
306 {
309 struct Test
307 char const * pInput;
308 bool bValid;
309 };
310 static Test const aTests[]
311 = { { "", false },
312 { "abc", false },
313 { "uno", false },
314 { "uno:", false },
315 { "uno:abc;def;ghi", true },
316 { "Uno:abc;def;ghi", true },
317 { "uNO:abc;def;ghi", true },
318 { "UNO:abc;def;ghi", true },
319 { "uno:abc,def=xxx,ghi=xxx;def,ghi=xxx,jkl=xxx;ghi", true },
320 { "uno:abc,def=xxx,ghi=xxx;def,ghi=xxx,jkl=xxx,;ghi", false },
321 { "uno:abc;def;", false },
322 { "uno:abc;def;a", true },
323 { "uno:abc;def;A", true },
324 { "uno:abc;def;1", true },
325 { "uno:abc;def;$&+,/:=?@", true },
326 { "uno:abc;def;%24&+,/:=?@", false } };
327 for (int i = 0; i < sizeof aTests / sizeof (Test); ++i)
328 {
329 bool bValid = false;
330 try
310 {
331 {
311 char const * pInput;
312 bool bValid;
313 };
314 static Test const aTests[]
315 = { { "", false },
316 { "abc", false },
317 { "uno", false },
318 { "uno:", false },
319 { "uno:abc;def;ghi", true },
320 { "Uno:abc;def;ghi", true },
321 { "uNO:abc;def;ghi", true },
322 { "UNO:abc;def;ghi", true },
323 { "uno:abc,def=xxx,ghi=xxx;def,ghi=xxx,jkl=xxx;ghi", true },
324 { "uno:abc,def=xxx,ghi=xxx;def,ghi=xxx,jkl=xxx,;ghi", false },
325 { "uno:abc;def;", false },
326 { "uno:abc;def;a", true },
327 { "uno:abc;def;A", true },
328 { "uno:abc;def;1", true },
329 { "uno:abc;def;$&+,/:=?@", true },
330 { "uno:abc;def;%24&+,/:=?@", false } };
331 for (int i = 0; i < sizeof aTests / sizeof (Test); ++i)
332 {
333 bool bValid = false;
334 try
335 {
336 cppu::UnoUrl aUrl(rtl::OUString::createFromAscii(aTests[i].pInput));
337 bValid = true;
338 }
339 catch (rtl::MalformedUriException &)
340 {}
332 cppu::UnoUrl aUrl(rtl::OUString::createFromAscii(aTests[i].pInput));
333 bValid = true;
334 }
335 catch (rtl::MalformedUriException &)
336 {}
341
337
342 if (aTests[i].bValid)
343 {
344 CPPUNIT_ASSERT_MESSAGE("Valid uri parsed as invalid", bValid);
345 }
346 else
347 {
348 CPPUNIT_ASSERT_MESSAGE("Invalid uri parsed as valid", !bValid);
349 }
350
338 if (aTests[i].bValid)
339 {
340 ASSERT_TRUE(bValid) << "Valid uri parsed as invalid";
351 }
341 }
342 else
343 {
344 ASSERT_TRUE(!bValid) << "Invalid uri parsed as valid";
345 }
346
352 }
347 }
348 }
353
349
354 void testUrlConnection()
350 TEST_F(UrlTest, testUrlConnection)
351 {
352 struct Test
355 {
353 {
356 struct Test
354 char const * pInput;
355 char const * pConnection;
356 };
357 static Test const aTests[]
358 = { { "uno:abc;def;ghi", "abc" },
359 { "uno:Abc;def;ghi", "Abc" },
360 { "uno:aBC;def;ghi", "aBC" },
361 { "uno:ABC;def;ghi", "ABC" },
362 { "uno:abc,def=xxx,ghi=xxx;def,ghi=xxx,jkl=xxx;ghi",
363 "abc,def=xxx,ghi=xxx" } };
364 for (int i = 0; i < sizeof aTests / sizeof (Test); ++i)
365 {
366 bool bValid = false;
367 rtl::OUString aConnection;
368 try
357 {
369 {
358 char const * pInput;
359 char const * pConnection;
360 };
361 static Test const aTests[]
362 = { { "uno:abc;def;ghi", "abc" },
363 { "uno:Abc;def;ghi", "Abc" },
364 { "uno:aBC;def;ghi", "aBC" },
365 { "uno:ABC;def;ghi", "ABC" },
366 { "uno:abc,def=xxx,ghi=xxx;def,ghi=xxx,jkl=xxx;ghi",
367 "abc,def=xxx,ghi=xxx" } };
368 for (int i = 0; i < sizeof aTests / sizeof (Test); ++i)
369 {
370 bool bValid = false;
371 rtl::OUString aConnection;
372 try
373 {
374 aConnection = cppu::UnoUrl(rtl::OUString::createFromAscii(
375 aTests[i].pInput)).
376 getConnection().getDescriptor();
377 bValid = true;
378 }
379 catch (rtl::MalformedUriException &)
380 {}
381 CPPUNIT_ASSERT_MESSAGE("Failed to parse URI", bValid);
382 CPPUNIT_ASSERT_MESSAGE("Failed to get param correctly",
383 aConnection.equalsAscii(
384 aTests[i].pConnection));
370 aConnection = cppu::UnoUrl(rtl::OUString::createFromAscii(
371 aTests[i].pInput)).
372 getConnection().getDescriptor();
373 bValid = true;
385 }
374 }
375 catch (rtl::MalformedUriException &)
376 {}
377 ASSERT_TRUE(bValid) << "Failed to parse URI";
378 ASSERT_TRUE(aConnection.equalsAscii(aTests[i].pConnection)) << "Failed to get param correctly";
386 }
379 }
380 }
387
381
388 void testUrlProtocol()
382 TEST_F(UrlTest, testUrlProtocol)
383 {
384 struct Test
389 {
385 {
390 struct Test
386 char const * pInput;
387 char const * pProtocol;
388 };
389 static Test const aTests[]
390 = { { "uno:abc;def;ghi", "def" },
391 { "uno:abc;Def;ghi", "Def" },
392 { "uno:abc;dEF;ghi", "dEF" },
393 { "uno:abc;DEF;ghi", "DEF" },
394 { "uno:abc,def=xxx,ghi=xxx;def,ghi=xxx,jkl=xxx;ghi",
395 "def,ghi=xxx,jkl=xxx" } };
396 for (int i = 0; i < sizeof aTests / sizeof (Test); ++i)
397 {
398 bool bValid = false;
399 rtl::OUString aProtocol;
400 try
391 {
401 {
392 char const * pInput;
393 char const * pProtocol;
394 };
395 static Test const aTests[]
396 = { { "uno:abc;def;ghi", "def" },
397 { "uno:abc;Def;ghi", "Def" },
398 { "uno:abc;dEF;ghi", "dEF" },
399 { "uno:abc;DEF;ghi", "DEF" },
400 { "uno:abc,def=xxx,ghi=xxx;def,ghi=xxx,jkl=xxx;ghi",
401 "def,ghi=xxx,jkl=xxx" } };
402 for (int i = 0; i < sizeof aTests / sizeof (Test); ++i)
403 {
404 bool bValid = false;
405 rtl::OUString aProtocol;
406 try
407 {
408 aProtocol = cppu::UnoUrl(rtl::OUString::createFromAscii(
409 aTests[i].pInput)).
410 getProtocol().getDescriptor();
411 bValid = true;
412 }
413 catch (rtl::MalformedUriException &)
414 {}
415 CPPUNIT_ASSERT_MESSAGE("Failed to parse URI", bValid);
416 CPPUNIT_ASSERT_MESSAGE("Failed to get protocol correctly",
417 aProtocol.equalsAscii(
418 aTests[i].pProtocol));
402 aProtocol = cppu::UnoUrl(rtl::OUString::createFromAscii(
403 aTests[i].pInput)).
404 getProtocol().getDescriptor();
405 bValid = true;
419 }
406 }
407 catch (rtl::MalformedUriException &)
408 {}
409 ASSERT_TRUE(bValid) << "Failed to parse URI";
410 ASSERT_TRUE(aProtocol.equalsAscii(aTests[i].pProtocol)) << "Failed to get protocol correctly";
420 }
411 }
412 }
421
413
422 void testUrlObjectName()
414 TEST_F(UrlTest, testUrlObjectName)
415 {
416 struct Test
423 {
417 {
424 struct Test
418 char const * pInput;
419 char const * pObjectName;
420 };
421 static Test const aTests[]
422 = { { "uno:abc;def;ghi", "ghi" },
423 { "uno:abc;def;Ghi", "Ghi" },
424 { "uno:abc;def;gHI", "gHI" },
425 { "uno:abc;def;GHI", "GHI" },
426 { "uno:abc,def=xxx,ghi=xxx;def,ghi=xxx,jkl=xxx;ghi", "ghi" },
427 { "uno:abc;def;a", "a" },
428 { "uno:abc;def;A", "A" },
429 { "uno:abc;def;1", "1" },
430 { "uno:abc;def;$&+,/:=?@", "$&+,/:=?@" } };
431 for (int i = 0; i < sizeof aTests / sizeof (Test); ++i)
432 {
433 bool bValid = false;
434 rtl::OUString aObjectName;
435 try
425 {
436 {
426 char const * pInput;
427 char const * pObjectName;
428 };
429 static Test const aTests[]
430 = { { "uno:abc;def;ghi", "ghi" },
431 { "uno:abc;def;Ghi", "Ghi" },
432 { "uno:abc;def;gHI", "gHI" },
433 { "uno:abc;def;GHI", "GHI" },
434 { "uno:abc,def=xxx,ghi=xxx;def,ghi=xxx,jkl=xxx;ghi", "ghi" },
435 { "uno:abc;def;a", "a" },
436 { "uno:abc;def;A", "A" },
437 { "uno:abc;def;1", "1" },
438 { "uno:abc;def;$&+,/:=?@", "$&+,/:=?@" } };
439 for (int i = 0; i < sizeof aTests / sizeof (Test); ++i)
440 {
441 bool bValid = false;
442 rtl::OUString aObjectName;
443 try
444 {
445 aObjectName = cppu::UnoUrl(rtl::OUString::createFromAscii(
446 aTests[i].pInput)).getObjectName();
447 bValid = true;
448 }
449 catch (rtl::MalformedUriException &)
450 {}
451 CPPUNIT_ASSERT_MESSAGE("Failed to parse URI", bValid);
452 CPPUNIT_ASSERT_MESSAGE("Failed to get protocol correctly",
453 aObjectName.equalsAscii(
454 aTests[i].pObjectName));
437 aObjectName = cppu::UnoUrl(rtl::OUString::createFromAscii(
438 aTests[i].pInput)).getObjectName();
439 bValid = true;
455 }
440 }
441 catch (rtl::MalformedUriException &)
442 {}
443 ASSERT_TRUE(bValid) << "Failed to parse URI";
444 ASSERT_TRUE(aObjectName.equalsAscii(aTests[i].pObjectName)) << "Failed to get protocol correctly";
456 }
445 }
457
458 // Automatic registration code
459 CPPUNIT_TEST_SUITE(UrlTest);
460 CPPUNIT_TEST(testDescriptorParsing);
461 CPPUNIT_TEST(testDescriptorDescriptor);
462 CPPUNIT_TEST(testDescriptorName);
463 CPPUNIT_TEST(testDescriptorKey);
464 CPPUNIT_TEST(testDescriptorValue);
465 CPPUNIT_TEST(testUrlParsing);
466 CPPUNIT_TEST(testUrlConnection);
467 CPPUNIT_TEST(testUrlProtocol);
468 CPPUNIT_TEST(testUrlObjectName);
469 CPPUNIT_TEST_SUITE_END();
470 };
446 }
471} // namespace cppu_ifcontainer
472
447} // namespace cppu_ifcontainer
448
473CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(cppu_unourl::UrlTest,
474 "cppu_unourl");
475
476NOADDITIONAL;
477