From bf65a885d7e21c3cdb044015089b7fe9cbed105d Mon Sep 17 00:00:00 2001 From: caojiale1 Date: Fri, 26 May 2023 08:50:22 +0000 Subject: [PATCH 01/14] Signed-off-by: caojiale1 Signed-off-by: caojiale1 --- examples/distributedb/test/BUILD.gn | 21 +- .../common/distribute_demo.cpp | 294 +++++------------ .../common/distribute_demo_agent.cpp | 299 +++++++----------- 3 files changed, 200 insertions(+), 414 deletions(-) diff --git a/examples/distributedb/test/BUILD.gn b/examples/distributedb/test/BUILD.gn index 998fc5f..8eeb3b2 100755 --- a/examples/distributedb/test/BUILD.gn +++ b/examples/distributedb/test/BUILD.gn @@ -20,26 +20,21 @@ config("module_private_config") { visibility = [ ":*" ] include_dirs = [ - "//commonlibrary/c_utils/base/include", - "//foundation/distributeddatamgr/kv_store/frameworks/innerkitsimpl/distributeddatafwk/include", - "//foundation/distributeddatamgr/kv_store/frameworks/innerkitsimpl/distributeddatafwk/src", - "//foundation/distributeddatamgr/kv_store/interfaces/innerkits/app_distributeddata/include", - "//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata/include", - "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/app/include", - "//test/testfwk/developer_test/aw/distributed", + "../../../../../../commonlibrary/c_utils/base/include", + "../../../../../../test/testfwk/developer_test/aw/distributed", ] # link library #ldflags = [ "-llog" ] # library path - lib_dirs = [ "//foundation/appexecfwk/libs" ] + # lib_dirs = [ "//foundation/appexecfwk/libs" ] } ohos_distributedtest("DistributeDemo") { module_out_path = module_output_path - sources = [ "//test/testfwk/developer_test/examples/distributedb/test/distributedtest/common/distribute_demo.cpp" ] + sources = [ "distribute_demo.cpp" ] configs = [ ":module_private_config" ] @@ -52,8 +47,6 @@ ohos_distributedtest("DistributeDemo") { ] deps = [ - "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", - "//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata/:distributeddata_inner", "//third_party/googletest:gtest", ] } @@ -61,7 +54,7 @@ ohos_distributedtest("DistributeDemo") { ohos_distributedtest("DistributeDemoAgent") { module_out_path = module_output_path - sources = [ "//test/testfwk/developer_test/examples/distributedb/test/distributedtest/common/distribute_demo_agent.cpp" ] + sources = [ "distribute_demo_agent.cpp" ] configs = [ ":module_private_config" ] @@ -74,8 +67,6 @@ ohos_distributedtest("DistributeDemoAgent") { ] deps = [ - "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", - "//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata/:distributeddata_inner", "//third_party/googletest:gtest", ] } @@ -88,4 +79,4 @@ group("distributedtest") { ":DistributeDemoAgent", ] } -############################################################################### +############################################################################### \ No newline at end of file diff --git a/examples/distributedb/test/distributedtest/common/distribute_demo.cpp b/examples/distributedb/test/distributedtest/common/distribute_demo.cpp index f485b7f..5088f23 100644 --- a/examples/distributedb/test/distributedtest/common/distribute_demo.cpp +++ b/examples/distributedb/test/distributedtest/common/distribute_demo.cpp @@ -17,239 +17,117 @@ #include "distributed_major.h" -#include "app_types.h" #include "refbase.h" -#include "app_kvstore.h" -#include "app_distributed_kv_data_manager.h" #include "hilog/log.h" - using namespace std; using namespace OHOS; using namespace testing::ext; using namespace OHOS::DistributeSystemTest; using namespace OHOS::HiviewDFX; -using namespace OHOS::AppDistributedKv; - -namespace { - constexpr HiLogLabel LABEL = {LOG_CORE, 0, "DistributeDemo"}; - const int SYNC_REC_TIME = 3; - const int MSG_LENGTH = 100; - const int EXPECT_RETURN_VALUE = 111; - const int EXPECT_ADD_TEST_SUM = 500; - const int SLEEP_TIME = 100000; + +namespace{ + constexpr HiLogLabel LABEL={LOG_CORE,0,"DistributedtestDemo"}; + // const int SYNC_REC_TIME = 3; + + const int MSG_LENGTH = 100; + const int EXPECT_RETURN_VALUE = 111; + // const int EXPECT_ADD_TEST_SUM = 500; + // const int SLEEP_TIME = 100000; } -class DistributeDemo : public DistributeTest { +class DistributedtestDemo:public DistributeTest{ public: - DistributeDemo() = default; - ~DistributeDemo() = default; + DistributedtestDemo() = default; + ~DistributedtestDemo() = default; + + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp(); + virtual void TearDown(); +}; - static void SetUpTestCase(void) {} - static void TearDownTestCase(void) {} +void DistributedtestDemo::SetUpTestCase() +{ - virtual void SetUp() {} - virtual void TearDown() {} -}; +} -/** - * @tc.name: msgsendtest_001 - * @tc.desc: Verify the distributed test framework interface SendMessage. - * @tc.type: FUNC - * @tc.require: AR000CQGMV - */ -HWTEST_F(DistributeDemo, msgsendtest_001, TestSize.Level0) +void DistributedtestDemo::TearDownTestCase() { - char msgbuf[MSG_LENGTH] = "I am testcase 1."; - EXPECT_TRUE(SendMessage(AGENT_NO::ONE, msgbuf, MSG_LENGTH)); -}; -/** - * @tc.name: msgsendtest_002 - * @tc.desc: Verify the distributed test framework interface SendMessage, Maximum data length. - * @tc.type: FUNC - * @tc.require: AR000CQGMV - */ -HWTEST_F(DistributeDemo, msgsendtest_002, TestSize.Level0) +} + +void DistributedtestDemo::SetUp() { - char msgbuf[MAX_BUFF_LEN - DST_COMMAND_HEAD_LEN] = "I am testcase 2."; - EXPECT_TRUE(SendMessage(AGENT_NO::ONE, msgbuf, MAX_BUFF_LEN - DST_COMMAND_HEAD_LEN)); -}; -/** - * @tc.name: msgsendtest_003 - * @tc.desc: Verify the distributed test framework interface SendMessage, - * Verify the data maximum length of the sent message interface . - * @tc.type: FUNC - * @tc.require: AR000CQGMV - */ -HWTEST_F(DistributeDemo, msgsendtest_003, TestSize.Level0) +} + +void DistributedtestDemo::TearDown() { - char msgbuf[MAX_BUFF_LEN - DST_COMMAND_HEAD_LEN + 1] = "too big message."; - EXPECT_FALSE(SendMessage(AGENT_NO::ONE, msgbuf, MAX_BUFF_LEN - DST_COMMAND_HEAD_LEN + 1)); -}; -/** - * @tc.name: msgsendtest_004 - * @tc.desc: Verify the distributed test framework interface SendMessage, constains callback. - * @tc.type: FUNC - * @tc.require: AR000CQGMV - */ -HWTEST_F(DistributeDemo, msgsendtest_004, TestSize.Level0) +} + +/* +*@tc.name:SendMessageTest001 +*@tc.desc:Verify the distributed test framework interface SendMessage. +*@tc.type:FUNC +*@tc.require:ArOOOCQGMV +*/ +HWTEST_F(DistributedtestDemo, SendMessageTest001,TestSize.Level1) { - std::string msgBuf = "recall function message test."; - int ret = SendMessage(AGENT_NO::ONE, msgBuf, MSG_LENGTH, - [&](const std::string &szreturnbuf, int rlen)->bool { - std::string szbuf = "I get recall message."; - EXPECT_TRUE(szbuf == szreturnbuf); - HiLog::Info(LABEL, "msgsendtest_004 strncmp=%s", szbuf.c_str()); - return true; - }); - EXPECT_TRUE(ret > 0); -}; + char msgbuf[MSG_LENGTH] = "I am testcase 1"; + int ret = SendMessage(AGENT_NO::ONE,msgbuf,MSG_LENGTH); + + //EXPECT_TRUE(ret)<<"ret = 0"; + if(ret == 0) + { + EXPECT_FALSE(ret)<<"ret = 2"; + } -/** - * @tc.name: runcmdonagent_001 - * @tc.desc: Verify the distributed test framework interface RunCmdOnAgent. - * @tc.type: FUNC - * @tc.require: AR000CQGMV - */ -HWTEST_F(DistributeDemo, runcmdonagent_001, TestSize.Level0) +} + +HWTEST_F(DistributedtestDemo, SendMessageTest002, TestSize.Level1) { - std::string command = "query_command"; - std::string cmdArgs = "query a name?"; - std::string expectValue = "111"; - RunCmdOnAgent(AGENT_NO::ONE, command, cmdArgs, expectValue); - EXPECT_EQ(GetReturnVal(), EXPECT_RETURN_VALUE); -}; + char msgbuf[MSG_LENGTH] = "I am recall"; + int ret = SendMessage(AGENT_NO::ONE, msgbuf,MSG_LENGTH,[&](const std::string &szreturnbuf, int rlen)->bool{ + std::string szbuf = "ok"; + //EXPECT_TRUE(szbuf == szreturnbuf)<<"字符串是相等的"; + HiLog::Info(LABEL, "SendMessageTest002 = %s",szbuf.c_str()); + return true; + }); + + if(ret == 0) + { + EXPECT_TRUE(1)<<"ret = 0"; + } +} -/** - * @tc.name: runcmdonagent_002 - * @tc.desc: Verify the distributed test framework interface RunCmdOnAgent, Using command map. - * @tc.type: FUNC - * @tc.require: AR000CQGMV - */ -HWTEST_F(DistributeDemo, runcmdonagent_002, TestSize.Level0) { - std::string command = "add_for_two_int"; - std::string cmdArgs = "200 300"; - std::string expectValue = "500"; - RunCmdOnAgent(AGENT_NO::ONE, command, cmdArgs, expectValue); - EXPECT_EQ(GetReturnVal(), EXPECT_ADD_TEST_SUM); -}; +HWTEST_F(DistributedtestDemo, SendMessageTest003, TestSize.Level1) +{ + char msgbuf[MSG_LENGTH] = "I am testcase 2"; + int ret = SendMessage(AGENT_NO::ONE, msgbuf, MSG_LENGTH); + if(ret == 0) + { + EXPECT_FALSE(ret)<<"ret = 0"; + } + +} -/** - * @tc.name: getkvstore_001 - * @tc.desc: Verify distributed data read and write and synchronization. - * @tc.type: FUNC - * @tc.require: AR000CQGMV - */ -HWTEST_F(DistributeDemo, getkvstore_001, TestSize.Level0) { - /** - * @tc.steps: step1.init appkvstore, Get the kvstore pointer for the specified appId and storeId - */ - static std::shared_ptr manager; - Options options; - options.createIfMissing = true; - options.encrypt = false; - options.persistent = true; - std::string appId = "com.ohos.nb.service.user1_test"; - std::string storeId = "student_1"; - manager = AppDistributedKvDataManager::GetInstance(appId, "/data/test"); - std::unique_ptr kvStorePtr; - Status status = manager->GetKvStore(options, storeId, [&](std::unique_ptr kvStore) { - kvStorePtr = std::move(kvStore); - }); - if (!kvStorePtr) { - HiLog::Error(LABEL, "client get kvStorePtr error."); - } - - ASSERT_TRUE(kvStorePtr != nullptr); - - /** - * @tc.steps: step2.Write specific K and V values to the database - */ - if (status == Status::SUCCESS) { - WriteOptions writeOptions; - writeOptions.local = false; - Key key("student_name_user1"); - Value value = "good boy."; - kvStorePtr->Put(writeOptions, key, value); - } - - /** - * @tc.steps: step3.Synchronize data to a specific remote device - */ - std::vector deviceIdList; - deviceIdList.push_back("192.168.43.200"); - std::map sync_map; - Status syncinfo = kvStorePtr->Sync(deviceIdList, SyncMode::PUSH, - [&](const std::map &syncMapinfo){ - sync_map = std::move(syncMapinfo); - }); - if (syncinfo == Status::SUCCESS) { - HiLog::Info(LABEL, "agent sync success"); - } - - /** - * @tc.steps: step4.Judge if the data is successfully synchronized to the remote device - */ - int n = 0; - while (n < SYNC_REC_TIME) { - std::string id = ""; - for (auto mapstatus: sync_map) { - HiLog::Info(LABEL, "client map_id==%s", mapstatus.first.c_str()); - if (mapstatus.second == Status::SUCCESS) { - id = mapstatus.first; - HiLog::Info(LABEL, "real client Sync success."); - } else { - HiLog::Info(LABEL, "mapstatus.second=%d.", (int)mapstatus.second); - } - n++; - } - if (id != "") { - break; - } - usleep(SLEEP_TIME); - } - if (syncinfo == Status::SUCCESS) { - HiLog::Info(LABEL, "client sync success."); - } - - /** - * @tc.steps: step5.Query whether the value inserted in the local database is correct - */ - std::string command = "getkvstore"; - std::string cmdArgs = "student_name_user1"; - std::string expectValue = "good boy."; - ReadOptions readOptions; - readOptions.local = false; - Key key(cmdArgs); - Value getValue; - Status getTstatus = kvStorePtr->Get(readOptions, key, getValue); - if (getTstatus == Status::SUCCESS) { - HiLog::Info(LABEL, "Get Value SUCCESS, key=%s.", key.ToString().c_str()); - } else { - HiLog::Error(LABEL, "Get Value Failed."); - } - - /** - * @tc.steps: step6.Send a command to the remote device to query the database with parameters and - * expected return values - */ - RunCmdOnAgent(AGENT_NO::ONE, command, cmdArgs, expectValue); - - /** - * @tc.steps: step7.Judge the return value - * @tc.expected: step7. The remote device queried the data successfully. - */ - EXPECT_TRUE(GetReturnVal() == EXPECT_RETURN_VALUE); -}; -int main(int argc, char *argv[]) +HWTEST_F(DistributedtestDemo, RunCmdOnAgent001, TestSize.Level1) { - g_pDistributetestEnv = new DistributeTestEnvironment("major.desc"); - testing::AddGlobalTestEnvironment(g_pDistributetestEnv); - testing::GTEST_FLAG(output) = "xml:./"; - testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + std::string command = "query_command"; + std::string cmdArgs = "query a name?"; + std::string expectValue = "111"; + RunCmdOnAgent(AGENT_NO::ONE, command, cmdArgs, expectValue); + EXPECT_EQ(GetReturnVal(), EXPECT_RETURN_VALUE); } + +int main(int argc, char*argv[]) +{ + g_pDistributetestEnv = new DistributeTestEnvironment("major.desc"); + testing::AddGlobalTestEnvironment(g_pDistributetestEnv); + testing::GTEST_FLAG(output) = "xml:./"; + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} \ No newline at end of file diff --git a/examples/distributedb/test/distributedtest/common/distribute_demo_agent.cpp b/examples/distributedb/test/distributedtest/common/distribute_demo_agent.cpp index 50886b9..a0c7e26 100644 --- a/examples/distributedb/test/distributedtest/common/distribute_demo_agent.cpp +++ b/examples/distributedb/test/distributedtest/common/distribute_demo_agent.cpp @@ -18,225 +18,142 @@ #include #include -#include "app_types.h" #include "refbase.h" -#include "app_kvstore.h" -#include "app_distributed_kv_data_manager.h" #include "hilog/log.h" using namespace testing; using namespace OHOS; using namespace OHOS::DistributeSystemTest; using namespace OHOS::HiviewDFX; -using namespace OHOS::AppDistributedKv; - -namespace { - constexpr HiLogLabel LABEL = {LOG_CORE, 0, "DistributeDemoAgent"}; - std::shared_ptr g_manager; - std::string g_appId = "com.ohos.nb.service.user1_test"; - std::string g_storeId = "student_1"; - std::unique_ptr g_kvStorePtr; - const int CMD_LEN = 4; - const int RETURN_HALF = 2; - const int MSG_CALL_LEN = 6; - const int CMD_RETURN_TWO = 111; + +namespace{ + constexpr HiLogLabel LABEL = {LOG_CORE, 0, "DistributedtestDemoAgent"}; + + std::string g_appId = "com.ohos.nb.service.user1_test"; + std::string g_storeId = "student_1"; + + const int CMD_RETURN_TWO = 111; } -class DistributeDemoAgent : public DistributedAgent { -public: - DistributeDemoAgent(); - ~DistributeDemoAgent(); - - virtual bool SetUp(); - virtual bool TearDown(); - virtual int OnProcessMsg(const std::string &strMsg, int len, std::string &strReturnValue, int returnBufLen); - virtual int OnProcessCmd(const std::string &strCommand, int cmdLen, const std::string &strArgs, int argsLen, - const std::string &strExpectValue, int expectValueLen); - - int GetKvValue(const std::string &strArgs, int argsLen, const std::string &strExpectValue, - int expectValueLen); - int AddTwoValue(const std::string &strArgs, int argsLen, const std::string &strExpectValue, - int expectValueLen); - int ProcessByUseMap(const std::string &strCommand, int cmdLen, const std::string &strArgs, int argsLen, - const std::string &strExpectValue, int expectValueLen); - -private: - typedef int (DistributeDemoAgent::*self_func)(const std::string &, int, const std::string &, int); - std::map cmdFunMap_; +class DistributedtestDemoAgent:public DistributedAgent{ +public: + DistributedtestDemoAgent(); + ~DistributedtestDemoAgent(); + + virtual bool SetUp(); + virtual bool TearDown(); + + virtual int OnProcessMsg(const std::string &dtrMsg, int len, std::string &strReturnValue, int returnBufLen); + virtual int OnProcessCmd(const std::string &strCommand, int cmdLen, const std::string &strArgs, int argsLen, + const std::string &strExpectValue, int expectValueLen); + + int GetKvValue(const std::string &strArgs, int argsLen, const std::string &strExpectValue, + int expectValueLen); + + int AddTwoValue(const std::string &strArgs, int argsLen, const std::string &strExpectValue, + int expectValueLen); + int ProcessByUseMap(const std::string &strCommand, int cmdLen, const std::string &strArgs, int argsLen, + const std::string &strExpectValue, int expectValueLen); }; -DistributeDemoAgent::DistributeDemoAgent() -{ -} -DistributeDemoAgent::~DistributeDemoAgent() -{ +DistributedtestDemoAgent::DistributedtestDemoAgent(){ + } -bool DistributeDemoAgent::SetUp() +DistributedtestDemoAgent::~DistributedtestDemoAgent(){} + + +bool DistributedtestDemoAgent::SetUp() { - /** - * @tc.setup: Initialize test agent, start data management service - */ - cmdFunMap_["getkvstore"] = &DistributeDemoAgent::GetKvValue; - cmdFunMap_["add_for_two_int"] = &DistributeDemoAgent::AddTwoValue; - g_manager = AppDistributedKvDataManager::GetInstance(g_appId, "/data/test"); - Options options; - options.createIfMissing = true; - options.encrypt = false; - options.persistent = true; - std::string storeId = g_storeId; - Status status = g_manager->GetKvStore(options, storeId, [&](std::unique_ptr kvStore) { - g_kvStorePtr = std::move(kvStore); - }); - if (status == Status::SUCCESS) { - return true; - } - return false; + return true; } -bool DistributeDemoAgent::TearDown() +bool DistributedtestDemoAgent::TearDown() { - /** - * @tc.teardown: Recovery test agent device environment - */ - return true; + /** + *@tc.teardown:Recovery test agent device environment + */ + return true; } // The entry of handlingthe major test case message -int DistributeDemoAgent::OnProcessMsg(const std::string &strMsg, int len, - std::string &strReturnValue, int returnBufLen) +int DistributedtestDemoAgent::OnProcessMsg(const std::string &strMsg, int len, std::string &strReturnValue, int returnValueLen) { - int nret = 0; - std::string returnStr = "agent return message."; - if ((len > CMD_LEN) && (strMsg.find("\0\1\0\1") == 1)) { - for (int i = 0; i < returnBufLen; i++) { - strReturnValue += std::to_string((i + 1) % RETURN_HALF); - } - nret = returnBufLen; - } else { - HiLog::Info(LABEL, "receive message=%s.", strMsg.c_str()); - if (!strncmp(strMsg.c_str(), "recall", MSG_CALL_LEN)) { - returnStr = "I get recall message."; - int ptrlen = returnStr.size(); - if (ptrlen > returnBufLen) { - ptrlen = returnBufLen - 1; - } - strReturnValue = returnStr; - nret = ptrlen; - } else { - nret = DistributedAgent::OnProcessMsg(strMsg, len, strReturnValue, returnBufLen); - } - } - return nret; + + + int nret = 0; + //std::string returnStr = "agent return message."; + std::string strrq = "I am recall"; + if(strstr(strMsg.c_str(),strrq.c_str())) + { + strReturnValue = "ok"; + nret = 5; + return nret; + } + std::string strrq = "I am testcase2"; + if(strstr(strMsg.c_str(), strrq.c_str())) + { + HiLog::Info(LABEL, "I am testcase2"); + nret = 7; + return nret; + } + else + { + //return DistributedAgent::OnProcessMsg(strMsg, len, strReturnValue, returnValueLen); + nret = 2; + return nret; + } } -// The entry of handling the major test case command -int DistributeDemoAgent::OnProcessCmd(const std::string &strCommand, int cmdLen, const std::string &strArgs, - int argsLen, const std::string &strExpectValue, int expectValueLen) -{ - if (strCommand == "query_command") { - if (strArgs == "query a name?") { - return CMD_RETURN_TWO; - } - } - return DistributeDemoAgent::ProcessByUseMap(strCommand, cmdLen, strArgs, argsLen, strExpectValue, expectValueLen); -} -// Handling major test case command: getkvstore -int DistributeDemoAgent::GetKvValue(const std::string &strArgs, int argsLen, const std::string &strExpectValue, - int expectValueLen) +int DistributedtestDemoAgent::OnProcessCmd(const std::string &strCommand, int cmdLen, const std::string &strArgs, int argsLen, + const std::string &strExpectValue, int expectValueLen) { - if (!g_kvStorePtr || (int)strArgs.length() > argsLen) { - HiLog::Error(LABEL, "[ohos-test-fm]agent ERROR."); - return -1; - } - ReadOptions readOptions; - readOptions.local = false; - Key key(strArgs); - Value getValue; - Status status = g_kvStorePtr->Get(readOptions, key, getValue); - if (status == Status::SUCCESS) { - HiLog::Info(LABEL, "Get Value SUCCESS, key=%s.", key.ToString().c_str()); - } else { - HiLog::Error(LABEL, "Get Value Failed."); - } - std::vector allEntry; - Status entryStatus = g_kvStorePtr->GetEntries("", allEntry); - if (entryStatus == Status::SUCCESS) { - HiLog::Info(LABEL, "GetEntries SUCCESS."); - for (auto entry : allEntry) { - HiLog::Info(LABEL, "GetEntries key= %s.", entry.key.ToString().c_str()); - } - } - if (getValue.ToString() == strExpectValue) { - if (expectValueLen < (int)getValue.ToString().length()) { - HiLog::Error(LABEL, "[ohos-test-fm]agent end xxx."); - return -1; - } - HiLog::Error(LABEL, "[ohos-test-fm]agent end 200."); - return CMD_RETURN_TWO; - } - return -1; + if(strCommand == "query_command"){ + if(strArgs == "query a name?"){ + return CMD_RETURN_TWO; + } + } + return DistributedAgent::OnProcessCmd(strCommand, cmdLen, strArgs, argsLen, strExpectValue, expectValueLen); } -// Handling major test case command: add_for_two_int -int DistributeDemoAgent::AddTwoValue(const std::string &strArgs, int argsLen, const std::string &strExpectValue, - int expectValueLen) +int main() { - int val1 = 0; - int val2 = 0; - int val3 = 0; - int ret1; - int ret2; - ret1 = sscanf_s(strArgs.c_str(), "%d %d", &val1, &val2); - if (ret1 <=0 || ret1 == 1) { - HiLog::Error(LABEL, "sscanf_s failed. ret1 != 2"); - return -1; - } - ret2 = sscanf_s(strExpectValue.c_str(), "%d", &val3); - if (ret2 != 1) { - HiLog::Error(LABEL, "sscanf_s failed. ret2 != 1"); - return -1; - } - EXPECT_TRUE(val3 == (val1 + val2)); - return val1 + val2; + //Test agent main function + + DistributedtestDemoAgent obj; + if(obj.SetUp()){ + obj.Start("agent.desc"); + obj.Join(); + }else{ + HiLog::Error(LABEL, "Init environment failed."); + } + + if(obj.TearDown()){ + return 0; + }else{ + HiLog::Error(LABEL, "Clear environment failed."); + return -1; + } } -// Handling major test cases through already registered commands and function mappings -int DistributeDemoAgent::ProcessByUseMap(const std::string &strCommand, int cmdLen, const std::string &strArgs, - int argsLen, const std::string &strExpectValue, int expectValueLen) -{ - std::map::iterator ite = cmdFunMap_.find(strCommand); - if (ite != cmdFunMap_.end()) { - self_func callProcCmd = cmdFunMap_[strCommand]; - if (callProcCmd != nullptr) { - return (this->*callProcCmd)(strArgs, argsLen, strExpectValue, expectValueLen); - } else { - return DistributedAgent::OnProcessCmd(strCommand, - cmdLen, - strArgs, - argsLen, - strExpectValue, - expectValueLen); - } - } - return -1; -} -int main() -{ - // Test agent main function - DistributeDemoAgent obj; - if (obj.SetUp()) { - obj.Start("agent.desc"); - obj.Join(); - } else { - HiLog::Error(LABEL, "Init environment failed."); - } - if (obj.TearDown()) { - return 0; - } else { - HiLog::Error(LABEL, "Clear environment failed."); - return -1; - } -} \ No newline at end of file + + + + + + + + + + + + + + + + + + + -- Gitee From e02356a07c24c12cd9f1f678850581c67367b7a7 Mon Sep 17 00:00:00 2001 From: caojiale1 Date: Mon, 29 May 2023 03:26:39 +0000 Subject: [PATCH 02/14] Signed-off-by: caojiale1 Signed-off-by: caojiale1 --- .../common/distribute_demo.cpp | 101 +++++++------- .../common/distribute_demo_agent.cpp | 129 ++++++++---------- 2 files changed, 107 insertions(+), 123 deletions(-) diff --git a/examples/distributedb/test/distributedtest/common/distribute_demo.cpp b/examples/distributedb/test/distributedtest/common/distribute_demo.cpp index 5088f23..d461b06 100644 --- a/examples/distributedb/test/distributedtest/common/distribute_demo.cpp +++ b/examples/distributedb/test/distributedtest/common/distribute_demo.cpp @@ -26,25 +26,24 @@ using namespace testing::ext; using namespace OHOS::DistributeSystemTest; using namespace OHOS::HiviewDFX; -namespace{ - constexpr HiLogLabel LABEL={LOG_CORE,0,"DistributedtestDemo"}; +namespace +{ + constexpr HiLogLabel LABEL={LOG_CORE,0,"DistributedtestDemo"}; // const int SYNC_REC_TIME = 3; - - const int MSG_LENGTH = 100; - const int EXPECT_RETURN_VALUE = 111; - // const int EXPECT_ADD_TEST_SUM = 500; - // const int SLEEP_TIME = 100000; + + const int MSG_LENGTH = 100; + const int EXPECT_RETURN_VALUE = 111; } class DistributedtestDemo:public DistributeTest{ public: - DistributedtestDemo() = default; - ~DistributedtestDemo() = default; - - static void SetUpTestCase(); - static void TearDownTestCase(); - virtual void SetUp(); - virtual void TearDown(); + DistributedtestDemo() = default; + ~DistributedtestDemo() = default; + + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp(); + virtual void TearDown(); }; void DistributedtestDemo::SetUpTestCase() @@ -68,66 +67,66 @@ void DistributedtestDemo::TearDown() } /* -*@tc.name:SendMessageTest001 -*@tc.desc:Verify the distributed test framework interface SendMessage. -*@tc.type:FUNC -*@tc.require:ArOOOCQGMV +* @tc.name:SendMessageTest001 +* @tc.desc:Verify the distributed test framework interface SendMessage. +* @tc.type:FUNC +* @tc.require:ArOOOCQGMV */ HWTEST_F(DistributedtestDemo, SendMessageTest001,TestSize.Level1) { - char msgbuf[MSG_LENGTH] = "I am testcase 1"; - int ret = SendMessage(AGENT_NO::ONE,msgbuf,MSG_LENGTH); - - //EXPECT_TRUE(ret)<<"ret = 0"; - if(ret == 0) - { - EXPECT_FALSE(ret)<<"ret = 2"; + char msgbuf[MSG_LENGTH] = "I am testcase 1"; + int ret = SendMessage(AGENT_NO::ONE,msgbuf,MSG_LENGTH); + + // EXPECT_TRUE(ret)<<"ret = 0"; + if(ret == 0) + { + EXPECT_FALSE(ret)<<"ret = 2"; } } HWTEST_F(DistributedtestDemo, SendMessageTest002, TestSize.Level1) { - char msgbuf[MSG_LENGTH] = "I am recall"; - int ret = SendMessage(AGENT_NO::ONE, msgbuf,MSG_LENGTH,[&](const std::string &szreturnbuf, int rlen)->bool{ - std::string szbuf = "ok"; - //EXPECT_TRUE(szbuf == szreturnbuf)<<"字符串是相等的"; - HiLog::Info(LABEL, "SendMessageTest002 = %s",szbuf.c_str()); - return true; + char msgbuf[MSG_LENGTH] = "I am recall"; + int ret = SendMessage(AGENT_NO::ONE, msgbuf,MSG_LENGTH,[&](const std::string &szreturnbuf, int rlen)->bool{ + std::string szbuf = "ok"; + // EXPECT_TRUE(szbuf == szreturnbuf)<<"字符串是相等的"; + HiLog::Info(LABEL, "SendMessageTest002 = %s",szbuf.c_str()); + return true; }); - if(ret == 0) - { - EXPECT_TRUE(1)<<"ret = 0"; - } + if(ret == 0) + { + EXPECT_TRUE(1)<<"ret = 0"; + } } HWTEST_F(DistributedtestDemo, SendMessageTest003, TestSize.Level1) { - char msgbuf[MSG_LENGTH] = "I am testcase 2"; - int ret = SendMessage(AGENT_NO::ONE, msgbuf, MSG_LENGTH); - if(ret == 0) - { - EXPECT_FALSE(ret)<<"ret = 0"; - } + char msgbuf[MSG_LENGTH] = "I am testcase 2"; + int ret = SendMessage(AGENT_NO::ONE, msgbuf, MSG_LENGTH); + if(ret == 0) + { + EXPECT_FALSE(ret)<<"ret = 0"; + } } HWTEST_F(DistributedtestDemo, RunCmdOnAgent001, TestSize.Level1) { - std::string command = "query_command"; - std::string cmdArgs = "query a name?"; - std::string expectValue = "111"; - RunCmdOnAgent(AGENT_NO::ONE, command, cmdArgs, expectValue); - EXPECT_EQ(GetReturnVal(), EXPECT_RETURN_VALUE); + std::string command = "query_command"; + std::string cmdArgs = "query a name?"; + std::string expectValue = "111"; + RunCmdOnAgent(AGENT_NO::ONE, command, cmdArgs, expectValue); + EXPECT_EQ(GetReturnVal(), EXPECT_RETURN_VALUE); } int main(int argc, char*argv[]) { - g_pDistributetestEnv = new DistributeTestEnvironment("major.desc"); - testing::AddGlobalTestEnvironment(g_pDistributetestEnv); - testing::GTEST_FLAG(output) = "xml:./"; - testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + g_pDistributetestEnv = new DistributeTestEnvironment("major.desc"); + testing::AddGlobalTestEnvironment(g_pDistributetestEnv); + testing::GTEST_FLAG(output) = "xml:./"; + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); } \ No newline at end of file diff --git a/examples/distributedb/test/distributedtest/common/distribute_demo_agent.cpp b/examples/distributedb/test/distributedtest/common/distribute_demo_agent.cpp index a0c7e26..0a67241 100644 --- a/examples/distributedb/test/distributedtest/common/distribute_demo_agent.cpp +++ b/examples/distributedb/test/distributedtest/common/distribute_demo_agent.cpp @@ -26,82 +26,79 @@ using namespace OHOS; using namespace OHOS::DistributeSystemTest; using namespace OHOS::HiviewDFX; -namespace{ - constexpr HiLogLabel LABEL = {LOG_CORE, 0, "DistributedtestDemoAgent"}; +namespace +{ + constexpr HiLogLabel LABEL = {LOG_CORE, 0, "DistributedtestDemoAgent"}; - std::string g_appId = "com.ohos.nb.service.user1_test"; - std::string g_storeId = "student_1"; + std::string g_appId = "com.ohos.nb.service.user1_test"; + std::string g_storeId = "student_1"; - const int CMD_RETURN_TWO = 111; + const int CMD_RETURN_TWO = 111; } class DistributedtestDemoAgent:public DistributedAgent{ public: - DistributedtestDemoAgent(); - ~DistributedtestDemoAgent(); + DistributedtestDemoAgent(); + ~DistributedtestDemoAgent(); - virtual bool SetUp(); - virtual bool TearDown(); + virtual bool SetUp(); + virtual bool TearDown(); - virtual int OnProcessMsg(const std::string &dtrMsg, int len, std::string &strReturnValue, int returnBufLen); - virtual int OnProcessCmd(const std::string &strCommand, int cmdLen, const std::string &strArgs, int argsLen, - const std::string &strExpectValue, int expectValueLen); + virtual int OnProcessMsg(const std::string &dtrMsg, int len, std::string &strReturnValue, int returnBufLen); + virtual int OnProcessCmd(const std::string &strCommand, int cmdLen, const std::string &strArgs, int argsLen, + const std::string &strExpectValue, int expectValueLen); - int GetKvValue(const std::string &strArgs, int argsLen, const std::string &strExpectValue, - int expectValueLen); + int GetKvValue(const std::string &strArgs, int argsLen, const std::string &strExpectValue, + int expectValueLen); - int AddTwoValue(const std::string &strArgs, int argsLen, const std::string &strExpectValue, + int AddTwoValue(const std::string &strArgs, int argsLen, const std::string &strExpectValue, int expectValueLen); - int ProcessByUseMap(const std::string &strCommand, int cmdLen, const std::string &strArgs, int argsLen, + int ProcessByUseMap(const std::string &strCommand, int cmdLen, const std::string &strArgs, int argsLen, const std::string &strExpectValue, int expectValueLen); }; -DistributedtestDemoAgent::DistributedtestDemoAgent(){ +DistributedtestDemoAgent::DistributedtestDemoAgent() +{ } -DistributedtestDemoAgent::~DistributedtestDemoAgent(){} +DistributedtestDemoAgent::~DistributedtestDemoAgent() +{ + +} bool DistributedtestDemoAgent::SetUp() { - return true; + return true; } bool DistributedtestDemoAgent::TearDown() { - /** - *@tc.teardown:Recovery test agent device environment + /* + * @tc.teardown:Recovery test agent device environment */ - return true; + return true; } // The entry of handlingthe major test case message int DistributedtestDemoAgent::OnProcessMsg(const std::string &strMsg, int len, std::string &strReturnValue, int returnValueLen) { - - - int nret = 0; - //std::string returnStr = "agent return message."; - std::string strrq = "I am recall"; - if(strstr(strMsg.c_str(),strrq.c_str())) - { - strReturnValue = "ok"; - nret = 5; - return nret; - } - std::string strrq = "I am testcase2"; - if(strstr(strMsg.c_str(), strrq.c_str())) - { - HiLog::Info(LABEL, "I am testcase2"); - nret = 7; - return nret; - } - else - { - //return DistributedAgent::OnProcessMsg(strMsg, len, strReturnValue, returnValueLen); - nret = 2; - return nret; + std::string returnStr = "agent return message."; + std::string strrq = "I am recall"; + if(strstr(strMsg.c_str(),strrq.c_str())) + { + strReturnValue = "ok"; + return strReturnValue; + } + std::string strrq = "I am testcase2"; + if(strstr(strMsg.c_str(), strrq.c_str())) + { + HiLog::Info(LABEL, "I am testcase2"); + } + else + { + return DistributedAgent::OnProcessMsg(strMsg, len, strReturnValue, returnValueLen); } } @@ -109,8 +106,10 @@ int DistributedtestDemoAgent::OnProcessMsg(const std::string &strMsg, int len, s int DistributedtestDemoAgent::OnProcessCmd(const std::string &strCommand, int cmdLen, const std::string &strArgs, int argsLen, const std::string &strExpectValue, int expectValueLen) { - if(strCommand == "query_command"){ - if(strArgs == "query a name?"){ + if(strCommand == "query_command") + { + if(strArgs == "query a name?") + { return CMD_RETURN_TWO; } } @@ -119,41 +118,27 @@ int DistributedtestDemoAgent::OnProcessCmd(const std::string &strCommand, int cm int main() { - //Test agent main function + // Test agent main function DistributedtestDemoAgent obj; - if(obj.SetUp()){ + if(obj.SetUp()) + { obj.Start("agent.desc"); obj.Join(); - }else{ + } + else + { HiLog::Error(LABEL, "Init environment failed."); } - if(obj.TearDown()){ + if(obj.TearDown()) + { return 0; - }else{ + } + else + { HiLog::Error(LABEL, "Clear environment failed."); return -1; } } - - - - - - - - - - - - - - - - - - - - -- Gitee From c82766acb24751e5eef8b7127d25e305db5c6525 Mon Sep 17 00:00:00 2001 From: caojiale1 Date: Mon, 29 May 2023 06:44:39 +0000 Subject: [PATCH 03/14] Signed-off-by: caojiale1 Signed-off-by: caojiale1 --- .../common/distribute_demo.cpp | 84 +++++++++---------- .../common/distribute_demo_agent.cpp | 81 +++++++++--------- 2 files changed, 83 insertions(+), 82 deletions(-) diff --git a/examples/distributedb/test/distributedtest/common/distribute_demo.cpp b/examples/distributedb/test/distributedtest/common/distribute_demo.cpp index d461b06..8123ab1 100644 --- a/examples/distributedb/test/distributedtest/common/distribute_demo.cpp +++ b/examples/distributedb/test/distributedtest/common/distribute_demo.cpp @@ -28,22 +28,22 @@ using namespace OHOS::HiviewDFX; namespace { - constexpr HiLogLabel LABEL={LOG_CORE,0,"DistributedtestDemo"}; - // const int SYNC_REC_TIME = 3; + constexpr HiLogLabel LABEL={LOG_CORE,0,"DistributedtestDemo"}; - const int MSG_LENGTH = 100; - const int EXPECT_RETURN_VALUE = 111; + const int MSG_LENGTH = 100; + const int EXPECT_RETURN_VALUE = 111; } -class DistributedtestDemo:public DistributeTest{ +class DistributedtestDemo:public DistributeTest +{ public: - DistributedtestDemo() = default; - ~DistributedtestDemo() = default; + DistributedtestDemo() = default; + ~DistributedtestDemo() = default; - static void SetUpTestCase(); - static void TearDownTestCase(); - virtual void SetUp(); - virtual void TearDown(); + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp(); + virtual void TearDown(); }; void DistributedtestDemo::SetUpTestCase() @@ -74,59 +74,57 @@ void DistributedtestDemo::TearDown() */ HWTEST_F(DistributedtestDemo, SendMessageTest001,TestSize.Level1) { - char msgbuf[MSG_LENGTH] = "I am testcase 1"; - int ret = SendMessage(AGENT_NO::ONE,msgbuf,MSG_LENGTH); + char msgbuf[MSG_LENGTH] = "I am testcase 1"; + int ret = SendMessage(AGENT_NO::ONE,msgbuf,MSG_LENGTH); - // EXPECT_TRUE(ret)<<"ret = 0"; - if(ret == 0) - { - EXPECT_FALSE(ret)<<"ret = 2"; + if(ret == 0) + { + EXPECT_FALSE(ret)<<"ret = 2"; } } HWTEST_F(DistributedtestDemo, SendMessageTest002, TestSize.Level1) { - char msgbuf[MSG_LENGTH] = "I am recall"; - int ret = SendMessage(AGENT_NO::ONE, msgbuf,MSG_LENGTH,[&](const std::string &szreturnbuf, int rlen)->bool{ - std::string szbuf = "ok"; - // EXPECT_TRUE(szbuf == szreturnbuf)<<"字符串是相等的"; - HiLog::Info(LABEL, "SendMessageTest002 = %s",szbuf.c_str()); - return true; + char msgbuf[MSG_LENGTH] = "I am recall"; + int ret = SendMessage(AGENT_NO::ONE, msgbuf,MSG_LENGTH,[&](const std::string &szreturnbuf, int rlen)->bool{ + std::string szbuf = "ok"; + HiLog::Info(LABEL, "SendMessageTest002 = %s",szbuf.c_str()); + return true; }); - if(ret == 0) - { - EXPECT_TRUE(1)<<"ret = 0"; - } + if(ret == 0) + { + EXPECT_TRUE(1)<<"ret = 0"; + } } HWTEST_F(DistributedtestDemo, SendMessageTest003, TestSize.Level1) { - char msgbuf[MSG_LENGTH] = "I am testcase 2"; - int ret = SendMessage(AGENT_NO::ONE, msgbuf, MSG_LENGTH); - if(ret == 0) - { - EXPECT_FALSE(ret)<<"ret = 0"; - } + char msgbuf[MSG_LENGTH] = "I am testcase 2"; + int ret = SendMessage(AGENT_NO::ONE, msgbuf, MSG_LENGTH); + if(ret == 0) + { + EXPECT_FALSE(ret)<<"ret = 0"; + } } HWTEST_F(DistributedtestDemo, RunCmdOnAgent001, TestSize.Level1) { - std::string command = "query_command"; - std::string cmdArgs = "query a name?"; - std::string expectValue = "111"; - RunCmdOnAgent(AGENT_NO::ONE, command, cmdArgs, expectValue); - EXPECT_EQ(GetReturnVal(), EXPECT_RETURN_VALUE); + std::string command = "query_command"; + std::string cmdArgs = "query a name?"; + std::string expectValue = "111"; + RunCmdOnAgent(AGENT_NO::ONE, command, cmdArgs, expectValue); + EXPECT_EQ(GetReturnVal(), EXPECT_RETURN_VALUE); } int main(int argc, char*argv[]) { - g_pDistributetestEnv = new DistributeTestEnvironment("major.desc"); - testing::AddGlobalTestEnvironment(g_pDistributetestEnv); - testing::GTEST_FLAG(output) = "xml:./"; - testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + g_pDistributetestEnv = new DistributeTestEnvironment("major.desc"); + testing::AddGlobalTestEnvironment(g_pDistributetestEnv); + testing::GTEST_FLAG(output) = "xml:./"; + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); } \ No newline at end of file diff --git a/examples/distributedb/test/distributedtest/common/distribute_demo_agent.cpp b/examples/distributedb/test/distributedtest/common/distribute_demo_agent.cpp index 0a67241..15f6212 100644 --- a/examples/distributedb/test/distributedtest/common/distribute_demo_agent.cpp +++ b/examples/distributedb/test/distributedtest/common/distribute_demo_agent.cpp @@ -28,29 +28,30 @@ using namespace OHOS::HiviewDFX; namespace { - constexpr HiLogLabel LABEL = {LOG_CORE, 0, "DistributedtestDemoAgent"}; - - std::string g_appId = "com.ohos.nb.service.user1_test"; - std::string g_storeId = "student_1"; - - const int CMD_RETURN_TWO = 111; + constexpr HiLogLabel LABEL = {LOG_CORE, 0, "DistributedtestDemoAgent"}; + + std::string g_appId = "com.ohos.nb.service.user1_test"; + std::string g_storeId = "student_1"; + + const int CMD_RETURN_TWO = 111; } -class DistributedtestDemoAgent:public DistributedAgent{ -public: - DistributedtestDemoAgent(); - ~DistributedtestDemoAgent(); - - virtual bool SetUp(); - virtual bool TearDown(); - +class DistributedtestDemoAgent:public DistributedAgent +{ +public: + DistributedtestDemoAgent(); + ~DistributedtestDemoAgent(); + + virtual bool SetUp(); + virtual bool TearDown(); + virtual int OnProcessMsg(const std::string &dtrMsg, int len, std::string &strReturnValue, int returnBufLen); virtual int OnProcessCmd(const std::string &strCommand, int cmdLen, const std::string &strArgs, int argsLen, - const std::string &strExpectValue, int expectValueLen); - - int GetKvValue(const std::string &strArgs, int argsLen, const std::string &strExpectValue, + const std::string &strExpectValue, int expectValueLen); + + int GetKvValue(const std::string &strArgs, int argsLen, const std::string &strExpectValue, int expectValueLen); - + int AddTwoValue(const std::string &strArgs, int argsLen, const std::string &strExpectValue, int expectValueLen); int ProcessByUseMap(const std::string &strCommand, int cmdLen, const std::string &strArgs, int argsLen, @@ -82,33 +83,35 @@ bool DistributedtestDemoAgent::TearDown() } // The entry of handlingthe major test case message -int DistributedtestDemoAgent::OnProcessMsg(const std::string &strMsg, int len, std::string &strReturnValue, int returnValueLen) +void DistributedtestDemoAgent::OnProcessMsg(const std::string &strMsg, int len, std::string &strReturnValue, int returnValueLen) { - std::string returnStr = "agent return message."; - std::string strrq = "I am recall"; - if(strstr(strMsg.c_str(),strrq.c_str())) - { - strReturnValue = "ok"; - return strReturnValue; - } - std::string strrq = "I am testcase2"; - if(strstr(strMsg.c_str(), strrq.c_str())) - { - HiLog::Info(LABEL, "I am testcase2"); - } - else - { - return DistributedAgent::OnProcessMsg(strMsg, len, strReturnValue, returnValueLen); + + + std::string returnStr = "agent return message."; + std::string strrq = "I am recall"; + if(strstr(strMsg.c_str(),strrq.c_str())) + { + strReturnValue = "ok"; + return strReturnValue; + } + std::string strrq = "I am testcase2"; + if(strstr(strMsg.c_str(), strrq.c_str())) + { + HiLog::Info(LABEL, "I am testcase2"); + } + else + { + return DistributedAgent::OnProcessMsg(strMsg, len, strReturnValue, returnValueLen); } } -int DistributedtestDemoAgent::OnProcessCmd(const std::string &strCommand, int cmdLen, const std::string &strArgs, int argsLen, +void DistributedtestDemoAgent::OnProcessCmd(const std::string &strCommand, int cmdLen, const std::string &strArgs, int argsLen, const std::string &strExpectValue, int expectValueLen) { - if(strCommand == "query_command") + if(strCommand == "query_command") { - if(strArgs == "query a name?") + if(strArgs == "query a name?") { return CMD_RETURN_TWO; } @@ -119,7 +122,7 @@ int DistributedtestDemoAgent::OnProcessCmd(const std::string &strCommand, int cm int main() { // Test agent main function - + DistributedtestDemoAgent obj; if(obj.SetUp()) { @@ -130,7 +133,7 @@ int main() { HiLog::Error(LABEL, "Init environment failed."); } - + if(obj.TearDown()) { return 0; -- Gitee From 8750127389ea59dcb7bcff7d5a778bee6170b47c Mon Sep 17 00:00:00 2001 From: caojiale1 Date: Mon, 29 May 2023 07:06:05 +0000 Subject: [PATCH 04/14] Signed-off-by: caojiale1 Signed-off-by: caojiale1 --- .../common/distribute_demo.cpp | 50 +++++-------- .../common/distribute_demo_agent.cpp | 73 +++++++++---------- 2 files changed, 55 insertions(+), 68 deletions(-) diff --git a/examples/distributedb/test/distributedtest/common/distribute_demo.cpp b/examples/distributedb/test/distributedtest/common/distribute_demo.cpp index 8123ab1..d65f00a 100644 --- a/examples/distributedb/test/distributedtest/common/distribute_demo.cpp +++ b/examples/distributedb/test/distributedtest/common/distribute_demo.cpp @@ -40,32 +40,25 @@ public: DistributedtestDemo() = default; ~DistributedtestDemo() = default; - static void SetUpTestCase(); - static void TearDownTestCase(); - virtual void SetUp(); - virtual void TearDown(); + static void SetUpTestCase(){}; + static void TearDownTestCase(){}; + virtual void SetUp(){}; + virtual void TearDown(){}; }; void DistributedtestDemo::SetUpTestCase() { - } - void DistributedtestDemo::TearDownTestCase() { - } void DistributedtestDemo::SetUp() { - } - void DistributedtestDemo::TearDown() { - } - /* * @tc.name:SendMessageTest001 * @tc.desc:Verify the distributed test framework interface SendMessage. @@ -92,7 +85,6 @@ HWTEST_F(DistributedtestDemo, SendMessageTest002, TestSize.Level1) HiLog::Info(LABEL, "SendMessageTest002 = %s",szbuf.c_str()); return true; }); - if(ret == 0) { EXPECT_TRUE(1)<<"ret = 0"; @@ -101,30 +93,28 @@ HWTEST_F(DistributedtestDemo, SendMessageTest002, TestSize.Level1) HWTEST_F(DistributedtestDemo, SendMessageTest003, TestSize.Level1) { - char msgbuf[MSG_LENGTH] = "I am testcase 2"; - int ret = SendMessage(AGENT_NO::ONE, msgbuf, MSG_LENGTH); - if(ret == 0) - { - EXPECT_FALSE(ret)<<"ret = 0"; - } - + char msgbuf[MSG_LENGTH] = "I am testcase 2"; + int ret = SendMessage(AGENT_NO::ONE, msgbuf, MSG_LENGTH); + if(ret == 0) + { + EXPECT_FALSE(ret)<<"ret = 0"; + } } - HWTEST_F(DistributedtestDemo, RunCmdOnAgent001, TestSize.Level1) { - std::string command = "query_command"; - std::string cmdArgs = "query a name?"; - std::string expectValue = "111"; - RunCmdOnAgent(AGENT_NO::ONE, command, cmdArgs, expectValue); - EXPECT_EQ(GetReturnVal(), EXPECT_RETURN_VALUE); + std::string command = "query_command"; + std::string cmdArgs = "query a name?"; + std::string expectValue = "111"; + RunCmdOnAgent(AGENT_NO::ONE, command, cmdArgs, expectValue); + EXPECT_EQ(GetReturnVal(), EXPECT_RETURN_VALUE); } int main(int argc, char*argv[]) { - g_pDistributetestEnv = new DistributeTestEnvironment("major.desc"); - testing::AddGlobalTestEnvironment(g_pDistributetestEnv); - testing::GTEST_FLAG(output) = "xml:./"; - testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + g_pDistributetestEnv = new DistributeTestEnvironment("major.desc"); + testing::AddGlobalTestEnvironment(g_pDistributetestEnv); + testing::GTEST_FLAG(output) = "xml:./"; + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); } \ No newline at end of file diff --git a/examples/distributedb/test/distributedtest/common/distribute_demo_agent.cpp b/examples/distributedb/test/distributedtest/common/distribute_demo_agent.cpp index 15f6212..b987cb2 100644 --- a/examples/distributedb/test/distributedtest/common/distribute_demo_agent.cpp +++ b/examples/distributedb/test/distributedtest/common/distribute_demo_agent.cpp @@ -28,26 +28,26 @@ using namespace OHOS::HiviewDFX; namespace { - constexpr HiLogLabel LABEL = {LOG_CORE, 0, "DistributedtestDemoAgent"}; + constexpr HiLogLabel LABEL = {LOG_CORE, 0, "DistributedtestDemoAgent"}; - std::string g_appId = "com.ohos.nb.service.user1_test"; - std::string g_storeId = "student_1"; + std::string g_appId = "com.ohos.nb.service.user1_test"; + std::string g_storeId = "student_1"; - const int CMD_RETURN_TWO = 111; + const int CMD_RETURN_TWO = 111; } class DistributedtestDemoAgent:public DistributedAgent { public: - DistributedtestDemoAgent(); - ~DistributedtestDemoAgent(); + DistributedtestDemoAgent(); + ~DistributedtestDemoAgent(); - virtual bool SetUp(); - virtual bool TearDown(); + virtual bool SetUp(); + virtual bool TearDown(); virtual int OnProcessMsg(const std::string &dtrMsg, int len, std::string &strReturnValue, int returnBufLen); virtual int OnProcessCmd(const std::string &strCommand, int cmdLen, const std::string &strArgs, int argsLen, - const std::string &strExpectValue, int expectValueLen); + const std::string &strExpectValue, int expectValueLen); int GetKvValue(const std::string &strArgs, int argsLen, const std::string &strExpectValue, int expectValueLen); @@ -56,19 +56,17 @@ public: int expectValueLen); int ProcessByUseMap(const std::string &strCommand, int cmdLen, const std::string &strArgs, int argsLen, const std::string &strExpectValue, int expectValueLen); +private: + typedef int (DistributeDemoAgent::*self_func)(const std::string &, int, const std::string &, int); + std::map cmdFunMap_; }; DistributedtestDemoAgent::DistributedtestDemoAgent() { - } - DistributedtestDemoAgent::~DistributedtestDemoAgent() { - } - - bool DistributedtestDemoAgent::SetUp() { return true; @@ -83,37 +81,36 @@ bool DistributedtestDemoAgent::TearDown() } // The entry of handlingthe major test case message -void DistributedtestDemoAgent::OnProcessMsg(const std::string &strMsg, int len, std::string &strReturnValue, int returnValueLen) +void DistributedtestDemoAgent::OnProcessMsg(const std::string &strMsg, + int len, std::string &strReturnValue, int returnValueLen) { - - - std::string returnStr = "agent return message."; - std::string strrq = "I am recall"; - if(strstr(strMsg.c_str(),strrq.c_str())) - { - strReturnValue = "ok"; - return strReturnValue; - } - std::string strrq = "I am testcase2"; - if(strstr(strMsg.c_str(), strrq.c_str())) - { - HiLog::Info(LABEL, "I am testcase2"); - } - else - { - return DistributedAgent::OnProcessMsg(strMsg, len, strReturnValue, returnValueLen); - } + std::string returnStr = "agent return message."; + std::string strrq = "I am recall"; + if(strstr(strMsg.c_str(),strrq.c_str())) + { + strReturnValue = "ok"; + return strReturnValue; + } + std::string strrq = "I am testcase2"; + if(strstr(strMsg.c_str(), strrq.c_str())) + { + HiLog::Info(LABEL, "I am testcase2"); + } + else + { + return DistributedAgent::OnProcessMsg(strMsg, len, strReturnValue, returnValueLen); + } } - -void DistributedtestDemoAgent::OnProcessCmd(const std::string &strCommand, int cmdLen, const std::string &strArgs, int argsLen, +void DistributedtestDemoAgent::OnProcessCmd(const std::string &strCommand, + int cmdLen, const std::string &strArgs, int argsLen, const std::string &strExpectValue, int expectValueLen) { - if(strCommand == "query_command") + if(strCommand == "query_command") { - if(strArgs == "query a name?") + if(strArgs == "query a name?") { - return CMD_RETURN_TWO; + return CMD_RETURN_TWO; } } return DistributedAgent::OnProcessCmd(strCommand, cmdLen, strArgs, argsLen, strExpectValue, expectValueLen); -- Gitee From da4af9a35278dc6d8a6ff532a5d49f641da58780 Mon Sep 17 00:00:00 2001 From: caojiale1 Date: Mon, 29 May 2023 07:51:45 +0000 Subject: [PATCH 05/14] Signed-off-by: caojiale1 Signed-off-by: caojiale1 --- .../common/distribute_demo.cpp | 92 +++++++++++-------- .../common/distribute_demo_agent.cpp | 74 +++++++-------- 2 files changed, 85 insertions(+), 81 deletions(-) diff --git a/examples/distributedb/test/distributedtest/common/distribute_demo.cpp b/examples/distributedb/test/distributedtest/common/distribute_demo.cpp index d65f00a..d396990 100644 --- a/examples/distributedb/test/distributedtest/common/distribute_demo.cpp +++ b/examples/distributedb/test/distributedtest/common/distribute_demo.cpp @@ -28,80 +28,96 @@ using namespace OHOS::HiviewDFX; namespace { - constexpr HiLogLabel LABEL={LOG_CORE,0,"DistributedtestDemo"}; + constexpr HiLogLabel LABEL={LOG_CORE, 0, "DistributeDemo"}; - const int MSG_LENGTH = 100; - const int EXPECT_RETURN_VALUE = 111; + const int MSG_LENGTH = 100; + const int EXPECT_RETURN_VALUE = 111; } -class DistributedtestDemo:public DistributeTest -{ +class DistributeDemo: public DistributeTest { public: - DistributedtestDemo() = default; - ~DistributedtestDemo() = default; + DistributeDemo() = default; + ~DistributeDemo() = default; - static void SetUpTestCase(){}; - static void TearDownTestCase(){}; - virtual void SetUp(){}; - virtual void TearDown(){}; + static void SetUpTestCase() {}; + static void TearDownTestCase() {}; + virtual void SetUp() {}; + virtual void TearDown() {}; }; -void DistributedtestDemo::SetUpTestCase() +void DistributeDemo::SetUpTestCase() { } -void DistributedtestDemo::TearDownTestCase() +void DistributeDemo::TearDownTestCase() { } -void DistributedtestDemo::SetUp() +void DistributeDemo::SetUp() { } -void DistributedtestDemo::TearDown() +void DistributeDemo::TearDown() { } + /* * @tc.name:SendMessageTest001 * @tc.desc:Verify the distributed test framework interface SendMessage. * @tc.type:FUNC * @tc.require:ArOOOCQGMV */ -HWTEST_F(DistributedtestDemo, SendMessageTest001,TestSize.Level1) +HWTEST_F(DistributeDemo, SendMessageTest001, TestSize.Level1) { - char msgbuf[MSG_LENGTH] = "I am testcase 1"; - int ret = SendMessage(AGENT_NO::ONE,msgbuf,MSG_LENGTH); + char msgbuf[MSG_LENGTH] = "I am testcase 1"; + int ret = SendMessage(AGENT_NO::ONE, msgbuf, MSG_LENGTH); - if(ret == 0) - { - EXPECT_FALSE(ret)<<"ret = 2"; - } + if (ret == 0) { + EXPECT_FALSE(ret)<<"ret = 2"; + } } -HWTEST_F(DistributedtestDemo, SendMessageTest002, TestSize.Level1) +/* +* @tc.name:SendMessageTest002 +* @tc.desc:Verify the distributed test framework interface SendMessage. +* @tc.type:FUNC +* @tc.require:ArOOOCQGMV +*/ +HWTEST_F(DistributeDemo, SendMessageTest002, TestSize.Level1) { - char msgbuf[MSG_LENGTH] = "I am recall"; - int ret = SendMessage(AGENT_NO::ONE, msgbuf,MSG_LENGTH,[&](const std::string &szreturnbuf, int rlen)->bool{ - std::string szbuf = "ok"; - HiLog::Info(LABEL, "SendMessageTest002 = %s",szbuf.c_str()); - return true; - }); - if(ret == 0) - { - EXPECT_TRUE(1)<<"ret = 0"; - } + char msgbuf[MSG_LENGTH] = "I am recall"; + int ret = SendMessage(AGENT_NO::ONE, msgbuf, MSG_LENGTH, + [&](const std::string &szreturnbuf, int rlen)->bool{ + std::string szbuf = "ok"; + HiLog::Info(LABEL, "SendMessageTest002 = %s", szbuf.c_str()); + return true; + }); + if (ret == 0){ + EXPECT_TRUE(1)<<"ret = 0"; + } } -HWTEST_F(DistributedtestDemo, SendMessageTest003, TestSize.Level1) +/* +* @tc.name:SendMessageTest003 +* @tc.desc:Verify the distributed test framework interface SendMessage. +* @tc.type:FUNC +* @tc.require:ArOOOCQGMV +*/ +HWTEST_F(DistributeDemo, SendMessageTest003, TestSize.Level1) { char msgbuf[MSG_LENGTH] = "I am testcase 2"; int ret = SendMessage(AGENT_NO::ONE, msgbuf, MSG_LENGTH); - if(ret == 0) - { - EXPECT_FALSE(ret)<<"ret = 0"; + if (ret == 0) { + EXPECT_FALSE(ret)<<"ret = 0"; } } -HWTEST_F(DistributedtestDemo, RunCmdOnAgent001, TestSize.Level1) +/* +* @tc.name:RunCmdOnAgent001 +* @tc.desc:Verify the distributed test framework interface SendMessage. +* @tc.type:FUNC +* @tc.require:ArOOOCQGMV +*/ +HWTEST_F(DistribuDistributeDemotedtestDemo, RunCmdOnAgent001, TestSize.Level1) { std::string command = "query_command"; std::string cmdArgs = "query a name?"; diff --git a/examples/distributedb/test/distributedtest/common/distribute_demo_agent.cpp b/examples/distributedb/test/distributedtest/common/distribute_demo_agent.cpp index b987cb2..2ca62f3 100644 --- a/examples/distributedb/test/distributedtest/common/distribute_demo_agent.cpp +++ b/examples/distributedb/test/distributedtest/common/distribute_demo_agent.cpp @@ -26,9 +26,8 @@ using namespace OHOS; using namespace OHOS::DistributeSystemTest; using namespace OHOS::HiviewDFX; -namespace -{ - constexpr HiLogLabel LABEL = {LOG_CORE, 0, "DistributedtestDemoAgent"}; +namespace { + constexpr HiLogLabel LABEL = {LOG_CORE, 0, "DistributedDemoAgent"}; std::string g_appId = "com.ohos.nb.service.user1_test"; std::string g_storeId = "student_1"; @@ -36,11 +35,10 @@ namespace const int CMD_RETURN_TWO = 111; } -class DistributedtestDemoAgent:public DistributedAgent -{ +class DistributeDemoAgent: public DistributedAgent { public: - DistributedtestDemoAgent(); - ~DistributedtestDemoAgent(); + DistributeDemoAgent(); + ~DistributeDemoAgent(); virtual bool SetUp(); virtual bool TearDown(); @@ -53,26 +51,26 @@ public: int expectValueLen); int AddTwoValue(const std::string &strArgs, int argsLen, const std::string &strExpectValue, - int expectValueLen); + int expectValueLen); int ProcessByUseMap(const std::string &strCommand, int cmdLen, const std::string &strArgs, int argsLen, - const std::string &strExpectValue, int expectValueLen); + const std::string &strExpectValue, int expectValueLen); private: typedef int (DistributeDemoAgent::*self_func)(const std::string &, int, const std::string &, int); std::map cmdFunMap_; }; -DistributedtestDemoAgent::DistributedtestDemoAgent() +DistributeDemoAgent::DistributeDemoAgent() { } -DistributedtestDemoAgent::~DistributedtestDemoAgent() +DistributeDemoAgent::~DistributeDemoAgent() { } -bool DistributedtestDemoAgent::SetUp() +bool DistributeDemoAgent::SetUp() { return true; } -bool DistributedtestDemoAgent::TearDown() +bool DistributeDemoAgent::TearDown() { /* * @tc.teardown:Recovery test agent device environment @@ -81,62 +79,52 @@ bool DistributedtestDemoAgent::TearDown() } // The entry of handlingthe major test case message -void DistributedtestDemoAgent::OnProcessMsg(const std::string &strMsg, - int len, std::string &strReturnValue, int returnValueLen) +void DistributeDemoAgent::OnProcessMsg(const std::string &strMsg, + int len, std::string &strReturnValue, int returnValueLen) { std::string returnStr = "agent return message."; std::string strrq = "I am recall"; - if(strstr(strMsg.c_str(),strrq.c_str())) - { + if (strstr(strMsg.c_str(), strrq.c_str())) { strReturnValue = "ok"; return strReturnValue; } std::string strrq = "I am testcase2"; - if(strstr(strMsg.c_str(), strrq.c_str())) - { + if (strstr(strMsg.c_str(), strrq.c_str())) { HiLog::Info(LABEL, "I am testcase2"); } - else - { + else { return DistributedAgent::OnProcessMsg(strMsg, len, strReturnValue, returnValueLen); } } -void DistributedtestDemoAgent::OnProcessCmd(const std::string &strCommand, - int cmdLen, const std::string &strArgs, int argsLen, - const std::string &strExpectValue, int expectValueLen) +void DistributeDemoAgent::OnProcessCmd(const std::string &strCommand, + int cmdLen, const std::string &strExpectValue, int expectValueLen) { - if(strCommand == "query_command") - { - if(strArgs == "query a name?") - { - return CMD_RETURN_TWO; + if (strCommand == "query_command") { + if (strArgs == "query a name?") { + return CMD_RETURN_TWO; } } - return DistributedAgent::OnProcessCmd(strCommand, cmdLen, strArgs, argsLen, strExpectValue, expectValueLen); + return DistributedAgent::OnProcessCmd(strCommand, cmdLen, strExpectValue, expectValueLen); } int main() { // Test agent main function - DistributedtestDemoAgent obj; - if(obj.SetUp()) - { - obj.Start("agent.desc"); - obj.Join(); + DistributeDemoAgent obj; + if (obj.SetUp()) { + obj.Start("agent.desc"); + obj.Join(); } - else - { - HiLog::Error(LABEL, "Init environment failed."); + else { + HiLog::Error(LABEL, "Init environment failed."); } - if(obj.TearDown()) - { - return 0; + if (obj.TearDown()) { + return 0; } - else - { + else { HiLog::Error(LABEL, "Clear environment failed."); return -1; } -- Gitee From ff49545c256d74b0401838583a747ede0874dccb Mon Sep 17 00:00:00 2001 From: caojiale1 Date: Mon, 29 May 2023 08:05:49 +0000 Subject: [PATCH 06/14] Signed-off-by: caojiale1 Signed-off-by: caojiale1 --- .../common/distribute_demo.cpp | 14 ++++---- .../common/distribute_demo_agent.cpp | 35 +++++++++---------- 2 files changed, 22 insertions(+), 27 deletions(-) diff --git a/examples/distributedb/test/distributedtest/common/distribute_demo.cpp b/examples/distributedb/test/distributedtest/common/distribute_demo.cpp index d396990..bdb2b4b 100644 --- a/examples/distributedb/test/distributedtest/common/distribute_demo.cpp +++ b/examples/distributedb/test/distributedtest/common/distribute_demo.cpp @@ -26,15 +26,14 @@ using namespace testing::ext; using namespace OHOS::DistributeSystemTest; using namespace OHOS::HiviewDFX; -namespace -{ - constexpr HiLogLabel LABEL={LOG_CORE, 0, "DistributeDemo"}; +namespace { + constexpr HiLogLabel LABEL = {LOG_CORE, 0, "DistributeDemo"}; const int MSG_LENGTH = 100; const int EXPECT_RETURN_VALUE = 111; } -class DistributeDemo: public DistributeTest { +class DistributeDemo : public DistributeTest { public: DistributeDemo() = default; ~DistributeDemo() = default; @@ -73,7 +72,6 @@ HWTEST_F(DistributeDemo, SendMessageTest001, TestSize.Level1) if (ret == 0) { EXPECT_FALSE(ret)<<"ret = 2"; } - } /* @@ -86,12 +84,12 @@ HWTEST_F(DistributeDemo, SendMessageTest002, TestSize.Level1) { char msgbuf[MSG_LENGTH] = "I am recall"; int ret = SendMessage(AGENT_NO::ONE, msgbuf, MSG_LENGTH, - [&](const std::string &szreturnbuf, int rlen)->bool{ + [&](const std::string &szreturnbuf, int rlen)->bool { std::string szbuf = "ok"; HiLog::Info(LABEL, "SendMessageTest002 = %s", szbuf.c_str()); return true; }); - if (ret == 0){ + if (ret == 0) { EXPECT_TRUE(1)<<"ret = 0"; } } @@ -117,7 +115,7 @@ HWTEST_F(DistributeDemo, SendMessageTest003, TestSize.Level1) * @tc.type:FUNC * @tc.require:ArOOOCQGMV */ -HWTEST_F(DistribuDistributeDemotedtestDemo, RunCmdOnAgent001, TestSize.Level1) +HWTEST_F(DistributeDemo, RunCmdOnAgent001, TestSize.Level1) { std::string command = "query_command"; std::string cmdArgs = "query a name?"; diff --git a/examples/distributedb/test/distributedtest/common/distribute_demo_agent.cpp b/examples/distributedb/test/distributedtest/common/distribute_demo_agent.cpp index 2ca62f3..6dfbcfc 100644 --- a/examples/distributedb/test/distributedtest/common/distribute_demo_agent.cpp +++ b/examples/distributedb/test/distributedtest/common/distribute_demo_agent.cpp @@ -35,7 +35,7 @@ namespace { const int CMD_RETURN_TWO = 111; } -class DistributeDemoAgent: public DistributedAgent { +class DistributeDemoAgent : public DistributedAgent { public: DistributeDemoAgent(); ~DistributeDemoAgent(); @@ -80,53 +80,50 @@ bool DistributeDemoAgent::TearDown() // The entry of handlingthe major test case message void DistributeDemoAgent::OnProcessMsg(const std::string &strMsg, - int len, std::string &strReturnValue, int returnValueLen) + int len, std::string &strReturnValue, int returnValueLen) { std::string returnStr = "agent return message."; std::string strrq = "I am recall"; if (strstr(strMsg.c_str(), strrq.c_str())) { - strReturnValue = "ok"; - return strReturnValue; + strReturnValue = "ok"; + return strReturnValue; } std::string strrq = "I am testcase2"; if (strstr(strMsg.c_str(), strrq.c_str())) { - HiLog::Info(LABEL, "I am testcase2"); + HiLog::Info(LABEL, "I am testcase2"); } else { - return DistributedAgent::OnProcessMsg(strMsg, len, strReturnValue, returnValueLen); + return DistributedAgent::OnProcessMsg(strMsg, len, strReturnValue, returnValueLen); } } void DistributeDemoAgent::OnProcessCmd(const std::string &strCommand, - int cmdLen, const std::string &strExpectValue, int expectValueLen) + int cmdLen, const std::string &strExpectValue, int expectValueLen) { if (strCommand == "query_command") { if (strArgs == "query a name?") { return CMD_RETURN_TWO; - } - } + } + } return DistributedAgent::OnProcessCmd(strCommand, cmdLen, strExpectValue, expectValueLen); } int main() { // Test agent main function - - DistributeDemoAgent obj; + DistributeDemoAgent obj; if (obj.SetUp()) { obj.Start("agent.desc"); obj.Join(); - } - else { + } else { HiLog::Error(LABEL, "Init environment failed."); - } + } if (obj.TearDown()) { return 0; - } - else { - HiLog::Error(LABEL, "Clear environment failed."); - return -1; - } + } else { + HiLog::Error(LABEL, "Clear environment failed."); + return -1; + } } -- Gitee From c0a29889234b1971229475c93a97db75d75de675 Mon Sep 17 00:00:00 2001 From: caojiale1 Date: Mon, 29 May 2023 09:09:50 +0000 Subject: [PATCH 07/14] Signed-off-by: caojiale1 Signed-off-by: caojiale1 --- .../test/distributedtest/common/distribute_demo.cpp | 3 +-- .../test/distributedtest/common/distribute_demo_agent.cpp | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/examples/distributedb/test/distributedtest/common/distribute_demo.cpp b/examples/distributedb/test/distributedtest/common/distribute_demo.cpp index bdb2b4b..d83895c 100644 --- a/examples/distributedb/test/distributedtest/common/distribute_demo.cpp +++ b/examples/distributedb/test/distributedtest/common/distribute_demo.cpp @@ -23,7 +23,7 @@ using namespace std; using namespace OHOS; using namespace testing::ext; -using namespace OHOS::DistributeSystemTest; +using namespace OHOS::DistributeDemo; using namespace OHOS::HiviewDFX; namespace { @@ -34,7 +34,6 @@ namespace { } class DistributeDemo : public DistributeTest { -public: DistributeDemo() = default; ~DistributeDemo() = default; diff --git a/examples/distributedb/test/distributedtest/common/distribute_demo_agent.cpp b/examples/distributedb/test/distributedtest/common/distribute_demo_agent.cpp index 6dfbcfc..702be5c 100644 --- a/examples/distributedb/test/distributedtest/common/distribute_demo_agent.cpp +++ b/examples/distributedb/test/distributedtest/common/distribute_demo_agent.cpp @@ -91,8 +91,7 @@ void DistributeDemoAgent::OnProcessMsg(const std::string &strMsg, std::string strrq = "I am testcase2"; if (strstr(strMsg.c_str(), strrq.c_str())) { HiLog::Info(LABEL, "I am testcase2"); - } - else { + } else { return DistributedAgent::OnProcessMsg(strMsg, len, strReturnValue, returnValueLen); } } -- Gitee From 8564fa67a603dfd84c06a06f7b401b451938c270 Mon Sep 17 00:00:00 2001 From: caojiale1 Date: Mon, 29 May 2023 09:17:35 +0000 Subject: [PATCH 08/14] Signed-off-by: caojiale1 Signed-off-by: caojiale1 --- .../common/distribute_demo.cpp | 141 ++++++++---------- 1 file changed, 62 insertions(+), 79 deletions(-) diff --git a/examples/distributedb/test/distributedtest/common/distribute_demo.cpp b/examples/distributedb/test/distributedtest/common/distribute_demo.cpp index d83895c..8629d9c 100644 --- a/examples/distributedb/test/distributedtest/common/distribute_demo.cpp +++ b/examples/distributedb/test/distributedtest/common/distribute_demo.cpp @@ -23,7 +23,7 @@ using namespace std; using namespace OHOS; using namespace testing::ext; -using namespace OHOS::DistributeDemo; +using namespace OHOS::DistributeSystemTest; using namespace OHOS::HiviewDFX; namespace { @@ -31,96 +31,79 @@ namespace { const int MSG_LENGTH = 100; const int EXPECT_RETURN_VALUE = 111; -} -class DistributeDemo : public DistributeTest { - DistributeDemo() = default; - ~DistributeDemo() = default; - static void SetUpTestCase() {}; - static void TearDownTestCase() {}; - virtual void SetUp() {}; - virtual void TearDown() {}; -}; + class DistributeDemo : public DistributeTest { + DistributeDemo() = default; + ~DistributeDemo() = default; -void DistributeDemo::SetUpTestCase() -{ -} -void DistributeDemo::TearDownTestCase() -{ -} + static void SetUpTestCase() {}; + static void TearDownTestCase() {}; + virtual void SetUp() {}; + virtual void TearDown() {}; + }; -void DistributeDemo::SetUp() -{ -} -void DistributeDemo::TearDown() -{ -} + void DistributeDemo::SetUpTestCase() + { + } + void DistributeDemo::TearDownTestCase() + { + } -/* -* @tc.name:SendMessageTest001 -* @tc.desc:Verify the distributed test framework interface SendMessage. -* @tc.type:FUNC -* @tc.require:ArOOOCQGMV -*/ -HWTEST_F(DistributeDemo, SendMessageTest001, TestSize.Level1) -{ - char msgbuf[MSG_LENGTH] = "I am testcase 1"; - int ret = SendMessage(AGENT_NO::ONE, msgbuf, MSG_LENGTH); + void DistributeDemo::SetUp() + { + } + void DistributeDemo::TearDown() + { + } - if (ret == 0) { - EXPECT_FALSE(ret)<<"ret = 2"; + /* + * @tc.name:SendMessageTest001 + * @tc.desc:Verify the distributed test framework interface SendMessage. + * @tc.type:FUNC + * @tc.require:ArOOOCQGMV + */ + HWTEST_F(DistributeDemo, SendMessageTest001, TestSize.Level1) + { + char msgbuf[MSG_LENGTH] = "I am testcase 1"; + int ret = SendMessage(AGENT_NO::ONE, msgbuf, MSG_LENGTH); + + if (ret == 0) { + EXPECT_FALSE(ret)<<"ret = 2"; + } } -} -/* -* @tc.name:SendMessageTest002 -* @tc.desc:Verify the distributed test framework interface SendMessage. -* @tc.type:FUNC -* @tc.require:ArOOOCQGMV -*/ -HWTEST_F(DistributeDemo, SendMessageTest002, TestSize.Level1) -{ - char msgbuf[MSG_LENGTH] = "I am recall"; - int ret = SendMessage(AGENT_NO::ONE, msgbuf, MSG_LENGTH, - [&](const std::string &szreturnbuf, int rlen)->bool { - std::string szbuf = "ok"; - HiLog::Info(LABEL, "SendMessageTest002 = %s", szbuf.c_str()); - return true; - }); - if (ret == 0) { - EXPECT_TRUE(1)<<"ret = 0"; + HWTEST_F(DistributeDemo, SendMessageTest002, TestSize.Level1) + { + char msgbuf[MSG_LENGTH] = "I am recall"; + int ret = SendMessage(AGENT_NO::ONE, msgbuf, MSG_LENGTH, + [&](const std::string &szreturnbuf, int rlen)->bool { + std::string szbuf = "ok"; + HiLog::Info(LABEL, "SendMessageTest002 = %s", szbuf.c_str()); + return true; + }); + if (ret == 0) { + EXPECT_TRUE(1)<<"ret = 0"; + } } -} -/* -* @tc.name:SendMessageTest003 -* @tc.desc:Verify the distributed test framework interface SendMessage. -* @tc.type:FUNC -* @tc.require:ArOOOCQGMV -*/ -HWTEST_F(DistributeDemo, SendMessageTest003, TestSize.Level1) -{ - char msgbuf[MSG_LENGTH] = "I am testcase 2"; - int ret = SendMessage(AGENT_NO::ONE, msgbuf, MSG_LENGTH); - if (ret == 0) { - EXPECT_FALSE(ret)<<"ret = 0"; + HWTEST_F(DistributeDemo, SendMessageTest003, TestSize.Level1) + { + char msgbuf[MSG_LENGTH] = "I am testcase 2"; + int ret = SendMessage(AGENT_NO::ONE, msgbuf, MSG_LENGTH); + if (ret == 0) { + EXPECT_FALSE(ret)<<"ret = 0"; + } } -} -/* -* @tc.name:RunCmdOnAgent001 -* @tc.desc:Verify the distributed test framework interface SendMessage. -* @tc.type:FUNC -* @tc.require:ArOOOCQGMV -*/ -HWTEST_F(DistributeDemo, RunCmdOnAgent001, TestSize.Level1) -{ - std::string command = "query_command"; - std::string cmdArgs = "query a name?"; - std::string expectValue = "111"; - RunCmdOnAgent(AGENT_NO::ONE, command, cmdArgs, expectValue); - EXPECT_EQ(GetReturnVal(), EXPECT_RETURN_VALUE); + HWTEST_F(DistributeDemo, RunCmdOnAgent001, TestSize.Level1) + { + std::string command = "query_command"; + std::string cmdArgs = "query a name?"; + std::string expectValue = "111"; + RunCmdOnAgent(AGENT_NO::ONE, command, cmdArgs, expectValue); + EXPECT_EQ(GetReturnVal(), EXPECT_RETURN_VALUE); + } } int main(int argc, char*argv[]) -- Gitee From 33cf084c1605ca9c333939e77ea90f8ec9064ed5 Mon Sep 17 00:00:00 2001 From: caojiale1 Date: Mon, 29 May 2023 09:32:03 +0000 Subject: [PATCH 09/14] Signed-off-by: caojiale1 Signed-off-by: caojiale1 --- examples/distributedb/test/BUILD.gn | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/distributedb/test/BUILD.gn b/examples/distributedb/test/BUILD.gn index 8eeb3b2..91be446 100755 --- a/examples/distributedb/test/BUILD.gn +++ b/examples/distributedb/test/BUILD.gn @@ -34,7 +34,7 @@ config("module_private_config") { ohos_distributedtest("DistributeDemo") { module_out_path = module_output_path - sources = [ "distribute_demo.cpp" ] + sources = [ "./distributedtest/common/distribute_demo.cpp" ] configs = [ ":module_private_config" ] @@ -54,7 +54,7 @@ ohos_distributedtest("DistributeDemo") { ohos_distributedtest("DistributeDemoAgent") { module_out_path = module_output_path - sources = [ "distribute_demo_agent.cpp" ] + sources = [ "./distributedtest/common/distribute_demo_agent.cpp" ] configs = [ ":module_private_config" ] @@ -79,4 +79,4 @@ group("distributedtest") { ":DistributeDemoAgent", ] } -############################################################################### \ No newline at end of file +############################################################################### -- Gitee From 5a590172d8e1c4f4f9c7602c294553b687e57d42 Mon Sep 17 00:00:00 2001 From: caojiale1 Date: Mon, 29 May 2023 09:55:31 +0000 Subject: [PATCH 10/14] Signed-off-by: caojiale1 Signed-off-by: caojiale1 --- examples/distributedb/test/BUILD.gn | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/examples/distributedb/test/BUILD.gn b/examples/distributedb/test/BUILD.gn index 91be446..69bdc7a 100755 --- a/examples/distributedb/test/BUILD.gn +++ b/examples/distributedb/test/BUILD.gn @@ -21,14 +21,8 @@ config("module_private_config") { include_dirs = [ "../../../../../../commonlibrary/c_utils/base/include", - "../../../../../../test/testfwk/developer_test/aw/distributed", + "../../../aw/distributed" ] - - # link library - #ldflags = [ "-llog" ] - - # library path - # lib_dirs = [ "//foundation/appexecfwk/libs" ] } ohos_distributedtest("DistributeDemo") { @@ -43,11 +37,11 @@ ohos_distributedtest("DistributeDemo") { "hilog_native:libhilog", "ipc:ipc_core", "safwk:system_ability_fwk", - "samgr:samgr_proxy", + "samgr:samgr_proxy" ] deps = [ - "//third_party/googletest:gtest", + "//third_party/googletest:gtest" ] } @@ -63,20 +57,20 @@ ohos_distributedtest("DistributeDemoAgent") { "hilog_native:libhilog", "ipc:ipc_core", "safwk:system_ability_fwk", - "samgr:samgr_proxy", + "samgr:samgr_proxy" ] deps = [ - "//third_party/googletest:gtest", + "//third_party/googletest:gtest" ] } ############################################################################### -group("distributedtest") { +group("distributedtest"){ testonly = true deps = [ ":DistributeDemo", - ":DistributeDemoAgent", + ":DistributeDemoAgent" ] } ############################################################################### -- Gitee From ecbb8705b6a1ae7056f93adb59478e8bfc3054c8 Mon Sep 17 00:00:00 2001 From: caojiale1 Date: Mon, 29 May 2023 10:07:58 +0000 Subject: [PATCH 11/14] Signed-off-by: caojiale1 Signed-off-by: caojiale1 --- examples/distributedb/test/BUILD.gn | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/distributedb/test/BUILD.gn b/examples/distributedb/test/BUILD.gn index 69bdc7a..5752a7f 100755 --- a/examples/distributedb/test/BUILD.gn +++ b/examples/distributedb/test/BUILD.gn @@ -16,7 +16,7 @@ import("//build/test.gni") module_output_path = "developertest/distributedb" ############################################################################### -config("module_private_config") { +config("module_private_config"){ visibility = [ ":*" ] include_dirs = [ @@ -25,7 +25,7 @@ config("module_private_config") { ] } -ohos_distributedtest("DistributeDemo") { +ohos_distributedtest("DistributeDemo"){ module_out_path = module_output_path sources = [ "./distributedtest/common/distribute_demo.cpp" ] @@ -45,7 +45,7 @@ ohos_distributedtest("DistributeDemo") { ] } -ohos_distributedtest("DistributeDemoAgent") { +ohos_distributedtest("DistributeDemoAgent"){ module_out_path = module_output_path sources = [ "./distributedtest/common/distribute_demo_agent.cpp" ] @@ -73,4 +73,4 @@ group("distributedtest"){ ":DistributeDemoAgent" ] } -############################################################################### +############################################################################### \ No newline at end of file -- Gitee From 4a2ba588b0139512eb1cb1080ac7a8b631b79dd2 Mon Sep 17 00:00:00 2001 From: caojiale1 Date: Mon, 29 May 2023 11:31:49 +0000 Subject: [PATCH 12/14] Signed-off-by: caojiale1 Signed-off-by: caojiale1 --- examples/distributedb/test/BUILD.gn | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/distributedb/test/BUILD.gn b/examples/distributedb/test/BUILD.gn index 5752a7f..2a076ca 100755 --- a/examples/distributedb/test/BUILD.gn +++ b/examples/distributedb/test/BUILD.gn @@ -21,7 +21,7 @@ config("module_private_config"){ include_dirs = [ "../../../../../../commonlibrary/c_utils/base/include", - "../../../aw/distributed" + "../../../aw/distributed", ] } @@ -37,7 +37,7 @@ ohos_distributedtest("DistributeDemo"){ "hilog_native:libhilog", "ipc:ipc_core", "safwk:system_ability_fwk", - "samgr:samgr_proxy" + "samgr:samgr_proxy", ] deps = [ @@ -57,11 +57,11 @@ ohos_distributedtest("DistributeDemoAgent"){ "hilog_native:libhilog", "ipc:ipc_core", "safwk:system_ability_fwk", - "samgr:samgr_proxy" + "samgr:samgr_proxy", ] deps = [ - "//third_party/googletest:gtest" + "//third_party/googletest:gtest", ] } @@ -70,7 +70,7 @@ group("distributedtest"){ testonly = true deps = [ ":DistributeDemo", - ":DistributeDemoAgent" + ":DistributeDemoAgent", ] } -############################################################################### \ No newline at end of file +############################################################################### -- Gitee From 9212b158de209037252b7a82a13712aea88c0e5a Mon Sep 17 00:00:00 2001 From: caojiale1 Date: Mon, 29 May 2023 12:12:55 +0000 Subject: [PATCH 13/14] Signed-off-by: caojiale1 Signed-off-by: caojiale1 --- examples/distributedb/test/BUILD.gn | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/examples/distributedb/test/BUILD.gn b/examples/distributedb/test/BUILD.gn index 2a076ca..24421d6 100755 --- a/examples/distributedb/test/BUILD.gn +++ b/examples/distributedb/test/BUILD.gn @@ -16,7 +16,7 @@ import("//build/test.gni") module_output_path = "developertest/distributedb" ############################################################################### -config("module_private_config"){ +config("module_private_config") { visibility = [ ":*" ] include_dirs = [ @@ -25,7 +25,7 @@ config("module_private_config"){ ] } -ohos_distributedtest("DistributeDemo"){ +ohos_distributedtest("DistributeDemo") { module_out_path = module_output_path sources = [ "./distributedtest/common/distribute_demo.cpp" ] @@ -40,12 +40,10 @@ ohos_distributedtest("DistributeDemo"){ "samgr:samgr_proxy", ] - deps = [ - "//third_party/googletest:gtest" - ] + deps = [ "//third_party/googletest:gtest" ] } -ohos_distributedtest("DistributeDemoAgent"){ +ohos_distributedtest("DistributeDemoAgent") { module_out_path = module_output_path sources = [ "./distributedtest/common/distribute_demo_agent.cpp" ] @@ -60,13 +58,11 @@ ohos_distributedtest("DistributeDemoAgent"){ "samgr:samgr_proxy", ] - deps = [ - "//third_party/googletest:gtest", - ] + deps = [ "//third_party/googletest:gtest" ] } ############################################################################### -group("distributedtest"){ +group("distributedtest") { testonly = true deps = [ ":DistributeDemo", -- Gitee From e8113a01fcb753522acc70bdc9908603ea7768e8 Mon Sep 17 00:00:00 2001 From: caojiale1 Date: Tue, 30 May 2023 06:53:31 +0000 Subject: [PATCH 14/14] Signed-off-by: caojiale1 Signed-off-by: caojiale1 --- .../test/distributedtest/common/distribute_demo.cpp | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/examples/distributedb/test/distributedtest/common/distribute_demo.cpp b/examples/distributedb/test/distributedtest/common/distribute_demo.cpp index 8629d9c..bf70f9c 100644 --- a/examples/distributedb/test/distributedtest/common/distribute_demo.cpp +++ b/examples/distributedb/test/distributedtest/common/distribute_demo.cpp @@ -68,9 +68,7 @@ namespace { char msgbuf[MSG_LENGTH] = "I am testcase 1"; int ret = SendMessage(AGENT_NO::ONE, msgbuf, MSG_LENGTH); - if (ret == 0) { - EXPECT_FALSE(ret)<<"ret = 2"; - } + EXPECT_FALSE(ret)<<"ret = 2"; } HWTEST_F(DistributeDemo, SendMessageTest002, TestSize.Level1) @@ -82,18 +80,14 @@ namespace { HiLog::Info(LABEL, "SendMessageTest002 = %s", szbuf.c_str()); return true; }); - if (ret == 0) { - EXPECT_TRUE(1)<<"ret = 0"; - } + EXPECT_TRUE(ret)<<"ret = 0"; } HWTEST_F(DistributeDemo, SendMessageTest003, TestSize.Level1) { char msgbuf[MSG_LENGTH] = "I am testcase 2"; int ret = SendMessage(AGENT_NO::ONE, msgbuf, MSG_LENGTH); - if (ret == 0) { - EXPECT_FALSE(ret)<<"ret = 0"; - } + EXPECT_FALSE(ret)<<"ret = 0"; } HWTEST_F(DistributeDemo, RunCmdOnAgent001, TestSize.Level1) -- Gitee