• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
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 
16 #include <gtest/gtest.h>
17 
18 #include "window_manager_lru.h"
19 
20 using namespace testing;
21 using namespace testing::ext;
22 namespace OHOS {
23 namespace Rosen {
24 constexpr std::size_t TEST_CACHE_CAPACITY = 3;
25 
26 class LRUCacheTest : public testing::Test {
27 public:
28     static void SetUpTestCase();
29     static void TearDownTestCase();
30     void SetUp() override;
31     void TearDown() override;
32 private:
33     std::unique_ptr<LRUCache> testLRUCache_;
34 };
35 
SetUpTestCase()36 void LRUCacheTest::SetUpTestCase()
37 {
38 }
39 
TearDownTestCase()40 void LRUCacheTest::TearDownTestCase()
41 {
42 }
43 
SetUp()44 void LRUCacheTest::SetUp()
45 {
46 }
47 
TearDown()48 void LRUCacheTest::TearDown()
49 {
50 }
51 
52 /**
53  * @tc.name: Visit
54  * @tc.desc: test function Visit
55  * @tc.type: FUNC
56  */
57 HWTEST_F(LRUCacheTest, Visit, Function | SmallTest | Level2)
58 {
59     testLRUCache_ = std::make_unique<LRUCache>(TEST_CACHE_CAPACITY);
60     bool res = testLRUCache_->Visit(30);
61     ASSERT_EQ(res, false);
62 
63     testLRUCache_->Put(30);
64     res = testLRUCache_->Visit(30);
65     ASSERT_EQ(res, true);
66 }
67 
68 /**
69  * @tc.name: Put
70  * @tc.desc: test function Put
71  * @tc.type: FUNC
72  */
73 HWTEST_F(LRUCacheTest, Put, Function | SmallTest | Level2)
74 {
75     testLRUCache_ = std::make_unique<LRUCache>(TEST_CACHE_CAPACITY);
76     int32_t res = testLRUCache_->Put(30);
77     ASSERT_EQ(res, -1);
78 
79     testLRUCache_->Put(31);
80     testLRUCache_->Put(32);
81     res = testLRUCache_->Put(33);
82     ASSERT_EQ(res, 30);
83 }
84 
85 /**
86  * @tc.name: Remove
87  * @tc.desc: test function Put
88  * @tc.type: FUNC
89  */
90 HWTEST_F(LRUCacheTest, Remove, Function | SmallTest | Level2)
91 {
92     testLRUCache_ = std::make_unique<LRUCache>(TEST_CACHE_CAPACITY);
93     int32_t res = testLRUCache_->Put(30);
94     ASSERT_EQ(res, -1);
95 
96     testLRUCache_->Put(31);
97     testLRUCache_->Put(32);
98     testLRUCache_->Remove(32);
99     res = testLRUCache_->Put(33);
100     ASSERT_EQ(res, -1);
101 }
102 }
103 }