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 <PropfindCache.hxx>
14 using namespace webdav_ucp
;
19 class webdav_propcache_test
: public test::BootstrapFixture
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
{
70 "DAV:getlastmodified",
71 "DAV:getcontentlength",
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
{
104 "DAV:getlastmodified",
105 "DAV:getcontentlength",
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
;
120 CPPUNIT_ASSERT_EQUAL( true, PropCache
.getCachedPropertyNames( aTheURL
, aRetPropsNames
) );
122 std::vector
< DAVResourceInfo
> aRetProp
= aRetPropsNames
.getPropertiesNames();
123 CPPUNIT_ASSERT_EQUAL( true, ( aProps
== aRetProp
) );
125 PropCache
.removeCachedPropertyNames( aTheURL
);
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: */