diff options
author | Stephan Bergmann <sb@openoffice.org> | 2002-08-13 07:27:02 +0000 |
---|---|---|
committer | Stephan Bergmann <sb@openoffice.org> | 2002-08-13 07:27:02 +0000 |
commit | 3da797d4f79b0e4ea45ef475307d53a3a18169ad (patch) | |
tree | dc0a746b134cce88cf583293a5b000538ede8fa7 /svtools/qa | |
parent | 6d96720fd51ca4710c9ffef3db68ac13678f5bed (diff) |
#101704# Redesigned FindFirstURLInText.
Diffstat (limited to 'svtools/qa')
-rw-r--r-- | svtools/qa/test_URIHelper.cxx | 149 |
1 files changed, 72 insertions, 77 deletions
diff --git a/svtools/qa/test_URIHelper.cxx b/svtools/qa/test_URIHelper.cxx index 1faf21e46561..a07029e87adf 100644 --- a/svtools/qa/test_URIHelper.cxx +++ b/svtools/qa/test_URIHelper.cxx @@ -2,9 +2,9 @@ * * $RCSfile: test_URIHelper.cxx,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: sb $ $Date: 2002-07-19 15:13:11 $ + * last change: $Author: sb $ $Date: 2002-08-13 08:27:02 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -67,6 +67,7 @@ #include "cppuhelper/bootstrap.hxx" #include "rtl/string.h" #include "rtl/tres.h" +#include "rtl/strbuf.hxx" #include "rtl/ustring.h" #include "rtl/ustring.hxx" #include "sal/types.h" @@ -104,89 +105,83 @@ extern "C" sal_Bool SAL_CALL test_URIHelper_FindFirstURLInText( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("US")), rtl::OUString())); - bool bReturn = true; - - { - rtl::OUString aText( - RTL_CONSTASCII_USTRINGPARAM("abc.def.ghi,www.xxx.yyy...")); - xub_StrLen nBegin = 0; - xub_StrLen nEnd = static_cast< xub_StrLen >(aText.getLength()); - rtl::OUString aResult(URIHelper::FindFirstURLInText(aText, nBegin, - nEnd, aClass)); - bool bSuccess = aResult.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM( - "http://www.xxx.yyy/")) - && nBegin == 12 && nEnd == 23; - pTestResult->pFuncs->state_( - pTestResult, bSuccess, "test_URIHelper_FindFirstURLInText", - "\"abc.def.ghi,www.xxx.yyy...\" -> http://www.xxx.yyy/", false); - bReturn = bReturn && bSuccess; - } - - { - rtl::OUString aText( - RTL_CONSTASCII_USTRINGPARAM("abc.def.ghi,wwww.xxx.yyy...")); - xub_StrLen nBegin = 0; - xub_StrLen nEnd = static_cast< xub_StrLen >(aText.getLength()); - rtl::OUString aResult(URIHelper::FindFirstURLInText(aText, nBegin, - nEnd, aClass)); - bool bSuccess = aResult.getLength() == 0 - && nBegin == static_cast< xub_StrLen >(aText.getLength()) - && nEnd == static_cast< xub_StrLen >(aText.getLength()); - pTestResult->pFuncs->state_( - pTestResult, bSuccess, "test_URIHelper_FindFirstURLInText", - "\"abc.def.ghi,wwww.xxx.yyy...\" -> none", false); - bReturn = bReturn && bSuccess; - } - + struct Test { - rtl::OUString aText( - RTL_CONSTASCII_USTRINGPARAM("abc.def.ghi,wWW.xxx.yyy...")); - xub_StrLen nBegin = 0; - xub_StrLen nEnd = static_cast< xub_StrLen >(aText.getLength()); - rtl::OUString aResult(URIHelper::FindFirstURLInText(aText, nBegin, - nEnd, aClass)); - bool bSuccess = aResult.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM( - "http://wWW.xxx.yyy/")) - && nBegin == 12 && nEnd == 23; - pTestResult->pFuncs->state_( - pTestResult, bSuccess, "test_URIHelper_FindFirstURLInText", - "\"abc.def.ghi,wWW.xxx.yyy...\" -> http://wWW.xxx.yyy/", false); - bReturn = bReturn && bSuccess; - } - - { - rtl::OUString aText( - RTL_CONSTASCII_USTRINGPARAM("abc.def.ghi,ftp.xxx.yyy/zzz...")); - xub_StrLen nBegin = 0; - xub_StrLen nEnd = static_cast< xub_StrLen >(aText.getLength()); - rtl::OUString aResult(URIHelper::FindFirstURLInText(aText, nBegin, - nEnd, aClass)); - bool bSuccess = aResult.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM( - "ftp://ftp.xxx.yyy/zzz")) - && nBegin == 12 && nEnd == 27; - pTestResult->pFuncs->state_( - pTestResult, bSuccess, "test_URIHelper_FindFirstURLInText", - "\"abc.def.ghi,ftp.xxx.yyy/zzz...\" -> ftp://ftp.xxx.yyy/zzz", - false); - bReturn = bReturn && bSuccess; - } + char const * sInput; + char const * sResult; + xub_StrLen nBegin; + xub_StrLen nEnd; + }; + static Test const aTests[] + = {{ "...ftp://bla.bla.bla/blubber/...", + "ftp://bla.bla.bla/blubber/", 3, 29 }, + { "..\\ftp://bla.bla.bla/blubber/...", 0, 0, 0 }, + { "..\\ftp:\\\\bla.bla.bla\\blubber/...", + "file://bla.bla.bla/blubber%2F", 7, 29 }, + { "http://sun.com", "http://sun.com/", 0, 14 }, + { "http://sun.com/", "http://sun.com/", 0, 15 }, + { "Version.1.2.3", 0, 0, 0 }, + { "Version:1.2.3", 0, 0, 0 }, + { "a.b.c", 0, 0, 0 }, + { "file:///a|...", "file:///a:", 0, 10 }, + { "file:///a||...", "file:///a%7C%7C", 0, 11 }, + { "file:///a|/bc#...", "file:///a:/bc", 0, 13 }, + { "file:///a|/bc#de...", "file:///a:/bc#de", 0, 16 }, + { "abc.def.ghi,ftp.xxx.yyy/zzz...", + "ftp://ftp.xxx.yyy/zzz", 12, 27 }, + { "abc.def.ghi,Ftp.xxx.yyy/zzz...", + "ftp://Ftp.xxx.yyy/zzz", 12, 27 }, + { "abc.def.ghi,www.xxx.yyy...", "http://www.xxx.yyy/", 12, 23 }, + { "abc.def.ghi,wwww.xxx.yyy...", 0, 0, 0 }, + { "abc.def.ghi,wWW.xxx.yyy...", "http://wWW.xxx.yyy/", 12, 23 }, + { "Bla {mailto.me@abc.def.g.h.i}...", + "mailto:%7Bmailto.me@abc.def.g.h.i", 4, 28 }, + { "abc@def@ghi", 0, 0, 0 }, + { "lala@sun.com", "mailto:lala@sun.com", 0, 12 }, + { "1lala@sun.com", "mailto:1lala@sun.com", 0, 13 }, + { "aaa_bbb@xxx.yy", "mailto:aaa_bbb@xxx.yy", 0, 14 }, + { "{a:\\bla/bla/bla...}", "file:///a:/bla/bla/bla", 1, 15 }, + { "#b:/c/d#e#f#", "file:///b:/c/d", 1, 7 }, + { "a:/", "file:///a:/", 0, 3 } }; + bool bReturn = true; + for (int i = 0; i < sizeof aTests / sizeof (Test); ++i) { - rtl::OUString aText( - RTL_CONSTASCII_USTRINGPARAM("abc.def.ghi,Ftp.xxx.yyy/zzz...")); + rtl::OUString aInput(rtl::OUString::createFromAscii(aTests[i].sInput)); xub_StrLen nBegin = 0; - xub_StrLen nEnd = static_cast< xub_StrLen >(aText.getLength()); - rtl::OUString aResult(URIHelper::FindFirstURLInText(aText, nBegin, + xub_StrLen nEnd = static_cast< xub_StrLen >(aInput.getLength()); + rtl::OUString aResult(URIHelper::FindFirstURLInText(aInput, nBegin, nEnd, aClass)); - bool bSuccess = aResult.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM( - "ftp://Ftp.xxx.yyy/zzz")) - && nBegin == 12 && nEnd == 27; + bool bSuccess = aTests[i].sResult == 0 + ? (aResult.getLength() == 0 + && nBegin == aInput.getLength() && nEnd == aInput.getLength()) + : (aResult.equalsAscii(aTests[i].sResult) + && nBegin == aTests[i].nBegin && nEnd == aTests[i].nEnd); + rtl::OStringBuffer aBuffer; + aBuffer.append('"'); + aBuffer.append(aTests[i].sInput); + aBuffer.append(RTL_CONSTASCII_STRINGPARAM("\" -> ")); + aBuffer.append(aTests[i].sResult == 0 ? "none" : aTests[i].sResult); + aBuffer.append(RTL_CONSTASCII_STRINGPARAM(" (")); + aBuffer.append(static_cast< sal_Int32 >(aTests[i].nBegin)); + aBuffer.append(RTL_CONSTASCII_STRINGPARAM(", ")); + aBuffer.append(static_cast< sal_Int32 >(aTests[i].nEnd)); + aBuffer.append(')'); + if (!bSuccess) + { + aBuffer.append(RTL_CONSTASCII_STRINGPARAM(" != ")); + aBuffer.append(rtl::OUStringToOString(aResult, + RTL_TEXTENCODING_UTF8)); + aBuffer.append(RTL_CONSTASCII_STRINGPARAM(" (")); + aBuffer.append(static_cast< sal_Int32 >(nBegin)); + aBuffer.append(RTL_CONSTASCII_STRINGPARAM(", ")); + aBuffer.append(static_cast< sal_Int32 >(nEnd)); + aBuffer.append(')'); + } pTestResult->pFuncs->state_( pTestResult, bSuccess, "test_URIHelper_FindFirstURLInText", - "\"abc.def.ghi,Ftp.xxx.yyy/zzz...\" -> ftp://Ftp.xxx.yyy/zzz", - false); + aBuffer.getStr(), false); bReturn = bReturn && bSuccess; } - return bReturn; } |