1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
10 #include <test/bootstrapfixture.hxx>
11 #include <cppunit/plugin/TestPlugIn.h>
12 #include <DAVResourceAccess.hxx>
13 #include <DAVException.hxx>
15 using namespace webdav_ucp
;
20 class webdav_resource_access_test
: public test::BootstrapFixture
24 webdav_resource_access_test() : BootstrapFixture( true, true ) {}
26 // initialise your test code values here.
27 void setUp() override
;
29 void tearDown() override
;
31 void DAVCheckRetries();
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.
37 CPPUNIT_TEST_SUITE( webdav_resource_access_test
);
38 CPPUNIT_TEST( DAVCheckRetries
);
39 CPPUNIT_TEST_SUITE_END();
40 }; // class webdav_local_test
42 // initialise your test code values here.
43 void webdav_resource_access_test::setUp()
47 void webdav_resource_access_test::tearDown()
51 // test when http connection should retry
52 void webdav_resource_access_test::DAVCheckRetries()
54 // instantiate a resource access class
55 DAVResourceAccess
ResourceAccess(nullptr, nullptr, "http://url");
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
++)
59 const DAVException
aTheException(DAVException::DAV_HTTP_ERROR
, "http error code", i
);
60 CPPUNIT_ASSERT_EQUAL( true , ResourceAccess
.handleException( aTheException
, 1 ) );
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
++)
65 const DAVException
aTheException(DAVException::DAV_HTTP_ERROR
, "http error code", i
);
66 CPPUNIT_ASSERT_EQUAL( false , ResourceAccess
.handleException( aTheException
, 1 ) );
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
++)
75 const DAVException
aTheException(DAVException::DAV_HTTP_ERROR
, "http error code", i
);
78 // the HTTP response status codes that can be retried
80 case SC_GATEWAY_TIMEOUT
:
81 case SC_SERVICE_UNAVAILABLE
:
82 case SC_INSUFFICIENT_STORAGE
:
83 CPPUNIT_ASSERT_EQUAL( true , ResourceAccess
.handleException( aTheException
, 1 ) );
85 // default is NOT retry
87 CPPUNIT_ASSERT_EQUAL( false , ResourceAccess
.handleException( aTheException
, 1 ) );
91 // check the retry request
93 const DAVException
aTheException(DAVException::DAV_HTTP_RETRY
, "the-host-name", 8080 );
94 CPPUNIT_ASSERT_EQUAL( true , ResourceAccess
.handleException( aTheException
, 1 ) );
98 CPPUNIT_TEST_SUITE_REGISTRATION( webdav_resource_access_test
);
99 } // namespace rtl_random
101 CPPUNIT_PLUGIN_IMPLEMENT();
103 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */