diff options
author | Giuseppe Castagno <giuseppe.castagno@acca-esse.eu> | 2016-01-09 17:32:26 +0100 |
---|---|---|
committer | Giuseppe Castagno <giuseppe.castagno@acca-esse.eu> | 2016-07-28 06:29:23 +0000 |
commit | f950b49393ee6539f2a7b3c306aa4fc119f24a84 (patch) | |
tree | 524db5b7c87e96ce1ce8525310b926f73da0cf2b /ucb/qa | |
parent | 66dd26659e7c4bb731a88e7dbc809c5b53cb79c3 (diff) |
tdf#101094 (1) OPTIONS: New class to store retrieved OPTIONS
This class describes the DAV options useful to LO.
Added behavioural unit tests as well.
Change-Id: I7ba0230f1a1469b12f9b3f59f21e5c2730c65b81
Reviewed-on: https://gerrit.libreoffice.org/27595
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Giuseppe Castagno <giuseppe.castagno@acca-esse.eu>
Diffstat (limited to 'ucb/qa')
-rw-r--r-- | ucb/qa/cppunit/webdav/webdav_options.cxx | 255 |
1 files changed, 255 insertions, 0 deletions
diff --git a/ucb/qa/cppunit/webdav/webdav_options.cxx b/ucb/qa/cppunit/webdav/webdav_options.cxx new file mode 100644 index 000000000000..dd7ad24f8755 --- /dev/null +++ b/ucb/qa/cppunit/webdav/webdav_options.cxx @@ -0,0 +1,255 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <test/bootstrapfixture.hxx> +#include <cppunit/plugin/TestPlugIn.h> +#include "DAVTypes.hxx" + + +namespace +{ + + class webdav_opts_test: public test::BootstrapFixture + { + + public: + webdav_opts_test() : BootstrapFixture( true, true ) {} + + // initialise your test code values here. + void setUp( ) override; + + void tearDown( ) override; + + void DAVTypesCheckReset( webdav_ucp::DAVOptions aDavType ); + void DAVTypesTest(); + + // 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. + + CPPUNIT_TEST_SUITE( webdav_opts_test ); + CPPUNIT_TEST( DAVTypesTest ); + CPPUNIT_TEST_SUITE_END(); + }; // class webdav_local_test + + // initialise your test code values here. + void webdav_opts_test::setUp() + { + } + + void webdav_opts_test::tearDown() + { + } + + void webdav_opts_test::DAVTypesCheckReset( webdav_ucp::DAVOptions aDavType ) + { + // check if the class is at reset state + // using accessors + CPPUNIT_ASSERT_EQUAL( false, aDavType.isResourceFound() ); + CPPUNIT_ASSERT_EQUAL( false, aDavType.isClass1() ); + CPPUNIT_ASSERT_EQUAL( false, aDavType.isClass2() ); + CPPUNIT_ASSERT_EQUAL( false, aDavType.isClass3() ); + CPPUNIT_ASSERT_EQUAL( true, aDavType.getAllowedMethods().isEmpty() ); + CPPUNIT_ASSERT_EQUAL( false, aDavType.isLockAllowed() ); + CPPUNIT_ASSERT_EQUAL( true, aDavType.getURL().isEmpty() ); + CPPUNIT_ASSERT_EQUAL( true, aDavType.getRedirectedURL().isEmpty() ); + CPPUNIT_ASSERT_EQUAL( sal_uInt32( 0 ), aDavType.getStaleTime() ); + } + + void webdav_opts_test::DAVTypesTest() + { + //our DAVOptions + webdav_ucp::DAVOptions aDavOpt; + DAVTypesCheckReset( aDavOpt ); + aDavOpt.setResourceFound(); + //recheck... + CPPUNIT_ASSERT_EQUAL( true, aDavOpt.isResourceFound() ); + CPPUNIT_ASSERT_EQUAL( false, aDavOpt.isClass1() ); + CPPUNIT_ASSERT_EQUAL( false, aDavOpt.isClass2() ); + CPPUNIT_ASSERT_EQUAL( false, aDavOpt.isClass3() ); + CPPUNIT_ASSERT_EQUAL( true, aDavOpt.getAllowedMethods().isEmpty() ); + CPPUNIT_ASSERT_EQUAL( false, aDavOpt.isLockAllowed() ); + CPPUNIT_ASSERT_EQUAL( true, aDavOpt.getURL().isEmpty() ); + CPPUNIT_ASSERT_EQUAL( true, aDavOpt.getRedirectedURL().isEmpty() ); + CPPUNIT_ASSERT_EQUAL( sal_uInt32( 0 ), aDavOpt.getStaleTime() ); + + aDavOpt.setResourceFound( false ); + aDavOpt.setClass1(); + CPPUNIT_ASSERT_EQUAL( false, aDavOpt.isResourceFound() ); + CPPUNIT_ASSERT_EQUAL( true, aDavOpt.isClass1() ); + CPPUNIT_ASSERT_EQUAL( false, aDavOpt.isClass2() ); + CPPUNIT_ASSERT_EQUAL( false, aDavOpt.isClass3() ); + CPPUNIT_ASSERT_EQUAL( true, aDavOpt.getAllowedMethods().isEmpty() ); + CPPUNIT_ASSERT_EQUAL( false, aDavOpt.isLockAllowed() ); + CPPUNIT_ASSERT_EQUAL( true, aDavOpt.getURL().isEmpty() ); + CPPUNIT_ASSERT_EQUAL( true, aDavOpt.getRedirectedURL().isEmpty() ); + CPPUNIT_ASSERT_EQUAL( sal_uInt32( 0 ), aDavOpt.getStaleTime() ); + + aDavOpt.setClass1( false ); + aDavOpt.setClass2(); + CPPUNIT_ASSERT_EQUAL( false, aDavOpt.isResourceFound() ); + CPPUNIT_ASSERT_EQUAL( false, aDavOpt.isClass1() ); + CPPUNIT_ASSERT_EQUAL( true, aDavOpt.isClass2() ); + CPPUNIT_ASSERT_EQUAL( false, aDavOpt.isClass3() ); + CPPUNIT_ASSERT_EQUAL( true, aDavOpt.getAllowedMethods().isEmpty() ); + CPPUNIT_ASSERT_EQUAL( false, aDavOpt.isLockAllowed() ); + + aDavOpt.setClass2( false ); + aDavOpt.setClass3(); + CPPUNIT_ASSERT_EQUAL( false, aDavOpt.isResourceFound() ); + CPPUNIT_ASSERT_EQUAL( false, aDavOpt.isClass1() ); + CPPUNIT_ASSERT_EQUAL( false, aDavOpt.isClass2() ); + CPPUNIT_ASSERT_EQUAL( true, aDavOpt.isClass3() ); + CPPUNIT_ASSERT_EQUAL( true, aDavOpt.getAllowedMethods().isEmpty() ); + CPPUNIT_ASSERT_EQUAL( false, aDavOpt.isLockAllowed() ); + CPPUNIT_ASSERT_EQUAL( true, aDavOpt.getURL().isEmpty() ); + CPPUNIT_ASSERT_EQUAL( true, aDavOpt.getRedirectedURL().isEmpty() ); + CPPUNIT_ASSERT_EQUAL( sal_uInt32( 0 ), aDavOpt.getStaleTime() ); + + aDavOpt.setClass3( false ); + + CPPUNIT_ASSERT_EQUAL( false, aDavOpt.isResourceFound() ); + CPPUNIT_ASSERT_EQUAL( false, aDavOpt.isClass1() ); + CPPUNIT_ASSERT_EQUAL( false, aDavOpt.isClass2() ); + CPPUNIT_ASSERT_EQUAL( false, aDavOpt.isClass3() ); + CPPUNIT_ASSERT_EQUAL( true, aDavOpt.getAllowedMethods().isEmpty() ); + CPPUNIT_ASSERT_EQUAL( false, aDavOpt.isLockAllowed() ); + CPPUNIT_ASSERT_EQUAL( true, aDavOpt.getURL().isEmpty() ); + CPPUNIT_ASSERT_EQUAL( true, aDavOpt.getRedirectedURL().isEmpty() ); + CPPUNIT_ASSERT_EQUAL( sal_uInt32( 0 ), aDavOpt.getStaleTime() ); + + DAVTypesCheckReset( aDavOpt ); + //example of allowed method for a Web resource + OUString aAllowedMethods = "POST,OPTIONS,GET,HEAD,TRACE"; + aDavOpt.setAllowedMethods( aAllowedMethods ); + // now check... + CPPUNIT_ASSERT_EQUAL( false, aDavOpt.isResourceFound() ); + CPPUNIT_ASSERT_EQUAL( false, aDavOpt.isClass1() ); + CPPUNIT_ASSERT_EQUAL( false, aDavOpt.isClass2() ); + CPPUNIT_ASSERT_EQUAL( false, aDavOpt.isClass3() ); + CPPUNIT_ASSERT_EQUAL( aAllowedMethods, aDavOpt.getAllowedMethods() ); + CPPUNIT_ASSERT_EQUAL( false, aDavOpt.isLockAllowed() ); + CPPUNIT_ASSERT_EQUAL( true, aDavOpt.getURL().isEmpty() ); + CPPUNIT_ASSERT_EQUAL( true, aDavOpt.getRedirectedURL().isEmpty() ); + CPPUNIT_ASSERT_EQUAL( sal_uInt32( 0 ), aDavOpt.getStaleTime() ); + + //example of allowed method for a WebDAV resource supporting LOCK + aAllowedMethods = "OPTIONS,GET,HEAD,POST,DELETE,TRACE,PROPFIND,PROPPATCH,COPY,MOVE,PUT,LOCK,UNLOCK"; + aDavOpt.setAllowedMethods( aAllowedMethods ); + // now check... + CPPUNIT_ASSERT_EQUAL( false, aDavOpt.isResourceFound() ); + CPPUNIT_ASSERT_EQUAL( false, aDavOpt.isClass1() ); + CPPUNIT_ASSERT_EQUAL( false, aDavOpt.isClass2() ); + CPPUNIT_ASSERT_EQUAL( false, aDavOpt.isClass3() ); + CPPUNIT_ASSERT_EQUAL( aAllowedMethods, aDavOpt.getAllowedMethods() ); + CPPUNIT_ASSERT_EQUAL( true, aDavOpt.isLockAllowed() ); + CPPUNIT_ASSERT_EQUAL( true, aDavOpt.getURL().isEmpty() ); + CPPUNIT_ASSERT_EQUAL( true, aDavOpt.getRedirectedURL().isEmpty() ); + CPPUNIT_ASSERT_EQUAL( sal_uInt32( 0 ), aDavOpt.getStaleTime() ); + + aAllowedMethods.clear(); + aDavOpt.setAllowedMethods( aAllowedMethods ); + aDavOpt.setStaleTime( 12345678 ); + CPPUNIT_ASSERT_EQUAL( false, aDavOpt.isResourceFound() ); + CPPUNIT_ASSERT_EQUAL( false, aDavOpt.isClass1() ); + CPPUNIT_ASSERT_EQUAL( false, aDavOpt.isClass2() ); + CPPUNIT_ASSERT_EQUAL( false, aDavOpt.isClass3() ); + CPPUNIT_ASSERT_EQUAL( true, aDavOpt.getAllowedMethods().isEmpty() ); + CPPUNIT_ASSERT_EQUAL( false, aDavOpt.isLockAllowed() ); + CPPUNIT_ASSERT_EQUAL( true , aDavOpt.getURL().isEmpty() ); + CPPUNIT_ASSERT_EQUAL( true, aDavOpt.getRedirectedURL().isEmpty() ); + CPPUNIT_ASSERT_EQUAL( sal_uInt32( 12345678 ), aDavOpt.getStaleTime() ); + + aDavOpt.setStaleTime( 0 ); + + OUString aURL = "http://a%20fake%20url/to%20test"; + aDavOpt.setURL( aURL ); + CPPUNIT_ASSERT_EQUAL( false, aDavOpt.isResourceFound() ); + CPPUNIT_ASSERT_EQUAL( false, aDavOpt.isClass1() ); + CPPUNIT_ASSERT_EQUAL( false, aDavOpt.isClass2() ); + CPPUNIT_ASSERT_EQUAL( false, aDavOpt.isClass3() ); + CPPUNIT_ASSERT_EQUAL( true, aDavOpt.getAllowedMethods().isEmpty() ); + CPPUNIT_ASSERT_EQUAL( false, aDavOpt.isLockAllowed() ); + CPPUNIT_ASSERT_EQUAL( aURL , aDavOpt.getURL() ); + CPPUNIT_ASSERT_EQUAL( true, aDavOpt.getRedirectedURL().isEmpty() ); + CPPUNIT_ASSERT_EQUAL( sal_uInt32( 0 ), aDavOpt.getStaleTime() ); + + aURL.clear(); + aDavOpt.setURL( aURL ); + aURL = "http://a%20fake%20url/to%20test/another-url"; + aDavOpt.setRedirectedURL( aURL ); + CPPUNIT_ASSERT_EQUAL( false, aDavOpt.isResourceFound() ); + CPPUNIT_ASSERT_EQUAL( false, aDavOpt.isClass1() ); + CPPUNIT_ASSERT_EQUAL( false, aDavOpt.isClass2() ); + CPPUNIT_ASSERT_EQUAL( false, aDavOpt.isClass3() ); + CPPUNIT_ASSERT_EQUAL( true, aDavOpt.getAllowedMethods().isEmpty() ); + CPPUNIT_ASSERT_EQUAL( false, aDavOpt.isLockAllowed() ); + CPPUNIT_ASSERT_EQUAL( true, aDavOpt.getURL().isEmpty() ); + CPPUNIT_ASSERT_EQUAL( aURL, aDavOpt.getRedirectedURL() ); + CPPUNIT_ASSERT_EQUAL( sal_uInt32( 0 ), aDavOpt.getStaleTime() ); + + //check the reset function + aAllowedMethods = "OPTIONS,GET,HEAD,POST,DELETE,TRACE,PROPFIND,PROPPATCH,COPY,MOVE,PUT,LOCK,UNLOCK"; + aURL = "http://a%20fake%20url/to%20test/another-url"; + aDavOpt.setResourceFound(); + aDavOpt.setClass1(); + aDavOpt.setClass2(); + aDavOpt.setClass3(); + aDavOpt.setAllowedMethods( aAllowedMethods ); + aDavOpt.setStaleTime( 1234567 ); + aDavOpt.setURL( aURL ); + aDavOpt.setRedirectedURL( aURL ); + + aDavOpt.reset(); + DAVTypesCheckReset( aDavOpt ); + // equality check + webdav_ucp::DAVOptions aDavOptTarget; + CPPUNIT_ASSERT_EQUAL( true , aDavOpt == aDavOptTarget ); + + aDavOpt.setClass1(); + CPPUNIT_ASSERT_EQUAL( false , aDavOpt == aDavOptTarget ); + aDavOpt.setClass1( false ); + CPPUNIT_ASSERT_EQUAL( true , aDavOpt == aDavOptTarget ); + + aDavOpt.setClass2(); + CPPUNIT_ASSERT_EQUAL( false , aDavOpt == aDavOptTarget ); + aDavOpt.setClass2( false ); + CPPUNIT_ASSERT_EQUAL( true , aDavOpt == aDavOptTarget ); + + aDavOpt.setClass3(); + CPPUNIT_ASSERT_EQUAL( false , aDavOpt == aDavOptTarget ); + aDavOpt.setClass3( false ); + CPPUNIT_ASSERT_EQUAL( true , aDavOpt == aDavOptTarget ); + + aDavOpt.setResourceFound(); + CPPUNIT_ASSERT_EQUAL( false , aDavOpt == aDavOptTarget ); + aDavOpt.setResourceFound( false ); + CPPUNIT_ASSERT_EQUAL( true , aDavOpt == aDavOptTarget ); + + aDavOpt.setStaleTime( 1234567 ); + CPPUNIT_ASSERT_EQUAL( false , aDavOpt == aDavOptTarget ); + aDavOpt.setStaleTime( 0 ); + CPPUNIT_ASSERT_EQUAL( true , aDavOpt == aDavOptTarget ); + + aDavOpt.setAllowedMethods( aAllowedMethods ); + CPPUNIT_ASSERT_EQUAL( false , aDavOpt == aDavOptTarget ); + aAllowedMethods.clear(); + aDavOpt.setAllowedMethods( aAllowedMethods ); + CPPUNIT_ASSERT_EQUAL( true , aDavOpt == aDavOptTarget ); + + aDavOpt.setURL( aURL ); + CPPUNIT_ASSERT_EQUAL( false , aDavOpt == aDavOptTarget ); + } + + CPPUNIT_TEST_SUITE_REGISTRATION( webdav_opts_test ); +} // namespace rtl_random + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |