• 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 Remove
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 }