xref: /aosp_15_r20/external/libgav1/src/utils/block_parameters_holder_test.cc (revision 095378508e87ed692bf8dfeb34008b65b3735891)
1 // Copyright 2021 The libgav1 Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "src/utils/block_parameters_holder.h"
16 
17 #include "gtest/gtest.h"
18 #include "src/utils/constants.h"
19 #include "src/utils/types.h"
20 
21 namespace libgav1 {
22 namespace {
23 
TEST(BlockParametersHolder,TestBasic)24 TEST(BlockParametersHolder, TestBasic) {
25   BlockParametersHolder holder;
26   ASSERT_TRUE(holder.Reset(20, 20));
27 
28   // Get a BlockParameters object.
29   BlockParameters* const bp1 = holder.Get(10, 10, kBlock32x32);
30   ASSERT_NE(bp1, nullptr);
31   // Ensure that cache was filled appropriately. From (10, 10) to (17, 17)
32   // should be bp1 (10 + 4x4 width/height of 32x32 block is 18).
33   for (int i = 10; i < 18; ++i) {
34     for (int j = 10; j < 18; ++j) {
35       EXPECT_EQ(holder.Find(i, j), bp1)
36           << "Mismatch in (" << i << ", " << j << ")";
37     }
38   }
39 
40   // Get the maximum number of BlockParameters objects.
41   for (int i = 0; i < 399; ++i) {
42     EXPECT_NE(holder.Get(10, 10, kBlock32x32), nullptr)
43         << "Mismatch in index " << i;
44   }
45 
46   // Get() should now return nullptr since there are no more BlockParameters
47   // objects available.
48   EXPECT_EQ(holder.Get(10, 10, kBlock32x32), nullptr);
49 
50   // Reset the holder to the same size.
51   ASSERT_TRUE(holder.Reset(20, 20));
52 
53   // Get a BlockParameters object. This should be the same as bp1 since the
54   // holder was Reset to the same size.
55   BlockParameters* const bp2 = holder.Get(10, 10, kBlock32x32);
56   EXPECT_EQ(bp2, bp1);
57 
58   // Reset the holder to a smaller size.
59   ASSERT_TRUE(holder.Reset(20, 10));
60 
61   // Get a BlockParameters object. This should be the same as bp1 since the
62   // holder was Reset to a smaller size.
63   BlockParameters* const bp3 = holder.Get(0, 0, kBlock32x32);
64   EXPECT_EQ(bp3, bp1);
65 
66   // Reset the holder to a larger size.
67   ASSERT_TRUE(holder.Reset(30, 30));
68 
69   // Get a BlockParameters object. This may or may not be the same as bp1 since
70   // the holder was Reset to a larger size.
71   BlockParameters* const bp4 = holder.Get(0, 0, kBlock32x32);
72   EXPECT_NE(bp4, nullptr);
73 }
74 
75 }  // namespace
76 }  // namespace libgav1
77