From e8603e503ae920ed32f6f071064f3a49dcb66f6a Mon Sep 17 00:00:00 2001 From: zhouaoteng Date: Thu, 25 Apr 2024 22:41:15 +0800 Subject: [PATCH] add ut Signed-off-by: zhouaoteng --- .../b_json_entity_extension_config_test.cpp | 149 ++++++++++++++++++ 1 file changed, 149 insertions(+) diff --git a/tests/unittests/backup_utils/b_json/b_json_entity_extension_config_test.cpp b/tests/unittests/backup_utils/b_json/b_json_entity_extension_config_test.cpp index ffeaf33b0..f2f276804 100644 --- a/tests/unittests/backup_utils/b_json/b_json_entity_extension_config_test.cpp +++ b/tests/unittests/backup_utils/b_json/b_json_entity_extension_config_test.cpp @@ -964,4 +964,153 @@ HWTEST_F(BJsonEntityExtensionConfigTest, b_json_entity_extension_config_3500, te GTEST_LOG_(INFO) << "BJsonEntityExtensionConfigTest-end b_json_entity_extension_config_3500"; } +/** + * @tc.number: SUB_backup_b_json_entity_extension_config_3600 + * @tc.name: b_json_entity_extension_config_3600 + * @tc.desc: 测试GetSupportScene接口能否在Json数据键值为"SupportScene"时值为"next2next,hmos2next"时是否能成功返回"next2next,hmos2next" + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 2 + * @tc.require: I6F3GV + */ +HWTEST_F(BJsonEntityExtensionConfigTest, b_json_entity_extension_config_3600, testing::ext::TestSize.Level2) +{ + GTEST_LOG_(INFO) << "BJsonEntityExtensionConfigTest-begin b_json_entity_extension_config_3600"; + try { + string_view sv = R"({"SupportScene":"next2next,hmos2next"})"; + BJsonCachedEntity cachedEntity(sv); + auto cache = cachedEntity.Structuralize(); + string depRead = cache.GetSupportScene(); + EXPECT_EQ(depRead, "next2next,hmos2next"); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "BJsonEntityExtensionConfigTest-an exception occurred by GetSupportScene."; + } + GTEST_LOG_(INFO) << "BJsonEntityExtensionConfigTest-end b_json_entity_extension_config_3600"; +} + +/** + * @tc.number: SUB_backup_b_json_entity_extension_config_3700 + * @tc.name: b_json_entity_extension_config_3700 + * @tc.desc: 测试GetSupportScene接口能否在Json数据对象不含SupportScene键时能否成功返回空 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 2 + * @tc.require: I6F3GV + */ +HWTEST_F(BJsonEntityExtensionConfigTest, b_json_entity_extension_config_3700, testing::ext::TestSize.Level2) +{ + GTEST_LOG_(INFO) << "BJsonEntityExtensionConfigTest-begin b_json_entity_extension_config_3700"; + try { + string_view sv = R"({"SupportScene_":"next2next,hmos2next"})"; + BJsonCachedEntity cachedEntity(sv); + auto cache = cachedEntity.Structuralize(); + string depRead = cache.GetSupportScene(); + EXPECT_EQ(depRead, ""); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "BJsonEntityExtensionConfigTest-an exception occurred by GetSupportScene."; + } + GTEST_LOG_(INFO) << "BJsonEntityExtensionConfigTest-end b_json_entity_extension_config_3700"; +} + +/** + * @tc.number: SUB_backup_b_json_entity_extension_config_3700 + * @tc.name: b_json_entity_extension_config_3800 + * @tc.desc: 测试GetSupportScene接口能否在Json数据对象键值为"SupportScene"时值不为字符串时是否成功返回空串; + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 2 + * @tc.require: I6F3GV + */ +HWTEST_F(BJsonEntityExtensionConfigTest, b_json_entity_extension_config_3800, testing::ext::TestSize.Level2) +{ + GTEST_LOG_(INFO) << "BJsonEntityExtensionConfigTest-begin b_json_entity_extension_config_3800"; + try { + string_view sv = R"({"SupportScene":1})"; + BJsonCachedEntity cachedEntity(sv); + auto cache = cachedEntity.Structuralize(); + string depRead = cache.GetSupportScene(); + EXPECT_EQ(depRead, ""); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "BJsonEntityExtensionConfigTest-an exception occurred by GetSupportScene."; + } + GTEST_LOG_(INFO) << "BJsonEntityExtensionConfigTest-end b_json_entity_extension_config_3800"; +} + +/** + * @tc.number: b_json_entity_extension_config_3900 + * @tc.name: b_json_entity_extension_config_3900 + * @tc.desc: 测试GetSupportScene接口在Json数据对象nullValue时能否成功返回空串 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 2 + * @tc.require: I6F3GV + */ +HWTEST_F(BJsonEntityExtensionConfigTest, b_json_entity_extension_config_3900, testing::ext::TestSize.Level2) +{ + GTEST_LOG_(INFO) << "BJsonEntityExtensionConfigTest-begin b_json_entity_extension_config_3900"; + try { + Json::Value jv(Json::nullValue); + BJsonCachedEntity cachedEntity(sv); + auto cache = cachedEntity.Structuralize(); + string depRead = cache.GetSupportScene(); + EXPECT_EQ(depRead, ""); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "BJsonEntityExtensionConfigTest-an exception occurred by GetSupportScene."; + } + GTEST_LOG_(INFO) << "BJsonEntityExtensionConfigTest-end b_json_entity_extension_config_3900"; +} + +/** + * @tc.number: b_json_entity_extension_config_4000 + * @tc.name: b_json_entity_extension_config_4000 + * @tc.desc: 测试GetExtraInfo接口在Json数据对象nullValue时能否成功返回空串 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 2 + * @tc.require: I6F3GV + */ +HWTEST_F(BJsonEntityExtensionConfigTest, b_json_entity_extension_config_4000, testing::ext::TestSize.Level2) +{ + GTEST_LOG_(INFO) << "BJsonEntityExtensionConfigTest-begin b_json_entity_extension_config_4000"; + try { + Json::Value jv(Json::nullValue); + BJsonCachedEntity cachedEntity(sv); + auto cache = cachedEntity.Structuralize(); + Json::Value depRead = cache.GetExtraInfo(); + EXPECT_EQ(depRead, ""); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "BJsonEntityExtensionConfigTest-an exception occurred by GetExtraInfo."; + } + GTEST_LOG_(INFO) << "BJsonEntityExtensionConfigTest-end b_json_entity_extension_config_4000"; +} + +/** + * @tc.number: SUB_backup_b_json_entity_extension_config_4100 + * @tc.name: b_json_entity_extension_config_4100 + * @tc.desc: 测试GetExtraInfo接口能否在Json数据键值为"GetExtraInfo"时值为"next2next"时是否能成功返回"next2next" + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 2 + * @tc.require: I6F3GV + */ +HWTEST_F(BJsonEntityExtensionConfigTest, b_json_entity_extension_config_4100, testing::ext::TestSize.Level2) +{ + GTEST_LOG_(INFO) << "BJsonEntityExtensionConfigTest-begin b_json_entity_extension_config_4100"; + try { + string_view sv = R"({"ExtraInfo""SupportScene":["next2next"]})"; + BJsonCachedEntity cachedEntity(sv); + auto cache = cachedEntity.Structuralize(); + Json::Value depRead = cache.GetExtraInfo(); + EXPECT_EQ(depRead, "next2next"); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "BJsonEntityExtensionConfigTest-an exception occurred by GetExtraInfo."; + } + GTEST_LOG_(INFO) << "BJsonEntityExtensionConfigTest-end b_json_entity_extension_config_4100"; +} } // namespace OHOS::FileManagement::Backup \ No newline at end of file -- Gitee