Kaydet (Commit) 8ea85c26 authored tarafından Giuseppe Castagno's avatar Giuseppe Castagno Kaydeden (comit) Jan Holesovsky

Add isSchemeEqualTo(), isAnyKnownWebDAVScheme() to INetURLObject

...which will be used when rebasing
    <https://gerrit.libreoffice.org/#/c/17189>
"tdf#82744: fix WebDAV lock/unlock behaviour - part 3" on top of
 d3de4904
 "Add vnd.sun.star.webdavs URL scheme."

Change-Id: I19bd715d755a6f070b95ce897d8a1bbb4910d537
Reviewed-on: https://gerrit.libreoffice.org/18151Reviewed-by: 's avatarJan Holesovsky <kendy@collabora.com>
Tested-by: 's avatarJan Holesovsky <kendy@collabora.com>
üst 8d65149d
......@@ -390,6 +390,17 @@ public:
inline INetProtocol GetProtocol() const { return m_eScheme; }
bool isSchemeEqualTo(INetProtocol scheme) const { return scheme == m_eScheme; }
bool isSchemeEqualTo(OUString const & scheme) const;
/** Check if the scheme is one of the WebDAV scheme
* we know about.
*
* @return true is one othe scheme either public scheme or private scheme.
*/
bool isAnyKnownWebDAVScheme() const;
/** Return the URL 'prefix' for a given scheme.
@param eTheScheme One of the supported URL schemes.
......
......@@ -329,6 +329,44 @@ namespace tools_urlobj
CPPUNIT_ASSERT(strm == 0);
}
void urlobjTest_isSchemeEqualTo() {
CPPUNIT_ASSERT(INetURLObject().isSchemeEqualTo(INetProtocol::NotValid));
CPPUNIT_ASSERT(!INetURLObject().isSchemeEqualTo(""));
CPPUNIT_ASSERT(
INetURLObject("http://example.org").isSchemeEqualTo(
INetProtocol::Http));
CPPUNIT_ASSERT(
!INetURLObject("http://example.org").isSchemeEqualTo(
INetProtocol::Https));
CPPUNIT_ASSERT(
INetURLObject("http://example.org").isSchemeEqualTo("Http"));
CPPUNIT_ASSERT(
!INetURLObject("http://example.org").isSchemeEqualTo("dav"));
CPPUNIT_ASSERT(
INetURLObject("dav://example.org").isSchemeEqualTo("dav"));
}
void urlobjTest_isAnyKnownWebDAVScheme() {
CPPUNIT_ASSERT(
INetURLObject("http://example.org").isAnyKnownWebDAVScheme());
CPPUNIT_ASSERT(
INetURLObject("https://example.org").isAnyKnownWebDAVScheme());
CPPUNIT_ASSERT(
INetURLObject("vnd.sun.star.webdav://example.org").isAnyKnownWebDAVScheme());
CPPUNIT_ASSERT(
INetURLObject("vnd.sun.star.webdavs://example.org").isAnyKnownWebDAVScheme());
CPPUNIT_ASSERT(
!INetURLObject("ftp://example.org").isAnyKnownWebDAVScheme());
CPPUNIT_ASSERT(
!INetURLObject("file://example.org").isAnyKnownWebDAVScheme());
CPPUNIT_ASSERT(
!INetURLObject("dav://example.org").isAnyKnownWebDAVScheme());
CPPUNIT_ASSERT(
!INetURLObject("davs://example.org").isAnyKnownWebDAVScheme());
CPPUNIT_ASSERT(
!INetURLObject("vnd.sun.star.pkg://example.org").isAnyKnownWebDAVScheme());
}
// Change the following lines only, if you add, remove or rename
// member functions of the current class,
// because these macros are need by auto register mechanism.
......@@ -343,6 +381,8 @@ namespace tools_urlobj
CPPUNIT_TEST( urlobjCmisTest );
CPPUNIT_TEST( urlobjTest_emptyPath );
CPPUNIT_TEST( urlobjTest_data );
CPPUNIT_TEST( urlobjTest_isSchemeEqualTo );
CPPUNIT_TEST( urlobjTest_isAnyKnownWebDAVScheme );
CPPUNIT_TEST_SUITE_END( );
}; // class createPool
......
......@@ -3911,6 +3911,22 @@ OUString INetURLObject::getExternalURL(DecodeMechanism eMechanism,
return aTheExtURIRef;
}
bool INetURLObject::isSchemeEqualTo(OUString const & scheme) const {
return m_aScheme.isPresent()
&& (rtl_ustr_compareIgnoreAsciiCase_WithLength(
scheme.getStr(), scheme.getLength(),
m_aAbsURIRef.getStr() + m_aScheme.getBegin(),
m_aScheme.getLength())
== 0);
}
bool INetURLObject::isAnyKnownWebDAVScheme() const {
return ( isSchemeEqualTo( INetProtocol::Http ) ||
isSchemeEqualTo( INetProtocol::Https ) ||
isSchemeEqualTo( INetProtocol::VndSunStarWebdav ) ||
isSchemeEqualTo( "vnd.sun.star.webdavs" ) );
}
// static
OUString INetURLObject::GetScheme(INetProtocol eTheScheme)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment