137adc4f0SAndrew Rist /**************************************************************
237adc4f0SAndrew Rist *
337adc4f0SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
437adc4f0SAndrew Rist * or more contributor license agreements. See the NOTICE file
537adc4f0SAndrew Rist * distributed with this work for additional information
637adc4f0SAndrew Rist * regarding copyright ownership. The ASF licenses this file
737adc4f0SAndrew Rist * to you under the Apache License, Version 2.0 (the
837adc4f0SAndrew Rist * "License"); you may not use this file except in compliance
937adc4f0SAndrew Rist * with the License. You may obtain a copy of the License at
1037adc4f0SAndrew Rist *
1137adc4f0SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
1237adc4f0SAndrew Rist *
1337adc4f0SAndrew Rist * Unless required by applicable law or agreed to in writing,
1437adc4f0SAndrew Rist * software distributed under the License is distributed on an
1537adc4f0SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1637adc4f0SAndrew Rist * KIND, either express or implied. See the License for the
1737adc4f0SAndrew Rist * specific language governing permissions and limitations
1837adc4f0SAndrew Rist * under the License.
1937adc4f0SAndrew Rist *
2037adc4f0SAndrew Rist *************************************************************/
2137adc4f0SAndrew Rist
2237adc4f0SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir #include "sal/config.h"
25cdf0e10cSrcweir
26*e5230ffaSDamjan Jovanovic #include "gtest/gtest.h"
27cdf0e10cSrcweir
28cdf0e10cSrcweir #include "../source/cache.hxx"
29cdf0e10cSrcweir
30cdf0e10cSrcweir namespace {
31cdf0e10cSrcweir
32*e5230ffaSDamjan Jovanovic class Test: public ::testing::Test {
33*e5230ffaSDamjan Jovanovic public:
34cdf0e10cSrcweir };
35cdf0e10cSrcweir
36cdf0e10cSrcweir // cf. jurt/test/com/sun/star/lib/uno/protocols/urp/Cache_Test.java:
TEST_F(Test,testNothingLostFromLruList)37*e5230ffaSDamjan Jovanovic TEST_F(Test, testNothingLostFromLruList) {
38cdf0e10cSrcweir int a[8];
39cdf0e10cSrcweir for (int i = 0; i != sizeof a / sizeof a[0]; ++i) {
40cdf0e10cSrcweir for (int j = 0; j != i; ++j) {
41cdf0e10cSrcweir a[j] = 0;
42cdf0e10cSrcweir }
43cdf0e10cSrcweir for (;;) {
44cdf0e10cSrcweir binaryurp::Cache< int > c(4);
45cdf0e10cSrcweir for (int k = 0; k != i; ++k) {
46cdf0e10cSrcweir bool f;
47cdf0e10cSrcweir c.add(a[k], &f);
48cdf0e10cSrcweir }
49cdf0e10cSrcweir bool f;
50*e5230ffaSDamjan Jovanovic ASSERT_EQ(
51cdf0e10cSrcweir 6,
52cdf0e10cSrcweir c.add(-1, &f) + c.add(-2, &f) + c.add(-3, &f) + c.add(-4, &f));
53cdf0e10cSrcweir int j = i - 1;
54cdf0e10cSrcweir while (j >= 0 && a[j] == 3) {
55cdf0e10cSrcweir --j;
56cdf0e10cSrcweir }
57cdf0e10cSrcweir if (j < 0) {
58cdf0e10cSrcweir break;
59cdf0e10cSrcweir }
60cdf0e10cSrcweir ++a[j];
61cdf0e10cSrcweir for (int k = j + 1; k != i; ++k) {
62cdf0e10cSrcweir a[k] = 0;
63cdf0e10cSrcweir }
64cdf0e10cSrcweir }
65cdf0e10cSrcweir }
66cdf0e10cSrcweir }
67cdf0e10cSrcweir
68cdf0e10cSrcweir
69cdf0e10cSrcweir }
70