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