xref: /trunk/main/cppuhelper/qa/unourl/cppu_unourl.cxx (revision 4b7589a400e7e3ccfa3f2b616a3eceaf5bb44c89)
19d7e27acSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
39d7e27acSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
49d7e27acSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
59d7e27acSAndrew Rist  * distributed with this work for additional information
69d7e27acSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
79d7e27acSAndrew Rist  * to you under the Apache License, Version 2.0 (the
89d7e27acSAndrew Rist  * "License"); you may not use this file except in compliance
99d7e27acSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
119d7e27acSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
139d7e27acSAndrew Rist  * Unless required by applicable law or agreed to in writing,
149d7e27acSAndrew Rist  * software distributed under the License is distributed on an
159d7e27acSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
169d7e27acSAndrew Rist  * KIND, either express or implied.  See the License for the
179d7e27acSAndrew Rist  * specific language governing permissions and limitations
189d7e27acSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
209d7e27acSAndrew Rist  *************************************************************/
219d7e27acSAndrew Rist 
22*4b7589a4SDamjan Jovanovic #include "precompiled_cppuhelper.hxx"
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "cppuhelper/unourl.hxx"
25cdf0e10cSrcweir #include "rtl/malformeduriexception.hxx"
26cdf0e10cSrcweir #include "rtl/strbuf.hxx"
27cdf0e10cSrcweir #include "rtl/string.h"
28cdf0e10cSrcweir #include "rtl/textenc.h"
29cdf0e10cSrcweir #include "rtl/ustring.hxx"
30cdf0e10cSrcweir #include "sal/types.h"
315c0ee992SDamjan Jovanovic #include "gtest/gtest.h"
32cdf0e10cSrcweir 
33cdf0e10cSrcweir namespace cppu_unourl
34cdf0e10cSrcweir {
355c0ee992SDamjan Jovanovic     class UrlTest : public ::testing::Test
36cdf0e10cSrcweir     {
37cdf0e10cSrcweir     public:
385c0ee992SDamjan Jovanovic     };
395c0ee992SDamjan Jovanovic 
405c0ee992SDamjan Jovanovic     TEST_F(UrlTest, testDescriptorParsing)
41cdf0e10cSrcweir     {
42cdf0e10cSrcweir         struct Test
43cdf0e10cSrcweir         {
44cdf0e10cSrcweir             char const * pInput;
45cdf0e10cSrcweir             bool bValid;
46cdf0e10cSrcweir         };
47cdf0e10cSrcweir         static Test const aTests[]
48cdf0e10cSrcweir             = { { "", false },
49cdf0e10cSrcweir                 { "abc", true },
50cdf0e10cSrcweir                 { "Abc", true },
51cdf0e10cSrcweir                 { "aBC", true },
52cdf0e10cSrcweir                 { "ABC", true },
53cdf0e10cSrcweir                 { "1abc", true },
54cdf0e10cSrcweir                 { "123", true },
55cdf0e10cSrcweir                 { "abc-1", false },
56cdf0e10cSrcweir                 { "ab%63", false },
57cdf0e10cSrcweir                 { "abc,", false },
58cdf0e10cSrcweir                 { "abc,def=", true },
59cdf0e10cSrcweir                 { "abc,Def=", true },
60cdf0e10cSrcweir                 { "abc,DEF=", true },
61cdf0e10cSrcweir                 { "abc,1def=", true },
62cdf0e10cSrcweir                 { "abc,123=", true },
63cdf0e10cSrcweir                 { "abc,def-1=", false },
64cdf0e10cSrcweir                 { "abc,def", false },
65cdf0e10cSrcweir                 { "abc,def=xxx,def=xxx", false },
66cdf0e10cSrcweir                 { "abc,def=xxx,ghi=xxx", true },
67cdf0e10cSrcweir                 { "abc,,def=xxx", false },
68cdf0e10cSrcweir                 { "abc,def=xxx,,ghi=xxx", false },
69cdf0e10cSrcweir                 { "abc,def=xxx,ghi=xxx,", false },
70cdf0e10cSrcweir                 { "abc,def=%", true },
71cdf0e10cSrcweir                 { "abc,def=%1", true },
72cdf0e10cSrcweir                 { "abc,def=%00", true },
73cdf0e10cSrcweir                 { "abc,def=%22", true },
74cdf0e10cSrcweir                 { "abc,def=\"", true },
75cdf0e10cSrcweir                 { "abc,def=%ed%a0%80", true } };
76cdf0e10cSrcweir         for (int i = 0; i < sizeof aTests / sizeof (Test); ++i)
77cdf0e10cSrcweir         {
78cdf0e10cSrcweir             bool bValid = false;
79cdf0e10cSrcweir             try
80cdf0e10cSrcweir             {
81cdf0e10cSrcweir                 cppu::UnoUrlDescriptor aDescriptor(rtl::OUString::createFromAscii(
82cdf0e10cSrcweir                                                        aTests[i].pInput));
83cdf0e10cSrcweir                 bValid = true;
84cdf0e10cSrcweir             }
85cdf0e10cSrcweir             catch (rtl::MalformedUriException &)
86cdf0e10cSrcweir             {}
87cdf0e10cSrcweir 
88cdf0e10cSrcweir             if (aTests[i].bValid)
89cdf0e10cSrcweir             {
905c0ee992SDamjan Jovanovic                 ASSERT_TRUE(bValid) << "Valid uri parsed as invalid";
91cdf0e10cSrcweir             }
92cdf0e10cSrcweir             else
93cdf0e10cSrcweir             {
945c0ee992SDamjan Jovanovic                 ASSERT_TRUE(!bValid) << "Invalid uri parsed as valid";
95cdf0e10cSrcweir             }
96cdf0e10cSrcweir         }
97cdf0e10cSrcweir     }
98cdf0e10cSrcweir 
995c0ee992SDamjan Jovanovic     TEST_F(UrlTest, testDescriptorDescriptor)
100cdf0e10cSrcweir     {
101cdf0e10cSrcweir         struct Test
102cdf0e10cSrcweir         {
103cdf0e10cSrcweir             char const * pInput;
104cdf0e10cSrcweir             char const * pDescriptor;
105cdf0e10cSrcweir         };
106cdf0e10cSrcweir         static Test const aTests[]
107cdf0e10cSrcweir             = {{ "abc", "abc" },
108cdf0e10cSrcweir                { "Abc", "Abc" },
109cdf0e10cSrcweir                { "aBC", "aBC" },
110cdf0e10cSrcweir                { "ABC", "ABC" },
111cdf0e10cSrcweir                { "1abc", "1abc" },
112cdf0e10cSrcweir                { "123", "123" },
113cdf0e10cSrcweir                { "abc,def=", "abc,def=" },
114cdf0e10cSrcweir                { "abc,Def=", "abc,Def=" },
115cdf0e10cSrcweir                { "abc,DEF=", "abc,DEF=" },
116cdf0e10cSrcweir                { "abc,1def=", "abc,1def=" },
117cdf0e10cSrcweir                { "abc,123=", "abc,123=" },
118cdf0e10cSrcweir                { "abc,def=xxx,ghi=xxx", "abc,def=xxx,ghi=xxx" },
119cdf0e10cSrcweir                { "abc,def=%", "abc,def=%" },
120cdf0e10cSrcweir                { "abc,def=%1", "abc,def=%1" },
121cdf0e10cSrcweir                { "abc,def=%00", "abc,def=%00" },
122cdf0e10cSrcweir                { "abc,def=%22", "abc,def=%22" },
123cdf0e10cSrcweir                { "abc,def=\"", "abc,def=\"" },
124cdf0e10cSrcweir                { "abc,def=%ed%a0%80", "abc,def=%ed%a0%80" } };
125cdf0e10cSrcweir         bool bResult = true;
126cdf0e10cSrcweir         for (int i = 0; i < sizeof aTests / sizeof (Test); ++i)
127cdf0e10cSrcweir         {
128cdf0e10cSrcweir             bool bValid = false;
129cdf0e10cSrcweir             rtl::OUString aDescriptor;
130cdf0e10cSrcweir             try
131cdf0e10cSrcweir             {
132cdf0e10cSrcweir                 aDescriptor = cppu::UnoUrlDescriptor(rtl::OUString::createFromAscii(
133cdf0e10cSrcweir                                                          aTests[i].pInput)).
134cdf0e10cSrcweir                    getDescriptor();
135cdf0e10cSrcweir                 bValid = true;
136cdf0e10cSrcweir             }
137cdf0e10cSrcweir             catch (rtl::MalformedUriException &)
138cdf0e10cSrcweir             {}
139cdf0e10cSrcweir 
1405c0ee992SDamjan Jovanovic             ASSERT_TRUE(bValid) << "Failed to parse URI";
1415c0ee992SDamjan Jovanovic             ASSERT_TRUE(aDescriptor.equalsAscii(aTests[i].pDescriptor)) << "Failed to parse URI correctly";
142cdf0e10cSrcweir         }
143cdf0e10cSrcweir     }
144cdf0e10cSrcweir 
145cdf0e10cSrcweir 
1465c0ee992SDamjan Jovanovic     TEST_F(UrlTest, testDescriptorName)
147cdf0e10cSrcweir     {
148cdf0e10cSrcweir         struct Test
149cdf0e10cSrcweir         {
150cdf0e10cSrcweir             char const * pInput;
151cdf0e10cSrcweir             char const * pName;
152cdf0e10cSrcweir         };
153cdf0e10cSrcweir         static Test const aTests[]
154cdf0e10cSrcweir             = { { "abc", "abc" },
155cdf0e10cSrcweir                 { "Abc", "abc" },
156cdf0e10cSrcweir                 { "aBC", "abc" },
157cdf0e10cSrcweir                 { "ABC", "abc" },
158cdf0e10cSrcweir                 { "1abc", "1abc" },
159cdf0e10cSrcweir                 { "123", "123" },
160cdf0e10cSrcweir                 { "abc,def=", "abc" },
161cdf0e10cSrcweir                 { "abc,Def=", "abc" },
162cdf0e10cSrcweir                 { "abc,DEF=", "abc" },
163cdf0e10cSrcweir                 { "abc,1def=", "abc" },
164cdf0e10cSrcweir                 { "abc,123=", "abc" },
165cdf0e10cSrcweir                 { "abc,def=xxx,ghi=xxx", "abc" },
166cdf0e10cSrcweir                 { "abc,def=%", "abc" },
167cdf0e10cSrcweir                 { "abc,def=%1", "abc" },
168cdf0e10cSrcweir                 { "abc,def=%00", "abc" },
169cdf0e10cSrcweir                 { "abc,def=%22", "abc" },
170cdf0e10cSrcweir                 { "abc,def=\"", "abc" },
171cdf0e10cSrcweir                 { "abc,def=%ed%a0%80", "abc" } };
172cdf0e10cSrcweir         for (int i = 0; i < sizeof aTests / sizeof (Test); ++i)
173cdf0e10cSrcweir         {
174cdf0e10cSrcweir             bool bValid = false;
175cdf0e10cSrcweir             rtl::OUString aName;
176cdf0e10cSrcweir             try
177cdf0e10cSrcweir             {
178cdf0e10cSrcweir                 aName = cppu::UnoUrlDescriptor(rtl::OUString::createFromAscii(
179cdf0e10cSrcweir                                                    aTests[i].pInput)).getName();
180cdf0e10cSrcweir                 bValid = true;
181cdf0e10cSrcweir             }
182cdf0e10cSrcweir             catch (rtl::MalformedUriException &)
183cdf0e10cSrcweir             {}
184cdf0e10cSrcweir 
1855c0ee992SDamjan Jovanovic             ASSERT_TRUE(bValid) << "Failed to parse URI";
1865c0ee992SDamjan Jovanovic             ASSERT_TRUE(aName.equalsAscii(aTests[i].pName)) << "Failed to parse URI correctly";
187cdf0e10cSrcweir         }
188cdf0e10cSrcweir     }
189cdf0e10cSrcweir 
1905c0ee992SDamjan Jovanovic     TEST_F(UrlTest, testDescriptorKey)
191cdf0e10cSrcweir     {
192cdf0e10cSrcweir         struct Test
193cdf0e10cSrcweir         {
194cdf0e10cSrcweir             char const * pInput;
195cdf0e10cSrcweir             char const * pKey;
196cdf0e10cSrcweir             bool bPresent;
197cdf0e10cSrcweir         };
198cdf0e10cSrcweir         static Test const aTests[]
199cdf0e10cSrcweir             = { { "abc", "abc", false },
200cdf0e10cSrcweir                 { "abc", "def", false },
201cdf0e10cSrcweir                 { "1abc", "def", false },
202cdf0e10cSrcweir                 { "123", "def", false },
203cdf0e10cSrcweir                 { "abc,def=", "abc", false },
204cdf0e10cSrcweir                 { "abc,def=", "def", true },
205cdf0e10cSrcweir                 { "abc,def=", "defg", false },
206cdf0e10cSrcweir                 { "abc,def=", "de", false },
207cdf0e10cSrcweir                 { "abc,def=", "ghi", false },
208cdf0e10cSrcweir                 { "abc,Def=", "def", true },
209cdf0e10cSrcweir                 { "abc,Def=", "Def", true },
210cdf0e10cSrcweir                 { "abc,Def=", "dEF", true },
211cdf0e10cSrcweir                 { "abc,Def=", "DEF", true },
212cdf0e10cSrcweir                 { "abc,def=xxx,ghi=xxx", "abc", false },
213cdf0e10cSrcweir                 { "abc,def=xxx,ghi=xxx", "def", true },
214cdf0e10cSrcweir                 { "abc,def=xxx,ghi=xxx", "ghi", true },
215cdf0e10cSrcweir                 { "abc,def=xxx,ghi=xxx", "jkl", false } };
216cdf0e10cSrcweir         for (int i = 0; i < sizeof aTests / sizeof (Test); ++i)
217cdf0e10cSrcweir         {
218cdf0e10cSrcweir             bool bValid = false;
219cdf0e10cSrcweir             bool bPresent = false;
220cdf0e10cSrcweir             try
221cdf0e10cSrcweir             {
222cdf0e10cSrcweir                 bPresent = cppu::UnoUrlDescriptor(rtl::OUString::createFromAscii(
223cdf0e10cSrcweir                                                       aTests[i].pInput)).
224cdf0e10cSrcweir                     hasParameter(rtl::OUString::createFromAscii(aTests[i].pKey));
225cdf0e10cSrcweir                 bValid = true;
226cdf0e10cSrcweir             }
227cdf0e10cSrcweir             catch (rtl::MalformedUriException &)
228cdf0e10cSrcweir             {}
229cdf0e10cSrcweir 
2305c0ee992SDamjan Jovanovic             ASSERT_TRUE(bValid) << "Failed to parse URI";
2315c0ee992SDamjan Jovanovic             ASSERT_TRUE(bPresent == aTests[i].bPresent) << "Failed to detect parameter correctly";
232cdf0e10cSrcweir         }
233cdf0e10cSrcweir     }
234cdf0e10cSrcweir 
2355c0ee992SDamjan Jovanovic     TEST_F(UrlTest, testDescriptorValue)
236cdf0e10cSrcweir     {
237cdf0e10cSrcweir         struct Test
238cdf0e10cSrcweir         {
239cdf0e10cSrcweir             char const * pInput;
240cdf0e10cSrcweir             char const * pKey;
241cdf0e10cSrcweir             char const * pValue;
242cdf0e10cSrcweir         };
243cdf0e10cSrcweir         static Test const aTests[]
244cdf0e10cSrcweir             = { { "abc", "abc", "" },
245cdf0e10cSrcweir                 { "abc", "def", "" },
246cdf0e10cSrcweir                 { "1abc", "def", "" },
247cdf0e10cSrcweir                 { "123", "def", "" },
248cdf0e10cSrcweir                 { "abc,def=", "abc", "" },
249cdf0e10cSrcweir                 { "abc,def=", "def", "" },
250cdf0e10cSrcweir                 { "abc,def=", "defg", "" },
251cdf0e10cSrcweir                 { "abc,def=", "de", "" },
252cdf0e10cSrcweir                 { "abc,def=", "ghi", "" },
253cdf0e10cSrcweir                 { "abc,Def=", "def", "" },
254cdf0e10cSrcweir                 { "abc,Def=", "Def", "" },
255cdf0e10cSrcweir                 { "abc,Def=", "dEF", "" },
256cdf0e10cSrcweir                 { "abc,Def=", "DEF", "" },
257cdf0e10cSrcweir                 { "abc,def=xxx,ghi=xxx", "abc", "" },
258cdf0e10cSrcweir                 { "abc,def=xxx,ghi=xxx", "def", "xxx" },
259cdf0e10cSrcweir                 { "abc,def=xxx,ghi=xxx", "ghi", "xxx" },
260cdf0e10cSrcweir                 { "abc,def=xxx,ghi=xxx", "jkl", "" },
261cdf0e10cSrcweir                 { "abc,def=%", "def", "%" },
262cdf0e10cSrcweir                 { "abc,def=%1", "def", "%1" },
263cdf0e10cSrcweir                 { "abc,def=%22", "def", "\"" },
264cdf0e10cSrcweir                 { "abc,def=\"", "def", "\"" },
265cdf0e10cSrcweir                 { "abc,def=abc", "def", "abc" },
266cdf0e10cSrcweir                 { "abc,def=Abc", "def", "Abc" },
267cdf0e10cSrcweir                 { "abc,def=aBC", "def", "aBC" },
268cdf0e10cSrcweir                 { "abc,def=ABC", "def", "ABC" },
269cdf0e10cSrcweir                 { "abc,def=%,ghi=", "def", "%" },
270cdf0e10cSrcweir                 { "abc,def=%1,ghi=", "def", "%1" },
271cdf0e10cSrcweir                 { "abc,def=%22,ghi=", "def", "\"" },
272cdf0e10cSrcweir                 { "abc,def=\",ghi=", "def", "\"" },
273cdf0e10cSrcweir                 { "abc,def=abc,ghi=", "def", "abc" },
274cdf0e10cSrcweir                 { "abc,def=Abc,ghi=", "def", "Abc" },
275cdf0e10cSrcweir                 { "abc,def=aBC,ghi=", "def", "aBC" },
276cdf0e10cSrcweir                 { "abc,def=ABC,ghi=", "def", "ABC" },
277cdf0e10cSrcweir                 { "abc,abc=,def=%", "def", "%" },
278cdf0e10cSrcweir                 { "abc,abc=,def=%1", "def", "%1" },
279cdf0e10cSrcweir                 { "abc,abc=,def=%22", "def", "\"" },
280cdf0e10cSrcweir                 { "abc,abc=,def=\"", "def", "\"" },
281cdf0e10cSrcweir                 { "abc,abc=,def=abc", "def", "abc" },
282cdf0e10cSrcweir                 { "abc,abc=,def=Abc", "def", "Abc" },
283cdf0e10cSrcweir                 { "abc,abc=,def=aBC", "def", "aBC" },
284cdf0e10cSrcweir                 { "abc,abc=,def=ABC", "def", "ABC" } };
285cdf0e10cSrcweir         for (int i = 0; i < sizeof aTests / sizeof (Test); ++i)
286cdf0e10cSrcweir         {
287cdf0e10cSrcweir             bool bValid = false;
288cdf0e10cSrcweir             rtl::OUString aValue;
289cdf0e10cSrcweir             try
290cdf0e10cSrcweir             {
291cdf0e10cSrcweir                 aValue = cppu::UnoUrlDescriptor(rtl::OUString::createFromAscii(
292cdf0e10cSrcweir                                                     aTests[i].pInput)).
293cdf0e10cSrcweir                     getParameter(rtl::OUString::createFromAscii(aTests[i].pKey));
294cdf0e10cSrcweir                 bValid = true;
295cdf0e10cSrcweir             }
296cdf0e10cSrcweir             catch (rtl::MalformedUriException &)
297cdf0e10cSrcweir             {}
2985c0ee992SDamjan Jovanovic             ASSERT_TRUE(bValid) << "Failed to parse URI";
2995c0ee992SDamjan Jovanovic             ASSERT_TRUE(aValue.equalsAscii(aTests[i].pValue)) << "Failed to get param correctly";
300cdf0e10cSrcweir         }
301cdf0e10cSrcweir     }
302cdf0e10cSrcweir 
3035c0ee992SDamjan Jovanovic     TEST_F(UrlTest, testUrlParsing)
304cdf0e10cSrcweir     {
305cdf0e10cSrcweir         struct Test
306cdf0e10cSrcweir         {
307cdf0e10cSrcweir             char const * pInput;
308cdf0e10cSrcweir             bool bValid;
309cdf0e10cSrcweir         };
310cdf0e10cSrcweir         static Test const aTests[]
311cdf0e10cSrcweir             = { { "", false },
312cdf0e10cSrcweir                 { "abc", false },
313cdf0e10cSrcweir                 { "uno", false },
314cdf0e10cSrcweir                 { "uno:", false },
315cdf0e10cSrcweir                 { "uno:abc;def;ghi", true },
316cdf0e10cSrcweir                 { "Uno:abc;def;ghi", true },
317cdf0e10cSrcweir                 { "uNO:abc;def;ghi", true },
318cdf0e10cSrcweir                 { "UNO:abc;def;ghi", true },
319cdf0e10cSrcweir                 { "uno:abc,def=xxx,ghi=xxx;def,ghi=xxx,jkl=xxx;ghi", true },
320cdf0e10cSrcweir                 { "uno:abc,def=xxx,ghi=xxx;def,ghi=xxx,jkl=xxx,;ghi", false },
321cdf0e10cSrcweir                 { "uno:abc;def;", false },
322cdf0e10cSrcweir                 { "uno:abc;def;a", true },
323cdf0e10cSrcweir                 { "uno:abc;def;A", true },
324cdf0e10cSrcweir                 { "uno:abc;def;1", true },
325cdf0e10cSrcweir                 { "uno:abc;def;$&+,/:=?@", true },
326cdf0e10cSrcweir                 { "uno:abc;def;%24&+,/:=?@", false } };
327cdf0e10cSrcweir         for (int i = 0; i < sizeof aTests / sizeof (Test); ++i)
328cdf0e10cSrcweir         {
329cdf0e10cSrcweir             bool bValid = false;
330cdf0e10cSrcweir             try
331cdf0e10cSrcweir             {
332cdf0e10cSrcweir                 cppu::UnoUrl aUrl(rtl::OUString::createFromAscii(aTests[i].pInput));
333cdf0e10cSrcweir                 bValid = true;
334cdf0e10cSrcweir             }
335cdf0e10cSrcweir             catch (rtl::MalformedUriException &)
336cdf0e10cSrcweir             {}
337cdf0e10cSrcweir 
338cdf0e10cSrcweir             if (aTests[i].bValid)
339cdf0e10cSrcweir             {
3405c0ee992SDamjan Jovanovic                 ASSERT_TRUE(bValid) << "Valid uri parsed as invalid";
341cdf0e10cSrcweir             }
342cdf0e10cSrcweir             else
343cdf0e10cSrcweir             {
3445c0ee992SDamjan Jovanovic                 ASSERT_TRUE(!bValid) << "Invalid uri parsed as valid";
345cdf0e10cSrcweir             }
346cdf0e10cSrcweir 
347cdf0e10cSrcweir         }
348cdf0e10cSrcweir     }
349cdf0e10cSrcweir 
3505c0ee992SDamjan Jovanovic     TEST_F(UrlTest, testUrlConnection)
351cdf0e10cSrcweir     {
352cdf0e10cSrcweir         struct Test
353cdf0e10cSrcweir         {
354cdf0e10cSrcweir             char const * pInput;
355cdf0e10cSrcweir             char const * pConnection;
356cdf0e10cSrcweir         };
357cdf0e10cSrcweir         static Test const aTests[]
358cdf0e10cSrcweir             = { { "uno:abc;def;ghi", "abc" },
359cdf0e10cSrcweir                 { "uno:Abc;def;ghi", "Abc" },
360cdf0e10cSrcweir                 { "uno:aBC;def;ghi", "aBC" },
361cdf0e10cSrcweir                 { "uno:ABC;def;ghi", "ABC" },
362cdf0e10cSrcweir                 { "uno:abc,def=xxx,ghi=xxx;def,ghi=xxx,jkl=xxx;ghi",
363cdf0e10cSrcweir                   "abc,def=xxx,ghi=xxx" } };
364cdf0e10cSrcweir         for (int i = 0; i < sizeof aTests / sizeof (Test); ++i)
365cdf0e10cSrcweir         {
366cdf0e10cSrcweir             bool bValid = false;
367cdf0e10cSrcweir             rtl::OUString aConnection;
368cdf0e10cSrcweir             try
369cdf0e10cSrcweir             {
370cdf0e10cSrcweir                 aConnection = cppu::UnoUrl(rtl::OUString::createFromAscii(
371cdf0e10cSrcweir                                                aTests[i].pInput)).
372cdf0e10cSrcweir                     getConnection().getDescriptor();
373cdf0e10cSrcweir                 bValid = true;
374cdf0e10cSrcweir             }
375cdf0e10cSrcweir             catch (rtl::MalformedUriException &)
376cdf0e10cSrcweir             {}
3775c0ee992SDamjan Jovanovic             ASSERT_TRUE(bValid) << "Failed to parse URI";
3785c0ee992SDamjan Jovanovic             ASSERT_TRUE(aConnection.equalsAscii(aTests[i].pConnection)) << "Failed to get param correctly";
379cdf0e10cSrcweir         }
380cdf0e10cSrcweir     }
381cdf0e10cSrcweir 
3825c0ee992SDamjan Jovanovic     TEST_F(UrlTest, testUrlProtocol)
383cdf0e10cSrcweir     {
384cdf0e10cSrcweir         struct Test
385cdf0e10cSrcweir         {
386cdf0e10cSrcweir             char const * pInput;
387cdf0e10cSrcweir             char const * pProtocol;
388cdf0e10cSrcweir         };
389cdf0e10cSrcweir         static Test const aTests[]
390cdf0e10cSrcweir             = { { "uno:abc;def;ghi", "def" },
391cdf0e10cSrcweir                 { "uno:abc;Def;ghi", "Def" },
392cdf0e10cSrcweir                 { "uno:abc;dEF;ghi", "dEF" },
393cdf0e10cSrcweir                 { "uno:abc;DEF;ghi", "DEF" },
394cdf0e10cSrcweir                 { "uno:abc,def=xxx,ghi=xxx;def,ghi=xxx,jkl=xxx;ghi",
395cdf0e10cSrcweir                   "def,ghi=xxx,jkl=xxx" } };
396cdf0e10cSrcweir         for (int i = 0; i < sizeof aTests / sizeof (Test); ++i)
397cdf0e10cSrcweir         {
398cdf0e10cSrcweir             bool bValid = false;
399cdf0e10cSrcweir             rtl::OUString aProtocol;
400cdf0e10cSrcweir             try
401cdf0e10cSrcweir             {
402cdf0e10cSrcweir                 aProtocol = cppu::UnoUrl(rtl::OUString::createFromAscii(
403cdf0e10cSrcweir                                              aTests[i].pInput)).
404cdf0e10cSrcweir                     getProtocol().getDescriptor();
405cdf0e10cSrcweir                 bValid = true;
406cdf0e10cSrcweir             }
407cdf0e10cSrcweir             catch (rtl::MalformedUriException &)
408cdf0e10cSrcweir             {}
4095c0ee992SDamjan Jovanovic             ASSERT_TRUE(bValid) << "Failed to parse URI";
4105c0ee992SDamjan Jovanovic             ASSERT_TRUE(aProtocol.equalsAscii(aTests[i].pProtocol)) << "Failed to get protocol correctly";
411cdf0e10cSrcweir         }
412cdf0e10cSrcweir     }
413cdf0e10cSrcweir 
4145c0ee992SDamjan Jovanovic     TEST_F(UrlTest, testUrlObjectName)
415cdf0e10cSrcweir     {
416cdf0e10cSrcweir         struct Test
417cdf0e10cSrcweir         {
418cdf0e10cSrcweir             char const * pInput;
419cdf0e10cSrcweir             char const * pObjectName;
420cdf0e10cSrcweir         };
421cdf0e10cSrcweir         static Test const aTests[]
422cdf0e10cSrcweir             = { { "uno:abc;def;ghi", "ghi" },
423cdf0e10cSrcweir                 { "uno:abc;def;Ghi", "Ghi" },
424cdf0e10cSrcweir                 { "uno:abc;def;gHI", "gHI" },
425cdf0e10cSrcweir                 { "uno:abc;def;GHI", "GHI" },
426cdf0e10cSrcweir                 { "uno:abc,def=xxx,ghi=xxx;def,ghi=xxx,jkl=xxx;ghi", "ghi" },
427cdf0e10cSrcweir                 { "uno:abc;def;a", "a" },
428cdf0e10cSrcweir                 { "uno:abc;def;A", "A" },
429cdf0e10cSrcweir                 { "uno:abc;def;1", "1" },
430cdf0e10cSrcweir                 { "uno:abc;def;$&+,/:=?@", "$&+,/:=?@" } };
431cdf0e10cSrcweir         for (int i = 0; i < sizeof aTests / sizeof (Test); ++i)
432cdf0e10cSrcweir         {
433cdf0e10cSrcweir             bool bValid = false;
434cdf0e10cSrcweir             rtl::OUString aObjectName;
435cdf0e10cSrcweir             try
436cdf0e10cSrcweir             {
437cdf0e10cSrcweir                 aObjectName = cppu::UnoUrl(rtl::OUString::createFromAscii(
438cdf0e10cSrcweir                                                aTests[i].pInput)).getObjectName();
439cdf0e10cSrcweir                 bValid = true;
440cdf0e10cSrcweir             }
441cdf0e10cSrcweir             catch (rtl::MalformedUriException &)
442cdf0e10cSrcweir             {}
4435c0ee992SDamjan Jovanovic             ASSERT_TRUE(bValid) << "Failed to parse URI";
4445c0ee992SDamjan Jovanovic             ASSERT_TRUE(aObjectName.equalsAscii(aTests[i].pObjectName)) << "Failed to get protocol correctly";
445cdf0e10cSrcweir         }
446cdf0e10cSrcweir     }
447cdf0e10cSrcweir } // namespace cppu_ifcontainer
448cdf0e10cSrcweir 
44926d3e425SDamjan Jovanovic int main(int argc, char **argv)
45026d3e425SDamjan Jovanovic {
45126d3e425SDamjan Jovanovic     ::testing::InitGoogleTest(&argc, argv);
45226d3e425SDamjan Jovanovic     return RUN_ALL_TESTS();
45326d3e425SDamjan Jovanovic }
45426d3e425SDamjan Jovanovic 
455