提交 76a50785 编写于 作者: W wanderer-dl122

update ut

Signed-off-by: Nwanderer-dl122 <dengliang21@huawei.com>
上级 73d31b0f
......@@ -38,6 +38,7 @@ ohos_unittest("IPCNativeUnitTest") {
"ipc_object_proxy_unittest.cpp",
"ipc_process_skeleton_unittest.cpp",
"ipc_thread_skeleton_unittest.cpp",
"ipc_thread_pool_unittest.cpp",
"iremote_object_unitest.cpp",
"message_parcel_unittest.cpp",
]
......@@ -69,6 +70,8 @@ ohos_unittest("IPCFileDescOpsTest") {
include_dirs = [
"//utils/system/safwk/native/include",
"//foundation/communication/ipc/ipc/native/c/rpc/include",
"//foundation/communication/ipc/ipc/native/c/ipc_adapter/include",
"//foundation/communication/ipc/interfaces/innerkits/ipc_core/include",
"//foundation/communication/ipc/interfaces/innerkits/libdbinder/include",
"//foundation/communication/ipc/native/src/core/include",
......
......@@ -16,9 +16,13 @@
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#define private public
#include "databus_session_callback.h"
#include "ipc_thread_skeleton.h"
#include "ipc_types.h"
#include "iremote_object.h"
#include "mock_session_impl.h"
#undef private
using namespace testing::ext;
using namespace OHOS;
......@@ -131,3 +135,48 @@ HWTEST_F(DbSessionCallbackUnitTest, OnSessionOpenedTest003, TestSize.Level1)
EXPECT_EQ(ret, SESSION_UNOPEN_ERR);
}
/**
* @tc.name: OnSessionOpenedTest004
* @tc.desc: Verify the OnSessionOpened function
* @tc.type: FUNC
*/
HWTEST_F(DbSessionCallbackUnitTest, OnSessionOpenedTest004, TestSize.Level1)
{
std::shared_ptr<MockSessionImpl> session = std::make_shared<MockSessionImpl>();
EXPECT_CALL(*session, GetChannelId())
.WillRepeatedly(testing::Return(1));
EXPECT_CALL(*session, IsServerSide())
.WillRepeatedly(testing::Return(true));
EXPECT_CALL(*session, GetPeerPid())
.WillRepeatedly(testing::Return(PID_TEST));
EXPECT_CALL(*session, GetPeerUid())
.WillRepeatedly(testing::Return(UID_TEST));
EXPECT_CALL(*session, GetPeerDeviceId())
.WillRepeatedly(testing::ReturnRef(DEVICE_ID_TEST));
EXPECT_CALL(*session, GetMySessionName())
.WillRepeatedly(testing::ReturnRef(SESSION_NAME_TEST));
EXPECT_CALL(*session, GetPeerSessionName())
.WillRepeatedly(testing::ReturnRef(PEER_SESSION_NAME_TEST));
IRemoteInvoker *invoker = nullptr;
IPCThreadSkeleton *current = IPCThreadSkeleton::GetCurrent();
current->invokers_[IRemoteObject::IF_PROT_DATABUS] = invoker;
DatabusSessionCallback dbSessionCallback;
int ret = dbSessionCallback.OnSessionOpened(session);
EXPECT_EQ(ret, SESSION_INVOKER_NULL_ERR);
char data[] = "testdata";
ssize_t len = strlen(data);
dbSessionCallback.OnBytesReceived(session, data, len);
dbSessionCallback.OnSessionClosed(session);
}
\ No newline at end of file
......@@ -18,9 +18,14 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <gtest/gtest.h>
#define private public
#include "binder_invoker.h"
#include "ipc_debug.h"
#include "ipc_file_descriptor.h"
#include "log_tags.h"
#include "ipc_thread_skeleton.h"
#undef private
namespace OHOS {
using namespace testing::ext;
......@@ -90,4 +95,50 @@ HWTEST_F(IPCFileDescOpsTest, fd_parcelable_003, TestSize.Level1)
fdesc.SetFd(fd);
EXPECT_EQ(fd, fdesc.GetFd());
}
HWTEST_F(IPCFileDescOpsTest, Marshalling001, TestSize.Level1)
{
int fd = 9876;
IPCFileDescriptor fdesc;
fdesc.SetFd(fd);
BinderInvoker *invoker = nullptr;
IPCThreadSkeleton *current = IPCThreadSkeleton::GetCurrent();
current->invokers_[IRemoteObject::IF_PROT_DEFAULT] = invoker;
Parcel parcel;
auto ret = fdesc.Marshalling(parcel);
ASSERT_FALSE(ret);
}
HWTEST_F(IPCFileDescOpsTest, Unmarshalling001, TestSize.Level1)
{
int fd = 9876;
IPCFileDescriptor fdesc;
fdesc.SetFd(fd);
BinderInvoker *invoker = nullptr;
IPCThreadSkeleton *current = IPCThreadSkeleton::GetCurrent();
current->invokers_[IRemoteObject::IF_PROT_DEFAULT] = invoker;
Parcel parcel;
auto ret = fdesc.Unmarshalling(parcel);
ASSERT_TRUE(ret == nullptr);
}
HWTEST_F(IPCFileDescOpsTest, Unmarshalling002, TestSize.Level1)
{
int fd = 9876;
IPCFileDescriptor fdesc;
Parcel parcel;
fdesc.SetFd(fd);
BinderInvoker *invoker = new BinderInvoker();
invoker->WriteFileDescriptor(parcel, fd, true);
IPCThreadSkeleton *current = IPCThreadSkeleton::GetCurrent();
current->invokers_[IRemoteObject::IF_PROT_DEFAULT] = invoker;
auto ret = fdesc.Unmarshalling(parcel);
ASSERT_TRUE(ret != nullptr);
}
} // namespace OHOS
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#define private public
#include "ipc_types.h"
#include "ipc_thread_pool.h"
#include "ipc_workthread.h"
#undef private
using namespace testing::ext;
using namespace OHOS;
class IPCWorkThreadPoolUnitTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void IPCWorkThreadPoolUnitTest::SetUpTestCase()
{
}
void IPCWorkThreadPoolUnitTest::TearDownTestCase()
{
}
void IPCWorkThreadPoolUnitTest::SetUp() {}
void IPCWorkThreadPoolUnitTest::TearDown() {}
/**
* @tc.name: RemoveThreadTest001
* @tc.desc: Verify the RemoveThread function
* @tc.type: FUNC
*/
HWTEST_F(IPCWorkThreadPoolUnitTest, RemoveThreadTest001, TestSize.Level1)
{
IPCWorkThreadPool threadPool(1);
std::string threadName = "threadName1";
auto ipcThread = new (std::nothrow) IPCWorkThread(threadName);
threadPool.threads_[threadName] = ipcThread;
ipcThread->proto_ = IRemoteObject::IF_PROT_DEFAULT;
auto ret = threadPool.RemoveThread(threadName);
EXPECT_EQ(ret, true);
}
/**
* @tc.name: RemoveThreadTest002
* @tc.desc: Verify the RemoveThread function
* @tc.type: FUNC
*/
HWTEST_F(IPCWorkThreadPoolUnitTest, RemoveThreadTest002, TestSize.Level1)
{
IPCWorkThreadPool threadPool(1);
std::string threadName = "threadName1";
auto ipcThread = new (std::nothrow) IPCWorkThread(threadName);
threadPool.threads_[threadName] = ipcThread;
ipcThread->proto_ = IRemoteObject::IF_PROT_DATABUS;
auto ret = threadPool.RemoveThread(threadName);
EXPECT_EQ(ret, true);
}
/**
* @tc.name: RemoveThreadTest004
* @tc.desc: Verify the RemoveThread function
* @tc.type: FUNC
*/
HWTEST_F(IPCWorkThreadPoolUnitTest, RemoveThreadTest004, TestSize.Level1)
{
IPCWorkThreadPool threadPool(1);
std::string threadName = "threadName1";
auto ipcThread = new (std::nothrow) IPCWorkThread(threadName);
threadPool.threads_[threadName] = ipcThread;
ipcThread->proto_ = IRemoteObject::IF_PROT_ERROR;
auto ret = threadPool.RemoveThread(threadName);
EXPECT_EQ(ret, true);
}
/**
* @tc.name: RemoveThreadTest005
* @tc.desc: Verify the RemoveThread function
* @tc.type: FUNC
*/
HWTEST_F(IPCWorkThreadPoolUnitTest, RemoveThreadTest005, TestSize.Level1)
{
IPCWorkThreadPool threadPool(1);
std::string threadName = "threadName1";
threadPool.threads_[threadName] = nullptr;
auto ret = threadPool.RemoveThread(threadName);
EXPECT_EQ(ret, false);
}
/**
* @tc.name: RemoveThreadTest006
* @tc.desc: Verify the RemoveThread function
* @tc.type: FUNC
*/
HWTEST_F(IPCWorkThreadPoolUnitTest, RemoveThreadTest006, TestSize.Level1)
{
IPCWorkThreadPool threadPool(1);
std::string threadName = "threadName1";
auto ret = threadPool.RemoveThread(threadName);
EXPECT_EQ(ret, false);
}
/**
* @tc.name: UpdateMaxThreadNumTest001
* @tc.desc: Verify the UpdateMaxThreadNum function
* @tc.type: FUNC
*/
HWTEST_F(IPCWorkThreadPoolUnitTest, UpdateMaxThreadNumTest001, TestSize.Level1)
{
IPCWorkThreadPool threadPool(1);
threadPool.UpdateMaxThreadNum(0);
EXPECT_EQ(threadPool.maxThreadNum_, 1);
}
\ No newline at end of file
......@@ -384,4 +384,30 @@ HWTEST_F(MessageParcelTest, WriteAshmemTest001, TestSize.Level1)
auto ret = parcel.WriteAshmem(ashmem);
ASSERT_TRUE(ret == true);
ashmem->CloseAshmem();
}
/**
* @tc.name: ReadAshmemTest001
* @tc.desc: Verify the MessageParcel::ReadAshmem function
* @tc.type: FUNC
*/
HWTEST_F(MessageParcelTest, ReadAshmemTest001, TestSize.Level1)
{
MessageParcel parcel;
auto ret = parcel.ReadAshmem();
ASSERT_TRUE(ret == nullptr);
}
/**
* @tc.name: AppendTest001
* @tc.desc: Verify the MessageParcel::Append function
* @tc.type: FUNC
*/
HWTEST_F(MessageParcelTest, AppendTest001, TestSize.Level1)
{
MessageParcel parcel;
MessageParcel data;
auto ret = parcel.Append(data);
ASSERT_TRUE(ret);
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册