119e95205Sopenharmony_ci/* 219e95205Sopenharmony_ci * Copyright (C) 2022 Huawei Device Co., Ltd. 319e95205Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 419e95205Sopenharmony_ci * you may not use this file except in compliance with the License. 519e95205Sopenharmony_ci * You may obtain a copy of the License at 619e95205Sopenharmony_ci * 719e95205Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 819e95205Sopenharmony_ci * 919e95205Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1019e95205Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1119e95205Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1219e95205Sopenharmony_ci * See the License for the specific language governing permissions and 1319e95205Sopenharmony_ci * limitations under the License. 1419e95205Sopenharmony_ci */ 1519e95205Sopenharmony_ci 1619e95205Sopenharmony_ci#include <gtest/gtest.h> 1719e95205Sopenharmony_ci#include "bluetooth_opp.h" 1819e95205Sopenharmony_ci#include "bluetooth_remote_device.h" 1919e95205Sopenharmony_ci#include "bluetooth_host.h" 2019e95205Sopenharmony_ci 2119e95205Sopenharmony_ciusing namespace testing; 2219e95205Sopenharmony_ciusing namespace testing::ext; 2319e95205Sopenharmony_ci 2419e95205Sopenharmony_cinamespace OHOS { 2519e95205Sopenharmony_cinamespace Bluetooth { 2619e95205Sopenharmony_ciusing namespace std; 2719e95205Sopenharmony_ci 2819e95205Sopenharmony_ciclass OppObserverTest : public OppObserver { 2919e95205Sopenharmony_cipublic: 3019e95205Sopenharmony_ci OppObserverTest() = default; 3119e95205Sopenharmony_ci virtual ~OppObserverTest() = default; 3219e95205Sopenharmony_ci virtual void OnReceiveIncomingFileChanged(const BluetoothOppTransferInformation &transferInformation) {} 3319e95205Sopenharmony_ci virtual void OnTransferStateChanged(const BluetoothOppTransferInformation &transferInformation) {} 3419e95205Sopenharmony_ci 3519e95205Sopenharmony_ciprivate: 3619e95205Sopenharmony_ci}; 3719e95205Sopenharmony_ci 3819e95205Sopenharmony_ci 3919e95205Sopenharmony_cistatic Bluetooth::Opp *profile_; 4019e95205Sopenharmony_cistatic std::shared_ptr<OppObserverTest> g_oppObserverTest = std::make_shared<OppObserverTest>(); 4119e95205Sopenharmony_ci 4219e95205Sopenharmony_ciclass OppTest : public testing::Test { 4319e95205Sopenharmony_cipublic: 4419e95205Sopenharmony_ci OppTest(); 4519e95205Sopenharmony_ci ~OppTest(); 4619e95205Sopenharmony_ci 4719e95205Sopenharmony_ci static void SetUpTestCase(void); 4819e95205Sopenharmony_ci static void TearDownTestCase(void); 4919e95205Sopenharmony_ci void SetUp(); 5019e95205Sopenharmony_ci void TearDown(); 5119e95205Sopenharmony_ci bool CompareDevice(std::vector<BluetoothRemoteDevice> bluetoothRemoteDeviceByState, 5219e95205Sopenharmony_ci std::vector<std::string> bluetoothRemoteDeviceAddr); 5319e95205Sopenharmony_ci bool CompareTransferInformation(const BluetoothOppTransferInformation &information, 5419e95205Sopenharmony_ci const BluetoothOppTransferInformation &transferInformation); 5519e95205Sopenharmony_ci 5619e95205Sopenharmony_ciprivate: 5719e95205Sopenharmony_ci}; 5819e95205Sopenharmony_ci 5919e95205Sopenharmony_ciOppTest::OppTest() 6019e95205Sopenharmony_ci{ 6119e95205Sopenharmony_ci} 6219e95205Sopenharmony_ci 6319e95205Sopenharmony_ciOppTest::~OppTest() 6419e95205Sopenharmony_ci{ 6519e95205Sopenharmony_ci} 6619e95205Sopenharmony_ci 6719e95205Sopenharmony_civoid OppTest::SetUpTestCase(void) 6819e95205Sopenharmony_ci{ 6919e95205Sopenharmony_ci} 7019e95205Sopenharmony_civoid OppTest::TearDownTestCase(void) 7119e95205Sopenharmony_ci{ 7219e95205Sopenharmony_ci} 7319e95205Sopenharmony_civoid OppTest::SetUp() 7419e95205Sopenharmony_ci{ 7519e95205Sopenharmony_ci} 7619e95205Sopenharmony_civoid OppTest::TearDown() 7719e95205Sopenharmony_ci{ 7819e95205Sopenharmony_ci} 7919e95205Sopenharmony_ci 8019e95205Sopenharmony_cibool OppTest::CompareDevice(std::vector<BluetoothRemoteDevice> bluetoothRemoteDeviceByState, 8119e95205Sopenharmony_ci std::vector<std::string> bluetoothRemoteDeviceAddr) 8219e95205Sopenharmony_ci{ 8319e95205Sopenharmony_ci if (bluetoothRemoteDeviceByState.size() != bluetoothRemoteDeviceAddr.size()) { 8419e95205Sopenharmony_ci return false; 8519e95205Sopenharmony_ci } 8619e95205Sopenharmony_ci for (int i = 0; i < bluetoothRemoteDeviceByState.size(); i++) { 8719e95205Sopenharmony_ci if (bluetoothRemoteDeviceByState[i].GetDeviceAddr().compare(bluetoothRemoteDeviceAddr[i]) != 0) { 8819e95205Sopenharmony_ci return false; 8919e95205Sopenharmony_ci } 9019e95205Sopenharmony_ci } 9119e95205Sopenharmony_ci return true; 9219e95205Sopenharmony_ci} 9319e95205Sopenharmony_ci 9419e95205Sopenharmony_cibool OppTest::CompareTransferInformation(const BluetoothOppTransferInformation &information, 9519e95205Sopenharmony_ci const BluetoothOppTransferInformation &transferInformation) 9619e95205Sopenharmony_ci{ 9719e95205Sopenharmony_ci if (&information == &transferInformation) { 9819e95205Sopenharmony_ci return true; 9919e95205Sopenharmony_ci } 10019e95205Sopenharmony_ci if ((information.GetFileName() != transferInformation.GetFileName()) || 10119e95205Sopenharmony_ci (information.GetFilePath() != transferInformation.GetFilePath()) || 10219e95205Sopenharmony_ci (information.GetMimeType() != transferInformation.GetMimeType()) || 10319e95205Sopenharmony_ci (information.GetDeviceName() != transferInformation.GetDeviceName()) || 10419e95205Sopenharmony_ci (information.GetDeviceAddress() != transferInformation.GetDeviceAddress()) || 10519e95205Sopenharmony_ci (information.GetTimeStamp() != transferInformation.GetTimeStamp()) || 10619e95205Sopenharmony_ci (information.GetCurrentBytes() != transferInformation.GetCurrentBytes()) || 10719e95205Sopenharmony_ci (information.GetTotalBytes() != transferInformation.GetTotalBytes()) || 10819e95205Sopenharmony_ci (information.GetFailedReason() != transferInformation.GetFailedReason()) || 10919e95205Sopenharmony_ci (information.GetDirection() != transferInformation.GetDirection()) || 11019e95205Sopenharmony_ci (information.GetStatus() != transferInformation.GetStatus()) || 11119e95205Sopenharmony_ci (information.GetId() != transferInformation.GetId())) { 11219e95205Sopenharmony_ci return false; 11319e95205Sopenharmony_ci } 11419e95205Sopenharmony_ci return true; 11519e95205Sopenharmony_ci} 11619e95205Sopenharmony_ci 11719e95205Sopenharmony_ci/* 11819e95205Sopenharmony_ci * @tc.number: OPP_ModuleTest_GetDevicesByStates_00100 11919e95205Sopenharmony_ci * @tc.name: GetDevicesByStates 12019e95205Sopenharmony_ci * @tc.desc: 12119e95205Sopenharmony_ci */ 12219e95205Sopenharmony_ciHWTEST_F(OppTest, OPP_ModuleTest_GetDevicesByStates_00100, TestSize.Level1) 12319e95205Sopenharmony_ci{ 12419e95205Sopenharmony_ci GTEST_LOG_(INFO) << "OPP_ModuleTest_GetDevicesByStates_00100 start"; 12519e95205Sopenharmony_ci 12619e95205Sopenharmony_ci GTEST_LOG_(INFO) << "GetDevicesByStates function test"; 12719e95205Sopenharmony_ci 12819e95205Sopenharmony_ci profile_ = Opp::GetProfile(); 12919e95205Sopenharmony_ci std::vector<int> states; 13019e95205Sopenharmony_ci std::vector<std::string> bluetoothRemoteDeviceAddr; 13119e95205Sopenharmony_ci std::vector<BluetoothRemoteDevice> bluetoothRemoteDeviceByState = profile_->GetDevicesByStates(states); 13219e95205Sopenharmony_ci EXPECT_TRUE(CompareDevice(bluetoothRemoteDeviceByState, bluetoothRemoteDeviceAddr)); 13319e95205Sopenharmony_ci 13419e95205Sopenharmony_ci GTEST_LOG_(INFO) << "OPP_ModuleTest_GetDevicesByStates_00100 end"; 13519e95205Sopenharmony_ci} 13619e95205Sopenharmony_ci 13719e95205Sopenharmony_ci 13819e95205Sopenharmony_ci/* 13919e95205Sopenharmony_ci * @tc.number: OPP_ModuleTest_GetDeviceState_00100 14019e95205Sopenharmony_ci * @tc.name: GetDeviceState 14119e95205Sopenharmony_ci * @tc.desc: 14219e95205Sopenharmony_ci */ 14319e95205Sopenharmony_ciHWTEST_F(OppTest, OPP_ModuleTest_GetDeviceState_00100, TestSize.Level1) 14419e95205Sopenharmony_ci{ 14519e95205Sopenharmony_ci GTEST_LOG_(INFO) << "OPP_ModuleTest_GetDeviceState_00100 start"; 14619e95205Sopenharmony_ci 14719e95205Sopenharmony_ci GTEST_LOG_(INFO) << "GetDeviceState function test"; 14819e95205Sopenharmony_ci 14919e95205Sopenharmony_ci int sucess = static_cast<int>(BTConnectState::DISCONNECTED); 15019e95205Sopenharmony_ci BluetoothRemoteDevice device; 15119e95205Sopenharmony_ci profile_ = Opp::GetProfile(); 15219e95205Sopenharmony_ci EXPECT_EQ(sucess, profile_->GetDeviceState(device)); 15319e95205Sopenharmony_ci 15419e95205Sopenharmony_ci GTEST_LOG_(INFO) << "OPP_ModuleTest_GetDeviceState_00100 end"; 15519e95205Sopenharmony_ci} 15619e95205Sopenharmony_ci 15719e95205Sopenharmony_ci/* 15819e95205Sopenharmony_ci * @tc.number: OPP_ModuleTest_SendFile_00100 15919e95205Sopenharmony_ci * @tc.name: SendFile 16019e95205Sopenharmony_ci * @tc.desc: 16119e95205Sopenharmony_ci */ 16219e95205Sopenharmony_ciHWTEST_F(OppTest, OPP_ModuleTest_SendFile_00100, TestSize.Level1) 16319e95205Sopenharmony_ci{ 16419e95205Sopenharmony_ci GTEST_LOG_(INFO) << "OPP_ModuleTest_SendFile_00100 start"; 16519e95205Sopenharmony_ci 16619e95205Sopenharmony_ci GTEST_LOG_(INFO) << "SendFile function test"; 16719e95205Sopenharmony_ci 16819e95205Sopenharmony_ci std::string device; 16919e95205Sopenharmony_ci std::vector<std::string>filePaths; 17019e95205Sopenharmony_ci std::vector<std::string>mimeTypes; 17119e95205Sopenharmony_ci profile_ = Opp::GetProfile(); 17219e95205Sopenharmony_ci EXPECT_FALSE(profile_->SendFile(device, filePaths, mimeTypes)); 17319e95205Sopenharmony_ci 17419e95205Sopenharmony_ci GTEST_LOG_(INFO) << "OPP_ModuleTest_SendFile_00100 end"; 17519e95205Sopenharmony_ci} 17619e95205Sopenharmony_ci 17719e95205Sopenharmony_ci/* 17819e95205Sopenharmony_ci * @tc.number: OPP_ModuleTest_SetIncomingFileConfirmation_00100 17919e95205Sopenharmony_ci * @tc.name: SetIncomingFileConfirmation 18019e95205Sopenharmony_ci * @tc.desc: 18119e95205Sopenharmony_ci */ 18219e95205Sopenharmony_ciHWTEST_F(OppTest, OPP_ModuleTest_SetIncomingFileConfirmation_00100, TestSize.Level1) 18319e95205Sopenharmony_ci{ 18419e95205Sopenharmony_ci GTEST_LOG_(INFO) << "OPP_ModuleTest_SetIncomingFileConfirmation_00100 start"; 18519e95205Sopenharmony_ci 18619e95205Sopenharmony_ci GTEST_LOG_(INFO) << "SetIncomingFileConfirmation function test"; 18719e95205Sopenharmony_ci 18819e95205Sopenharmony_ci bool accept = true; 18919e95205Sopenharmony_ci profile_ = Opp::GetProfile(); 19019e95205Sopenharmony_ci EXPECT_FALSE(profile_->SetIncomingFileConfirmation(accept)); 19119e95205Sopenharmony_ci 19219e95205Sopenharmony_ci GTEST_LOG_(INFO) << "OPP_ModuleTest_SetIncomingFileConfirmation_00100 end"; 19319e95205Sopenharmony_ci} 19419e95205Sopenharmony_ci 19519e95205Sopenharmony_ci/* 19619e95205Sopenharmony_ci * @tc.number: OPP_ModuleTest_GetCurrentTransferInformation_00100 19719e95205Sopenharmony_ci * @tc.name: GetCurrentTransferInformation 19819e95205Sopenharmony_ci * @tc.desc: 19919e95205Sopenharmony_ci */ 20019e95205Sopenharmony_ciHWTEST_F(OppTest, OPP_ModuleTest_GetCurrentTransferInformation_00100, TestSize.Level1) 20119e95205Sopenharmony_ci{ 20219e95205Sopenharmony_ci GTEST_LOG_(INFO) << "OPP_ModuleTest_GetCurrentTransferInformation_00100 start"; 20319e95205Sopenharmony_ci 20419e95205Sopenharmony_ci GTEST_LOG_(INFO) << "GetCurrentTransferInformation function test"; 20519e95205Sopenharmony_ci 20619e95205Sopenharmony_ci profile_ = Opp::GetProfile(); 20719e95205Sopenharmony_ci BluetoothOppTransferInformation Infermation; 20819e95205Sopenharmony_ci BluetoothOppTransferInformation transferInfermation = profile_->GetCurrentTransferInformation(); 20919e95205Sopenharmony_ci EXPECT_TRUE(CompareTransferInformation(Infermation, transferInfermation)); 21019e95205Sopenharmony_ci 21119e95205Sopenharmony_ci GTEST_LOG_(INFO) << "OPP_ModuleTest_GetCurrentTransferInformation_00100 end"; 21219e95205Sopenharmony_ci} 21319e95205Sopenharmony_ci 21419e95205Sopenharmony_ci/* 21519e95205Sopenharmony_ci * @tc.number: OPP_ModuleTest_CancelTransfer_00100 21619e95205Sopenharmony_ci * @tc.name: CancelTransfer 21719e95205Sopenharmony_ci * @tc.desc: 21819e95205Sopenharmony_ci */ 21919e95205Sopenharmony_ciHWTEST_F(OppTest, OPP_ModuleTest_CancelTransfer_00100, TestSize.Level1) 22019e95205Sopenharmony_ci{ 22119e95205Sopenharmony_ci GTEST_LOG_(INFO) << "OPP_ModuleTest_CancelTransfer_00100 start"; 22219e95205Sopenharmony_ci 22319e95205Sopenharmony_ci GTEST_LOG_(INFO) << "CancelTransfer function test"; 22419e95205Sopenharmony_ci 22519e95205Sopenharmony_ci profile_ = Opp::GetProfile(); 22619e95205Sopenharmony_ci EXPECT_FALSE(profile_->CancelTransfer()); 22719e95205Sopenharmony_ci 22819e95205Sopenharmony_ci GTEST_LOG_(INFO) << "OPP_ModuleTest_CancelTransfer_00100 end"; 22919e95205Sopenharmony_ci} 23019e95205Sopenharmony_ci 23119e95205Sopenharmony_ci/* 23219e95205Sopenharmony_ci * @tc.number: OPP_ModuleTest_RegisterObserver_00100 23319e95205Sopenharmony_ci * @tc.name: RegisterObserver 23419e95205Sopenharmony_ci * @tc.desc: 23519e95205Sopenharmony_ci */ 23619e95205Sopenharmony_ciHWTEST_F(OppTest, OPP_ModuleTest_RegisterObserver_00100, TestSize.Level1) 23719e95205Sopenharmony_ci{ 23819e95205Sopenharmony_ci GTEST_LOG_(INFO) << "OPP_ModuleTest_RegisterObserver_00100 start"; 23919e95205Sopenharmony_ci 24019e95205Sopenharmony_ci GTEST_LOG_(INFO) << "RegisterObserver function test"; 24119e95205Sopenharmony_ci 24219e95205Sopenharmony_ci profile_ = Opp::GetProfile(); 24319e95205Sopenharmony_ci profile_->RegisterObserver(g_oppObserverTest); 24419e95205Sopenharmony_ci 24519e95205Sopenharmony_ci GTEST_LOG_(INFO) << "OPP_ModuleTest_RegisterObserver_00100 end"; 24619e95205Sopenharmony_ci} 24719e95205Sopenharmony_ci 24819e95205Sopenharmony_ci/* 24919e95205Sopenharmony_ci * @tc.number: OPP_ModuleTest_DeregisterObserver_00100 25019e95205Sopenharmony_ci * @tc.name: DeregisterObserver 25119e95205Sopenharmony_ci * @tc.desc: 25219e95205Sopenharmony_ci */ 25319e95205Sopenharmony_ciHWTEST_F(OppTest, OPP_ModuleTest_DeregisterObserver_00100, TestSize.Level1) 25419e95205Sopenharmony_ci{ 25519e95205Sopenharmony_ci GTEST_LOG_(INFO) << "OPP_ModuleTest_DeregisterObserver_00100 start"; 25619e95205Sopenharmony_ci 25719e95205Sopenharmony_ci GTEST_LOG_(INFO) << "DeregisterObserver function test"; 25819e95205Sopenharmony_ci 25919e95205Sopenharmony_ci profile_ = Opp::GetProfile(); 26019e95205Sopenharmony_ci profile_->DeregisterObserver(g_oppObserverTest); 26119e95205Sopenharmony_ci 26219e95205Sopenharmony_ci GTEST_LOG_(INFO) << "OPP_ModuleTest_DeregisterObserver_00100 end"; 26319e95205Sopenharmony_ci} 26419e95205Sopenharmony_ci 26519e95205Sopenharmony_ci/* 26619e95205Sopenharmony_ci * @tc.number: OPP_ModuleTest_OnReceiveIncomingFileChanged_00100 26719e95205Sopenharmony_ci * @tc.name: OnReceiveIncomingFileChanged 26819e95205Sopenharmony_ci * @tc.desc: 26919e95205Sopenharmony_ci */ 27019e95205Sopenharmony_ciHWTEST_F(OppTest, OPP_ModuleTest_OnReceiveIncomingFileChanged_00100, TestSize.Level1) 27119e95205Sopenharmony_ci{ 27219e95205Sopenharmony_ci GTEST_LOG_(INFO) << "OPP_ModuleTest_OnReceiveIncomingFileChanged_00100 start"; 27319e95205Sopenharmony_ci 27419e95205Sopenharmony_ci GTEST_LOG_(INFO) << "OnReceiveIncomingFileChanged function test"; 27519e95205Sopenharmony_ci 27619e95205Sopenharmony_ci BluetoothOppTransferInformation trasnferInformation; 27719e95205Sopenharmony_ci g_oppObserverTest->OnReceiveIncomingFileChanged(trasnferInformation); 27819e95205Sopenharmony_ci 27919e95205Sopenharmony_ci GTEST_LOG_(INFO) << "OPP_ModuleTest_OnReceiveIncomingFileChanged_00100 end"; 28019e95205Sopenharmony_ci} 28119e95205Sopenharmony_ci 28219e95205Sopenharmony_ci/* 28319e95205Sopenharmony_ci * @tc.number: OPP_ModuleTest_OnTransferStateChanged_00100 28419e95205Sopenharmony_ci * @tc.name: OnTransferStateChanged 28519e95205Sopenharmony_ci * @tc.desc: 28619e95205Sopenharmony_ci */ 28719e95205Sopenharmony_ciHWTEST_F(OppTest, OPP_ModuleTest_OnTransferStateChanged_00100, TestSize.Level1) 28819e95205Sopenharmony_ci{ 28919e95205Sopenharmony_ci GTEST_LOG_(INFO) << "OPP_ModuleTest_OnTransferStateChanged_00100 start"; 29019e95205Sopenharmony_ci 29119e95205Sopenharmony_ci GTEST_LOG_(INFO) << "OnTransferStateChanged function test"; 29219e95205Sopenharmony_ci 29319e95205Sopenharmony_ci BluetoothOppTransferInformation trasnferInformation; 29419e95205Sopenharmony_ci g_oppObserverTest->OnTransferStateChanged(trasnferInformation); 29519e95205Sopenharmony_ci 29619e95205Sopenharmony_ci GTEST_LOG_(INFO) << "OPP_ModuleTest_OnTransferStateChanged_00100 end"; 29719e95205Sopenharmony_ci} 29819e95205Sopenharmony_ci} // namespace Bluetooth 29919e95205Sopenharmony_ci} // namespace OHOS 300