From 966c000baff07fcb85290adb7c94d167bd56fb12 Mon Sep 17 00:00:00 2001 From: jiangzhijun8 Date: Tue, 30 Jul 2024 17:52:32 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E8=A1=A5=E5=85=85tdd?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jiangzhijun8 --- .../common/recorder/event_recorder_test.cpp | 164 +++++++++++++++++- 1 file changed, 163 insertions(+), 1 deletion(-) diff --git a/test/unittest/core/common/recorder/event_recorder_test.cpp b/test/unittest/core/common/recorder/event_recorder_test.cpp index f63bbc2c15b..81ae31684f6 100644 --- a/test/unittest/core/common/recorder/event_recorder_test.cpp +++ b/test/unittest/core/common/recorder/event_recorder_test.cpp @@ -85,6 +85,48 @@ void GetConfigDisable(std::string& config) "\"duration\":5000},{\"id\":\"scroll_item_12\",\"ratio\":0.4,\"duration\":3000}]}]}"; } +void GetConfigTest(std::string& config) +{ + config = + "{\"enable\":false,\"switch\":{\"page\":true,\"component\":true,\"exposure\":true},\"x\":[{\"pageUrl\":" + "\"pages/" + "Index\",\"shareNode\":[\"hahaha\",\"btn_TitleExpand\",\"btn_OpenSelf\",\"btn_Screenshot\",\"btn_inspect\"," + "\"btn_xxx\",\"\"],\"exposureCfg\":[{\"id\":\"btn_Grid\",\"ratio\":0.75,\"duration\":5000},{\"id\":\"btn_" + "TitleExpand\",\"ratio\":0.9,\"duration\":1000}]},{\"pageUrl\":\"pages/" + "ScrollPage\",\"shareNode\":[\"scroll_item_1\"],\"exposureCfg\":[{\"id\":\"scroll_item_2\",\"ratio\":0.85," + "\"duration\":5000},{\"id\":\"scroll_item_12\",\"ratio\":0.4,\"duration\":3000}]}]}"; +} + +void GetConfigTest2(std::string& config) +{ + config = + "{\"enable\":true,\"switch\":{\"page\":true,\"component\":true,\"exposure\":true},\"config\":[{\"shareNode\":[\"hahaha\",\"btn_TitleExpand\",\"btn_OpenSelf\",\"btn_Screenshot\",\"btn_inspect\"," + "\"btn_xxx\",\"\"],\"exposureCfg\":[{\"id\":\"btn_Grid\",\"ratio\":0.75,\"duration\":5000},{\"id\":\"btn_" + "TitleExpand\",\"ratio\":0.9,\"duration\":1000}]},{\"shareNode\":[\"scroll_item_1\"],\"exposureCfg\":[{\"id\":\"scroll_item_2\",\"ratio\":0.85," + "\"duration\":5000},{\"id\":\"scroll_item_12\",\"ratio\":0.4,\"duration\":3000}]}]}"; +} + +void GetConfigTest3(std::string& config) +{ + config = + "{\"enable\":true,\"switch\":{\"page\":true,\"component\":true,\"exposure\":true},\"config\":[{\"pageUrl\":" + "\"pages/" + "Index\"},{\"pageUrl\":\"pages/" + "ScrollPage\"}]}"; +} + +void GetConfigTest4(std::string& config) +{ + config = + "{\"enable\":true,\"globalSwitch\":{\"page\":true,\"component\":true,\"exposure\":true},\"config\":[{\"pageUrl\":" + "\"pages/" + "Index\",\"shareNode\":[\"hahaha\",\"btn_TitleExpand\",\"btn_OpenSelf\",\"btn_Screenshot\",\"btn_inspect\"," + "\"btn_xxx\",\"\"],\"exposureCfg\":[{\"id\":\"btn_Grid\",\"ratio\":0.75,\"duration\":5000},{\"id\":\"btn_" + "TitleExpand\",\"ratio\":0.9,\"duration\":1000}]},{\"pageUrl\":\"pages/" + "ScrollPage\",\"shareNode\":[\"scroll_item_1\"],\"exposureCfg\":[{\"id\":\"scroll_item_2\",\"ratio\":0.85," + "\"duration\":5000},{\"id\":\"scroll_item_12\",\"ratio\":0.4,\"duration\":3000}]}]}"; +} + RefPtr CreatePageNode(const std::string pageUrl) { auto pageNodeId = ElementRegister::GetInstance()->MakeUniqueId(); @@ -671,8 +713,66 @@ HWTEST_F(EventRecorderTest, SetFocusContainerInfo002, TestSize.Level1) */ HWTEST_F(EventRecorderTest, Init001, TestSize.Level1) { + std::string str = ""; Recorder::EventConfig* config = new Recorder::EventConfig(); - config->Init(""); + config->Init(str); + EXPECT_EQ(str, ""); +} + +/** + * @tc.name: Init002 + * @tc.desc: Test Init. + * @tc.type: FUNC + */ +HWTEST_F(EventRecorderTest, Init002, TestSize.Level1) +{ + std::string str; + GetConfigTest(str); + Recorder::EventConfig* config = new Recorder::EventConfig(); + config->Init(str); + EXPECT_NE(str, ""); +} + +/** + * @tc.name: Init003 + * @tc.desc: Test Init. + * @tc.type: FUNC + */ +HWTEST_F(EventRecorderTest, Init003, TestSize.Level1) +{ + std::string str; + GetConfigTest2(str); + Recorder::EventConfig* config = new Recorder::EventConfig(); + config->Init(str); + EXPECT_NE(str, ""); +} + +/** + * @tc.name: Init004 + * @tc.desc: Test Init. + * @tc.type: FUNC + */ +HWTEST_F(EventRecorderTest, Init004, TestSize.Level1) +{ + std::string str; + GetConfigTest3(str); + Recorder::EventConfig* config = new Recorder::EventConfig(); + config->Init(str); + EXPECT_NE(str, ""); +} + +/** + * @tc.name: Init005 + * @tc.desc: Test Init. + * @tc.type: FUNC + */ +HWTEST_F(EventRecorderTest, Init005, TestSize.Level1) +{ + std::string str; + GetConfigTest4(str); + Recorder::EventConfig* config = new Recorder::EventConfig(); + config->Init(str); + EXPECT_NE(str, ""); } /** @@ -1101,4 +1201,66 @@ HWTEST_F(EventRecorderTest, GetPageUrl001, TestSize.Level1) std::string url = Recorder::EventRecorder::Get().GetPageUrl(); EXPECT_NE(url, ""); } + +/** + * @tc.name: PutString005 + * @tc.desc: Test PutString. + * @tc.type: FUNC + */ +HWTEST_F(EventRecorderTest, PutString005, TestSize.Level1) +{ + Recorder::ExposureCfg cfg; + Recorder::NodeDataCache::Get().Clear(""); + auto node = CreatePageNode("pages/Index"); + std::string id = ""; + std::string value = ""; + bool result = Recorder::NodeDataCache::Get().PutString(node, id, value); + EXPECT_FALSE(result); + + id = ""; + value = "test"; + result = Recorder::NodeDataCache::Get().PutString(node, id, value); + EXPECT_FALSE(result); + + id = "test"; + value = ""; + result = Recorder::NodeDataCache::Get().PutString(node, id, value); + EXPECT_FALSE(result); + + id = "test"; + value = "ROMYWBdsOgXB07y1XB1iVzym8n6QR5ZWaTDbjsCDe5PFbZKrPflxEEGpGPNbuNnHM1k1m9uveVLruC2KUkKOKGIxDo91RpTN1e7Etest"; + result = Recorder::NodeDataCache::Get().PutString(node, id, value); + EXPECT_FALSE(result); + + id = ""; + value = "ROMYWBdsOgXB07y1XB1iVzym8n6QR5ZWaTDbjsCDe5PFbZKrPflxEEGpGPNbuNnHM1k1m9uveVLruC2KUkKOKGIxDo91RpTN1e7Etest"; + result = Recorder::NodeDataCache::Get().PutString(node, id, value); + EXPECT_FALSE(result); + + id = "test"; + value = "test"; + Recorder::NodeDataCache::Get().shouldCollectFull_ = false; + result = Recorder::NodeDataCache::Get().PutString(node, id, value); + + Recorder::NodeDataCache::Get().shouldCollectFull_ = true; + result = Recorder::NodeDataCache::Get().PutString(node, id, value); + + auto pageNode = node->GetPageNode(); + auto pagePattern = pageNode->GetPattern(); + pagePattern->pageInfo_->url_ = ""; + Recorder::NodeDataCache::Get().shouldCollectFull_ = true; + result = Recorder::NodeDataCache::Get().PutString(node, id, value); + + EXPECT_FALSE(result); +} + +/** + * @tc.name: OnPageReady001 + * @tc.desc: Test OnPageReady. + * @tc.type: FUNC + */ +HWTEST_F(EventRecorderTest, OnPageReady001, TestSize.Level1) +{ + Recorder::NodeDataCache::Get().OnPageReady(); +} } // namespace OHOS::Ace From d49af2b29a587b602f4a889527a5c707c962104e Mon Sep 17 00:00:00 2001 From: jiangzhijun8 Date: Tue, 30 Jul 2024 18:01:10 +0800 Subject: [PATCH 2/3] =?UTF-8?q?tdd=E8=A6=86=E7=9B=96=E7=8E=87=E6=8F=90?= =?UTF-8?q?=E5=8D=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jiangzhijun8 --- .../core/common/recorder/event_recorder_test.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/test/unittest/core/common/recorder/event_recorder_test.cpp b/test/unittest/core/common/recorder/event_recorder_test.cpp index 81ae31684f6..1687fb68abc 100644 --- a/test/unittest/core/common/recorder/event_recorder_test.cpp +++ b/test/unittest/core/common/recorder/event_recorder_test.cpp @@ -99,11 +99,12 @@ void GetConfigTest(std::string& config) void GetConfigTest2(std::string& config) { - config = - "{\"enable\":true,\"switch\":{\"page\":true,\"component\":true,\"exposure\":true},\"config\":[{\"shareNode\":[\"hahaha\",\"btn_TitleExpand\",\"btn_OpenSelf\",\"btn_Screenshot\",\"btn_inspect\"," - "\"btn_xxx\",\"\"],\"exposureCfg\":[{\"id\":\"btn_Grid\",\"ratio\":0.75,\"duration\":5000},{\"id\":\"btn_" - "TitleExpand\",\"ratio\":0.9,\"duration\":1000}]},{\"shareNode\":[\"scroll_item_1\"],\"exposureCfg\":[{\"id\":\"scroll_item_2\",\"ratio\":0.85," - "\"duration\":5000},{\"id\":\"scroll_item_12\",\"ratio\":0.4,\"duration\":3000}]}]}"; + config = "{\"enable\":true,\"switch\":{\"page\":true,\"component\":true,\"exposure\":true},\"config\":[{" + "\"shareNode\":[\"hahaha\",\"btn_TitleExpand\",\"btn_OpenSelf\",\"btn_Screenshot\",\"btn_inspect\"," + "\"btn_xxx\",\"\"],\"exposureCfg\":[{\"id\":\"btn_Grid\",\"ratio\":0.75,\"duration\":5000},{\"id\":\"btn_" + "TitleExpand\",\"ratio\":0.9,\"duration\":1000}]},{\"shareNode\":[\"scroll_item_1\"],\"exposureCfg\":[{" + "\"id\":\"scroll_item_2\",\"ratio\":0.85," + "\"duration\":5000},{\"id\":\"scroll_item_12\",\"ratio\":0.4,\"duration\":3000}]}]}"; } void GetConfigTest3(std::string& config) @@ -118,7 +119,8 @@ void GetConfigTest3(std::string& config) void GetConfigTest4(std::string& config) { config = - "{\"enable\":true,\"globalSwitch\":{\"page\":true,\"component\":true,\"exposure\":true},\"config\":[{\"pageUrl\":" + "{\"enable\":true,\"globalSwitch\":{\"page\":true,\"component\":true,\"exposure\":true},\"config\":[{" + "\"pageUrl\":" "\"pages/" "Index\",\"shareNode\":[\"hahaha\",\"btn_TitleExpand\",\"btn_OpenSelf\",\"btn_Screenshot\",\"btn_inspect\"," "\"btn_xxx\",\"\"],\"exposureCfg\":[{\"id\":\"btn_Grid\",\"ratio\":0.75,\"duration\":5000},{\"id\":\"btn_" From ee06358b2380b1c6be1699817f475b371766b20b Mon Sep 17 00:00:00 2001 From: jiangzhijun8 Date: Wed, 31 Jul 2024 11:59:50 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9C=AA=E9=87=8A?= =?UTF-8?q?=E6=94=BE=E6=8C=87=E9=92=88bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jiangzhijun8 --- test/unittest/core/common/recorder/event_recorder_test.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/unittest/core/common/recorder/event_recorder_test.cpp b/test/unittest/core/common/recorder/event_recorder_test.cpp index 1687fb68abc..34d5eca032a 100644 --- a/test/unittest/core/common/recorder/event_recorder_test.cpp +++ b/test/unittest/core/common/recorder/event_recorder_test.cpp @@ -719,6 +719,7 @@ HWTEST_F(EventRecorderTest, Init001, TestSize.Level1) Recorder::EventConfig* config = new Recorder::EventConfig(); config->Init(str); EXPECT_EQ(str, ""); + delete config; } /** @@ -733,6 +734,7 @@ HWTEST_F(EventRecorderTest, Init002, TestSize.Level1) Recorder::EventConfig* config = new Recorder::EventConfig(); config->Init(str); EXPECT_NE(str, ""); + delete config; } /** @@ -747,6 +749,7 @@ HWTEST_F(EventRecorderTest, Init003, TestSize.Level1) Recorder::EventConfig* config = new Recorder::EventConfig(); config->Init(str); EXPECT_NE(str, ""); + delete config; } /** @@ -761,6 +764,7 @@ HWTEST_F(EventRecorderTest, Init004, TestSize.Level1) Recorder::EventConfig* config = new Recorder::EventConfig(); config->Init(str); EXPECT_NE(str, ""); + delete config; } /** @@ -775,6 +779,7 @@ HWTEST_F(EventRecorderTest, Init005, TestSize.Level1) Recorder::EventConfig* config = new Recorder::EventConfig(); config->Init(str); EXPECT_NE(str, ""); + delete config; } /** @@ -1109,6 +1114,7 @@ HWTEST_F(EventRecorderTest, IsCategoryEnable001, TestSize.Level1) config->switches_->emplace(Recorder::EventCategory::CATEGORY_COMPONENT, false); bool result = config->IsCategoryEnable(Recorder::EventCategory::CATEGORY_PAGE); EXPECT_FALSE(result); + delete config; } /**