Debian Codegraph @

ucb/qa/cppunit/webdav/webdav_propfindcache.cxx

raw
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 <PropfindCache.hxx>
13
14 using namespace http_dav_ucp;
15
16 namespace
17 {
18
19 class webdav_propcache_test: public test::BootstrapFixture
20 {
21
22 public:
23 webdav_propcache_test() : BootstrapFixture( true, true ) {}
24
25 // initialise your test code values here.
26 void setUp( ) override;
27
28 void tearDown( ) override;
29
30 void PropfindCacheElemTests();
31 void PropfindCacheTests();
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_propcache_test );
38 CPPUNIT_TEST( PropfindCacheElemTests );
39 CPPUNIT_TEST( PropfindCacheTests );
40 CPPUNIT_TEST_SUITE_END();
41 }; // class webdav_local_test
42
43 // initialise your test code values here.
44 void webdav_propcache_test::setUp()
45 {
46 }
47
48 void webdav_propcache_test::tearDown()
49 {
50 }
51
52 void webdav_propcache_test::PropfindCacheElemTests( )
53 {
54 OUString aTheURL( u"http:://server/path/filename.odt"_ustr );
55 PropertyNames aPropsNames( aTheURL );
56
57 CPPUNIT_ASSERT_EQUAL( aTheURL, aPropsNames.getURL() );
58 CPPUNIT_ASSERT_EQUAL( static_cast< sal_uInt32 >(0), aPropsNames.getStaleTime() );
59
60 sal_uInt32 maxTime = static_cast< sal_uInt32 >(std::pow(2,32)-1);
61
62 aPropsNames.setStaleTime( maxTime );
63 CPPUNIT_ASSERT_EQUAL( maxTime, aPropsNames.getStaleTime() );
64
65 std::vector < OUString > properties {
66 u"DAV:lockdiscovery"_ustr,
67 u"DAV:supportedlock"_ustr,
68 u"DAV:resourcetype"_ustr,
69 u"DAV:displayname"_ustr,
70 u"DAV:getlastmodified"_ustr,
71 u"DAV:getcontentlength"_ustr,
72 u"DAV:creationdate"_ustr,
73 u"DAV:getetag"_ustr,
74 u"DAV:authticket"_ustr,
75 };
76
77 DAVResourceInfo aSingleInfo { properties };
78 std::vector< DAVResourceInfo > aProps { aSingleInfo };
79 std::vector< DAVResourceInfo > aRetProp;
80
81 aPropsNames.setPropertiesNames( std::vector(aProps) );
82 aRetProp = aPropsNames.getPropertiesNames();
83 CPPUNIT_ASSERT_EQUAL( true, ( aProps == aRetProp ) );
84
85 aProps[0].properties.emplace_back("DAV:getlastmodified" );
86 aRetProp = aPropsNames.getPropertiesNames();
87 CPPUNIT_ASSERT_EQUAL( false, ( aProps == aRetProp ) );
88 }
89
90 void webdav_propcache_test::PropfindCacheTests( )
91 {
92 PropertyNamesCache PropCache;
93 OUString aTheURL( u"http:://server/path/filename.odt"_ustr );
94 PropertyNames aPropsNames( aTheURL );
95
96 // check cache emptiness
97 CPPUNIT_ASSERT_EQUAL( false, PropCache.getCachedPropertyNames( aTheURL, aPropsNames ) );
98
99 std::vector < OUString > properties {
100 u"DAV:lockdiscovery"_ustr,
101 u"DAV:supportedlock"_ustr,
102 u"DAV:resourcetype"_ustr,
103 u"DAV:displayname"_ustr,
104 u"DAV:getlastmodified"_ustr,
105 u"DAV:getcontentlength"_ustr,
106 u"DAV:creationdate"_ustr,
107 u"DAV:getetag"_ustr,
108 u"DAV:authticket"_ustr,
109 };
110
111 DAVResourceInfo aSingleInfo { properties };
112 std::vector< DAVResourceInfo > aProps { aSingleInfo };
113
114 // add the cache an element
115 aPropsNames.setPropertiesNames( std::vector(aProps) );
116 PropCache.addCachePropertyNames( aPropsNames, 10 );
117
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 ) );
128 }
129
130 CPPUNIT_TEST_SUITE_REGISTRATION( webdav_propcache_test );
131 }
132
133 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */