From 42454bf1a48ff9d070fa4735e11efd8aab42375f Mon Sep 17 00:00:00 2001 From: zhaoyuan17 Date: Sat, 30 Oct 2021 12:44:52 +0000 Subject: [PATCH] modift test code Signed-off-by: zhaoyuan17 --- include/appspawn_server.h | 2 -- src/appspawn_server.cpp | 28 ++++--------------- .../app_spawn_msg_peer_test.cpp | 16 +++++------ .../app_spawn_server_override_test.cpp | 3 -- .../app_spawn_socket_test.cpp | 4 +-- 5 files changed, 16 insertions(+), 37 deletions(-) diff --git a/include/appspawn_server.h b/include/appspawn_server.h index 281eb5a3..c73cf79f 100644 --- a/include/appspawn_server.h +++ b/include/appspawn_server.h @@ -143,8 +143,6 @@ private: */ bool CheckAppProperty(const ClientSocket::AppProperty *appProperty); - void LoadAceLib(); - private: const std::string deviceNull_ = "/dev/null"; std::string socketName_ {}; diff --git a/src/appspawn_server.cpp b/src/appspawn_server.cpp index 2c8e7d11..2bba92e3 100644 --- a/src/appspawn_server.cpp +++ b/src/appspawn_server.cpp @@ -28,9 +28,6 @@ #include "main_thread.h" #include "securec.h" -#include -#include - #define GRAPHIC_PERMISSION_CHECK constexpr static size_t ERR_STRING_SZ = 64; @@ -45,6 +42,8 @@ constexpr int32_t MAX_GIDS = 64; constexpr std::string_view BUNDLE_NAME_CAMERA("com.ohos.camera"); constexpr std::string_view BUNDLE_NAME_PHOTOS("com.ohos.photos"); +constexpr std::string_view BUNDLE_NAME_MEDIA_LIBRARY("com.ohos.medialibrary.MediaLibraryDataA"); +constexpr std::string_view BUNDLE_NAME_SCANNER("com.ohos.medialibrary.MediaScannerAbilityA"); } // namespace using namespace OHOS::HiviewDFX; @@ -157,20 +156,6 @@ void AppSpawnServer::ConnectionPeer() } } -void AppSpawnServer::LoadAceLib() -{ - std::string acelibdir("/system/lib/libace.z.so"); - void *AceAbilityLib = nullptr; - HiLog::Info(LABEL, "MainThread::LoadAbilityLibrary. Start calling dlopen acelibdir."); - AceAbilityLib = dlopen(acelibdir.c_str(), RTLD_NOW | RTLD_GLOBAL); - if (AceAbilityLib == nullptr) { - HiLog::Error(LABEL, "Fail to dlopen %{public}s, [%{public}s]", acelibdir.c_str(), dlerror()); - } else { - HiLog::Info(LABEL, "Success to dlopen %{public}s", acelibdir.c_str()); - } - HiLog::Info(LABEL, "MainThread::LoadAbilityLibrary. End calling dlopen."); -} - bool AppSpawnServer::ServerMain(char *longProcName, int64_t longProcNameLen) { if (socket_->RegisterServerSocket() != 0) { @@ -179,8 +164,6 @@ bool AppSpawnServer::ServerMain(char *longProcName, int64_t longProcNameLen) } std::thread(&AppSpawnServer::ConnectionPeer, this).detach(); - LoadAceLib(); - while (isRunning_) { std::unique_lock lock(mut_); dataCond_.wait(lock, [this] { return !this->appQueue_.empty(); }); @@ -211,8 +194,7 @@ bool AppSpawnServer::ServerMain(char *longProcName, int64_t longProcNameLen) continue; } else if (pid == 0) { SpecialHandle(appProperty); - SetAppProcProperty(connectFd, appProperty, longProcName, longProcNameLen, fd); - _exit(0); + return SetAppProcProperty(connectFd, appProperty, longProcName, longProcNameLen, fd); } read(fd[0], &buff, sizeof(buff)); // wait child process resutl @@ -465,7 +447,9 @@ void AppSpawnServer::SpecialHandle(ClientSocket::AppProperty *appProperty) } // special handle bundle name "com.ohos.photos" and "com.ohos.camera" if ((strcmp(appProperty->processName, BUNDLE_NAME_CAMERA.data()) == 0) || - (strcmp(appProperty->processName, BUNDLE_NAME_PHOTOS.data()) == 0)) { + (strcmp(appProperty->processName, BUNDLE_NAME_PHOTOS.data()) == 0) || + (strcmp(appProperty->processName, BUNDLE_NAME_MEDIA_LIBRARY.data()) == 0) || + (strcmp(appProperty->processName, BUNDLE_NAME_SCANNER.data()) == 0)) { if (appProperty->gidCount < MAX_GIDS) { appProperty->gidTable[appProperty->gidCount] = GID_MEDIA; appProperty->gidCount++; diff --git a/test/unittest/app_spawn_msg_peer_test/app_spawn_msg_peer_test.cpp b/test/unittest/app_spawn_msg_peer_test/app_spawn_msg_peer_test.cpp index 57192929..ea60f09c 100644 --- a/test/unittest/app_spawn_msg_peer_test/app_spawn_msg_peer_test.cpp +++ b/test/unittest/app_spawn_msg_peer_test/app_spawn_msg_peer_test.cpp @@ -57,7 +57,7 @@ HWTEST(AppSpawnMsgPeerTest, App_Spawn_Msg_Peer_001, TestSize.Level0) GTEST_LOG_(INFO) << "App_Spawn_Msg_Peer_001 start"; std::shared_ptr serverSocket = std::make_shared("ServerSocket"); - int32_t connectFd = -1; + const int32_t connectFd = -1; std::unique_ptr appSpawnMsgPeer = std::make_unique(serverSocket, connectFd); EXPECT_EQ(-1, appSpawnMsgPeer->GetConnectFd()); @@ -79,7 +79,7 @@ HWTEST(AppSpawnMsgPeerTest, App_Spawn_Msg_Peer_002, TestSize.Level0) GTEST_LOG_(INFO) << "App_Spawn_Msg_Peer_002 start"; std::shared_ptr serverSocket = std::make_shared("ServerSocket"); - int32_t connectFd = -1; + const int32_t connectFd = -1; std::unique_ptr appSpawnMsgPeer = std::make_unique(serverSocket, connectFd); EXPECT_EQ(-1, appSpawnMsgPeer->MsgPeer()); @@ -100,7 +100,7 @@ HWTEST(AppSpawnMsgPeerTest, App_Spawn_Msg_Peer_003, TestSize.Level0) GTEST_LOG_(INFO) << "App_Spawn_Msg_Peer_003 start"; std::shared_ptr serverSocket = nullptr; - int32_t connectFd = 1; + const int32_t connectFd = 1; std::unique_ptr appSpawnMsgPeer = std::make_unique(serverSocket, connectFd); EXPECT_EQ(-1, appSpawnMsgPeer->MsgPeer()); @@ -121,7 +121,7 @@ HWTEST(AppSpawnMsgPeerTest, App_Spawn_Msg_Peer_004, TestSize.Level0) GTEST_LOG_(INFO) << "App_Spawn_Msg_Peer_004 start"; std::shared_ptr serverSocket = std::make_shared("ServerSocket"); - int32_t connectFd = -1; + const int32_t connectFd = -1; std::unique_ptr appSpawnMsgPeer = std::make_unique(serverSocket, connectFd); EXPECT_EQ(-1, appSpawnMsgPeer->Response(1)); @@ -142,7 +142,7 @@ HWTEST(AppSpawnMsgPeerTest, App_Spawn_Msg_Peer_005, TestSize.Level0) GTEST_LOG_(INFO) << "App_Spawn_Msg_Peer_005 start"; std::shared_ptr serverSocket = nullptr; - int32_t connectFd = 1; + const int32_t connectFd = 1; std::unique_ptr appSpawnMsgPeer = std::make_unique(serverSocket, connectFd); EXPECT_EQ(-1, appSpawnMsgPeer->Response(1)); @@ -163,7 +163,7 @@ HWTEST(AppSpawnMsgPeerTest, App_Spawn_Msg_Peer_006, TestSize.Level0) GTEST_LOG_(INFO) << "App_Spawn_Msg_Peer_006 start"; std::shared_ptr mockServerSocket = std::make_shared("MockServerSocket"); - int32_t connectFd = 1; + const int32_t connectFd = 1; std::unique_ptr appSpawnMsgPeer = std::make_unique(mockServerSocket, connectFd); EXPECT_CALL(*mockServerSocket, ReadSocketMessage(_, _, _)).WillOnce(Return(-1)); @@ -186,7 +186,7 @@ HWTEST(AppSpawnMsgPeerTest, App_Spawn_Msg_Peer_007, TestSize.Level0) GTEST_LOG_(INFO) << "App_Spawn_Msg_Peer_007 start"; std::shared_ptr mockServerSocket = std::make_shared("MockServerSocket"); - int32_t connectFd = 1; + const int32_t connectFd = 1; std::unique_ptr appSpawnMsgPeer = std::make_unique(mockServerSocket, connectFd); EXPECT_CALL(*mockServerSocket, ReadSocketMessage(_, _, _)).WillOnce(Return(sizeof(ClientSocket::AppProperty) + 1)); @@ -209,7 +209,7 @@ HWTEST(AppSpawnMsgPeerTest, App_Spawn_Msg_Peer_008, TestSize.Level0) GTEST_LOG_(INFO) << "App_Spawn_Msg_Peer_008 start"; std::shared_ptr mockServerSocket = std::make_shared("MockServerSocket"); - int32_t connectFd = 1; + const int32_t connectFd = 1; std::unique_ptr appSpawnMsgPeer = std::make_unique(mockServerSocket, connectFd); EXPECT_EQ(nullptr, appSpawnMsgPeer->GetMsg()); diff --git a/test/unittest/app_spawn_server_test/app_spawn_server_override_test.cpp b/test/unittest/app_spawn_server_test/app_spawn_server_override_test.cpp index 8956e0c2..33422757 100644 --- a/test/unittest/app_spawn_server_test/app_spawn_server_override_test.cpp +++ b/test/unittest/app_spawn_server_test/app_spawn_server_override_test.cpp @@ -24,9 +24,6 @@ #undef private #undef protected -#include -#include - using namespace testing; using namespace testing::ext; using namespace OHOS::AppSpawn; diff --git a/test/unittest/app_spawn_socket_test/app_spawn_socket_test.cpp b/test/unittest/app_spawn_socket_test/app_spawn_socket_test.cpp index ca5a5bb4..0145797e 100644 --- a/test/unittest/app_spawn_socket_test/app_spawn_socket_test.cpp +++ b/test/unittest/app_spawn_socket_test/app_spawn_socket_test.cpp @@ -274,7 +274,7 @@ HWTEST(AppSpawnSocketTest, App_Spawn_Socket_010, TestSize.Level0) EXPECT_TRUE(appSpawnSocket); std::string content = "hiworld"; int32_t len = content.length(); - EXPECT_TRUE(len); + EXPECT_TRUE(len > 0); std::unique_ptr buff = std::make_unique(len); EXPECT_TRUE(buff); int32_t fd[2] = {0, 0}; @@ -405,7 +405,7 @@ HWTEST(AppSpawnSocketTest, App_Spawn_Socket_015, TestSize.Level0) EXPECT_TRUE(appSpawnSocket); std::string content = "hiworld"; int32_t len = content.length(); - EXPECT_TRUE(len); + EXPECT_TRUE(len > 0); std::unique_ptr buff = std::make_unique(len); EXPECT_TRUE(buff); int32_t fd[2] = {0, 0}; -- Gitee