140df464eSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
340df464eSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
440df464eSAndrew Rist * or more contributor license agreements. See the NOTICE file
540df464eSAndrew Rist * distributed with this work for additional information
640df464eSAndrew Rist * regarding copyright ownership. The ASF licenses this file
740df464eSAndrew Rist * to you under the Apache License, Version 2.0 (the
840df464eSAndrew Rist * "License"); you may not use this file except in compliance
940df464eSAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
1140df464eSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
1340df464eSAndrew Rist * Unless required by applicable law or agreed to in writing,
1440df464eSAndrew Rist * software distributed under the License is distributed on an
1540df464eSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1640df464eSAndrew Rist * KIND, either express or implied. See the License for the
1740df464eSAndrew Rist * specific language governing permissions and limitations
1840df464eSAndrew Rist * under the License.
19cdf0e10cSrcweir *
2040df464eSAndrew Rist *************************************************************/
2140df464eSAndrew Rist
2240df464eSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svl.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include "sal/config.h"
28cdf0e10cSrcweir
29cdf0e10cSrcweir #include <cstddef>
30cdf0e10cSrcweir
31cdf0e10cSrcweir #include "com/sun/star/lang/Locale.hpp"
32cdf0e10cSrcweir #include "com/sun/star/lang/XComponent.hpp"
33cdf0e10cSrcweir #include "com/sun/star/lang/XMultiComponentFactory.hpp"
34cdf0e10cSrcweir #include "com/sun/star/lang/XMultiServiceFactory.hpp"
35cdf0e10cSrcweir #include "com/sun/star/ucb/Command.hpp"
36cdf0e10cSrcweir #include "com/sun/star/ucb/CommandAbortedException.hpp"
37cdf0e10cSrcweir #include "com/sun/star/ucb/IllegalIdentifierException.hpp"
38cdf0e10cSrcweir #include "com/sun/star/ucb/XCommandProcessor.hpp"
39cdf0e10cSrcweir #include "com/sun/star/ucb/XContent.hpp"
40cdf0e10cSrcweir #include "com/sun/star/ucb/XContentIdentifier.hpp"
41cdf0e10cSrcweir #include "com/sun/star/ucb/XContentProvider.hpp"
42cdf0e10cSrcweir #include "com/sun/star/ucb/XContentProviderManager.hpp"
43cdf0e10cSrcweir #include "com/sun/star/uno/Any.hxx"
44cdf0e10cSrcweir #include "com/sun/star/uno/Exception.hpp"
45cdf0e10cSrcweir #include "com/sun/star/uno/Reference.hxx"
46cdf0e10cSrcweir #include "com/sun/star/uno/RuntimeException.hpp"
47cdf0e10cSrcweir #include "com/sun/star/uno/Sequence.hxx"
48cdf0e10cSrcweir #include "com/sun/star/uno/XComponentContext.hpp"
49cdf0e10cSrcweir #include "com/sun/star/uri/XUriReference.hpp"
50cdf0e10cSrcweir #include "cppuhelper/bootstrap.hxx"
51cdf0e10cSrcweir #include "cppuhelper/implbase1.hxx"
52cdf0e10cSrcweir #include "cppuhelper/implbase2.hxx"
53cdf0e10cSrcweir #include "osl/diagnose.h"
54cdf0e10cSrcweir #include "rtl/strbuf.hxx"
55cdf0e10cSrcweir #include "rtl/string.h"
56cdf0e10cSrcweir #include "rtl/string.hxx"
57cdf0e10cSrcweir #include "rtl/textenc.h"
58cdf0e10cSrcweir #include "rtl/ustring.h"
59cdf0e10cSrcweir #include "rtl/ustring.hxx"
60cdf0e10cSrcweir #include "sal/types.h"
61cdf0e10cSrcweir #include "tools/solar.h"
62cdf0e10cSrcweir #include "unotools/charclass.hxx"
63*2958961eSDamjan Jovanovic #include "gtest/gtest.h"
64cdf0e10cSrcweir
65cdf0e10cSrcweir #include "urihelper.hxx"
66cdf0e10cSrcweir
67*2958961eSDamjan Jovanovic // FIXME:
68*2958961eSDamjan Jovanovic #define RUN_OLD_FAILING_TESTS 0
69*2958961eSDamjan Jovanovic
70cdf0e10cSrcweir // This test needs a UNO component context that supports various services (the
71cdf0e10cSrcweir // UCB, an UriReferenceFactory, ...), so it is best executed within an OOo
72cdf0e10cSrcweir // installation.
73cdf0e10cSrcweir
74cdf0e10cSrcweir namespace com { namespace sun { namespace star { namespace ucb {
75cdf0e10cSrcweir class XCommandEnvironment;
76cdf0e10cSrcweir class XContentEventListener;
77cdf0e10cSrcweir } } } }
78cdf0e10cSrcweir
79cdf0e10cSrcweir namespace {
80cdf0e10cSrcweir
81cdf0e10cSrcweir namespace css = com::sun::star;
82cdf0e10cSrcweir
83cdf0e10cSrcweir // This class only implements that subset of functionality of a proper
84cdf0e10cSrcweir // css::ucb::Content that is known to be needed here:
85cdf0e10cSrcweir class Content:
86cdf0e10cSrcweir public cppu::WeakImplHelper2<
87cdf0e10cSrcweir css::ucb::XContent, css::ucb::XCommandProcessor >
88cdf0e10cSrcweir {
89cdf0e10cSrcweir public:
90cdf0e10cSrcweir explicit Content(
91cdf0e10cSrcweir css::uno::Reference< css::ucb::XContentIdentifier > const & identifier);
92cdf0e10cSrcweir
93cdf0e10cSrcweir virtual css::uno::Reference< css::ucb::XContentIdentifier > SAL_CALL
getIdentifier()94cdf0e10cSrcweir getIdentifier() throw (css::uno::RuntimeException) {
95cdf0e10cSrcweir return m_identifier;
96cdf0e10cSrcweir }
97cdf0e10cSrcweir
getContentType()98cdf0e10cSrcweir virtual rtl::OUString SAL_CALL getContentType()
99cdf0e10cSrcweir throw (css::uno::RuntimeException)
100cdf0e10cSrcweir {
101cdf0e10cSrcweir return rtl::OUString();
102cdf0e10cSrcweir }
103cdf0e10cSrcweir
addContentEventListener(css::uno::Reference<css::ucb::XContentEventListener> const &)104cdf0e10cSrcweir virtual void SAL_CALL addContentEventListener(
105cdf0e10cSrcweir css::uno::Reference< css::ucb::XContentEventListener > const &)
106cdf0e10cSrcweir throw (css::uno::RuntimeException)
107cdf0e10cSrcweir {}
108cdf0e10cSrcweir
removeContentEventListener(css::uno::Reference<css::ucb::XContentEventListener> const &)109cdf0e10cSrcweir virtual void SAL_CALL removeContentEventListener(
110cdf0e10cSrcweir css::uno::Reference< css::ucb::XContentEventListener > const &)
111cdf0e10cSrcweir throw (css::uno::RuntimeException)
112cdf0e10cSrcweir {}
113cdf0e10cSrcweir
createCommandIdentifier()114cdf0e10cSrcweir virtual sal_Int32 SAL_CALL createCommandIdentifier()
115cdf0e10cSrcweir throw (css::uno::RuntimeException)
116cdf0e10cSrcweir {
117cdf0e10cSrcweir return 0;
118cdf0e10cSrcweir }
119cdf0e10cSrcweir
120cdf0e10cSrcweir virtual css::uno::Any SAL_CALL execute(
121cdf0e10cSrcweir css::ucb::Command const & command, sal_Int32 commandId,
122cdf0e10cSrcweir css::uno::Reference< css::ucb::XCommandEnvironment > const &)
123cdf0e10cSrcweir throw (
124cdf0e10cSrcweir css::uno::Exception, css::ucb::CommandAbortedException,
125cdf0e10cSrcweir css::uno::RuntimeException);
126cdf0e10cSrcweir
abort(sal_Int32)127cdf0e10cSrcweir virtual void SAL_CALL abort(sal_Int32) throw (css::uno::RuntimeException) {}
128cdf0e10cSrcweir
129cdf0e10cSrcweir private:
130cdf0e10cSrcweir static char const m_prefix[];
131cdf0e10cSrcweir
132cdf0e10cSrcweir css::uno::Reference< css::ucb::XContentIdentifier > m_identifier;
133cdf0e10cSrcweir };
134cdf0e10cSrcweir
135cdf0e10cSrcweir char const Content::m_prefix[] = "test:";
136cdf0e10cSrcweir
Content(css::uno::Reference<css::ucb::XContentIdentifier> const & identifier)137cdf0e10cSrcweir Content::Content(
138cdf0e10cSrcweir css::uno::Reference< css::ucb::XContentIdentifier > const & identifier):
139cdf0e10cSrcweir m_identifier(identifier)
140cdf0e10cSrcweir {
141cdf0e10cSrcweir OSL_ASSERT(m_identifier.is());
142cdf0e10cSrcweir rtl::OUString uri(m_identifier->getContentIdentifier());
143cdf0e10cSrcweir if (!uri.matchIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM(m_prefix))
144cdf0e10cSrcweir || uri.indexOf('#', RTL_CONSTASCII_LENGTH(m_prefix)) != -1)
145cdf0e10cSrcweir {
146cdf0e10cSrcweir throw css::ucb::IllegalIdentifierException();
147cdf0e10cSrcweir }
148cdf0e10cSrcweir }
149cdf0e10cSrcweir
execute(css::ucb::Command const & command,sal_Int32,css::uno::Reference<css::ucb::XCommandEnvironment> const &)150cdf0e10cSrcweir css::uno::Any Content::execute(
151cdf0e10cSrcweir css::ucb::Command const & command, sal_Int32,
152cdf0e10cSrcweir css::uno::Reference< css::ucb::XCommandEnvironment > const &)
153cdf0e10cSrcweir throw (
154cdf0e10cSrcweir css::uno::Exception, css::ucb::CommandAbortedException,
155cdf0e10cSrcweir css::uno::RuntimeException)
156cdf0e10cSrcweir {
157cdf0e10cSrcweir if (!command.Name.equalsAsciiL(
158cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM("getCasePreservingURL")))
159cdf0e10cSrcweir {
160cdf0e10cSrcweir throw css::uno::RuntimeException();
161cdf0e10cSrcweir }
162cdf0e10cSrcweir // If any non-empty segment starts with anything but '0', '1', or '2', fail;
163cdf0e10cSrcweir // otherwise, if the last non-empty segment starts with '1', add a final
164cdf0e10cSrcweir // slash, and if the last non-empty segment starts with '2', remove a final
165cdf0e10cSrcweir // slash (if any); also, turn the given uri into all-lowercase:
166cdf0e10cSrcweir rtl::OUString uri(m_identifier->getContentIdentifier());
167cdf0e10cSrcweir sal_Unicode c = '0';
168cdf0e10cSrcweir for (sal_Int32 i = RTL_CONSTASCII_LENGTH(m_prefix); i != -1;) {
169cdf0e10cSrcweir rtl::OUString seg(uri.getToken(0, '/', i));
170cdf0e10cSrcweir if (seg.getLength() > 0) {
171cdf0e10cSrcweir c = seg[0];
172cdf0e10cSrcweir if (c < '0' || c > '2') {
173cdf0e10cSrcweir throw css::uno::Exception();
174cdf0e10cSrcweir }
175cdf0e10cSrcweir }
176cdf0e10cSrcweir }
177cdf0e10cSrcweir switch (c) {
178cdf0e10cSrcweir case '1':
179cdf0e10cSrcweir uri += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/"));
180cdf0e10cSrcweir break;
181cdf0e10cSrcweir case '2':
182cdf0e10cSrcweir if (uri.getLength() > 0 && uri[uri.getLength() - 1] == '/') {
183cdf0e10cSrcweir uri = uri.copy(0, uri.getLength() -1);
184cdf0e10cSrcweir }
185cdf0e10cSrcweir break;
186cdf0e10cSrcweir }
187cdf0e10cSrcweir return css::uno::makeAny(uri.toAsciiLowerCase());
188cdf0e10cSrcweir }
189cdf0e10cSrcweir
190cdf0e10cSrcweir class Provider: public cppu::WeakImplHelper1< css::ucb::XContentProvider > {
191cdf0e10cSrcweir public:
queryContent(css::uno::Reference<css::ucb::XContentIdentifier> const & identifier)192cdf0e10cSrcweir virtual css::uno::Reference< css::ucb::XContent > SAL_CALL queryContent(
193cdf0e10cSrcweir css::uno::Reference< css::ucb::XContentIdentifier > const & identifier)
194cdf0e10cSrcweir throw (css::ucb::IllegalIdentifierException, css::uno::RuntimeException)
195cdf0e10cSrcweir {
196cdf0e10cSrcweir return new Content(identifier);
197cdf0e10cSrcweir }
198cdf0e10cSrcweir
compareContentIds(css::uno::Reference<css::ucb::XContentIdentifier> const & id1,css::uno::Reference<css::ucb::XContentIdentifier> const & id2)199cdf0e10cSrcweir virtual sal_Int32 SAL_CALL compareContentIds(
200cdf0e10cSrcweir css::uno::Reference< css::ucb::XContentIdentifier > const & id1,
201cdf0e10cSrcweir css::uno::Reference< css::ucb::XContentIdentifier > const & id2)
202cdf0e10cSrcweir throw (css::uno::RuntimeException)
203cdf0e10cSrcweir {
204cdf0e10cSrcweir OSL_ASSERT(id1.is() && id2.is());
205cdf0e10cSrcweir return
206cdf0e10cSrcweir id1->getContentIdentifier().compareTo(id2->getContentIdentifier());
207cdf0e10cSrcweir }
208cdf0e10cSrcweir };
209cdf0e10cSrcweir
210*2958961eSDamjan Jovanovic class Test: public ::testing::Test {
211cdf0e10cSrcweir public:
212*2958961eSDamjan Jovanovic virtual void SetUp();
213cdf0e10cSrcweir
214cdf0e10cSrcweir void finish();
215cdf0e10cSrcweir
216*2958961eSDamjan Jovanovic protected:
217cdf0e10cSrcweir static css::uno::Reference< css::uno::XComponentContext > m_context;
218cdf0e10cSrcweir };
219cdf0e10cSrcweir
SetUp()220*2958961eSDamjan Jovanovic void Test::SetUp() {
221cdf0e10cSrcweir // For whatever reason, on W32 it does not work to create/destroy a fresh
222cdf0e10cSrcweir // component context for each test in Test::setUp/tearDown; therefore, a
223cdf0e10cSrcweir // single component context is used for all tests and destroyed in the last
224cdf0e10cSrcweir // pseudo-test "finish":
225cdf0e10cSrcweir if (!m_context.is()) {
226cdf0e10cSrcweir m_context = cppu::defaultBootstrap_InitialComponentContext();
227cdf0e10cSrcweir }
228cdf0e10cSrcweir }
229cdf0e10cSrcweir
finish()230cdf0e10cSrcweir void Test::finish() {
231cdf0e10cSrcweir css::uno::Reference< css::lang::XComponent >(
232cdf0e10cSrcweir m_context, css::uno::UNO_QUERY_THROW)->dispose();
233cdf0e10cSrcweir }
234cdf0e10cSrcweir
235*2958961eSDamjan Jovanovic #if RUN_OLD_FAILING_TESTS
236*2958961eSDamjan Jovanovic
TEST_F(Test,testNormalizedMakeRelative)237*2958961eSDamjan Jovanovic TEST_F(Test, testNormalizedMakeRelative) {
238cdf0e10cSrcweir css::uno::Sequence< css::uno::Any > args(2);
239cdf0e10cSrcweir args[0] <<= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Local"));
240cdf0e10cSrcweir args[1] <<= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Office"));
241cdf0e10cSrcweir css::uno::Reference< css::ucb::XContentProviderManager >(
242cdf0e10cSrcweir (css::uno::Reference< css::lang::XMultiComponentFactory >(
243cdf0e10cSrcweir m_context->getServiceManager(), css::uno::UNO_QUERY_THROW)->
244cdf0e10cSrcweir createInstanceWithArgumentsAndContext(
245cdf0e10cSrcweir rtl::OUString(
246cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM(
247cdf0e10cSrcweir "com.sun.star.ucb.UniversalContentBroker")),
248cdf0e10cSrcweir args, m_context)),
249cdf0e10cSrcweir css::uno::UNO_QUERY_THROW)->registerContentProvider(
250cdf0e10cSrcweir new Provider, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("test")),
251cdf0e10cSrcweir true);
252cdf0e10cSrcweir struct Test {
253cdf0e10cSrcweir char const * base;
254cdf0e10cSrcweir char const * absolute;
255cdf0e10cSrcweir char const * relative;
256cdf0e10cSrcweir };
257cdf0e10cSrcweir static Test const tests[] = {
258cdf0e10cSrcweir { "hierarchical:/", "mailto:def@a.b.c.", "mailto:def@a.b.c." },
259cdf0e10cSrcweir { "hierarchical:/", "a/b/c", "a/b/c" },
260cdf0e10cSrcweir { "hierarchical:/a", "hierarchical:/a/b/c?d#e", "/a/b/c?d#e" },
261cdf0e10cSrcweir { "hierarchical:/a/", "hierarchical:/a/b/c?d#e", "b/c?d#e" },
262cdf0e10cSrcweir { "test:/0/0/a", "test:/0/b", "../b" },
263cdf0e10cSrcweir { "test:/1/1/a", "test:/1/b", "../b" },
264cdf0e10cSrcweir { "test:/2/2//a", "test:/2/b", "../../b" },
265cdf0e10cSrcweir { "test:/0a/b", "test:/0A/c#f", "c#f" },
266cdf0e10cSrcweir { "file:///usr/bin/nonex1/nonex2",
267cdf0e10cSrcweir "file:///usr/bin/nonex1/nonex3/nonex4", "nonex3/nonex4" },
268cdf0e10cSrcweir { "file:///usr/bin/nonex1/nonex2#fragmentA",
269cdf0e10cSrcweir "file:///usr/bin/nonex1/nonex3/nonex4#fragmentB",
270cdf0e10cSrcweir "nonex3/nonex4#fragmentB" },
271cdf0e10cSrcweir { "file:///usr/nonex1/nonex2", "file:///usr/nonex3", "../nonex3" },
272cdf0e10cSrcweir { "file:///c:/windows/nonex1", "file:///c:/nonex2", "../nonex2" },
273cdf0e10cSrcweir #if defined WNT
274cdf0e10cSrcweir { "file:///c:/nonex1/nonex2", "file:///C:/nonex1/nonex3/nonex4",
275cdf0e10cSrcweir "nonex3/nonex4" }
276cdf0e10cSrcweir #endif
277cdf0e10cSrcweir };
278cdf0e10cSrcweir for (std::size_t i = 0; i < sizeof tests / sizeof tests[0]; ++i) {
279cdf0e10cSrcweir css::uno::Reference< css::uri::XUriReference > ref(
280cdf0e10cSrcweir URIHelper::normalizedMakeRelative(
281cdf0e10cSrcweir m_context, rtl::OUString::createFromAscii(tests[i].base),
282cdf0e10cSrcweir rtl::OUString::createFromAscii(tests[i].absolute)));
283cdf0e10cSrcweir bool ok = tests[i].relative == 0
284cdf0e10cSrcweir ? !ref.is()
285cdf0e10cSrcweir : ref.is() && ref->getUriReference().equalsAscii(tests[i].relative);
286cdf0e10cSrcweir rtl::OString msg;
287cdf0e10cSrcweir if (!ok) {
288cdf0e10cSrcweir rtl::OStringBuffer buf;
289cdf0e10cSrcweir buf.append('<');
290cdf0e10cSrcweir buf.append(tests[i].base);
291cdf0e10cSrcweir buf.append(RTL_CONSTASCII_STRINGPARAM(">, <"));
292cdf0e10cSrcweir buf.append(tests[i].absolute);
293cdf0e10cSrcweir buf.append(RTL_CONSTASCII_STRINGPARAM(">: "));
294cdf0e10cSrcweir if (ref.is()) {
295cdf0e10cSrcweir buf.append('<');
296cdf0e10cSrcweir buf.append(
297cdf0e10cSrcweir rtl::OUStringToOString(
298cdf0e10cSrcweir ref->getUriReference(), RTL_TEXTENCODING_UTF8));
299cdf0e10cSrcweir buf.append('>');
300cdf0e10cSrcweir } else {
301cdf0e10cSrcweir buf.append(RTL_CONSTASCII_STRINGPARAM("none"));
302cdf0e10cSrcweir }
303cdf0e10cSrcweir buf.append(RTL_CONSTASCII_STRINGPARAM(" instead of "));
304cdf0e10cSrcweir if (tests[i].relative == 0) {
305cdf0e10cSrcweir buf.append(RTL_CONSTASCII_STRINGPARAM("none"));
306cdf0e10cSrcweir } else {
307cdf0e10cSrcweir buf.append('<');
308cdf0e10cSrcweir buf.append(tests[i].relative);
309cdf0e10cSrcweir buf.append('>');
310cdf0e10cSrcweir }
311cdf0e10cSrcweir msg = buf.makeStringAndClear();
312cdf0e10cSrcweir }
313*2958961eSDamjan Jovanovic ASSERT_TRUE(ok) << msg.getStr();
314cdf0e10cSrcweir }
315cdf0e10cSrcweir }
316cdf0e10cSrcweir
317*2958961eSDamjan Jovanovic #endif
318*2958961eSDamjan Jovanovic
TEST_F(Test,testFindFirstURLInText)319*2958961eSDamjan Jovanovic TEST_F(Test, testFindFirstURLInText) {
320cdf0e10cSrcweir struct Test {
321cdf0e10cSrcweir char const * input;
322cdf0e10cSrcweir char const * result;
323cdf0e10cSrcweir xub_StrLen begin;
324cdf0e10cSrcweir xub_StrLen end;
325cdf0e10cSrcweir };
326cdf0e10cSrcweir static Test const tests[] = {
327cdf0e10cSrcweir { "...ftp://bla.bla.bla/blubber/...",
328cdf0e10cSrcweir "ftp://bla.bla.bla/blubber/", 3, 29 },
329cdf0e10cSrcweir { "..\\ftp://bla.bla.bla/blubber/...", 0, 0, 0 },
330cdf0e10cSrcweir { "..\\ftp:\\\\bla.bla.bla\\blubber/...",
331cdf0e10cSrcweir "file://bla.bla.bla/blubber%2F", 7, 29 },
332cdf0e10cSrcweir { "http://sun.com", "http://sun.com/", 0, 14 },
333cdf0e10cSrcweir { "http://sun.com/", "http://sun.com/", 0, 15 },
334cdf0e10cSrcweir { "http://www.xerox.com@www.pcworld.com/go/3990332.htm", 0, 0, 0 },
335cdf0e10cSrcweir { "ftp://www.xerox.com@www.pcworld.com/go/3990332.htm",
336cdf0e10cSrcweir "ftp://www.xerox.com@www.pcworld.com/go/3990332.htm", 0, 50 },
337cdf0e10cSrcweir { "Version.1.2.3", 0, 0, 0 },
338cdf0e10cSrcweir { "Version:1.2.3", 0, 0, 0 },
339cdf0e10cSrcweir { "a.b.c", 0, 0, 0 },
340cdf0e10cSrcweir { "file:///a|...", "file:///a:", 0, 10 },
341cdf0e10cSrcweir { "file:///a||...", "file:///a%7C%7C", 0, 11 },
342cdf0e10cSrcweir { "file:///a|/bc#...", "file:///a:/bc", 0, 13 },
343cdf0e10cSrcweir { "file:///a|/bc#de...", "file:///a:/bc#de", 0, 16 },
344cdf0e10cSrcweir { "abc.def.ghi,ftp.xxx.yyy/zzz...", "ftp://ftp.xxx.yyy/zzz", 12, 27 },
345cdf0e10cSrcweir { "abc.def.ghi,Ftp.xxx.yyy/zzz...", "ftp://Ftp.xxx.yyy/zzz", 12, 27 },
346cdf0e10cSrcweir { "abc.def.ghi,www.xxx.yyy...", "http://www.xxx.yyy/", 12, 23 },
347cdf0e10cSrcweir { "abc.def.ghi,wwww.xxx.yyy...", 0, 0, 0 },
348cdf0e10cSrcweir { "abc.def.ghi,wWW.xxx.yyy...", "http://wWW.xxx.yyy/", 12, 23 },
349cdf0e10cSrcweir { "Bla {mailto.me@abc.def.g.h.i}...",
350cdf0e10cSrcweir "mailto:%7Bmailto.me@abc.def.g.h.i", 4, 28 },
351cdf0e10cSrcweir { "abc@def@ghi", 0, 0, 0 },
352cdf0e10cSrcweir { "lala@sun.com", "mailto:lala@sun.com", 0, 12 },
353cdf0e10cSrcweir { "1lala@sun.com", "mailto:1lala@sun.com", 0, 13 },
354cdf0e10cSrcweir { "aaa_bbb@xxx.yy", "mailto:aaa_bbb@xxx.yy", 0, 14 },
355cdf0e10cSrcweir { "{a:\\bla/bla/bla...}", "file:///a:/bla/bla/bla", 1, 15 },
356cdf0e10cSrcweir { "#b:/c/d#e#f#", "file:///b:/c/d", 1, 7 },
357cdf0e10cSrcweir { "a:/", "file:///a:/", 0, 3 },
358cdf0e10cSrcweir { ".component:", 0, 0, 0 },
359cdf0e10cSrcweir { ".uno:", 0, 0, 0 },
360cdf0e10cSrcweir { "cid:", 0, 0, 0 },
361cdf0e10cSrcweir { "data:", 0, 0, 0 },
362cdf0e10cSrcweir { "db:", 0, 0, 0 },
363cdf0e10cSrcweir { "file:", 0, 0, 0 },
364cdf0e10cSrcweir { "ftp:", 0, 0, 0 },
365cdf0e10cSrcweir { "http:", 0, 0, 0 },
366cdf0e10cSrcweir { "https:", 0, 0, 0 },
367cdf0e10cSrcweir { "imap:", 0, 0, 0 },
368cdf0e10cSrcweir { "javascript:", 0, 0, 0 },
369cdf0e10cSrcweir { "ldap:", 0, 0, 0 },
370cdf0e10cSrcweir { "macro:", 0, 0, 0 },
371cdf0e10cSrcweir { "mailto:", 0, 0, 0 },
372cdf0e10cSrcweir { "news:", 0, 0, 0 },
373cdf0e10cSrcweir { "out:", 0, 0, 0 },
374cdf0e10cSrcweir { "pop3:", 0, 0, 0 },
375cdf0e10cSrcweir { "private:", 0, 0, 0 },
376cdf0e10cSrcweir { "slot:", 0, 0, 0 },
377cdf0e10cSrcweir { "staroffice.component:", 0, 0, 0 },
378cdf0e10cSrcweir { "staroffice.db:", 0, 0, 0 },
379cdf0e10cSrcweir { "staroffice.factory:", 0, 0, 0 },
380cdf0e10cSrcweir { "staroffice.helpid:", 0, 0, 0 },
381cdf0e10cSrcweir { "staroffice.java:", 0, 0, 0 },
382cdf0e10cSrcweir { "staroffice.macro:", 0, 0, 0 },
383cdf0e10cSrcweir { "staroffice.out:", 0, 0, 0 },
384cdf0e10cSrcweir { "staroffice.pop3:", 0, 0, 0 },
385cdf0e10cSrcweir { "staroffice.private:", 0, 0, 0 },
386cdf0e10cSrcweir { "staroffice.searchfolder:", 0, 0, 0 },
387cdf0e10cSrcweir { "staroffice.slot:", 0, 0, 0 },
388cdf0e10cSrcweir { "staroffice.trashcan:", 0, 0, 0 },
389cdf0e10cSrcweir { "staroffice.uno:", 0, 0, 0 },
390cdf0e10cSrcweir { "staroffice.vim:", 0, 0, 0 },
391cdf0e10cSrcweir { "staroffice:", 0, 0, 0 },
392cdf0e10cSrcweir { "vim:", 0, 0, 0 },
393cdf0e10cSrcweir { "vnd.sun.star.cmd:", 0, 0, 0 },
394cdf0e10cSrcweir { "vnd.sun.star.help:", 0, 0, 0 },
395cdf0e10cSrcweir { "vnd.sun.star.hier:", 0, 0, 0 },
396cdf0e10cSrcweir { "vnd.sun.star.odma:", 0, 0, 0 },
397cdf0e10cSrcweir { "vnd.sun.star.pkg:", 0, 0, 0 },
398cdf0e10cSrcweir { "vnd.sun.star.script:", 0, 0, 0 },
399cdf0e10cSrcweir { "vnd.sun.star.webdav:", 0, 0, 0 },
400cdf0e10cSrcweir { "vnd.sun.star.wfs:", 0, 0, 0 },
401cdf0e10cSrcweir { "generic:path", 0, 0, 0 },
402cdf0e10cSrcweir { "wfs:", 0, 0, 0 }
403cdf0e10cSrcweir };
404cdf0e10cSrcweir CharClass charClass(
405cdf0e10cSrcweir css::uno::Reference< css::lang::XMultiServiceFactory >(
406cdf0e10cSrcweir m_context->getServiceManager(), css::uno::UNO_QUERY_THROW),
407cdf0e10cSrcweir com::sun::star::lang::Locale(
408cdf0e10cSrcweir rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("en")),
409cdf0e10cSrcweir rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("US")), rtl::OUString()));
410cdf0e10cSrcweir for (std::size_t i = 0; i < sizeof tests / sizeof tests[0]; ++i) {
411cdf0e10cSrcweir rtl::OUString input(rtl::OUString::createFromAscii(tests[i].input));
412cdf0e10cSrcweir xub_StrLen begin = 0;
413cdf0e10cSrcweir xub_StrLen end = static_cast< xub_StrLen >(input.getLength());
414cdf0e10cSrcweir rtl::OUString result(
415cdf0e10cSrcweir URIHelper::FindFirstURLInText(input, begin, end, charClass));
416cdf0e10cSrcweir bool ok = tests[i].result == 0
417cdf0e10cSrcweir ? (result.getLength() == 0 && begin == input.getLength()
418cdf0e10cSrcweir && end == input.getLength())
419cdf0e10cSrcweir : (result.equalsAscii(tests[i].result) && begin == tests[i].begin
420cdf0e10cSrcweir && end == tests[i].end);
421cdf0e10cSrcweir rtl::OString msg;
422cdf0e10cSrcweir if (!ok) {
423cdf0e10cSrcweir rtl::OStringBuffer buf;
424cdf0e10cSrcweir buf.append('"');
425cdf0e10cSrcweir buf.append(tests[i].input);
426cdf0e10cSrcweir buf.append(RTL_CONSTASCII_STRINGPARAM("\" -> "));
427cdf0e10cSrcweir buf.append(tests[i].result == 0 ? "none" : tests[i].result);
428cdf0e10cSrcweir buf.append(RTL_CONSTASCII_STRINGPARAM(" ("));
429cdf0e10cSrcweir buf.append(static_cast< sal_Int32 >(tests[i].begin));
430cdf0e10cSrcweir buf.append(RTL_CONSTASCII_STRINGPARAM(", "));
431cdf0e10cSrcweir buf.append(static_cast< sal_Int32 >(tests[i].end));
432cdf0e10cSrcweir buf.append(')');
433cdf0e10cSrcweir buf.append(RTL_CONSTASCII_STRINGPARAM(" != "));
434cdf0e10cSrcweir buf.append(rtl::OUStringToOString(result, RTL_TEXTENCODING_UTF8));
435cdf0e10cSrcweir buf.append(RTL_CONSTASCII_STRINGPARAM(" ("));
436cdf0e10cSrcweir buf.append(static_cast< sal_Int32 >(begin));
437cdf0e10cSrcweir buf.append(RTL_CONSTASCII_STRINGPARAM(", "));
438cdf0e10cSrcweir buf.append(static_cast< sal_Int32 >(end));
439cdf0e10cSrcweir buf.append(')');
440cdf0e10cSrcweir msg = buf.makeStringAndClear();
441cdf0e10cSrcweir }
442*2958961eSDamjan Jovanovic ASSERT_TRUE(ok) << msg.getStr();
443cdf0e10cSrcweir }
444cdf0e10cSrcweir }
445cdf0e10cSrcweir
446cdf0e10cSrcweir css::uno::Reference< css::uno::XComponentContext > Test::m_context;
447cdf0e10cSrcweir
448cdf0e10cSrcweir
449cdf0e10cSrcweir }
450cdf0e10cSrcweir
main(int argc,char ** argv)451*2958961eSDamjan Jovanovic int main(int argc, char **argv)
452*2958961eSDamjan Jovanovic {
453*2958961eSDamjan Jovanovic ::testing::InitGoogleTest(&argc, argv);
454*2958961eSDamjan Jovanovic return RUN_ALL_TESTS();
455*2958961eSDamjan Jovanovic }
456