• 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 
33 private:
34     std::unique_ptr<LruCache> testLruCache_;
35 };
36 
SetUpTestCase()37 void LruCacheTest::SetUpTestCase() {}
38 
TearDownTestCase()39 void LruCacheTest::TearDownTestCase() {}
40 
SetUp()41 void LruCacheTest::SetUp() {}
42 
TearDown()43 void LruCacheTest::TearDown() {}
44 
45 /**
46  * @tc.name: Visit
47  * @tc.desc: test function Visit
48  * @tc.type: FUNC
49  */
50 HWTEST_F(LruCacheTest, Visit, TestSize.Level1)
51 {
52     testLruCache_ = std::make_unique<LruCache>(TEST_CACHE_CAPACITY);
53     bool res = testLruCache_->Visit(30);
54     ASSERT_EQ(res, false);
55 
56     testLruCache_->Put(30);
57     res = testLruCache_->Visit(30);
58     ASSERT_EQ(res, true);
59 }
60 
61 /**
62  * @tc.name: Put
63  * @tc.desc: test function Put
64  * @tc.type: FUNC
65  */
66 HWTEST_F(LruCacheTest, Put, TestSize.Level1)
67 {
68     testLruCache_ = std::make_unique<LruCache>(TEST_CACHE_CAPACITY);
69     int32_t res = testLruCache_->Put(30);
70     ASSERT_EQ(res, -1);
71 
72     testLruCache_->Put(31);
73     testLruCache_->Put(32);
74     res = testLruCache_->Put(33);
75     ASSERT_EQ(res, 30);
76 }
77 
78 /**
79  * @tc.name: Remove
80  * @tc.desc: test function Remove
81  * @tc.type: FUNC
82  */
83 HWTEST_F(LruCacheTest, Remove, TestSize.Level1)
84 {
85     testLruCache_ = std::make_unique<LruCache>(TEST_CACHE_CAPACITY);
86     int32_t res = testLruCache_->Put(30);
87     ASSERT_EQ(res, -1);
88 
89     testLruCache_->Put(31);
90     testLruCache_->Put(32);
91     testLruCache_->Remove(32);
92     res = testLruCache_->Put(33);
93     ASSERT_EQ(res, -1);
94 }
95 } // namespace Rosen
96 } // namespace OHOS