From 128e5424644d75726fc920ba207e6315d8ada409 Mon Sep 17 00:00:00 2001 From: jiangkai43 Date: Thu, 24 Nov 2022 16:16:04 +0800 Subject: [PATCH] fixed 781a388 from https://gitee.com/jiangkai43/xts_acts/pulls/6675 The afterRemoval function is called when the cache size is larger than the maxsize https://gitee.com/openharmony/xts_acts/issues/I62XQR Signed-off-by: jiangkai43 --- .../src/main/js/test/util.test.js | 54 +++++++++++++++++++ .../src/main/js/test/util.test.js | 54 +++++++++++++++++++ 2 files changed, 108 insertions(+) diff --git a/commonlibrary/ets_utils/util2_lib_standard/src/main/js/test/util.test.js b/commonlibrary/ets_utils/util2_lib_standard/src/main/js/test/util.test.js index 8453e3e79..dd6d3b26c 100644 --- a/commonlibrary/ets_utils/util2_lib_standard/src/main/js/test/util.test.js +++ b/commonlibrary/ets_utils/util2_lib_standard/src/main/js/test/util.test.js @@ -3253,6 +3253,60 @@ describe('LRUCacheTest', function () { ChildLRUCache.getInstance().afterRemoval(true,'abc','ab','string') expect(arr[2]).assertEqual('string') }) + + /** + * @tc.name: testLRUCacheAfterRemoval006 + * @tc.desc: Executes subsequent operations after a value is deleted. + */ + it('testLRUCacheAfterRemoval006', 0, function () { + var arr = []; + class ChildLRUCache extends util.LRUCache + { + constructor(capacity) + { + super(capacity); + } + afterRemoval(isEvict, key, value, newValue) + { + if (isEvict === true) + { + arr = [key, value]; + } + } + } + var that = new ChildLRUCache(2); + that.put(1,2) + that.put(3,10) + that.put('abc',20) + expect(arr[1]).assertEqual(20) + }) + + /** + * @tc.name: testLRUCacheAfterRemoval007 + * @tc.desc: Executes subsequent operations after a value is deleted. + */ + it('testLRUCacheAfterRemoval007', 0, function () { + var arr = []; + class ChildLRUCache extends util.LRUCache + { + constructor(capacity) + { + super(capacity); + } + afterRemoval(isEvict, key, value, newValue) + { + if (isEvict === false) + { + arr = [key, value, newValue]; + } + } + } + var that = new ChildLRUCache(3); + that.put(1,2) + that.put(3,10) + that.put(1,8) + expect(arr[2]).assertEqual(8) + }) }) describe('FunctionTest', function () { diff --git a/commonlibrary/ets_utils/util_lib_standard/src/main/js/test/util.test.js b/commonlibrary/ets_utils/util_lib_standard/src/main/js/test/util.test.js index fe8af2855..9939c48a2 100644 --- a/commonlibrary/ets_utils/util_lib_standard/src/main/js/test/util.test.js +++ b/commonlibrary/ets_utils/util_lib_standard/src/main/js/test/util.test.js @@ -4683,6 +4683,60 @@ describe('LruBufferFunTest', function () { ChildLruBuffer.getInstance().afterRemoval(true,'abc','ab','string') expect(arr[2]).assertEqual('string') }) + + /** + * @tc.name: testLruBufferAfterRemoval006 + * @tc.desc: Executes subsequent operations after a value is deleted. + */ + it('testLruBufferAfterRemoval006', 0, function () { + var arr = []; + class ChildLruBuffer extends util.LruBuffer + { + constructor(capacity) + { + super(capacity); + } + afterRemoval(isEvict, key, value, newValue) + { + if (isEvict === true) + { + arr = [key, value]; + } + } + } + var that = new ChildLruBuffer(2); + that.put(1,2) + that.put(3,10) + that.put('abc',20) + expect(arr[1]).assertEqual(20) + }) + + /** + * @tc.name: testLruBufferAfterRemoval007 + * @tc.desc: Executes subsequent operations after a value is deleted. + */ + it('testLruBufferAfterRemoval007', 0, function () { + var arr = []; + class ChildLruBuffer extends util.LruBuffer + { + constructor(capacity) + { + super(capacity); + } + afterRemoval(isEvict, key, value, newValue) + { + if (isEvict === false) + { + arr = [key, value, newValue]; + } + } + } + var that = new ChildLruBuffer(3); + that.put(1,2) + that.put(3,10) + that.put(1,8) + expect(arr[2]).assertEqual(8) + }) }) describe('TypesTest', function() { -- GitLab