diff --git a/ipc/test/unittest/ipc/client/client.cpp b/ipc/test/unittest/ipc/client/client.cpp index 91bdc48212efe99f0969c217148fcb9a7eb52d95..ff9cfd0edf412b5d0accf71fff33f403e6f89824 100644 --- a/ipc/test/unittest/ipc/client/client.cpp +++ b/ipc/test/unittest/ipc/client/client.cpp @@ -15,17 +15,17 @@ #include "gtest/gtest.h" -#include -#include +#include #include "ipc_proxy.h" - -#include "rpc_log.h" -#include "rpc_errno.h" #include "ipc_skeleton.h" +#include "rpc_errno.h" +#include "rpc_log.h" #include "serializer.h" -static SvcIdentity sidServer; +namespace { +constexpr int32_t PERFORMANCE_TEST_TIMES = 100; +SvcIdentity sidServer; MessageOption g_option = TF_OP_SYNC; uint32_t cbId1 = -1; @@ -82,6 +82,7 @@ void ServerDead3() { RPC_LOG_INFO("#### server dead callback33 called ... "); } +} using namespace testing::ext; @@ -168,15 +169,15 @@ HWTEST_F(IpcClientTest, IpcClientTest003, TestSize.Level1) HWTEST_F(IpcClientTest, IpcClientTest004, TestSize.Level0) { RPC_LOG_INFO("============= test case for add death callback ============"); - int ret = AddDeathRecipient(sidServer, (OnRemoteDead)ServerDead1, NULL, &cbId1); + int ret = AddDeathRecipient(sidServer, (OnRemoteDead)ServerDead1, nullptr, &cbId1); EXPECT_EQ(ret, ERR_NONE); - ret = AddDeathRecipient(sidServer, (OnRemoteDead)ServerDead2, NULL, &cbId2); + ret = AddDeathRecipient(sidServer, (OnRemoteDead)ServerDead2, nullptr, &cbId2); EXPECT_EQ(ret, ERR_NONE); - ret = AddDeathRecipient(sidServer, (OnRemoteDead)ServerDead3, NULL, &cbId3); + ret = AddDeathRecipient(sidServer, (OnRemoteDead)ServerDead3, nullptr, &cbId3); EXPECT_EQ(ret, ERR_NONE); - ret = AddDeathRecipient(sidServer, (OnRemoteDead)ServerDead3, NULL, &cbId4); + ret = AddDeathRecipient(sidServer, (OnRemoteDead)ServerDead3, nullptr, &cbId4); EXPECT_EQ(ret, ERR_NONE); - ret = AddDeathRecipient(sidServer, (OnRemoteDead)ServerDead3, NULL, &cbId5); // failed + ret = AddDeathRecipient(sidServer, (OnRemoteDead)ServerDead3, nullptr, &cbId5); // failed EXPECT_EQ(ret, ERR_INVALID_PARAM); } @@ -196,7 +197,7 @@ HWTEST_F(IpcClientTest, IpcClientTest005, TestSize.Level0) HWTEST_F(IpcClientTest, IpcClientTest006, TestSize.Level1) { ++sidServer.handle; - int ret = AddDeathRecipient(sidServer, (OnRemoteDead)ServerDead3, NULL, &cbId5); // failed + int ret = AddDeathRecipient(sidServer, (OnRemoteDead)ServerDead3, nullptr, &cbId5); // failed EXPECT_EQ(ret, ERR_INVALID_PARAM); ret = RemoveDeathRecipient(sidServer, cbId3); // failed @@ -246,7 +247,7 @@ HWTEST_F(IpcClientTest, IpcClientTest008, TestSize.Level2) // 异步性能测 clock_gettime(CLOCK_REALTIME, &start); for (int i = 0; i < PERFORMANCE_TEST_TIMES; i++) { - SendRequest(sidServer, SERVER_OP_ADD, &data2, NULL, option, NULL); + SendRequest(sidServer, SERVER_OP_ADD, &data2, nullptr, option, nullptr); } clock_gettime(CLOCK_REALTIME, &end); @@ -256,9 +257,9 @@ HWTEST_F(IpcClientTest, IpcClientTest008, TestSize.Level2) // 异步性能测 HWTEST_F(IpcClientTest, IpcClientTest009, TestSize.Level0) { - int ret = AddDeathRecipient(sidServer, (OnRemoteDead)ServerDead1, NULL, &cbId1); + int ret = AddDeathRecipient(sidServer, (OnRemoteDead)ServerDead1, nullptr, &cbId1); EXPECT_EQ(ret, ERR_NONE); - ret = AddDeathRecipient(sidServer, (OnRemoteDead)ServerDead2, NULL, &cbId2); + ret = AddDeathRecipient(sidServer, (OnRemoteDead)ServerDead2, nullptr, &cbId2); EXPECT_EQ(ret, ERR_NONE); JoinWorkThread(); } diff --git a/ipc/test/unittest/ipc/include/ipc_proxy.h b/ipc/test/unittest/ipc/include/ipc_proxy.h index bc906161c51e65895246b14bbbef4aa60cce1cc3..b438fb3e538fbbedb62a64df6c94d6b5e02857a7 100644 --- a/ipc/test/unittest/ipc/include/ipc_proxy.h +++ b/ipc/test/unittest/ipc/include/ipc_proxy.h @@ -41,10 +41,6 @@ enum { SERVER_SA_ID2 = 18, }; -#define IPC_TEST_TIME_INTERVAL 120 - -#define PERFORMANCE_TEST_TIMES 100 - #define OP_A 12 #define OP_B 17 diff --git a/ipc/test/unittest/ipc/samgr/samgr.cpp b/ipc/test/unittest/ipc/samgr/samgr.cpp index 4a0bbe1dcc54628a89bb1869b8bf64f81b5f75e9..9f66d5d526840c6dfd26df1eaf1409392eb4e2eb 100644 --- a/ipc/test/unittest/ipc/samgr/samgr.cpp +++ b/ipc/test/unittest/ipc/samgr/samgr.cpp @@ -13,16 +13,12 @@ * limitations under the License. */ -#include "ipc_proxy.h" - #include "gtest/gtest.h" -#include -#include - -#include "rpc_log.h" -#include "rpc_errno.h" +#include "ipc_proxy.h" #include "ipc_skeleton.h" +#include "rpc_errno.h" +#include "rpc_log.h" #include "serializer.h" #include "utils_list.h" @@ -32,12 +28,13 @@ typedef struct { SvcIdentity *sid; } SvcInfo; -static UTILS_DL_LIST *g_saList = NULL; -static int32_t g_saSum = 0; +namespace { +UTILS_DL_LIST *g_saList = nullptr; +int32_t g_saSum = 0; int32_t AddSystemAbility(int32_t saId, SvcIdentity *sid) { - if (g_saList == NULL) { + if (g_saList == nullptr) { return ERR_FAILED; } @@ -52,8 +49,8 @@ int32_t AddSystemAbility(int32_t saId, SvcIdentity *sid) int32_t GetSystemAbility(int32_t saId, const char* deviceId, SvcIdentity *sid) { - SvcInfo* node = NULL; - SvcInfo* next = NULL; + SvcInfo* node = nullptr; + SvcInfo* next = nullptr; UTILS_DL_LIST_FOR_EACH_ENTRY_SAFE(node, next, g_saList, SvcInfo, list) { if (node->saId == saId) { @@ -103,12 +100,13 @@ int32_t mainFunc(void) RPC_LOG_INFO("Enter System Ability Manager .... "); g_saList = (UTILS_DL_LIST *)calloc(1, sizeof(UTILS_DL_LIST)); - if (g_saList == NULL) { + if (g_saList == nullptr) { return -1; } UtilsListInit(g_saList); return ERR_NONE; } +} using namespace testing::ext; diff --git a/ipc/test/unittest/ipc/server/server.cpp b/ipc/test/unittest/ipc/server/server.cpp index b61dde855572679b9d7ac399ac052767f3dc6f9b..fb74ca6bbd6724b98ec8f61abcdf03c8a1febbfa 100644 --- a/ipc/test/unittest/ipc/server/server.cpp +++ b/ipc/test/unittest/ipc/server/server.cpp @@ -13,25 +13,24 @@ * limitations under the License. */ -#include "ipc_proxy.h" - #include "gtest/gtest.h" -#include #include -#include "rpc_log.h" #include "rpc_errno.h" +#include "rpc_log.h" +#include "ipc_proxy.h" #include "ipc_skeleton.h" #include "serializer.h" -#include -static SvcIdentity *sid = NULL; +namespace { +constexpr uint32_t IPC_TEST_TIME_INTERVAL = 120; +SvcIdentity *sid = nullptr; MessageOption g_option = TF_OP_SYNC; -static void CallAnonymosFunc(const char *str) +void CallAnonymosFunc(const char *str) { - if (sid == NULL) { + if (sid == nullptr) { RPC_LOG_INFO("invalid anonymous client"); return; } @@ -43,7 +42,7 @@ static void CallAnonymosFunc(const char *str) IpcIo reply; MessageOption option = TF_OP_ASYNC; - SendRequest(*sid, CLIENT_OP_PRINT, &data, &reply, option, NULL); + SendRequest(*sid, CLIENT_OP_PRINT, &data, &reply, option, nullptr); } int32_t RemoteRequestOne(uint32_t code, IpcIo *data, IpcIo *reply, MessageOption option) @@ -123,37 +122,38 @@ int32_t RemoteRequestTwo(uint32_t code, IpcIo *data, IpcIo *reply, MessageOption return result; } -static void *ThreadHandler(void *args) +void *ThreadHandler(void *args) { sleep(IPC_TEST_TIME_INTERVAL); // sleep 2 min const char *str = "server call anonymos service new thread."; CallAnonymosFunc(str); - return NULL; + return nullptr; } -static IpcObjectStub objectStubOne = { +IpcObjectStub objectStubOne = { .func = RemoteRequestOne, .isRemote = false }; -static IpcObjectStub objectStubTwo = { +IpcObjectStub objectStubTwo = { .func = RemoteRequestTwo, .isRemote = false }; -static SvcIdentity svcOne = { +SvcIdentity svcOne = { .handle = -1, .token = (uintptr_t)&objectStubOne, .cookie = (uintptr_t)&objectStubOne }; -static SvcIdentity svcTwo = { +SvcIdentity svcTwo = { .handle = -1, .token = (uintptr_t)&objectStubTwo, .cookie = (uintptr_t)&objectStubTwo }; -static SvcIdentity sidOne; +SvcIdentity sidOne; +} using namespace testing::ext; @@ -178,7 +178,7 @@ HWTEST_F(IpcServerTest, IpcServerTest001, TestSize.Level1) uint8_t tmpData1[IPC_MAX_SIZE]; IpcIoInit(&data, tmpData1, IPC_MAX_SIZE, 1); WriteInt32(&data, SERVER_SA_ID1); - bool res = WriteRemoteObject(NULL, &svcOne); + bool res = WriteRemoteObject(nullptr, &svcOne); EXPECT_EQ(res, false); } @@ -188,7 +188,7 @@ HWTEST_F(IpcServerTest, IpcServerTest002, TestSize.Level1) uint8_t tmpData1[IPC_MAX_SIZE]; IpcIoInit(&data, tmpData1, IPC_MAX_SIZE, 1); WriteInt32(&data, SERVER_SA_ID1); - bool res = WriteRemoteObject(&data, NULL); + bool res = WriteRemoteObject(&data, nullptr); EXPECT_EQ(res, false); } @@ -275,7 +275,7 @@ HWTEST_F(IpcServerTest, IpcServerTest006, TestSize.Level0) HWTEST_F(IpcServerTest, IpcServerTest007, TestSize.Level0) { pthread_t pid; - pthread_create(&pid, NULL, ThreadHandler, NULL); + pthread_create(&pid, nullptr, ThreadHandler, nullptr); pthread_detach(pid); JoinWorkThread();