179a732c7Sopenharmony_ci/* 279a732c7Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 379a732c7Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 479a732c7Sopenharmony_ci * you may not use this file except in compliance with the License. 579a732c7Sopenharmony_ci * You may obtain a copy of the License at 679a732c7Sopenharmony_ci * 779a732c7Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 879a732c7Sopenharmony_ci * 979a732c7Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1079a732c7Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1179a732c7Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1279a732c7Sopenharmony_ci * See the License for the specific language governing permissions and 1379a732c7Sopenharmony_ci * limitations under the License. 1479a732c7Sopenharmony_ci */ 1579a732c7Sopenharmony_ci 1679a732c7Sopenharmony_ci#include "UTTest_relationship_sync_mgr.h" 1779a732c7Sopenharmony_ci 1879a732c7Sopenharmony_ci#include "dm_constants.h" 1979a732c7Sopenharmony_ci 2079a732c7Sopenharmony_cinamespace OHOS { 2179a732c7Sopenharmony_cinamespace DistributedHardware { 2279a732c7Sopenharmony_civoid ReleationShipSyncMgrTest::SetUp() 2379a732c7Sopenharmony_ci{ 2479a732c7Sopenharmony_ci} 2579a732c7Sopenharmony_ci 2679a732c7Sopenharmony_civoid ReleationShipSyncMgrTest::TearDown() 2779a732c7Sopenharmony_ci{ 2879a732c7Sopenharmony_ci} 2979a732c7Sopenharmony_ci 3079a732c7Sopenharmony_civoid ReleationShipSyncMgrTest::SetUpTestCase() 3179a732c7Sopenharmony_ci{ 3279a732c7Sopenharmony_ci} 3379a732c7Sopenharmony_ci 3479a732c7Sopenharmony_civoid ReleationShipSyncMgrTest::TearDownTestCase() 3579a732c7Sopenharmony_ci{ 3679a732c7Sopenharmony_ci} 3779a732c7Sopenharmony_ci 3879a732c7Sopenharmony_cinamespace { 3979a732c7Sopenharmony_ci 4079a732c7Sopenharmony_ciHWTEST_F(ReleationShipSyncMgrTest, SyncTrustRelationShip_001, testing::ext::TestSize.Level0) 4179a732c7Sopenharmony_ci{ 4279a732c7Sopenharmony_ci std::vector<std::string> peerUdids; 4379a732c7Sopenharmony_ci RelationShipChangeMsg msg; 4479a732c7Sopenharmony_ci msg.type = RelationShipChangeType::ACCOUNT_LOGOUT; 4579a732c7Sopenharmony_ci msg.userId = UINT32_MAX; 4679a732c7Sopenharmony_ci msg.peerUdids = peerUdids; 4779a732c7Sopenharmony_ci msg.accountId = "1"; 4879a732c7Sopenharmony_ci msg.accountName = "1"; 4979a732c7Sopenharmony_ci std::string broadCastMsg = ReleationShipSyncMgr::GetInstance().SyncTrustRelationShip(msg); 5079a732c7Sopenharmony_ci ASSERT_EQ(broadCastMsg, ""); 5179a732c7Sopenharmony_ci} 5279a732c7Sopenharmony_ci 5379a732c7Sopenharmony_ciHWTEST_F(ReleationShipSyncMgrTest, SyncTrustRelationShip_002, testing::ext::TestSize.Level0) 5479a732c7Sopenharmony_ci{ 5579a732c7Sopenharmony_ci std::vector<std::string> peerUdids; 5679a732c7Sopenharmony_ci RelationShipChangeMsg msg; 5779a732c7Sopenharmony_ci msg.type = RelationShipChangeType::ACCOUNT_LOGOUT; 5879a732c7Sopenharmony_ci msg.userId = 1; 5979a732c7Sopenharmony_ci msg.peerUdids = peerUdids; 6079a732c7Sopenharmony_ci msg.accountId = "1"; 6179a732c7Sopenharmony_ci msg.accountName = "1"; 6279a732c7Sopenharmony_ci std::string broadCastMsg = ReleationShipSyncMgr::GetInstance().SyncTrustRelationShip(msg); 6379a732c7Sopenharmony_ci ASSERT_EQ(broadCastMsg, ""); 6479a732c7Sopenharmony_ci} 6579a732c7Sopenharmony_ci 6679a732c7Sopenharmony_ciHWTEST_F(ReleationShipSyncMgrTest, SyncTrustRelationShip_003, testing::ext::TestSize.Level0) 6779a732c7Sopenharmony_ci{ 6879a732c7Sopenharmony_ci std::vector<std::string> peerUdids; 6979a732c7Sopenharmony_ci RelationShipChangeMsg msg; 7079a732c7Sopenharmony_ci msg.type = RelationShipChangeType::ACCOUNT_LOGOUT; 7179a732c7Sopenharmony_ci msg.userId = 1; 7279a732c7Sopenharmony_ci msg.peerUdids = peerUdids; 7379a732c7Sopenharmony_ci msg.accountId = "1111111"; 7479a732c7Sopenharmony_ci msg.accountName = "1"; 7579a732c7Sopenharmony_ci std::string broadCastMsg = ReleationShipSyncMgr::GetInstance().SyncTrustRelationShip(msg); 7679a732c7Sopenharmony_ci ASSERT_NE(broadCastMsg, ""); 7779a732c7Sopenharmony_ci} 7879a732c7Sopenharmony_ci 7979a732c7Sopenharmony_ciHWTEST_F(ReleationShipSyncMgrTest, SyncTrustRelationShip_004, testing::ext::TestSize.Level0) 8079a732c7Sopenharmony_ci{ 8179a732c7Sopenharmony_ci std::vector<std::string> peerUdids; 8279a732c7Sopenharmony_ci RelationShipChangeMsg msg; 8379a732c7Sopenharmony_ci msg.type = RelationShipChangeType::DEVICE_UNBIND; 8479a732c7Sopenharmony_ci msg.userId = UINT32_MAX; 8579a732c7Sopenharmony_ci msg.peerUdids = peerUdids; 8679a732c7Sopenharmony_ci msg.accountId = "1111111"; 8779a732c7Sopenharmony_ci msg.accountName = "1"; 8879a732c7Sopenharmony_ci std::string broadCastMsg = ReleationShipSyncMgr::GetInstance().SyncTrustRelationShip(msg); 8979a732c7Sopenharmony_ci ASSERT_EQ(broadCastMsg, ""); 9079a732c7Sopenharmony_ci} 9179a732c7Sopenharmony_ci 9279a732c7Sopenharmony_ciHWTEST_F(ReleationShipSyncMgrTest, SyncTrustRelationShip_005, testing::ext::TestSize.Level0) 9379a732c7Sopenharmony_ci{ 9479a732c7Sopenharmony_ci std::vector<std::string> peerUdids; 9579a732c7Sopenharmony_ci RelationShipChangeMsg msg; 9679a732c7Sopenharmony_ci msg.type = RelationShipChangeType::DEVICE_UNBIND; 9779a732c7Sopenharmony_ci msg.userId = 1; 9879a732c7Sopenharmony_ci msg.peerUdids = peerUdids; 9979a732c7Sopenharmony_ci msg.accountId = "1111111"; 10079a732c7Sopenharmony_ci msg.accountName = "1"; 10179a732c7Sopenharmony_ci std::string broadCastMsg = ReleationShipSyncMgr::GetInstance().SyncTrustRelationShip(msg); 10279a732c7Sopenharmony_ci ASSERT_NE(broadCastMsg, ""); 10379a732c7Sopenharmony_ci} 10479a732c7Sopenharmony_ci 10579a732c7Sopenharmony_ciHWTEST_F(ReleationShipSyncMgrTest, SyncTrustRelationShip_006, testing::ext::TestSize.Level0) 10679a732c7Sopenharmony_ci{ 10779a732c7Sopenharmony_ci std::vector<std::string> peerUdids; 10879a732c7Sopenharmony_ci RelationShipChangeMsg msg; 10979a732c7Sopenharmony_ci msg.type = RelationShipChangeType::APP_UNBIND; 11079a732c7Sopenharmony_ci msg.userId = UINT32_MAX; 11179a732c7Sopenharmony_ci msg.peerUdids = peerUdids; 11279a732c7Sopenharmony_ci msg.accountId = "1111111"; 11379a732c7Sopenharmony_ci msg.accountName = "1"; 11479a732c7Sopenharmony_ci std::string broadCastMsg = ReleationShipSyncMgr::GetInstance().SyncTrustRelationShip(msg); 11579a732c7Sopenharmony_ci ASSERT_EQ(broadCastMsg, ""); 11679a732c7Sopenharmony_ci} 11779a732c7Sopenharmony_ci 11879a732c7Sopenharmony_ciHWTEST_F(ReleationShipSyncMgrTest, SyncTrustRelationShip_007, testing::ext::TestSize.Level0) 11979a732c7Sopenharmony_ci{ 12079a732c7Sopenharmony_ci std::vector<std::string> peerUdids; 12179a732c7Sopenharmony_ci RelationShipChangeMsg msg; 12279a732c7Sopenharmony_ci msg.type = RelationShipChangeType::APP_UNBIND; 12379a732c7Sopenharmony_ci msg.userId = 1; 12479a732c7Sopenharmony_ci msg.peerUdids = peerUdids; 12579a732c7Sopenharmony_ci msg.accountId = "1111111"; 12679a732c7Sopenharmony_ci msg.accountName = "1"; 12779a732c7Sopenharmony_ci msg.tokenId = UINT64_MAX; 12879a732c7Sopenharmony_ci std::string broadCastMsg = ReleationShipSyncMgr::GetInstance().SyncTrustRelationShip(msg); 12979a732c7Sopenharmony_ci ASSERT_EQ(broadCastMsg, ""); 13079a732c7Sopenharmony_ci} 13179a732c7Sopenharmony_ci 13279a732c7Sopenharmony_ciHWTEST_F(ReleationShipSyncMgrTest, SyncTrustRelationShip_008, testing::ext::TestSize.Level0) 13379a732c7Sopenharmony_ci{ 13479a732c7Sopenharmony_ci std::vector<std::string> peerUdids; 13579a732c7Sopenharmony_ci RelationShipChangeMsg msg; 13679a732c7Sopenharmony_ci msg.type = RelationShipChangeType::APP_UNBIND; 13779a732c7Sopenharmony_ci msg.userId = 1; 13879a732c7Sopenharmony_ci msg.peerUdids = peerUdids; 13979a732c7Sopenharmony_ci msg.accountId = "1111111"; 14079a732c7Sopenharmony_ci msg.accountName = "1"; 14179a732c7Sopenharmony_ci msg.tokenId = 1; 14279a732c7Sopenharmony_ci std::string broadCastMsg = ReleationShipSyncMgr::GetInstance().SyncTrustRelationShip(msg); 14379a732c7Sopenharmony_ci ASSERT_NE(broadCastMsg, ""); 14479a732c7Sopenharmony_ci} 14579a732c7Sopenharmony_ci 14679a732c7Sopenharmony_ciHWTEST_F(ReleationShipSyncMgrTest, SyncTrustRelationShip_009, testing::ext::TestSize.Level0) 14779a732c7Sopenharmony_ci{ 14879a732c7Sopenharmony_ci std::vector<std::string> peerUdids; 14979a732c7Sopenharmony_ci RelationShipChangeMsg msg; 15079a732c7Sopenharmony_ci msg.type = RelationShipChangeType::SERVICE_UNBIND; 15179a732c7Sopenharmony_ci msg.userId = 1; 15279a732c7Sopenharmony_ci msg.peerUdids = peerUdids; 15379a732c7Sopenharmony_ci msg.accountId = "1111111"; 15479a732c7Sopenharmony_ci msg.accountName = "1"; 15579a732c7Sopenharmony_ci msg.tokenId = 1; 15679a732c7Sopenharmony_ci std::string broadCastMsg = ReleationShipSyncMgr::GetInstance().SyncTrustRelationShip(msg); 15779a732c7Sopenharmony_ci msg.type = RelationShipChangeType::DEL_USER; 15879a732c7Sopenharmony_ci broadCastMsg = ReleationShipSyncMgr::GetInstance().SyncTrustRelationShip(msg); 15979a732c7Sopenharmony_ci msg.type = RelationShipChangeType::APP_UNINSTALL; 16079a732c7Sopenharmony_ci broadCastMsg = ReleationShipSyncMgr::GetInstance().SyncTrustRelationShip(msg); 16179a732c7Sopenharmony_ci msg.type = RelationShipChangeType::TYPE_MAX; 16279a732c7Sopenharmony_ci broadCastMsg = ReleationShipSyncMgr::GetInstance().SyncTrustRelationShip(msg); 16379a732c7Sopenharmony_ci ASSERT_EQ(broadCastMsg, ""); 16479a732c7Sopenharmony_ci} 16579a732c7Sopenharmony_ci 16679a732c7Sopenharmony_ciHWTEST_F(ReleationShipSyncMgrTest, ParseTrustRelationShipChange_001, testing::ext::TestSize.Level0) 16779a732c7Sopenharmony_ci{ 16879a732c7Sopenharmony_ci std::string msg = ""; 16979a732c7Sopenharmony_ci RelationShipChangeMsg relationShipMsg = 17079a732c7Sopenharmony_ci ReleationShipSyncMgr::GetInstance().ParseTrustRelationShipChange(msg); 17179a732c7Sopenharmony_ci ASSERT_EQ(relationShipMsg.userId, UINT32_MAX); 17279a732c7Sopenharmony_ci} 17379a732c7Sopenharmony_ci 17479a732c7Sopenharmony_ciHWTEST_F(ReleationShipSyncMgrTest, ParseTrustRelationShipChange_002, testing::ext::TestSize.Level0) 17579a732c7Sopenharmony_ci{ 17679a732c7Sopenharmony_ci std::string msg = R"( 17779a732c7Sopenharmony_ci { 17879a732c7Sopenharmony_ci "xx": "xx" 17979a732c7Sopenharmony_ci } 18079a732c7Sopenharmony_ci )"; 18179a732c7Sopenharmony_ci RelationShipChangeMsg relationShipMsg = 18279a732c7Sopenharmony_ci ReleationShipSyncMgr::GetInstance().ParseTrustRelationShipChange(msg); 18379a732c7Sopenharmony_ci ASSERT_EQ(relationShipMsg.userId, UINT32_MAX); 18479a732c7Sopenharmony_ci} 18579a732c7Sopenharmony_ci 18679a732c7Sopenharmony_ciHWTEST_F(ReleationShipSyncMgrTest, ParseTrustRelationShipChange_003, testing::ext::TestSize.Level0) 18779a732c7Sopenharmony_ci{ 18879a732c7Sopenharmony_ci std::string msg = R"( 18979a732c7Sopenharmony_ci { 19079a732c7Sopenharmony_ci "TYPE": "xx" 19179a732c7Sopenharmony_ci } 19279a732c7Sopenharmony_ci )"; 19379a732c7Sopenharmony_ci RelationShipChangeMsg relationShipMsg = 19479a732c7Sopenharmony_ci ReleationShipSyncMgr::GetInstance().ParseTrustRelationShipChange(msg); 19579a732c7Sopenharmony_ci ASSERT_EQ(relationShipMsg.userId, UINT32_MAX); 19679a732c7Sopenharmony_ci} 19779a732c7Sopenharmony_ci 19879a732c7Sopenharmony_ciHWTEST_F(ReleationShipSyncMgrTest, ParseTrustRelationShipChange_004, testing::ext::TestSize.Level0) 19979a732c7Sopenharmony_ci{ 20079a732c7Sopenharmony_ci std::string msg = R"( 20179a732c7Sopenharmony_ci { 20279a732c7Sopenharmony_ci "TYPE": 0 20379a732c7Sopenharmony_ci } 20479a732c7Sopenharmony_ci )"; 20579a732c7Sopenharmony_ci RelationShipChangeMsg relationShipMsg = 20679a732c7Sopenharmony_ci ReleationShipSyncMgr::GetInstance().ParseTrustRelationShipChange(msg); 20779a732c7Sopenharmony_ci msg = R"( 20879a732c7Sopenharmony_ci { 20979a732c7Sopenharmony_ci "TYPE": 1 21079a732c7Sopenharmony_ci } 21179a732c7Sopenharmony_ci )"; 21279a732c7Sopenharmony_ci relationShipMsg = 21379a732c7Sopenharmony_ci ReleationShipSyncMgr::GetInstance().ParseTrustRelationShipChange(msg); 21479a732c7Sopenharmony_ci msg = R"( 21579a732c7Sopenharmony_ci { 21679a732c7Sopenharmony_ci "TYPE": 2 21779a732c7Sopenharmony_ci } 21879a732c7Sopenharmony_ci )"; 21979a732c7Sopenharmony_ci relationShipMsg = 22079a732c7Sopenharmony_ci ReleationShipSyncMgr::GetInstance().ParseTrustRelationShipChange(msg); 22179a732c7Sopenharmony_ci msg = R"( 22279a732c7Sopenharmony_ci { 22379a732c7Sopenharmony_ci "TYPE": 3 22479a732c7Sopenharmony_ci } 22579a732c7Sopenharmony_ci )"; 22679a732c7Sopenharmony_ci relationShipMsg = 22779a732c7Sopenharmony_ci ReleationShipSyncMgr::GetInstance().ParseTrustRelationShipChange(msg); 22879a732c7Sopenharmony_ci ASSERT_EQ(relationShipMsg.userId, UINT32_MAX); 22979a732c7Sopenharmony_ci} 23079a732c7Sopenharmony_ci 23179a732c7Sopenharmony_ciHWTEST_F(ReleationShipSyncMgrTest, ParseTrustRelationShipChange_005, testing::ext::TestSize.Level0) 23279a732c7Sopenharmony_ci{ 23379a732c7Sopenharmony_ci std::string msg = R"( 23479a732c7Sopenharmony_ci { 23579a732c7Sopenharmony_ci "TYPE": 0, 23679a732c7Sopenharmony_ci "VALUE": "" 23779a732c7Sopenharmony_ci } 23879a732c7Sopenharmony_ci )"; 23979a732c7Sopenharmony_ci RelationShipChangeMsg relationShipMsg = 24079a732c7Sopenharmony_ci ReleationShipSyncMgr::GetInstance().ParseTrustRelationShipChange(msg); 24179a732c7Sopenharmony_ci ASSERT_EQ(relationShipMsg.userId, UINT32_MAX); 24279a732c7Sopenharmony_ci} 24379a732c7Sopenharmony_ci} 24479a732c7Sopenharmony_ci} // namespace DistributedHardware 24579a732c7Sopenharmony_ci} // namespace OHOS 246