未验证 提交 26bfed96 编写于 作者: O openharmony_ci 提交者: Gitee

!600 新增ipc模块c接口的测试用例

Merge pull request !600 from Yanying/master
......@@ -16,6 +16,8 @@
#include <gtest/gtest.h>
#include <refbase.h>
#include <securec.h>
#include "c_ashmem.h"
#include "c_parcel.h"
#include "c_parcel_internal.h"
......@@ -51,10 +53,13 @@ static bool CParcelBytesAllocatorOk(void *stringData, char **buffer, int32_t len
if (buffer == nullptr || len < 0) {
return false;
}
if (len != 0) {
*buffer = (char *)malloc(len);
if (*buffer == nullptr) {
return false;
}
(void)memset_s(*buffer, len, 0, len);
}
void **ptr = reinterpret_cast<void **>(stringData);
if (ptr != nullptr) {
*ptr = *buffer;
......@@ -458,3 +463,122 @@ HWTEST_F(IpcCMessageParcelUnitTest, CParcelDataInfo, TestSize.Level1)
CParcelDecStrongRef(parcel);
}
/**
* @tc.name: CParcelContainFileDescriptors
* @tc.desc: Verify whether there is fd with this description
* @tc.type: FUNC
*/
HWTEST_F(IpcCMessageParcelUnitTest, CParcelContainFileDescriptors, TestSize.Level1)
{
CParcel *parcel = CParcelObtain();
EXPECT_NE(parcel, nullptr);
CParcelContainFileDescriptors(parcel);
EXPECT_EQ(CParcelGetRawDataSize(parcel), 0);
CParcelDecStrongRef(parcel);
}
/**
* @tc.name: CParcelClearFileDescriptor
* @tc.desc: Verify clear fd by this description
* @tc.type: FUNC
*/
HWTEST_F(IpcCMessageParcelUnitTest, CParcelClearFileDescriptor, TestSize.Level1)
{
CParcel *parcel = CParcelObtain();
EXPECT_NE(parcel, nullptr);
CParcelClearFileDescriptor(parcel);
EXPECT_EQ(CParcelGetRawDataSize(parcel), 0);
CParcelDecStrongRef(parcel);
}
/**
* @tc.name: CParcelGetRawDataSize
* @tc.desc: Get raw data size
* @tc.type: FUNC
*/
HWTEST_F(IpcCMessageParcelUnitTest, CParcelGetRawDataSize, TestSize.Level1)
{
CParcel *parcel = CParcelObtain();
EXPECT_NE(parcel, nullptr);
EXPECT_EQ(CParcelGetRawDataSize(parcel), 0);
CParcelDecStrongRef(parcel);
}
/**
* @tc.name: CParcelGetRawDataCapacity
* @tc.desc: Get raw data capacity
* @tc.type: FUNC
*/
HWTEST_F(IpcCMessageParcelUnitTest, CParcelGetRawDataCapacity, TestSize.Level1)
{
CParcel *parcel = CParcelObtain();
EXPECT_NE(parcel, nullptr);
EXPECT_EQ(CParcelGetRawDataCapacity(parcel), 128 * 1024 * 1024);
CParcelDecStrongRef(parcel);
}
/**
* @tc.name: CParcelSetClearFdFlag
* @tc.desc: Verify set clear fd flag
* @tc.type: FUNC
*/
HWTEST_F(IpcCMessageParcelUnitTest, CParcelSetClearFdFlag, TestSize.Level1)
{
CParcel *parcel = CParcelObtain();
EXPECT_NE(parcel, nullptr);
CParcelSetClearFdFlag(parcel);
CParcelDecStrongRef(parcel);
}
/**
* @tc.name: CParcelAppend
* @tc.desc: Verify Whether the parcel is appended successfully
* @tc.type: FUNC
*/
HWTEST_F(IpcCMessageParcelUnitTest, CParcelAppend, TestSize.Level1)
{
CParcel *parcel = CParcelObtain();
EXPECT_NE(parcel, nullptr);
CParcel *parcel2= CParcelObtain();
EXPECT_NE(parcel, nullptr);
EXPECT_EQ(CParcelAppend(parcel, parcel2), true);
CParcelDecStrongRef(parcel);
CParcelDecStrongRef(parcel2);
}
/**
* @tc.name: ReadAndWriteAshmemTest
* @tc.desc: Verify the read and write ashmem function
* @tc.type: FUNC
*/
HWTEST_F(IpcCMessageParcelUnitTest, ReadAndWriteAshmemTest, TestSize.Level1)
{
CParcel *parcel = CParcelObtain();
EXPECT_NE(parcel, nullptr);
std::string name = "AshmemIpc";
std::string ashmemString = "HelloWorld2023";
CAshmem *ashmem = CreateCAshmem(name.c_str(), 1024);
ASSERT_TRUE(ashmem != nullptr);
EXPECT_EQ(MapReadAndWriteCAshmem(ashmem), true);
EXPECT_EQ(WriteToCAshmem(ashmem, const_cast<uint8_t *>(reinterpret_cast<const uint8_t *>(ashmemString.c_str())),
strlen(ashmemString.c_str()), 0), true);
EXPECT_EQ(CParcelWriteAshmem(parcel, ashmem), true);
EXPECT_EQ(CParcelRewindRead(parcel, 0), true);
CAshmem *ashmem2 = CParcelReadAshmem(parcel);
ASSERT_TRUE(ashmem2 != nullptr);
ASSERT_TRUE(MapReadOnlyCAshmem(ashmem2));
const void *content = ReadFromCAshmem(ashmem2, strlen(ashmemString.c_str()), 0);
ASSERT_TRUE(content != nullptr);
auto readContent = static_cast<const char *>(content);
std::string str(readContent, strlen(ashmemString.c_str()));
EXPECT_EQ(str, ashmemString);
UnmapCAshmem(ashmem);
CloseCAshmem(ashmem);
UnmapCAshmem(ashmem2);
CloseCAshmem(ashmem2);
}
\ No newline at end of file
......@@ -16,6 +16,7 @@
#include <gtest/gtest.h>
#include <nativetoken_kit.h>
#include <securec.h>
#include <token_setproc.h>
#include <unistd.h>
#include "c_process.h"
......@@ -59,6 +60,25 @@ static void InitTokenId(void)
SetSelfTokenID(tokenId);
}
static bool BytesAllocator(void *stringData, char **buffer, int32_t len)
{
if (buffer == nullptr || len < 0) {
return false;
}
if (len != 0) {
*buffer = (char *)malloc(len);
if (*buffer == nullptr) {
return false;
}
(void)memset_s(*buffer, len, 0, len);
}
void **ptr = reinterpret_cast<void **>(stringData);
if (ptr != nullptr) {
*ptr = *buffer;
}
return true;
}
/**
* @tc.name: CProcessCallingInfo
* @tc.desc: Verify the CProcess calling info functions
......@@ -73,3 +93,68 @@ HWTEST_F(IpcCProcessUnitTest, CProcessCallingInfo, TestSize.Level1)
EXPECT_EQ(GetCallingPid(), static_cast<uint64_t>(getpid()));
EXPECT_EQ(GetCallingUid(), static_cast<uint64_t>(getuid()));
}
/**
* @tc.name: SetMaxWorkThreadNum
* @tc.desc: Verify set max work thread
* @tc.type: FUNC
*/
HWTEST_F(IpcCProcessUnitTest, SetMaxWorkThreadNum, TestSize.Level1)
{
EXPECT_EQ(true, SetMaxWorkThreadNum(3));
}
/**
* @tc.name: CallingIdentity
* @tc.desc: Verify reset and set calling identity
* @tc.type: FUNC
*/
HWTEST_F(IpcCProcessUnitTest, CallingIdentity, TestSize.Level1)
{
void *value = nullptr;
bool ret = ResetCallingIdentity(reinterpret_cast<void *>(&value), BytesAllocator);
EXPECT_EQ(true, ret);
ret = SetCallingIdentity(reinterpret_cast<const char *>(value));
EXPECT_EQ(false, ret);
if (value != nullptr) {
free(value);
}
}
/**
* @tc.name: IsLocalCalling
* @tc.desc: Verify whether it is local calling
* @tc.type: FUNC
*/
HWTEST_F(IpcCProcessUnitTest, IsLocalCalling, TestSize.Level1)
{
EXPECT_EQ(true, IsLocalCalling());
}
/**
* @tc.name: GetCallingDeviceID
* @tc.desc: Get calling device ID
* @tc.type: FUNC
*/
HWTEST_F(IpcCProcessUnitTest, GetCallingDeviceID, TestSize.Level1)
{
void *value = nullptr;
EXPECT_EQ(GetCallingDeviceID(value, BytesAllocator), true);
if (value != nullptr) {
free(value);
}
}
/**
* @tc.name: GetLocalDeviceID
* @tc.desc: Get local device ID
* @tc.type: FUNC
*/
HWTEST_F(IpcCProcessUnitTest, GetLocalDeviceID, TestSize.Level1)
{
void *value = nullptr;
EXPECT_EQ(GetLocalDeviceID(value, BytesAllocator), true);
if (value != nullptr) {
free(value);
}
}
\ No newline at end of file
......@@ -15,6 +15,8 @@
#include <gtest/gtest.h>
#include <cstring>
#include <securec.h>
#include "c_process.h"
#include "c_remote_object.h"
#include "c_remote_object_internal.h"
......@@ -69,6 +71,34 @@ static void OnDeathRecipientDestroy(const void *userData)
(void)userData;
}
static bool Bytes16Allocator(void *stringData, uint16_t **buffer, int32_t len)
{
if (buffer == nullptr || len < 0) {
return false;
}
if (len != 0) {
*buffer = (uint16_t *)malloc(len * sizeof(uint16_t));
if (*buffer == nullptr) {
return false;
}
(void)memset_s(*buffer, len * sizeof(uint16_t), 0, len * sizeof(uint16_t));
}
void **ptr = reinterpret_cast<void **>(stringData);
if (ptr != nullptr) {
*ptr = *buffer;
}
return true;
}
static bool StringArrayWrite(const void *array, const void *value, uint32_t len)
{
if (value == nullptr || len < 0) {
return false;
}
array = value;
return true;
}
/**
* @tc.name: CRemoteObjectRefCount
* @tc.desc: Verify the CRemoteObject reference count functions
......@@ -220,3 +250,68 @@ HWTEST_F(IpcCRemoteObjectUnitTest, CDeathRecipient, TestSize.Level1)
DeathRecipientDecStrongRef(recipient);
RemoteObjectDecStrongRef(samgr);
}
/**
* @tc.name: CRemoteObjectIsProxyObject
* @tc.desc: Verify whether the bit proxy object
* @tc.type: FUNC
*/
HWTEST_F(IpcCRemoteObjectUnitTest, CRemoteObjectIsProxyObject, TestSize.Level1)
{
int8_t userData;
CRemoteObject *remote = CreateRemoteStub(SERVICE_NAME, OnRemoteRequest, OnRemoteObjectDestroy, &userData);
EXPECT_NE(remote, nullptr);
bool ret = IsProxyObject(remote);
EXPECT_EQ(ret, false);
}
/**
* @tc.name: CRemoteObjectIsObjectDead
* @tc.desc: Verify whether the object is dead
* @tc.type: FUNC
*/
HWTEST_F(IpcCRemoteObjectUnitTest, CRemoteObjectIsObjectDead, TestSize.Level1)
{
int8_t userData;
CRemoteObject *remote = CreateRemoteStub(SERVICE_NAME, OnRemoteRequest, OnRemoteObjectDestroy, &userData);
EXPECT_NE(remote, nullptr);
bool ret = IsObjectDead(remote);
EXPECT_EQ(ret, false);
}
/**
* @tc.name: CRemoteObjectGetInterfaceDescriptor
* @tc.desc: Get interface descriptor
* @tc.type: FUNC
*/
HWTEST_F(IpcCRemoteObjectUnitTest, CRemoteObjectGetInterfaceDescriptor, TestSize.Level1)
{
int8_t userData;
CRemoteObject *remote = CreateRemoteStub(SERVICE_NAME, OnRemoteRequest, OnRemoteObjectDestroy, &userData);
EXPECT_NE(remote, nullptr);
void *data = nullptr;
bool ret = GetInterfaceDescriptor(remote, reinterpret_cast<void *>(&data), Bytes16Allocator);
EXPECT_EQ(ret, false);
if (data != nullptr) {
free(data);
}
}
/**
* @tc.name: CRemoteObjectDump
* @tc.desc: Dump the service through the incoming string
* @tc.type: FUNC
*/
HWTEST_F(IpcCRemoteObjectUnitTest, CRemoteObjectDump, TestSize.Level1)
{
int8_t userData;
CRemoteObject *remote = CreateRemoteStub(SERVICE_NAME, OnRemoteRequest, OnRemoteObjectDestroy, &userData);
EXPECT_NE(remote, nullptr);
const char *data = SERVICE_NAME;
int ret = Dump(remote, 0, reinterpret_cast<const void *>(&data), strlen(data), StringArrayWrite);
EXPECT_EQ(ret, 0);
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册