From d113e4d639058945d66326fa1dbb1730f94bfbae Mon Sep 17 00:00:00 2001 From: qinlong0101 Date: Thu, 20 Oct 2022 14:31:53 +0800 Subject: [PATCH] =?UTF-8?q?UT=E8=A6=86=E7=9B=96=E7=8E=87=E8=A1=A5=E9=BD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: qinlong0101 --- .../softbusadapter/test/unittest/BUILD.gn | 7 +- .../unittest/src/softbus_adapter_test.cpp | 65 ++++++++++++++++++- 2 files changed, 70 insertions(+), 2 deletions(-) diff --git a/services/softbusadapter/test/unittest/BUILD.gn b/services/softbusadapter/test/unittest/BUILD.gn index 9aa6673b..04045d27 100644 --- a/services/softbusadapter/test/unittest/BUILD.gn +++ b/services/softbusadapter/test/unittest/BUILD.gn @@ -57,7 +57,12 @@ ohos_unittest("SoftBusAdapterTest") { "//third_party/googletest:gtest_main", ] - external_deps = [ "c_utils:utils" ] + external_deps = [ + "access_token:libaccesstoken_sdk", + "access_token:libnativetoken", + "access_token:libtoken_setproc", + "c_utils:utils", + ] } group("soft_bus_adapter_test") { diff --git a/services/softbusadapter/test/unittest/src/softbus_adapter_test.cpp b/services/softbusadapter/test/unittest/src/softbus_adapter_test.cpp index a50bf7a9..4d7922a5 100644 --- a/services/softbusadapter/test/unittest/src/softbus_adapter_test.cpp +++ b/services/softbusadapter/test/unittest/src/softbus_adapter_test.cpp @@ -15,6 +15,10 @@ #include "softbus_adapter_test.h" +#include "accesstoken_kit.h" +#include "nativetoken_kit.h" +#include "token_setproc.h" + using namespace testing::ext; namespace OHOS { @@ -23,10 +27,69 @@ void SoftbusAdapterTest::SetUpTestCase(void) {} void SoftbusAdapterTest::TearDownTestCase(void) {} -void SoftbusAdapterTest::SetUp(void) {} +void SoftbusAdapterTest::SetUp(void) +{ + uint64_t tokenId; + const char *perms[2]; + perms[0] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER; + perms[1] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC; + NativeTokenInfoParams infoInstance = { + .dcapsNum = 0, + .permsNum = 2, + .aclsNum = 0, + .dcaps = NULL, + .perms = perms, + .acls = NULL, + .processName = "softbus_adapter_test", + .aplStr = "system_basic", + }; + tokenId = GetAccessTokenId(&infoInstance); + SetSelfTokenID(tokenId); + OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo(); +} void SoftbusAdapterTest::TearDown(void) {} +static int32_t ScreenOnSoftbusSessionOpened(int32_t sessionId, int32_t result) +{ + return 0; +} + +static void ScreenOnSoftbusSessionClosed(int32_t sessionId) {} + +static void ScreenOnBytesReceived(int32_t sessionId, const void *data, uint32_t dataLen) {} + +static void ScreenOnStreamReceived(int32_t sessionId, const StreamData *data, const StreamData *ext, + const StreamFrameInfo *frameInfo) {} + +static void ScreenOnMessageReceived(int sessionId, const void *data, unsigned int dataLen) {} + +static void ScreenOnQosEvent(int sessionId, int eventId, int tvCount, const QosTv *tvList) {} + +/** + * @tc.name: CreateSoftbusSessionServer_001 + * @tc.desc: Verify the CreateSoftbusSessionServer function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(SoftbusAdapterTest, CreateSoftbusSessionServer_001, TestSize.Level1) +{ + softbusAdapter.sessListener_.OnSessionOpened = ScreenOnSoftbusSessionOpened; + softbusAdapter.sessListener_.OnSessionClosed = ScreenOnSoftbusSessionClosed; + softbusAdapter.sessListener_.OnBytesReceived = ScreenOnBytesReceived; + softbusAdapter.sessListener_.OnStreamReceived = ScreenOnStreamReceived; + softbusAdapter.sessListener_.OnMessageReceived = ScreenOnMessageReceived; + softbusAdapter.sessListener_.OnQosEvent = ScreenOnQosEvent; + + std::string pkgname = PKG_NAME; + std::string sessionName = DATA_SESSION_NAME; + std::string peerDevId = "peerDevId"; + + int32_t actual = softbusAdapter.CreateSoftbusSessionServer(pkgname, sessionName, peerDevId); + EXPECT_EQ(DH_SUCCESS, actual); + softbusAdapter.RemoveSoftbusSessionServer(pkgname, sessionName, peerDevId); +} + /** * @tc.name: RegisterSoftbusListener_001 * @tc.desc: Verify the RegisterSoftbusListener function. -- Gitee