From e62c02a089e454eeea472e758e113e7e28568a02 Mon Sep 17 00:00:00 2001 From: Giuseppe Castagno Date: Sat, 24 Sep 2016 13:35:54 +0200 Subject: tdf#102499 (1): Add WebDAV test to check HTTP reponse status codes retry Change-Id: I4ff36df3ac1cc0788322768378fb74f70892f922 Reviewed-on: https://gerrit.libreoffice.org/29245 Tested-by: Giuseppe Castagno Reviewed-by: Giuseppe Castagno --- ucb/CppunitTest_ucb_webdav_res_access.mk | 55 +++++++++++++++ ucb/Module_ucb.mk | 1 + ucb/qa/cppunit/webdav/webdav_options.cxx | 2 + ucb/qa/cppunit/webdav/webdav_resource_access.cxx | 85 ++++++++++++++++++++++++ ucb/source/ucp/webdav-neon/DAVResourceAccess.hxx | 5 +- 5 files changed, 146 insertions(+), 2 deletions(-) create mode 100644 ucb/CppunitTest_ucb_webdav_res_access.mk create mode 100644 ucb/qa/cppunit/webdav/webdav_resource_access.cxx (limited to 'ucb') diff --git a/ucb/CppunitTest_ucb_webdav_res_access.mk b/ucb/CppunitTest_ucb_webdav_res_access.mk new file mode 100644 index 000000000000..ac48f87bc876 --- /dev/null +++ b/ucb/CppunitTest_ucb_webdav_res_access.mk @@ -0,0 +1,55 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +#************************************************************************* +# +# 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/. +# +#************************************************************************* + +$(eval $(call gb_CppunitTest_CppunitTest,ucb_webdav_res_access)) + +$(eval $(call gb_CppunitTest_use_api,ucb_webdav_res_access, \ + offapi \ + udkapi \ +)) + +$(eval $(call gb_CppunitTest_use_libraries,ucb_webdav_res_access, \ + comphelper \ + cppu \ + cppuhelper \ + sal \ + salhelper \ + test \ + ucbhelper \ +)) + +$(eval $(call gb_CppunitTest_use_library_objects,ucb_webdav_res_access, \ + ucpdav1 \ +)) + +$(eval $(call gb_CppunitTest_use_externals,ucb_webdav_res_access,\ + boost_headers \ + libxml2 \ + neon \ + openssl \ +)) + +$(eval $(call gb_CppunitTest_use_custom_headers,ucb_webdav_res_access,\ + officecfg/registry \ +)) + +$(eval $(call gb_CppunitTest_add_exception_objects,ucb_webdav_res_access, \ + ucb/qa/cppunit/webdav/webdav_resource_access \ +)) + +$(eval $(call gb_CppunitTest_set_include,ucb_webdav_res_access,\ + $$(INCLUDE) \ + -I$(SRCDIR)/ucb/source/ucp/webdav-neon \ +)) + +$(eval $(call gb_CppunitTest_use_static_libraries,ucb_webdav_res_access)) + +# vim: set noet sw=4 ts=4: diff --git a/ucb/Module_ucb.mk b/ucb/Module_ucb.mk index 5fcd1e71fd11..fca05b8f4f5f 100644 --- a/ucb/Module_ucb.mk +++ b/ucb/Module_ucb.mk @@ -37,6 +37,7 @@ $(eval $(call gb_Module_add_check_targets,ucb,\ CppunitTest_ucb_webdav_local_neon \ CppunitTest_ucb_webdav_neon_opts \ CppunitTest_ucb_webdav_propfindcache \ + CppunitTest_ucb_webdav_res_access \ )) endif diff --git a/ucb/qa/cppunit/webdav/webdav_options.cxx b/ucb/qa/cppunit/webdav/webdav_options.cxx index bad3adc8da77..924eaf9a142d 100644 --- a/ucb/qa/cppunit/webdav/webdav_options.cxx +++ b/ucb/qa/cppunit/webdav/webdav_options.cxx @@ -9,6 +9,8 @@ #include #include +#include "DAVResourceAccess.hxx" +#include "DAVException.hxx" #include "DAVTypes.hxx" namespace diff --git a/ucb/qa/cppunit/webdav/webdav_resource_access.cxx b/ucb/qa/cppunit/webdav/webdav_resource_access.cxx new file mode 100644 index 000000000000..4097d9e4b73a --- /dev/null +++ b/ucb/qa/cppunit/webdav/webdav_resource_access.cxx @@ -0,0 +1,85 @@ +/* -*- 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 +#include +#include "DAVResourceAccess.hxx" +#include "DAVException.hxx" + +using namespace webdav_ucp; + +namespace +{ + + class webdav_resource_access_test: public test::BootstrapFixture + { + + public: + webdav_resource_access_test() : BootstrapFixture( true, true ) {} + + // initialise your test code values here. + void setUp() override; + + void tearDown() override; + + void DAVCheckRetries(); + + // 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_resource_access_test ); + CPPUNIT_TEST( DAVCheckRetries ); + CPPUNIT_TEST_SUITE_END(); + }; // class webdav_local_test + + // initialise your test code values here. + void webdav_resource_access_test::setUp() + { + } + + void webdav_resource_access_test::tearDown() + { + } + + // test when http connection should retry + void webdav_resource_access_test::DAVCheckRetries() + { + // instantiate a resource access class + DAVResourceAccess ResourceAccess(nullptr, nullptr, "http://url"); + // first check: all http errors from 100 to 399 should return true, to force a retry + for (auto i = SC_CONTINUE; i < SC_BAD_REQUEST; i++) + { + const DAVException aTheException(DAVException::DAV_HTTP_ERROR, "http error code", i ); + CPPUNIT_ASSERT_EQUAL( true , ResourceAccess.handleException( aTheException, 1 ) ); + } + // http error code from 400 to 499 should NOT force a retry + for (auto i = SC_BAD_REQUEST; i < SC_INTERNAL_SERVER_ERROR; i++) + { + const DAVException aTheException(DAVException::DAV_HTTP_ERROR, "http error code", i ); + CPPUNIT_ASSERT_EQUAL( false , ResourceAccess.handleException( aTheException, 1 ) ); + } + // http error code from 500 (SC_INTERNAL_SERVER_ERROR) up should force a retry + // except: SC_NOT_IMPLEMENTED + for (auto i = SC_INTERNAL_SERVER_ERROR; i < 2000; i++) + { + const DAVException aTheException(DAVException::DAV_HTTP_ERROR, "http error code", i ); + if( i != SC_NOT_IMPLEMENTED ) + CPPUNIT_ASSERT_EQUAL( true , ResourceAccess.handleException( aTheException, 1 ) ); + else + CPPUNIT_ASSERT_EQUAL( false , ResourceAccess.handleException( aTheException, 1 ) ); + } + } + + CPPUNIT_TEST_SUITE_REGISTRATION( webdav_resource_access_test ); +} // namespace rtl_random + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/ucb/source/ucp/webdav-neon/DAVResourceAccess.hxx b/ucb/source/ucp/webdav-neon/DAVResourceAccess.hxx index f2fa411dd050..aed404ff1932 100644 --- a/ucb/source/ucp/webdav-neon/DAVResourceAccess.hxx +++ b/ucb/source/ucp/webdav-neon/DAVResourceAccess.hxx @@ -220,12 +220,13 @@ public: css::ucb::WebDAVHTTPMethod eMethod, DAVRequestHeaders & rRequestHeaders ); + bool handleException( const DAVException & e, int errorCount ) + throw ( DAVException ); + private: const OUString & getRequestURI() const; bool detectRedirectCycle( const OUString& rRedirectURL ) throw ( DAVException ); - bool handleException( const DAVException & e, int errorCount ) - throw ( DAVException ); void initialize() throw ( DAVException ); }; -- cgit