Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / ucb / qa / cppunit / webdav / webdav_propfindcache.cxx
blob29ccf8a462be4109c034b7e6e00c8b49de91aa03
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
10 #include <test/bootstrapfixture.hxx>
11 #include <cppunit/plugin/TestPlugIn.h>
12 #include <PropfindCache.hxx>
14 using namespace webdav_ucp;
16 namespace
19 class webdav_propcache_test: public test::BootstrapFixture
22 public:
23 webdav_propcache_test() : BootstrapFixture( true, true ) {}
25 // initialise your test code values here.
26 void setUp( ) override;
28 void tearDown( ) override;
30 void PropfindCacheElemTests();
31 void PropfindCacheTests();
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_propcache_test );
38 CPPUNIT_TEST( PropfindCacheElemTests );
39 CPPUNIT_TEST( PropfindCacheTests );
40 CPPUNIT_TEST_SUITE_END();
41 }; // class webdav_local_test
43 // initialise your test code values here.
44 void webdav_propcache_test::setUp()
48 void webdav_propcache_test::tearDown()
52 void webdav_propcache_test::PropfindCacheElemTests( )
54 OUString aTheURL( "http:://server/path/filename.odt" );
55 PropertyNames aPropsNames( aTheURL );
57 CPPUNIT_ASSERT_EQUAL( aTheURL, aPropsNames.getURL() );
58 CPPUNIT_ASSERT_EQUAL( static_cast< sal_uInt32 >(0), aPropsNames.getStaleTime() );
60 sal_uInt32 maxTime = static_cast< sal_uInt32 >(std::pow(2,32)-1);
62 aPropsNames.setStaleTime( maxTime );
63 CPPUNIT_ASSERT_EQUAL( maxTime, aPropsNames.getStaleTime() );
65 std::vector < OUString > properties {
66 "DAV:lockdiscovery",
67 "DAV:supportedlock",
68 "DAV:resourcetype",
69 "DAV:displayname",
70 "DAV:getlastmodified",
71 "DAV:getcontentlength",
72 "DAV:creationdate",
73 "DAV:getetag",
74 "DAV:authticket",
77 DAVResourceInfo aSingleInfo { properties };
78 std::vector< DAVResourceInfo > aProps { aSingleInfo };
79 std::vector< DAVResourceInfo > aRetProp;
81 aPropsNames.setPropertiesNames( aProps );
82 aRetProp = aPropsNames.getPropertiesNames();
83 CPPUNIT_ASSERT_EQUAL( true, ( aProps == aRetProp ) );
85 aProps[0].properties.emplace_back("DAV:getlastmodified" );
86 aRetProp = aPropsNames.getPropertiesNames();
87 CPPUNIT_ASSERT_EQUAL( false, ( aProps == aRetProp ) );
90 void webdav_propcache_test::PropfindCacheTests( )
92 PropertyNamesCache PropCache;
93 OUString aTheURL( "http:://server/path/filename.odt" );
94 PropertyNames aPropsNames( aTheURL );
96 // check cache emptiness
97 CPPUNIT_ASSERT_EQUAL( false, PropCache.getCachedPropertyNames( aTheURL, aPropsNames ) );
99 std::vector < OUString > properties {
100 "DAV:lockdiscovery",
101 "DAV:supportedlock",
102 "DAV:resourcetype",
103 "DAV:displayname",
104 "DAV:getlastmodified",
105 "DAV:getcontentlength",
106 "DAV:creationdate",
107 "DAV:getetag",
108 "DAV:authticket",
111 DAVResourceInfo aSingleInfo { properties };
112 std::vector< DAVResourceInfo > aProps { aSingleInfo };
114 // add the cache an element
115 aPropsNames.setPropertiesNames( aProps );
116 PropCache.addCachePropertyNames( aPropsNames );
118 PropertyNames aRetPropsNames;
119 //test existence
120 CPPUNIT_ASSERT_EQUAL( true, PropCache.getCachedPropertyNames( aTheURL, aRetPropsNames ) );
121 //check equality
122 std::vector< DAVResourceInfo > aRetProp = aRetPropsNames.getPropertiesNames();
123 CPPUNIT_ASSERT_EQUAL( true, ( aProps == aRetProp ) );
124 //remove from cache
125 PropCache.removeCachedPropertyNames( aTheURL );
126 //check absence
127 CPPUNIT_ASSERT_EQUAL( false, PropCache.getCachedPropertyNames( aTheURL, aPropsNames ) );
130 CPPUNIT_TEST_SUITE_REGISTRATION( webdav_propcache_test );
131 } // namespace rtl_random
133 CPPUNIT_PLUGIN_IMPLEMENT();
135 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */