| 1 |
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 |
/* |
| 3 |
* This file is part of the LibreOffice project. |
| 4 |
* |
| 5 |
* This Source Code Form is subject to the terms of the Mozilla Public |
| 6 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 7 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 8 |
*/ |
| 9 |
|
| 10 |
#include <test/bootstrapfixture.hxx> |
| 11 |
#include <cppunit/plugin/TestPlugIn.h> |
| 12 |
#include <DAVResourceAccess.hxx> |
| 13 |
#include <DAVException.hxx> |
| 14 |
|
| 15 |
using namespace http_dav_ucp; |
| 16 |
|
| 17 |
namespace |
| 18 |
{ |
| 19 |
|
| 20 |
class webdav_resource_access_test: public test::BootstrapFixture |
| 21 |
{ |
| 22 |
|
| 23 |
public: |
| 24 |
webdav_resource_access_test() : BootstrapFixture( true, true ) {} |
| 25 |
|
| 26 |
// initialise your test code values here. |
| 27 |
void setUp() override; |
| 28 |
|
| 29 |
void tearDown() override; |
| 30 |
|
| 31 |
void DAVCheckRetries(); |
| 32 |
|
| 33 |
// Change the following lines only, if you add, remove or rename |
| 34 |
// member functions of the current class, |
| 35 |
// because these macros are need by auto register mechanism. |
| 36 |
|
| 37 |
CPPUNIT_TEST_SUITE( webdav_resource_access_test ); |
| 38 |
CPPUNIT_TEST( DAVCheckRetries ); |
| 39 |
CPPUNIT_TEST_SUITE_END(); |
| 40 |
}; // class webdav_local_test |
| 41 |
|
| 42 |
// initialise your test code values here. |
| 43 |
void webdav_resource_access_test::setUp() |
| 44 |
{ |
| 45 |
} |
| 46 |
|
| 47 |
void webdav_resource_access_test::tearDown() |
| 48 |
{ |
| 49 |
} |
| 50 |
|
| 51 |
// test when http connection should retry |
| 52 |
void webdav_resource_access_test::DAVCheckRetries() |
| 53 |
{ |
| 54 |
// instantiate a resource access class |
| 55 |
DAVResourceAccess ResourceAccess(nullptr, nullptr, u"http://url"_ustr); |
| 56 |
// first check: all http errors from 100 to 399 should return true, to force a retry |
| 57 |
for (auto i = SC_CONTINUE; i < SC_BAD_REQUEST; i++) |
| 58 |
{ |
| 59 |
const DAVException aTheException(DAVException::DAV_HTTP_ERROR, u"http error code"_ustr, i ); |
| 60 |
CPPUNIT_ASSERT_EQUAL( true , ResourceAccess.handleException( aTheException, 1 ) ); |
| 61 |
} |
| 62 |
// http error code from 400 to 499 should NOT force a retry |
| 63 |
for (auto i = SC_BAD_REQUEST; i < SC_INTERNAL_SERVER_ERROR; i++) |
| 64 |
{ |
| 65 |
const DAVException aTheException(DAVException::DAV_HTTP_ERROR, u"http error code"_ustr, i ); |
| 66 |
CPPUNIT_ASSERT_EQUAL( false , ResourceAccess.handleException( aTheException, 1 ) ); |
| 67 |
} |
| 68 |
|
| 69 |
// http error code from 500 (SC_INTERNAL_SERVER_ERROR) up should force a retry |
| 70 |
// except in special value |
| 71 |
// 1999 as high limit is just a current (2016-09-25) choice. |
| 72 |
// RFC poses no limit to the max value of response status code |
| 73 |
for (auto i = SC_INTERNAL_SERVER_ERROR; i < 2000; i++) |
| 74 |
{ |
| 75 |
const DAVException aTheException(DAVException::DAV_HTTP_ERROR, u"http error code"_ustr, i ); |
| 76 |
switch ( i ) |
| 77 |
{ |
| 78 |
// the HTTP response status codes that can be retried |
| 79 |
case SC_BAD_GATEWAY: |
| 80 |
case SC_GATEWAY_TIMEOUT: |
| 81 |
case SC_SERVICE_UNAVAILABLE: |
| 82 |
case SC_INSUFFICIENT_STORAGE: |
| 83 |
CPPUNIT_ASSERT_EQUAL( true , ResourceAccess.handleException( aTheException, 1 ) ); |
| 84 |
break; |
| 85 |
// default is NOT retry |
| 86 |
default: |
| 87 |
CPPUNIT_ASSERT_EQUAL( false , ResourceAccess.handleException( aTheException, 1 ) ); |
| 88 |
} |
| 89 |
} |
| 90 |
|
| 91 |
// check the retry request |
| 92 |
{ |
| 93 |
const DAVException aTheException(DAVException::DAV_HTTP_RETRY, u"the-host-name"_ustr, 8080 ); |
| 94 |
CPPUNIT_ASSERT_EQUAL( true , ResourceAccess.handleException( aTheException, 1 ) ); |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
CPPUNIT_TEST_SUITE_REGISTRATION( webdav_resource_access_test ); |
| 99 |
} |
| 100 |
|
| 101 |
CPPUNIT_PLUGIN_IMPLEMENT(); |
| 102 |
|
| 103 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |