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
109d7e27acSAndrew Rist *
119d7e27acSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
129d7e27acSAndrew Rist *
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.
199d7e27acSAndrew Rist *
209d7e27acSAndrew Rist *************************************************************/
219d7e27acSAndrew Rist
224b7589a4SDamjan 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
TEST_F(UrlTest,testDescriptorParsing)405c0ee992SDamjan Jovanovic TEST_F(UrlTest, testDescriptorParsing)
415c0ee992SDamjan Jovanovic {
425c0ee992SDamjan Jovanovic struct Test
43cdf0e10cSrcweir {
445c0ee992SDamjan Jovanovic char const * pInput;
455c0ee992SDamjan Jovanovic bool bValid;
465c0ee992SDamjan Jovanovic };
475c0ee992SDamjan Jovanovic static Test const aTests[]
485c0ee992SDamjan Jovanovic = { { "", false },
495c0ee992SDamjan Jovanovic { "abc", true },
505c0ee992SDamjan Jovanovic { "Abc", true },
515c0ee992SDamjan Jovanovic { "aBC", true },
525c0ee992SDamjan Jovanovic { "ABC", true },
535c0ee992SDamjan Jovanovic { "1abc", true },
545c0ee992SDamjan Jovanovic { "123", true },
555c0ee992SDamjan Jovanovic { "abc-1", false },
565c0ee992SDamjan Jovanovic { "ab%63", false },
575c0ee992SDamjan Jovanovic { "abc,", false },
585c0ee992SDamjan Jovanovic { "abc,def=", true },
595c0ee992SDamjan Jovanovic { "abc,Def=", true },
605c0ee992SDamjan Jovanovic { "abc,DEF=", true },
615c0ee992SDamjan Jovanovic { "abc,1def=", true },
625c0ee992SDamjan Jovanovic { "abc,123=", true },
635c0ee992SDamjan Jovanovic { "abc,def-1=", false },
645c0ee992SDamjan Jovanovic { "abc,def", false },
655c0ee992SDamjan Jovanovic { "abc,def=xxx,def=xxx", false },
665c0ee992SDamjan Jovanovic { "abc,def=xxx,ghi=xxx", true },
675c0ee992SDamjan Jovanovic { "abc,,def=xxx", false },
685c0ee992SDamjan Jovanovic { "abc,def=xxx,,ghi=xxx", false },
695c0ee992SDamjan Jovanovic { "abc,def=xxx,ghi=xxx,", false },
705c0ee992SDamjan Jovanovic { "abc,def=%", true },
715c0ee992SDamjan Jovanovic { "abc,def=%1", true },
725c0ee992SDamjan Jovanovic { "abc,def=%00", true },
735c0ee992SDamjan Jovanovic { "abc,def=%22", true },
745c0ee992SDamjan Jovanovic { "abc,def=\"", true },
755c0ee992SDamjan Jovanovic { "abc,def=%ed%a0%80", true } };
76*2cfa35e9SPeter Kovacs for (unsigned int i = 0; i < sizeof aTests / sizeof (Test); ++i)
775c0ee992SDamjan Jovanovic {
785c0ee992SDamjan Jovanovic bool bValid = false;
795c0ee992SDamjan Jovanovic try
80cdf0e10cSrcweir {
815c0ee992SDamjan Jovanovic cppu::UnoUrlDescriptor aDescriptor(rtl::OUString::createFromAscii(
825c0ee992SDamjan Jovanovic aTests[i].pInput));
835c0ee992SDamjan Jovanovic bValid = true;
845c0ee992SDamjan Jovanovic }
855c0ee992SDamjan Jovanovic catch (rtl::MalformedUriException &)
865c0ee992SDamjan Jovanovic {}
87cdf0e10cSrcweir
885c0ee992SDamjan Jovanovic if (aTests[i].bValid)
895c0ee992SDamjan Jovanovic {
905c0ee992SDamjan Jovanovic ASSERT_TRUE(bValid) << "Valid uri parsed as invalid";
915c0ee992SDamjan Jovanovic }
925c0ee992SDamjan Jovanovic else
935c0ee992SDamjan Jovanovic {
945c0ee992SDamjan Jovanovic ASSERT_TRUE(!bValid) << "Invalid uri parsed as valid";
95cdf0e10cSrcweir }
96cdf0e10cSrcweir }
975c0ee992SDamjan Jovanovic }
98cdf0e10cSrcweir
TEST_F(UrlTest,testDescriptorDescriptor)995c0ee992SDamjan Jovanovic TEST_F(UrlTest, testDescriptorDescriptor)
1005c0ee992SDamjan Jovanovic {
1015c0ee992SDamjan Jovanovic struct Test
102cdf0e10cSrcweir {
1035c0ee992SDamjan Jovanovic char const * pInput;
1045c0ee992SDamjan Jovanovic char const * pDescriptor;
1055c0ee992SDamjan Jovanovic };
1065c0ee992SDamjan Jovanovic static Test const aTests[]
1075c0ee992SDamjan Jovanovic = {{ "abc", "abc" },
1085c0ee992SDamjan Jovanovic { "Abc", "Abc" },
1095c0ee992SDamjan Jovanovic { "aBC", "aBC" },
1105c0ee992SDamjan Jovanovic { "ABC", "ABC" },
1115c0ee992SDamjan Jovanovic { "1abc", "1abc" },
1125c0ee992SDamjan Jovanovic { "123", "123" },
1135c0ee992SDamjan Jovanovic { "abc,def=", "abc,def=" },
1145c0ee992SDamjan Jovanovic { "abc,Def=", "abc,Def=" },
1155c0ee992SDamjan Jovanovic { "abc,DEF=", "abc,DEF=" },
1165c0ee992SDamjan Jovanovic { "abc,1def=", "abc,1def=" },
1175c0ee992SDamjan Jovanovic { "abc,123=", "abc,123=" },
1185c0ee992SDamjan Jovanovic { "abc,def=xxx,ghi=xxx", "abc,def=xxx,ghi=xxx" },
1195c0ee992SDamjan Jovanovic { "abc,def=%", "abc,def=%" },
1205c0ee992SDamjan Jovanovic { "abc,def=%1", "abc,def=%1" },
1215c0ee992SDamjan Jovanovic { "abc,def=%00", "abc,def=%00" },
1225c0ee992SDamjan Jovanovic { "abc,def=%22", "abc,def=%22" },
1235c0ee992SDamjan Jovanovic { "abc,def=\"", "abc,def=\"" },
1245c0ee992SDamjan Jovanovic { "abc,def=%ed%a0%80", "abc,def=%ed%a0%80" } };
125*2cfa35e9SPeter Kovacs for (unsigned int i = 0; i < sizeof aTests / sizeof (Test); ++i)
1265c0ee992SDamjan Jovanovic {
1275c0ee992SDamjan Jovanovic bool bValid = false;
1285c0ee992SDamjan Jovanovic rtl::OUString aDescriptor;
1295c0ee992SDamjan Jovanovic try
130cdf0e10cSrcweir {
1315c0ee992SDamjan Jovanovic aDescriptor = cppu::UnoUrlDescriptor(rtl::OUString::createFromAscii(
1325c0ee992SDamjan Jovanovic aTests[i].pInput)).
1335c0ee992SDamjan Jovanovic getDescriptor();
1345c0ee992SDamjan Jovanovic bValid = true;
135cdf0e10cSrcweir }
1365c0ee992SDamjan Jovanovic catch (rtl::MalformedUriException &)
1375c0ee992SDamjan Jovanovic {}
1385c0ee992SDamjan Jovanovic
1395c0ee992SDamjan Jovanovic ASSERT_TRUE(bValid) << "Failed to parse URI";
1405c0ee992SDamjan Jovanovic ASSERT_TRUE(aDescriptor.equalsAscii(aTests[i].pDescriptor)) << "Failed to parse URI correctly";
141cdf0e10cSrcweir }
1425c0ee992SDamjan Jovanovic }
143cdf0e10cSrcweir
144cdf0e10cSrcweir
TEST_F(UrlTest,testDescriptorName)1455c0ee992SDamjan Jovanovic TEST_F(UrlTest, testDescriptorName)
1465c0ee992SDamjan Jovanovic {
1475c0ee992SDamjan Jovanovic struct Test
148cdf0e10cSrcweir {
1495c0ee992SDamjan Jovanovic char const * pInput;
1505c0ee992SDamjan Jovanovic char const * pName;
1515c0ee992SDamjan Jovanovic };
1525c0ee992SDamjan Jovanovic static Test const aTests[]
1535c0ee992SDamjan Jovanovic = { { "abc", "abc" },
1545c0ee992SDamjan Jovanovic { "Abc", "abc" },
1555c0ee992SDamjan Jovanovic { "aBC", "abc" },
1565c0ee992SDamjan Jovanovic { "ABC", "abc" },
1575c0ee992SDamjan Jovanovic { "1abc", "1abc" },
1585c0ee992SDamjan Jovanovic { "123", "123" },
1595c0ee992SDamjan Jovanovic { "abc,def=", "abc" },
1605c0ee992SDamjan Jovanovic { "abc,Def=", "abc" },
1615c0ee992SDamjan Jovanovic { "abc,DEF=", "abc" },
1625c0ee992SDamjan Jovanovic { "abc,1def=", "abc" },
1635c0ee992SDamjan Jovanovic { "abc,123=", "abc" },
1645c0ee992SDamjan Jovanovic { "abc,def=xxx,ghi=xxx", "abc" },
1655c0ee992SDamjan Jovanovic { "abc,def=%", "abc" },
1665c0ee992SDamjan Jovanovic { "abc,def=%1", "abc" },
1675c0ee992SDamjan Jovanovic { "abc,def=%00", "abc" },
1685c0ee992SDamjan Jovanovic { "abc,def=%22", "abc" },
1695c0ee992SDamjan Jovanovic { "abc,def=\"", "abc" },
1705c0ee992SDamjan Jovanovic { "abc,def=%ed%a0%80", "abc" } };
171*2cfa35e9SPeter Kovacs for (unsigned int i = 0; i < sizeof aTests / sizeof (Test); ++i)
1725c0ee992SDamjan Jovanovic {
1735c0ee992SDamjan Jovanovic bool bValid = false;
1745c0ee992SDamjan Jovanovic rtl::OUString aName;
1755c0ee992SDamjan Jovanovic try
176cdf0e10cSrcweir {
1775c0ee992SDamjan Jovanovic aName = cppu::UnoUrlDescriptor(rtl::OUString::createFromAscii(
1785c0ee992SDamjan Jovanovic aTests[i].pInput)).getName();
1795c0ee992SDamjan Jovanovic bValid = true;
180cdf0e10cSrcweir }
1815c0ee992SDamjan Jovanovic catch (rtl::MalformedUriException &)
1825c0ee992SDamjan Jovanovic {}
1835c0ee992SDamjan Jovanovic
1845c0ee992SDamjan Jovanovic ASSERT_TRUE(bValid) << "Failed to parse URI";
1855c0ee992SDamjan Jovanovic ASSERT_TRUE(aName.equalsAscii(aTests[i].pName)) << "Failed to parse URI correctly";
186cdf0e10cSrcweir }
1875c0ee992SDamjan Jovanovic }
188cdf0e10cSrcweir
TEST_F(UrlTest,testDescriptorKey)1895c0ee992SDamjan Jovanovic TEST_F(UrlTest, testDescriptorKey)
1905c0ee992SDamjan Jovanovic {
1915c0ee992SDamjan Jovanovic struct Test
192cdf0e10cSrcweir {
1935c0ee992SDamjan Jovanovic char const * pInput;
1945c0ee992SDamjan Jovanovic char const * pKey;
1955c0ee992SDamjan Jovanovic bool bPresent;
1965c0ee992SDamjan Jovanovic };
1975c0ee992SDamjan Jovanovic static Test const aTests[]
1985c0ee992SDamjan Jovanovic = { { "abc", "abc", false },
1995c0ee992SDamjan Jovanovic { "abc", "def", false },
2005c0ee992SDamjan Jovanovic { "1abc", "def", false },
2015c0ee992SDamjan Jovanovic { "123", "def", false },
2025c0ee992SDamjan Jovanovic { "abc,def=", "abc", false },
2035c0ee992SDamjan Jovanovic { "abc,def=", "def", true },
2045c0ee992SDamjan Jovanovic { "abc,def=", "defg", false },
2055c0ee992SDamjan Jovanovic { "abc,def=", "de", false },
2065c0ee992SDamjan Jovanovic { "abc,def=", "ghi", false },
2075c0ee992SDamjan Jovanovic { "abc,Def=", "def", true },
2085c0ee992SDamjan Jovanovic { "abc,Def=", "Def", true },
2095c0ee992SDamjan Jovanovic { "abc,Def=", "dEF", true },
2105c0ee992SDamjan Jovanovic { "abc,Def=", "DEF", true },
2115c0ee992SDamjan Jovanovic { "abc,def=xxx,ghi=xxx", "abc", false },
2125c0ee992SDamjan Jovanovic { "abc,def=xxx,ghi=xxx", "def", true },
2135c0ee992SDamjan Jovanovic { "abc,def=xxx,ghi=xxx", "ghi", true },
2145c0ee992SDamjan Jovanovic { "abc,def=xxx,ghi=xxx", "jkl", false } };
215*2cfa35e9SPeter Kovacs for (unsigned int i = 0; i < sizeof aTests / sizeof (Test); ++i)
2165c0ee992SDamjan Jovanovic {
2175c0ee992SDamjan Jovanovic bool bValid = false;
2185c0ee992SDamjan Jovanovic bool bPresent = false;
2195c0ee992SDamjan Jovanovic try
220cdf0e10cSrcweir {
2215c0ee992SDamjan Jovanovic bPresent = cppu::UnoUrlDescriptor(rtl::OUString::createFromAscii(
2225c0ee992SDamjan Jovanovic aTests[i].pInput)).
2235c0ee992SDamjan Jovanovic hasParameter(rtl::OUString::createFromAscii(aTests[i].pKey));
2245c0ee992SDamjan Jovanovic bValid = true;
225cdf0e10cSrcweir }
2265c0ee992SDamjan Jovanovic catch (rtl::MalformedUriException &)
2275c0ee992SDamjan Jovanovic {}
2285c0ee992SDamjan Jovanovic
2295c0ee992SDamjan Jovanovic ASSERT_TRUE(bValid) << "Failed to parse URI";
2305c0ee992SDamjan Jovanovic ASSERT_TRUE(bPresent == aTests[i].bPresent) << "Failed to detect parameter correctly";
231cdf0e10cSrcweir }
2325c0ee992SDamjan Jovanovic }
233cdf0e10cSrcweir
TEST_F(UrlTest,testDescriptorValue)2345c0ee992SDamjan Jovanovic TEST_F(UrlTest, testDescriptorValue)
2355c0ee992SDamjan Jovanovic {
2365c0ee992SDamjan Jovanovic struct Test
237cdf0e10cSrcweir {
2385c0ee992SDamjan Jovanovic char const * pInput;
2395c0ee992SDamjan Jovanovic char const * pKey;
2405c0ee992SDamjan Jovanovic char const * pValue;
2415c0ee992SDamjan Jovanovic };
2425c0ee992SDamjan Jovanovic static Test const aTests[]
2435c0ee992SDamjan Jovanovic = { { "abc", "abc", "" },
2445c0ee992SDamjan Jovanovic { "abc", "def", "" },
2455c0ee992SDamjan Jovanovic { "1abc", "def", "" },
2465c0ee992SDamjan Jovanovic { "123", "def", "" },
2475c0ee992SDamjan Jovanovic { "abc,def=", "abc", "" },
2485c0ee992SDamjan Jovanovic { "abc,def=", "def", "" },
2495c0ee992SDamjan Jovanovic { "abc,def=", "defg", "" },
2505c0ee992SDamjan Jovanovic { "abc,def=", "de", "" },
2515c0ee992SDamjan Jovanovic { "abc,def=", "ghi", "" },
2525c0ee992SDamjan Jovanovic { "abc,Def=", "def", "" },
2535c0ee992SDamjan Jovanovic { "abc,Def=", "Def", "" },
2545c0ee992SDamjan Jovanovic { "abc,Def=", "dEF", "" },
2555c0ee992SDamjan Jovanovic { "abc,Def=", "DEF", "" },
2565c0ee992SDamjan Jovanovic { "abc,def=xxx,ghi=xxx", "abc", "" },
2575c0ee992SDamjan Jovanovic { "abc,def=xxx,ghi=xxx", "def", "xxx" },
2585c0ee992SDamjan Jovanovic { "abc,def=xxx,ghi=xxx", "ghi", "xxx" },
2595c0ee992SDamjan Jovanovic { "abc,def=xxx,ghi=xxx", "jkl", "" },
2605c0ee992SDamjan Jovanovic { "abc,def=%", "def", "%" },
2615c0ee992SDamjan Jovanovic { "abc,def=%1", "def", "%1" },
2625c0ee992SDamjan Jovanovic { "abc,def=%22", "def", "\"" },
2635c0ee992SDamjan Jovanovic { "abc,def=\"", "def", "\"" },
2645c0ee992SDamjan Jovanovic { "abc,def=abc", "def", "abc" },
2655c0ee992SDamjan Jovanovic { "abc,def=Abc", "def", "Abc" },
2665c0ee992SDamjan Jovanovic { "abc,def=aBC", "def", "aBC" },
2675c0ee992SDamjan Jovanovic { "abc,def=ABC", "def", "ABC" },
2685c0ee992SDamjan Jovanovic { "abc,def=%,ghi=", "def", "%" },
2695c0ee992SDamjan Jovanovic { "abc,def=%1,ghi=", "def", "%1" },
2705c0ee992SDamjan Jovanovic { "abc,def=%22,ghi=", "def", "\"" },
2715c0ee992SDamjan Jovanovic { "abc,def=\",ghi=", "def", "\"" },
2725c0ee992SDamjan Jovanovic { "abc,def=abc,ghi=", "def", "abc" },
2735c0ee992SDamjan Jovanovic { "abc,def=Abc,ghi=", "def", "Abc" },
2745c0ee992SDamjan Jovanovic { "abc,def=aBC,ghi=", "def", "aBC" },
2755c0ee992SDamjan Jovanovic { "abc,def=ABC,ghi=", "def", "ABC" },
2765c0ee992SDamjan Jovanovic { "abc,abc=,def=%", "def", "%" },
2775c0ee992SDamjan Jovanovic { "abc,abc=,def=%1", "def", "%1" },
2785c0ee992SDamjan Jovanovic { "abc,abc=,def=%22", "def", "\"" },
2795c0ee992SDamjan Jovanovic { "abc,abc=,def=\"", "def", "\"" },
2805c0ee992SDamjan Jovanovic { "abc,abc=,def=abc", "def", "abc" },
2815c0ee992SDamjan Jovanovic { "abc,abc=,def=Abc", "def", "Abc" },
2825c0ee992SDamjan Jovanovic { "abc,abc=,def=aBC", "def", "aBC" },
2835c0ee992SDamjan Jovanovic { "abc,abc=,def=ABC", "def", "ABC" } };
284*2cfa35e9SPeter Kovacs for (unsigned int i = 0; i < sizeof aTests / sizeof (Test); ++i)
2855c0ee992SDamjan Jovanovic {
2865c0ee992SDamjan Jovanovic bool bValid = false;
2875c0ee992SDamjan Jovanovic rtl::OUString aValue;
2885c0ee992SDamjan Jovanovic try
289cdf0e10cSrcweir {
2905c0ee992SDamjan Jovanovic aValue = cppu::UnoUrlDescriptor(rtl::OUString::createFromAscii(
2915c0ee992SDamjan Jovanovic aTests[i].pInput)).
2925c0ee992SDamjan Jovanovic getParameter(rtl::OUString::createFromAscii(aTests[i].pKey));
2935c0ee992SDamjan Jovanovic bValid = true;
294cdf0e10cSrcweir }
2955c0ee992SDamjan Jovanovic catch (rtl::MalformedUriException &)
2965c0ee992SDamjan Jovanovic {}
2975c0ee992SDamjan Jovanovic ASSERT_TRUE(bValid) << "Failed to parse URI";
2985c0ee992SDamjan Jovanovic ASSERT_TRUE(aValue.equalsAscii(aTests[i].pValue)) << "Failed to get param correctly";
299cdf0e10cSrcweir }
3005c0ee992SDamjan Jovanovic }
301cdf0e10cSrcweir
TEST_F(UrlTest,testUrlParsing)3025c0ee992SDamjan Jovanovic TEST_F(UrlTest, testUrlParsing)
3035c0ee992SDamjan Jovanovic {
3045c0ee992SDamjan Jovanovic struct Test
305cdf0e10cSrcweir {
3065c0ee992SDamjan Jovanovic char const * pInput;
3075c0ee992SDamjan Jovanovic bool bValid;
3085c0ee992SDamjan Jovanovic };
3095c0ee992SDamjan Jovanovic static Test const aTests[]
3105c0ee992SDamjan Jovanovic = { { "", false },
3115c0ee992SDamjan Jovanovic { "abc", false },
3125c0ee992SDamjan Jovanovic { "uno", false },
3135c0ee992SDamjan Jovanovic { "uno:", false },
3145c0ee992SDamjan Jovanovic { "uno:abc;def;ghi", true },
3155c0ee992SDamjan Jovanovic { "Uno:abc;def;ghi", true },
3165c0ee992SDamjan Jovanovic { "uNO:abc;def;ghi", true },
3175c0ee992SDamjan Jovanovic { "UNO:abc;def;ghi", true },
3185c0ee992SDamjan Jovanovic { "uno:abc,def=xxx,ghi=xxx;def,ghi=xxx,jkl=xxx;ghi", true },
3195c0ee992SDamjan Jovanovic { "uno:abc,def=xxx,ghi=xxx;def,ghi=xxx,jkl=xxx,;ghi", false },
3205c0ee992SDamjan Jovanovic { "uno:abc;def;", false },
3215c0ee992SDamjan Jovanovic { "uno:abc;def;a", true },
3225c0ee992SDamjan Jovanovic { "uno:abc;def;A", true },
3235c0ee992SDamjan Jovanovic { "uno:abc;def;1", true },
3245c0ee992SDamjan Jovanovic { "uno:abc;def;$&+,/:=?@", true },
3255c0ee992SDamjan Jovanovic { "uno:abc;def;%24&+,/:=?@", false } };
326*2cfa35e9SPeter Kovacs for (unsigned int i = 0; i < sizeof aTests / sizeof (Test); ++i)
3275c0ee992SDamjan Jovanovic {
3285c0ee992SDamjan Jovanovic bool bValid = false;
3295c0ee992SDamjan Jovanovic try
330cdf0e10cSrcweir {
3315c0ee992SDamjan Jovanovic cppu::UnoUrl aUrl(rtl::OUString::createFromAscii(aTests[i].pInput));
3325c0ee992SDamjan Jovanovic bValid = true;
3335c0ee992SDamjan Jovanovic }
3345c0ee992SDamjan Jovanovic catch (rtl::MalformedUriException &)
3355c0ee992SDamjan Jovanovic {}
336cdf0e10cSrcweir
3375c0ee992SDamjan Jovanovic if (aTests[i].bValid)
3385c0ee992SDamjan Jovanovic {
3395c0ee992SDamjan Jovanovic ASSERT_TRUE(bValid) << "Valid uri parsed as invalid";
3405c0ee992SDamjan Jovanovic }
3415c0ee992SDamjan Jovanovic else
3425c0ee992SDamjan Jovanovic {
3435c0ee992SDamjan Jovanovic ASSERT_TRUE(!bValid) << "Invalid uri parsed as valid";
344cdf0e10cSrcweir }
3455c0ee992SDamjan Jovanovic
346cdf0e10cSrcweir }
3475c0ee992SDamjan Jovanovic }
348cdf0e10cSrcweir
TEST_F(UrlTest,testUrlConnection)3495c0ee992SDamjan Jovanovic TEST_F(UrlTest, testUrlConnection)
3505c0ee992SDamjan Jovanovic {
3515c0ee992SDamjan Jovanovic struct Test
352cdf0e10cSrcweir {
3535c0ee992SDamjan Jovanovic char const * pInput;
3545c0ee992SDamjan Jovanovic char const * pConnection;
3555c0ee992SDamjan Jovanovic };
3565c0ee992SDamjan Jovanovic static Test const aTests[]
3575c0ee992SDamjan Jovanovic = { { "uno:abc;def;ghi", "abc" },
3585c0ee992SDamjan Jovanovic { "uno:Abc;def;ghi", "Abc" },
3595c0ee992SDamjan Jovanovic { "uno:aBC;def;ghi", "aBC" },
3605c0ee992SDamjan Jovanovic { "uno:ABC;def;ghi", "ABC" },
3615c0ee992SDamjan Jovanovic { "uno:abc,def=xxx,ghi=xxx;def,ghi=xxx,jkl=xxx;ghi",
3625c0ee992SDamjan Jovanovic "abc,def=xxx,ghi=xxx" } };
363*2cfa35e9SPeter Kovacs for (unsigned int i = 0; i < sizeof aTests / sizeof (Test); ++i)
3645c0ee992SDamjan Jovanovic {
3655c0ee992SDamjan Jovanovic bool bValid = false;
3665c0ee992SDamjan Jovanovic rtl::OUString aConnection;
3675c0ee992SDamjan Jovanovic try
368cdf0e10cSrcweir {
3695c0ee992SDamjan Jovanovic aConnection = cppu::UnoUrl(rtl::OUString::createFromAscii(
3705c0ee992SDamjan Jovanovic aTests[i].pInput)).
3715c0ee992SDamjan Jovanovic getConnection().getDescriptor();
3725c0ee992SDamjan Jovanovic bValid = true;
373cdf0e10cSrcweir }
3745c0ee992SDamjan Jovanovic catch (rtl::MalformedUriException &)
3755c0ee992SDamjan Jovanovic {}
3765c0ee992SDamjan Jovanovic ASSERT_TRUE(bValid) << "Failed to parse URI";
3775c0ee992SDamjan Jovanovic ASSERT_TRUE(aConnection.equalsAscii(aTests[i].pConnection)) << "Failed to get param correctly";
378cdf0e10cSrcweir }
3795c0ee992SDamjan Jovanovic }
380cdf0e10cSrcweir
TEST_F(UrlTest,testUrlProtocol)3815c0ee992SDamjan Jovanovic TEST_F(UrlTest, testUrlProtocol)
3825c0ee992SDamjan Jovanovic {
3835c0ee992SDamjan Jovanovic struct Test
384cdf0e10cSrcweir {
3855c0ee992SDamjan Jovanovic char const * pInput;
3865c0ee992SDamjan Jovanovic char const * pProtocol;
3875c0ee992SDamjan Jovanovic };
3885c0ee992SDamjan Jovanovic static Test const aTests[]
3895c0ee992SDamjan Jovanovic = { { "uno:abc;def;ghi", "def" },
3905c0ee992SDamjan Jovanovic { "uno:abc;Def;ghi", "Def" },
3915c0ee992SDamjan Jovanovic { "uno:abc;dEF;ghi", "dEF" },
3925c0ee992SDamjan Jovanovic { "uno:abc;DEF;ghi", "DEF" },
3935c0ee992SDamjan Jovanovic { "uno:abc,def=xxx,ghi=xxx;def,ghi=xxx,jkl=xxx;ghi",
3945c0ee992SDamjan Jovanovic "def,ghi=xxx,jkl=xxx" } };
395*2cfa35e9SPeter Kovacs for (unsigned int i = 0; i < sizeof aTests / sizeof (Test); ++i)
3965c0ee992SDamjan Jovanovic {
3975c0ee992SDamjan Jovanovic bool bValid = false;
3985c0ee992SDamjan Jovanovic rtl::OUString aProtocol;
3995c0ee992SDamjan Jovanovic try
400cdf0e10cSrcweir {
4015c0ee992SDamjan Jovanovic aProtocol = cppu::UnoUrl(rtl::OUString::createFromAscii(
4025c0ee992SDamjan Jovanovic aTests[i].pInput)).
4035c0ee992SDamjan Jovanovic getProtocol().getDescriptor();
4045c0ee992SDamjan Jovanovic bValid = true;
405cdf0e10cSrcweir }
4065c0ee992SDamjan Jovanovic catch (rtl::MalformedUriException &)
4075c0ee992SDamjan Jovanovic {}
4085c0ee992SDamjan Jovanovic ASSERT_TRUE(bValid) << "Failed to parse URI";
4095c0ee992SDamjan Jovanovic ASSERT_TRUE(aProtocol.equalsAscii(aTests[i].pProtocol)) << "Failed to get protocol correctly";
410cdf0e10cSrcweir }
4115c0ee992SDamjan Jovanovic }
412cdf0e10cSrcweir
TEST_F(UrlTest,testUrlObjectName)4135c0ee992SDamjan Jovanovic TEST_F(UrlTest, testUrlObjectName)
4145c0ee992SDamjan Jovanovic {
4155c0ee992SDamjan Jovanovic struct Test
416cdf0e10cSrcweir {
4175c0ee992SDamjan Jovanovic char const * pInput;
4185c0ee992SDamjan Jovanovic char const * pObjectName;
4195c0ee992SDamjan Jovanovic };
4205c0ee992SDamjan Jovanovic static Test const aTests[]
4215c0ee992SDamjan Jovanovic = { { "uno:abc;def;ghi", "ghi" },
4225c0ee992SDamjan Jovanovic { "uno:abc;def;Ghi", "Ghi" },
4235c0ee992SDamjan Jovanovic { "uno:abc;def;gHI", "gHI" },
4245c0ee992SDamjan Jovanovic { "uno:abc;def;GHI", "GHI" },
4255c0ee992SDamjan Jovanovic { "uno:abc,def=xxx,ghi=xxx;def,ghi=xxx,jkl=xxx;ghi", "ghi" },
4265c0ee992SDamjan Jovanovic { "uno:abc;def;a", "a" },
4275c0ee992SDamjan Jovanovic { "uno:abc;def;A", "A" },
4285c0ee992SDamjan Jovanovic { "uno:abc;def;1", "1" },
4295c0ee992SDamjan Jovanovic { "uno:abc;def;$&+,/:=?@", "$&+,/:=?@" } };
430*2cfa35e9SPeter Kovacs for (unsigned int i = 0; i < sizeof aTests / sizeof (Test); ++i)
4315c0ee992SDamjan Jovanovic {
4325c0ee992SDamjan Jovanovic bool bValid = false;
4335c0ee992SDamjan Jovanovic rtl::OUString aObjectName;
4345c0ee992SDamjan Jovanovic try
435cdf0e10cSrcweir {
4365c0ee992SDamjan Jovanovic aObjectName = cppu::UnoUrl(rtl::OUString::createFromAscii(
4375c0ee992SDamjan Jovanovic aTests[i].pInput)).getObjectName();
4385c0ee992SDamjan Jovanovic bValid = true;
439cdf0e10cSrcweir }
4405c0ee992SDamjan Jovanovic catch (rtl::MalformedUriException &)
4415c0ee992SDamjan Jovanovic {}
4425c0ee992SDamjan Jovanovic ASSERT_TRUE(bValid) << "Failed to parse URI";
4435c0ee992SDamjan Jovanovic ASSERT_TRUE(aObjectName.equalsAscii(aTests[i].pObjectName)) << "Failed to get protocol correctly";
444cdf0e10cSrcweir }
4455c0ee992SDamjan Jovanovic }
446cdf0e10cSrcweir } // namespace cppu_ifcontainer
447cdf0e10cSrcweir
main(int argc,char ** argv)44826d3e425SDamjan Jovanovic int main(int argc, char **argv)
44926d3e425SDamjan Jovanovic {
45026d3e425SDamjan Jovanovic ::testing::InitGoogleTest(&argc, argv);
45126d3e425SDamjan Jovanovic return RUN_ALL_TESTS();
45226d3e425SDamjan Jovanovic }
45326d3e425SDamjan Jovanovic
454