xref: /aoo4110/main/binaryurp/qa/test-cache.cxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "sal/config.h"
25 
26 #include "cppunit/TestAssert.h"
27 #include "cppunit/TestFixture.h"
28 #include "cppunit/extensions/HelperMacros.h"
29 #include "cppunit/plugin/TestPlugIn.h"
30 
31 #include "../source/cache.hxx"
32 
33 namespace {
34 
35 class Test: public CppUnit::TestFixture {
36 private:
37     CPPUNIT_TEST_SUITE(Test);
38     CPPUNIT_TEST(testNothingLostFromLruList);
39     CPPUNIT_TEST_SUITE_END();
40 
41     void testNothingLostFromLruList();
42 };
43 
44 // cf. jurt/test/com/sun/star/lib/uno/protocols/urp/Cache_Test.java:
testNothingLostFromLruList()45 void Test::testNothingLostFromLruList() {
46     int a[8];
47     for (int i = 0; i != sizeof a / sizeof a[0]; ++i) {
48         for (int j = 0; j != i; ++j) {
49             a[j] = 0;
50         }
51         for (;;) {
52             binaryurp::Cache< int > c(4);
53             for (int k = 0; k != i; ++k) {
54                 bool f;
55                 c.add(a[k], &f);
56             }
57             bool f;
58             CPPUNIT_ASSERT_EQUAL(
59                 6,
60                 c.add(-1, &f) + c.add(-2, &f) + c.add(-3, &f) + c.add(-4, &f));
61             int j = i - 1;
62             while (j >= 0 && a[j] == 3) {
63                 --j;
64             }
65             if (j < 0) {
66                 break;
67             }
68             ++a[j];
69             for (int k = j + 1; k != i; ++k) {
70                 a[k] = 0;
71             }
72         }
73     }
74 }
75 
76 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
77 
78 }
79 
80 CPPUNIT_PLUGIN_IMPLEMENT();
81