diff --git a/test/framework/BUILD.gn b/test/framework/BUILD.gn index 67f4745bf13abacce178726ec202b23fc9c8c71a..3642f44529f86132b83d519d99f6c802b2e83fda 100644 --- a/test/framework/BUILD.gn +++ b/test/framework/BUILD.gn @@ -82,10 +82,6 @@ if (enable_video_component) { } auto_test_sources = [ - "../uitest/test_layout/ui_auto_test_basic_layout.cpp", - "../uitest/test_render/ui_auto_test_render.cpp", - "src/auto_test_app.cpp", - "src/auto_test_case_group.cpp", "src/compare_tools.cpp", "src/ui_auto_test.cpp", ] diff --git a/test/framework/include/auto_test_case_group.h b/test/framework/include/auto_test_case_group.h deleted file mode 100644 index 0cdce028840eba92ea69eb8e1f410a807a8a0c7c..0000000000000000000000000000000000000000 --- a/test/framework/include/auto_test_case_group.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef GRAPHIC_LITE_AUTO_TEST_CASE_GROUP_H -#define GRAPHIC_LITE_AUTO_TEST_CASE_GROUP_H - -#include "gfx_utils/list.h" - -namespace OHOS { -class AutoTestCaseGroup { -public: - class AutoTestCase { - public: - AutoTestCase() {} - virtual ~AutoTestCase() {} - virtual void RunTestList() = 0; - virtual void Reset() const = 0; - virtual void ResetMainMenu() const = 0; - }; - - static List& GetTestCase(); - static void TearDownTestCase(); - static void AddTestCase(AutoTestCase* testCaseInfo); - -private: - static List testCaseList_; -}; -} // namespace OHOS -#endif // GRAPHIC_LITE_AUTO_TEST_CASE_GROUP_H diff --git a/test/framework/include/auto_test_manager.h b/test/framework/include/auto_test_manager.h new file mode 100644 index 0000000000000000000000000000000000000000..d546e6e5c41e3b4cd72b714a70e22bd0d7534223 --- /dev/null +++ b/test/framework/include/auto_test_manager.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef GRAPHIC_LITE_AUTO_TEST_MANAGER_H +#define GRAPHIC_LITE_AUTO_TEST_MANAGER_H + +#include "components/ui_view.h" +#include "graphic_config.h" +#include "ui_test_message.h" +#include "ui_auto_test.h" + +namespace OHOS { +using SendMsgFunc = std::function; +class AutoTestManager { +public: + AutoTestManager(); + virtual ~AutoTestManager(); + static AutoTestManager* GetInstance(); + + void SetUpTestCase(); + void TearDownTestCase(); + void SendMsg(size_t mainID); + void StartTest(std::vector> msgInfo); + void SetSendMsgFuncCallBack(SendMsgFunc sendMsgFunc); + void SetConfigInfo(const std::shared_ptr configInfo); + std::shared_ptr GetConfigInfo(); + void TestComplete(); + +private: + std::shared_ptr autoTest_; + SendMsgFunc sendMsgFunc_; + std::shared_ptr configInfo_; +}; +} // namespace OHOS + +#endif // GRAPHIC_LITE_AUTO_TEST_MANAGER_H diff --git a/test/framework/include/compare_tools.h b/test/framework/include/compare_tools.h index 99e24244f8b46596b83781d2c8ab3b990e8d7cb6..a7cdc129c4c30050943983498202cb9570321a38 100644 --- a/test/framework/include/compare_tools.h +++ b/test/framework/include/compare_tools.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Copyright (c) 2020-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -17,6 +17,7 @@ #define GRAPHIC_LITE_COMPARE_TOOLS_H #include "graphic_config.h" +#include #ifdef _WIN32 #include #else @@ -25,7 +26,7 @@ namespace OHOS { namespace { - constexpr uint16_t DEFAULT_WAIT_TIME_MS = 300; + constexpr uint16_t DEFAULT_WAIT_TIME_MS = 500; constexpr size_t DEFAULT_FILE_NAME_MAX_LENGTH = 256; constexpr uint8_t BITMAP_HEADER_SIZE = 54; } @@ -56,12 +57,16 @@ public: static bool CheckFileExist(const char* filePath, size_t length); static void SetLogPath(const char* filePath, size_t length); static void UnsetLogPath(); + static void SaveResultLog(const char* filePath, const char* buff, size_t bufSize); + static bool CompareFile(const char* fileBasePath, const char* fileRunPath); private: CompareTools() {} virtual ~CompareTools() {} - static bool SaveLog(const char* buff, size_t bufSize); + static bool CompareByBitmap(const BitmapInfoHeader bitmapInfoBase, const BitmapInfoHeader bitmapInfoRun, + uint32_t fdBase, uint32_t fdRun); + static bool SaveLog(const char* buff, size_t bufSize, const char* filePath = nullptr); static bool CompareByBit(uint32_t fd); static bool SaveByBit(uint32_t fd); static bool enableLog_; diff --git a/test/framework/include/ui_auto_test.h b/test/framework/include/ui_auto_test.h index 3e5f5642f2b53a6433cbc8f07f8d732d0dd1ad2e..89b5708037c6ab32129ef7ac379b00de285ad509 100644 --- a/test/framework/include/ui_auto_test.h +++ b/test/framework/include/ui_auto_test.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Copyright (c) 2020-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,24 +13,42 @@ * limitations under the License. */ -#ifndef GRAPHIC_LITE_UI_AUTO_TEST_H -#define GRAPHIC_LITE_UI_AUTO_TEST_H +#ifndef GRAPHIC_LITE_AUTO_TEST_H +#define GRAPHIC_LITE_AUTO_TEST_H -#include "auto_test_case_group.h" #include "components/ui_view.h" +#include "compare_tools.h" +#include "ui_test_message.h" namespace OHOS { -class UIAutoTest : public AutoTestCaseGroup::AutoTestCase { +class UIAutoTest { public: - UIAutoTest() {} - virtual ~UIAutoTest() {} + UIAutoTest(); + virtual ~UIAutoTest(); - static void SetUpTestCase(); void ResetMainMenu() const; + void Reset(std::string testID) const; + + void RunTest(std::vector> msgInfo); + void TestComplete() const; + void EnterSubMenu(const char* id) const; void ClickViewById(const char* id) const; void DragViewToHead(const char* id) const; - void CompareByBinary(const char* fileName) const; + bool CompareByBinary(const char* fileName) const; + void DrageToView(const char* id, int16_t x, int16_t y) const; + +private: + void OnTest(std::shared_ptr info); + void OnEnterPage(std::vector pageNav); + void OnTestBySteps(std::vector steps, std::string className); + void OnTestOneStep(TestSteps step, std::string className, size_t stepIndex); + void OnSaveFile(std::string className, std::string viewID, size_t stepIndex); + void OnCompareFile(std::string fileName) const; + std::string OnGetSystemTime() const; + +private: + std::vector fileNames_; }; } // namespace OHOS -#endif // GRAPHIC_LITE_UI_AUTO_TEST_H +#endif // GRAPHIC_LITE_AUTO_TEST_H diff --git a/test/framework/include/ui_test_app.h b/test/framework/include/ui_test_app.h index 7775cd122bfb4179c221ad2566a3ec5a096011da..dadf8764c68e9155e7c8d09686de5ec470308a95 100644 --- a/test/framework/include/ui_test_app.h +++ b/test/framework/include/ui_test_app.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Copyright (c) 2020-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,14 +13,13 @@ * limitations under the License. */ -#ifndef UI_TEST_APP_LIST_H -#define UI_TEST_APP_LIST_H +#ifndef GRAPHIC_LITE_TEST_APP_H +#define GRAPHIC_LITE_TEST_APP_H #include "components/root_view.h" #include "components/ui_label.h" #include "components/ui_label_button.h" #include "components/ui_list.h" -#include "graphic_thread.h" #include "test_case_list_adapter.h" namespace OHOS { @@ -28,11 +27,6 @@ namespace { constexpr char* UI_TEST_MAIN_LIST_ID = "main_list"; constexpr char* UI_TEST_BACK_BUTTON_ID = "back_button"; } -#ifdef _WIN32 -DWORD AutoTestThread(LPVOID); -#elif defined __linux__ || defined __LITEOS__ || defined __APPLE__ -void* AutoTestThread(void*); -#endif // _WIN32 class UITestApp { public: static UITestApp* GetInstance(); @@ -61,4 +55,4 @@ private: UIViewGroup* mainMenu_ = nullptr; }; } // namespace OHOS -#endif +#endif // GRAPHIC_LITE_TEST_APP_H diff --git a/test/framework/include/ui_test_message.h b/test/framework/include/ui_test_message.h new file mode 100644 index 0000000000000000000000000000000000000000..85b8909c851d540403cc70899642769e104df898 --- /dev/null +++ b/test/framework/include/ui_test_message.h @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef GRAPHIC_LITE_TEST_MESSAGE_H +#define GRAPHIC_LITE_TEST_MESSAGE_H + +#include +#include +#include +#include +#include +#include + +namespace OHOS { +enum TestEventID : uint8_t { + TEST_CLICK_EVENT, + TEST_MOVE_EVENT, +}; + +enum TestMode: uint8_t { + TEST_MODE_BASE = 1, + TEST_MODE_RUN, +}; + +struct TestSteps { + std::string viewID; + TestEventID eventID; + std::vector eventValue; + bool saveCheckPoint; +}; + +struct TestMsgInfo { + std::string className; + std::vector pageNav; + std::vector steps; +}; + +struct TestConfigInfo { + TestConfigInfo() + { + testMode = TEST_MODE_BASE; + } + TestMode testMode; + std::string baseDir; + std::string runDir; + std::string logDir; +}; + +const std::string JSON_VALUE_MAIN_ID = "main_id"; +const std::string JOSN_VALUE_TEST_MODE = "test_mode"; +const std::string JSON_VALUE_BASE_DIR = "base_dir"; +const std::string JSON_VALUE_RUN_DIR = "run_dir"; +const std::string JSON_VALUE_LOG_DIR = "log_dir"; + +const std::string JSON_VALUE_TEST_INFO = "testInfo"; +const std::string JSON_VALUE_CLASS_NAME = "className"; +const std::string JSON_VALUE_PAGE_NAV = "pageNav"; +const std::string JSON_VALUE_TEST_STEPS = "testSteps"; +const std::string JSON_VALUE_VIEW_ID = "viewID"; +const std::string JSON_VALUE_EVENT_ID = "eventID"; +const std::string JSON_VALUE_EVENT_VALUE = "eventValue"; +const std::string JSON_VALUE_SAVE_CHECK_POINT = "saveCheckPoint"; + +const size_t EVENT_VALUE_SIZE_TWO = 2; + +const size_t S_C_MAIN_ID_SEND_CONFIG_INFO = 1; // Send config information +const size_t C_S_MAIN_ID_REQUEST_TEST_INFO = 2; // Request to start test +const size_t S_C_MAIN_ID_SEND_TEST_INFO = 3; // Distribute test data +const size_t C_S_MAIN_ID_TEST_FINISH_INFO = 4; // Test a set of data +const size_t S_C_MAIN_ID_All_TESTS_COMPLETE = 5; // All tests completed +} // namespace OHOS + +#endif // GRAPHIC_LITE_TEST_MESSAGE_H diff --git a/test/framework/src/auto_test_app.cpp b/test/framework/src/auto_test_app.cpp deleted file mode 100644 index 9a3a42bd5200e29ec9ec0d2c2b7426b2516c8ebb..0000000000000000000000000000000000000000 --- a/test/framework/src/auto_test_app.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "auto_test_app.h" -#include "auto_test_case_group.h" -#include "compare_tools.h" -#include "dfx/event_injector.h" -#if ENABLE_WINDOW -#include "window/window.h" -#endif - -namespace OHOS { -AutoTestApp* AutoTestApp::GetInstance() -{ - static AutoTestApp instance; - return &instance; -} - -void AutoTestApp::Start() -{ - EventInjector::GetInstance()->RegisterEventInjector(EventDataType::POINT_TYPE); - EventInjector::GetInstance()->RegisterEventInjector(EventDataType::KEY_TYPE); - -#if ENABLE_WINDOW - Window* window = RootView::GetInstance()->GetBoundWindow(); - if (window != nullptr) { - EventInjector::GetInstance()->SetWindowId(window->GetWindowId()); - } -#endif - CompareTools::WaitSuspend(); - - ListNode* node = AutoTestCaseGroup::GetTestCase().Begin(); - while (node != AutoTestCaseGroup::GetTestCase().End()) { - node->data_->RunTestList(); - node->data_->ResetMainMenu(); - node = node->next_; - } -} - -AutoTestApp::~AutoTestApp() -{ - if (EventInjector::GetInstance()->IsEventInjectorRegistered(EventDataType::POINT_TYPE)) { - EventInjector::GetInstance()->UnregisterEventInjector(EventDataType::POINT_TYPE); - } - if (EventInjector::GetInstance()->IsEventInjectorRegistered(EventDataType::KEY_TYPE)) { - EventInjector::GetInstance()->UnregisterEventInjector(EventDataType::KEY_TYPE); - } - AutoTestCaseGroup::TearDownTestCase(); -} -} // namespace OHOS diff --git a/test/framework/src/auto_test_case_group.cpp b/test/framework/src/auto_test_case_group.cpp deleted file mode 100644 index 2210e01f2be38671e0fbff9d1960216a2965f82f..0000000000000000000000000000000000000000 --- a/test/framework/src/auto_test_case_group.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "auto_test_case_group.h" -#include "graphic_config.h" - -namespace OHOS { -List AutoTestCaseGroup::testCaseList_; - -List& AutoTestCaseGroup::GetTestCase() -{ - return testCaseList_; -} - -void AutoTestCaseGroup::TearDownTestCase() -{ - ListNode* node = testCaseList_.Begin(); - while (node != testCaseList_.End()) { - delete node->data_; - node->data_ = nullptr; - node = node->next_; - } - testCaseList_.Clear(); -} - -void AutoTestCaseGroup::AddTestCase(AutoTestCase* testCaseInfo) -{ - if (testCaseInfo != nullptr) { - testCaseList_.PushBack(testCaseInfo); - } -} -} // namespace OHOS diff --git a/test/framework/src/auto_test_manager.cpp b/test/framework/src/auto_test_manager.cpp new file mode 100644 index 0000000000000000000000000000000000000000..361aa3e29c3f1919aecc7816830c83be1b68b506 --- /dev/null +++ b/test/framework/src/auto_test_manager.cpp @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "auto_test_manager.h" + +#include +#include + +#include "dfx/event_injector.h" + +namespace OHOS { +AutoTestManager::AutoTestManager() +{ + SetUpTestCase(); +} + +AutoTestManager::~AutoTestManager() +{ + TearDownTestCase(); +} + +AutoTestManager* AutoTestManager::GetInstance() +{ + static AutoTestManager instance; + return &instance; +} + +void AutoTestManager::SetUpTestCase() +{ + autoTest_ = std::make_shared(); + +#ifdef _WIN32 + const char logPath[] = ".\\auto_test_log.txt"; + CompareTools::SetLogPath(logPath, sizeof(logPath)); +#else + const char logPath[] = "./auto_test_log.txt"; + CompareTools::SetLogPath(logPath, sizeof(logPath)); +#endif + EventInjector::GetInstance()->RegisterEventInjector(EventDataType::POINT_TYPE); + EventInjector::GetInstance()->RegisterEventInjector(EventDataType::KEY_TYPE); +#if ENABLE_WINDOW + Window* window = RootView::GetInstance()->GetBoundWindow(); + if (window != nullptr) { + EventInjector::GetInstance()->SetWindowId(window->GetWindowId()); + } +#endif +} + +void AutoTestManager::TearDownTestCase() +{ + if (EventInjector::GetInstance()->IsEventInjectorRegistered(EventDataType::POINT_TYPE)) { + EventInjector::GetInstance()->UnregisterEventInjector(EventDataType::POINT_TYPE); + } + if (EventInjector::GetInstance()->IsEventInjectorRegistered(EventDataType::KEY_TYPE)) { + EventInjector::GetInstance()->UnregisterEventInjector(EventDataType::KEY_TYPE); + } +} + +void AutoTestManager::SendMsg(size_t mainID) +{ + sendMsgFunc_(mainID); +} + +void AutoTestManager::SetSendMsgFuncCallBack(SendMsgFunc sendMsgFunc) +{ + sendMsgFunc_ = sendMsgFunc; +} + +void AutoTestManager::StartTest(std::vector> msgInfo) +{ + printf("AutoTestManager::StartTest----msgInfo.size=[%d]\n", msgInfo.size()); + fflush(stdout); + if (!autoTest_) { + return; + } + + autoTest_->RunTest(msgInfo); +} + +void AutoTestManager::TestComplete() +{ + if (!autoTest_) { + return; + } + + autoTest_->TestComplete(); +} + +void AutoTestManager::SetConfigInfo(const std::shared_ptr configInfo) +{ + configInfo_ = configInfo; + printf("AutoTestManager::SetConfigInfo--testMode=[%zu], baseDir=[%s], runDir=[%s], logDir=[%s]\n", + configInfo_->testMode, configInfo_->baseDir.c_str(), configInfo_->runDir.c_str(), + configInfo_->logDir.c_str()); + fflush(stdout); + SendMsg(C_S_MAIN_ID_REQUEST_TEST_INFO); +} + +std::shared_ptr AutoTestManager::GetConfigInfo() +{ + return configInfo_; +} +} diff --git a/test/framework/src/compare_tools.cpp b/test/framework/src/compare_tools.cpp index f92dbc4780469b38cbf8b2e013697cf39c4f04f9..06385becb3682e5e8a47264255a414f5b8ec0cdc 100644 --- a/test/framework/src/compare_tools.cpp +++ b/test/framework/src/compare_tools.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Copyright (c) 2020-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -103,6 +103,102 @@ bool CompareTools::CompareByBit(uint32_t fd) return flag; } +bool CompareTools::CompareByBitmap(const BitmapInfoHeader bitmapInfoBase, + const BitmapInfoHeader bitmapInfoRun, uint32_t fdBase, uint32_t fdRun) +{ + bool flag = true; + uint32_t buffSizeBase = bitmapInfoBase.biSizeImage / MATH_ABS(bitmapInfoBase.biHeight); + auto buffBase = new uint8_t[buffSizeBase]; + + uint32_t buffSizeRun = bitmapInfoRun.biSizeImage / MATH_ABS(bitmapInfoRun.biHeight); + auto buffRun = new uint8_t[buffSizeRun]; + + for (uint32_t i = 0; i < MATH_ABS(bitmapInfoBase.biHeight); i++) { + if (flag && (memset_s(buffBase, buffSizeBase, 0, buffSizeBase) != EOK)) { + flag = false; + break; + } + if (flag && (memset_s(buffRun, buffSizeRun, 0, buffSizeRun) != EOK)) { + flag = false; + break; + } + uint32_t retBase = read(fdBase, buffBase, buffSizeBase); + if (retBase < 0) { + flag = false; + break; + } + uint32_t retRun = read(fdRun, buffRun, buffSizeBase); + if (retRun < 0) { + flag = false; + break; + } + if (retBase != retRun) { + flag = false; + break; + } + + for (uint32_t j = 0; j < retBase; j++) { + if (buffBase[j] != buffRun[j]) { + flag = false; + break; + } + } + } + + delete [] buffBase; + buffBase = nullptr; + delete [] buffRun; + buffRun = nullptr; + + return flag; +} + + +bool CompareTools::CompareFile(const char* fileBasePath, const char* fileRunPath) +{ + if (fileBasePath == nullptr || fileRunPath == nullptr) { + return false; + } +#ifdef _WIN32 + uint32_t fdBase = open(fileBasePath, O_RDONLY | O_BINARY); + uint32_t fdRun = open(fileRunPath, O_RDONLY | O_BINARY); +#else + uint32_t fdBase = open(fileBasePath, O_RDONLY); + uint32_t fdRun = open(fileRunPath, O_RDONLY); +#endif + struct BitmapInfoHeader bitmapInfoBase = {0}; + lseek(fdBase, sizeof(uint16_t), SEEK_SET); + if (read(fdBase, &bitmapInfoBase, sizeof(bitmapInfoBase)) < 0) { + close(fdBase); + close(fdRun); + return false; + } + + struct BitmapInfoHeader bitmapInfoRun = {0}; + lseek(fdRun, sizeof(uint16_t), SEEK_SET); + if (read(fdRun, &bitmapInfoRun, sizeof(bitmapInfoRun)) < 0) { + close(fdBase); + close(fdRun); + return false; + } + + if (bitmapInfoBase.biSizeImage != bitmapInfoRun.biSizeImage) { + close(fdBase); + close(fdRun); + return false; + } + + if (!CompareByBitmap(bitmapInfoBase, bitmapInfoRun, fdBase, fdRun)) { + close(fdBase); + close(fdRun); + return false; + } + + close(fdBase); + close(fdRun); + return true; +} + bool CompareTools::CompareFile(const char* filePath, size_t length) { if ((filePath == nullptr) || (length > DEFAULT_FILE_NAME_MAX_LENGTH)) { @@ -169,6 +265,15 @@ bool CompareTools::SaveByBit(uint32_t fd) return flag; } +void CompareTools::SaveResultLog(const char* filePath, const char* buff, size_t bufSize) +{ + if (filePath == nullptr || buff == nullptr || bufSize <= 0) { + return; + } + + SaveLog(buff, bufSize, filePath); +} + bool CompareTools::SaveFile(const char* filePath, size_t length) { if ((filePath == nullptr) || (length > DEFAULT_FILE_NAME_MAX_LENGTH)) { @@ -184,25 +289,6 @@ bool CompareTools::SaveFile(const char* filePath, size_t length) } bool flag = SaveByBit(fd); close(fd); - if (flag) { - GRAPHIC_LOGI("[SAVE_SUCCESS]:filePath = %s", filePath); - if (enableLog_) { - char logInfo[DEFAULT_FILE_NAME_MAX_LENGTH] = {0}; - if (sprintf_s(logInfo, sizeof(logInfo), "[SAVE_SUCCESS]:fileName=%s\n", filePath) < 0) { - return false; - } - SaveLog(logInfo, strlen(logInfo)); - } - } else { - GRAPHIC_LOGI("[SAVE_FAILURE]:filePath = %s", filePath); - if (enableLog_) { - char logInfo[DEFAULT_FILE_NAME_MAX_LENGTH] = {0}; - if (sprintf_s(logInfo, sizeof(logInfo), "[SAVE_FAILURE]:fileName=%s\n", filePath) < 0) { - return false; - } - SaveLog(logInfo, strlen(logInfo)); - } - } return flag; } @@ -243,12 +329,18 @@ void CompareTools::UnsetLogPath() } } -bool CompareTools::SaveLog(const char* buff, size_t bufSize) +bool CompareTools::SaveLog(const char* buff, size_t bufSize, const char* filePath) { - if ((buff == nullptr) || (logPath_ == nullptr)) { + if (buff == nullptr) { return false; } - uint32_t logFd = open(logPath_, O_WRONLY | O_CREAT | O_APPEND, DEFAULT_FILE_PERMISSION); + + const char* useLogPath = filePath == nullptr ? logPath_ : filePath; + if (useLogPath == nullptr) { + return false; + } + + uint32_t logFd = open(useLogPath, O_WRONLY | O_CREAT | O_APPEND, DEFAULT_FILE_PERMISSION); if (logFd == -1) { GRAPHIC_LOGE("open log failed"); return false; diff --git a/test/framework/src/test_ability.cpp b/test/framework/src/test_ability.cpp index 6d28b0ea7a6ea4f550783ec41a31854d5cd70956..bf51ef17d378d9be025e63ee842aff821d2f2401 100644 --- a/test/framework/src/test_ability.cpp +++ b/test/framework/src/test_ability.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Copyright (c) 2020-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -19,8 +19,4 @@ void RunApp() { OHOS::UITestApp::GetInstance()->Start(); -#if ENABEL_UI_AUTO_TEST - ThreadAttr attr; - ThreadCreate(OHOS::AutoTestThread, nullptr, &attr); -#endif // ENABEL_UI_AUTO_TEST } diff --git a/test/framework/src/ui_auto_test.cpp b/test/framework/src/ui_auto_test.cpp index a3ab1209eab9db05bb3eec98a8bb073bc0636133..16b6b924e36e464f3dce3991d098e783c281e1c1 100644 --- a/test/framework/src/ui_auto_test.cpp +++ b/test/framework/src/ui_auto_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Copyright (c) 2020-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -15,17 +15,28 @@ #include "ui_auto_test.h" -#include "compare_tools.h" +#include "auto_test_manager.h" #include "components/root_view.h" -#include "components/ui_list.h" #include "components/ui_view_group.h" #include "dfx/event_injector.h" -#include "test_layout/ui_auto_test_basic_layout.h" -#include "test_render/ui_auto_test_render.h" #include "ui_test_app.h" #include "ui_test_group.h" namespace OHOS { +UIAutoTest::UIAutoTest() +{ +} + +UIAutoTest::~UIAutoTest() +{ +} + +void UIAutoTest::Reset(std::string testID) const +{ + ResetMainMenu(); + ClickViewById(testID.c_str()); +} + void UIAutoTest::ResetMainMenu() const { while (RootView::GetInstance()->GetChildById(UI_TEST_MAIN_LIST_ID) == nullptr) { @@ -38,6 +49,7 @@ void UIAutoTest::EnterSubMenu(const char* id) const if (id == nullptr) { return; } + UIView* view = RootView::GetInstance()->GetChildById(id); if (view == nullptr) { UIView* view = RootView::GetInstance()->GetChildById(UI_TEST_MAIN_LIST_ID); @@ -56,6 +68,7 @@ void UIAutoTest::EnterSubMenu(const char* id) const reinterpret_cast(view)->RefreshList(); CompareTools::WaitSuspend(); } + ClickViewById(id); } @@ -95,23 +108,169 @@ void UIAutoTest::DragViewToHead(const char* id) const CompareTools::WaitSuspend(); } -void UIAutoTest::CompareByBinary(const char* fileName) const +void UIAutoTest::DrageToView(const char* id, int16_t x, int16_t y) const { - if (fileName == nullptr) { + if (id == nullptr) { + return; + } + UIView* view = RootView::GetInstance()->GetChildById(id); + if (view == nullptr) { return; } + Point startPoint; + startPoint.x = view->GetOrigRect().GetX(); + startPoint.y = view->GetOrigRect().GetY(); + + Point endPoint; + endPoint.x = x; + endPoint.y = y; + EventInjector::GetInstance()->SetDragEvent(startPoint, endPoint, 300); // 300: drag time + CompareTools::WaitSuspend(); +} + +bool UIAutoTest::CompareByBinary(const char* fileName) const +{ + if (fileName == nullptr) { + return false; + } char filePath[DEFAULT_FILE_NAME_MAX_LENGTH] = {0}; CompareTools::StrnCatPath(filePath, DEFAULT_FILE_NAME_MAX_LENGTH, fileName, strlen(fileName)); if (CompareTools::CheckFileExist(filePath, sizeof(filePath))) { - CompareTools::CompareFile(filePath, sizeof(filePath)); + return CompareTools::CompareFile(filePath, sizeof(filePath)); } else { - CompareTools::SaveFile(filePath, sizeof(filePath)); + return CompareTools::SaveFile(filePath, sizeof(filePath)); + } +} + +void UIAutoTest::RunTest(std::vector> msgInfo) +{ + printf("UIAutoTest::RunTest----testInfo.size=[%d]\n", msgInfo.size()); + fflush(stdout); + for (auto it: msgInfo) { + OnTest(it); + } + + AutoTestManager::GetInstance()->SendMsg(C_S_MAIN_ID_TEST_FINISH_INFO); +} + +void UIAutoTest::OnTest(std::shared_ptr info) +{ + ResetMainMenu(); + OnEnterPage(info->pageNav); + OnTestBySteps(info->steps, info->className); +} + +void UIAutoTest::OnTestBySteps(std::vector steps, std::string className) +{ + if (steps.empty()) { + return; + } + + int stepIndex = 0; + for (auto it: steps) { + OnTestOneStep(it, className, stepIndex++); } } -void UIAutoTest::SetUpTestCase() +void UIAutoTest::OnTestOneStep(TestSteps step, std::string className, size_t stepIndex) { - AutoTestCaseGroup::AddTestCase(new UIAutoTestRender()); - AutoTestCaseGroup::AddTestCase(new UIAutoTestBasicLayout()); + if (step.eventID == TestEventID::TEST_CLICK_EVENT) { + ClickViewById(step.viewID.c_str()); + } else if (step.eventID == TestEventID::TEST_MOVE_EVENT) { + if (step.eventValue.size() < EVENT_VALUE_SIZE_TWO) { + return; + } + + int16_t x = static_cast(step.eventValue[0]); + int16_t y = static_cast(step.eventValue[1]); + DrageToView(step.viewID.c_str(), x, y); + } + + if (step.saveCheckPoint) { + OnSaveFile(className, step.viewID, stepIndex); + } +} + +void UIAutoTest::OnEnterPage(std::vector pageNav) +{ + if (pageNav.empty()) { + return; + } + + for (auto it: pageNav) { + EnterSubMenu(it.c_str()); + } +} + +void UIAutoTest::OnSaveFile(std::string className, std::string viewID, size_t stepIndex) +{ + std::string fileName = className + "@" + viewID + "@" + std::to_string(stepIndex) + ".bmp"; + fileNames_.push_back(fileName); + + std::string filePath; + std::shared_ptr config = AutoTestManager::GetInstance()->GetConfigInfo(); + if (config->testMode == TestMode::TEST_MODE_BASE) { + filePath = config->baseDir + fileName; + } else if (config->testMode == TestMode::TEST_MODE_RUN) { + filePath = config->runDir + fileName; + } + + printf("OnSaveFile, filePath = %s\n", filePath.c_str()); + fflush(stdout); + CompareTools::SaveFile(filePath.c_str(), strlen(filePath.c_str())); +} + +void UIAutoTest::TestComplete() const +{ + printf("UIAutoTest::TestComplete"); + fflush(stdout); + std::shared_ptr config = AutoTestManager::GetInstance()->GetConfigInfo(); + if (!config) { + return; + } + if (config->testMode != TestMode::TEST_MODE_RUN) { + return; + } + + config->logDir += OnGetSystemTime(); + config->logDir += ".txt"; + printf("UIAutoTest::OnCompareFile--logDir=[%s]\n", config->logDir.c_str()); + fflush(stdout); + for (auto it: fileNames_) { + OnCompareFile(it); + } +} + +void UIAutoTest::OnCompareFile(std::string fileName) const +{ + std::shared_ptr config = AutoTestManager::GetInstance()->GetConfigInfo(); + if (!config) { + return; + } + + std::string fileBasePath = config->baseDir + fileName; + std::string fileRunPath = config->runDir + fileName; + + std::string log; + if (!CompareTools::CompareFile(fileBasePath.c_str(), fileRunPath.c_str())) { + printf("UIAutoTest::OnCompareFile----different\n"); + fflush(stdout); + log = "[FAIL]:[" + fileName + "]\n"; + } else { + log = "[SUCESS]:[" + fileName + "]\n"; + } + + CompareTools::SaveResultLog(config->logDir.c_str(), log.c_str(), strlen(log.c_str())); +} + +std::string UIAutoTest::OnGetSystemTime() const +{ + time_t t = time(0); + char tmp[32] = { 0 }; + strftime(tmp, sizeof(tmp), "%Y-%m-%d-%H-%M-%S", localtime(&t)); + + std::string loctime = tmp; + + return loctime; } } // namespace OHOS diff --git a/test/framework/src/ui_test_app.cpp b/test/framework/src/ui_test_app.cpp index 0f69aa9c8932a56c6f0b9a4e31bd65e0eb4444eb..d5003012a1c2353c3566f6fd62348a5a44cb0bfa 100644 --- a/test/framework/src/ui_test_app.cpp +++ b/test/framework/src/ui_test_app.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Copyright (c) 2020-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -15,35 +15,12 @@ #include "ui_test_app.h" -#include "auto_test_app.h" #include "compare_tools.h" #include "test_resource_config.h" -#include "ui_auto_test.h" #include "ui_test.h" #include "ui_test_group.h" namespace OHOS { -#ifdef _WIN32 -DWORD AutoTestThread(LPVOID) -#elif defined __linux__ || defined __LITEOS__ || defined __APPLE__ -void* AutoTestThread(void*) -#endif // _WIN32 -{ -#ifdef _WIN32 - const char logPath[] = ".\\auto_test_log.txt"; - CompareTools::SetLogPath(logPath, sizeof(logPath)); -#else - const char logPath[] = "./auto_test_log.txt"; - CompareTools::SetLogPath(logPath, sizeof(logPath)); -#endif - // 装载用例 - UIAutoTest::SetUpTestCase(); - AutoTestApp::GetInstance()->Start(); - AutoTestCaseGroup::TearDownTestCase(); - CompareTools::UnsetLogPath(); - return nullptr; -} - UITestApp* UITestApp::GetInstance() { static UITestApp instance; @@ -73,8 +50,6 @@ public: bool OnClick(UIView& view, const ClickEvent& event) override { - ThreadCreate(AutoTestThread, nullptr, nullptr); - return true; } }; @@ -111,6 +86,7 @@ void UITestApp::InitMainMenu() autoTestBtn_->SetStyleForState(STYLE_BACKGROUND_OPA, 0, UIButton::RELEASED); autoTestBtn_->SetStyleForState(STYLE_BACKGROUND_OPA, 0, UIButton::PRESSED); autoTestBtn_->SetStyleForState(STYLE_BACKGROUND_OPA, 0, UIButton::INACTIVE); + autoTestBtn_->SetVisible(false); mainMenu_->Add(autoTestBtn_); } if ((mainList_ == nullptr) && (adapter_ == nullptr)) { diff --git a/test/uitest/test_clip/ui_test_clip.cpp b/test/uitest/test_clip/ui_test_clip.cpp index ee1639bd005edfce071536de60c3ae1e11460648..bbc68b41e8c5dc5928e0e272c8aef9dbdfd163cd 100644 --- a/test/uitest/test_clip/ui_test_clip.cpp +++ b/test/uitest/test_clip/ui_test_clip.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2020-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -16,6 +16,7 @@ #include "ui_test_clip.h" #include + #include "common/image.h" #include "draw/clip_utils.h" #include "gfx_utils/graphic_math.h" @@ -137,7 +138,7 @@ UIImageView* UITestClip::CreateImageView() return imageVIew; } -void UITestClip::SetUpButton(UILabelButton* btn, const char* title, int16_t x, int16_t y) +void UITestClip::SetUpButton(UILabelButton* btn, const char* title, int16_t x, int16_t y, const char* id) { if (btn == nullptr) { return; @@ -147,6 +148,7 @@ void UITestClip::SetUpButton(UILabelButton* btn, const char* title, int16_t x, i btn->SetText(title); btn->SetFont(DEFAULT_VECTOR_FONT_FILENAME, BUTTON_LABEL_SIZE); btn->SetOnClickListener(this); + btn->SetViewId(id); btn->SetStyleForState(STYLE_BORDER_RADIUS, BUTTON_STYLE_BORDER_RADIUS_VALUE, UIButton::RELEASED); btn->SetStyleForState(STYLE_BORDER_RADIUS, BUTTON_STYLE_BORDER_RADIUS_VALUE, UIButton::PRESSED); btn->SetStyleForState(STYLE_BORDER_RADIUS, BUTTON_STYLE_BORDER_RADIUS_VALUE, UIButton::INACTIVE); @@ -171,14 +173,14 @@ void UITestClip::UIKitClipTest001() int16_t x = VIEW_DISTANCE_TO_LEFT_SIDE + BLOCK_WIDTH + GAP; int16_t y = positionY_; btnRadiusInc1_ = new UILabelButton(); - SetUpButton(btnRadiusInc1_, "半径+1", x, y); + SetUpButton(btnRadiusInc1_, "半径+1", x, y, UI_TEST_RADIUS_1); btnRadiusDec1_ = new UILabelButton(); - SetUpButton(btnRadiusDec1_, "半径-1", x + BUTTON_WIDHT2 + GAP, y); + SetUpButton(btnRadiusDec1_, "半径-1", x + BUTTON_WIDHT2 + GAP, y, UI_TEST_RADIUS_2); btnRadiusInc5_ = new UILabelButton(); y += BUTTON_HEIGHT2 + GAP; - SetUpButton(btnRadiusInc5_, "半径+5", x, y); + SetUpButton(btnRadiusInc5_, "半径+5", x, y, UI_TEST_RADIUS_3); btnRadiusDec5_ = new UILabelButton(); - SetUpButton(btnRadiusDec5_, "半径-5", x + BUTTON_WIDHT2 + GAP, y); + SetUpButton(btnRadiusDec5_, "半径-5", x + BUTTON_WIDHT2 + GAP, y, UI_TEST_RADIUS_4); y += BUTTON_HEIGHT2 + GAP; radiusText_ = new UILabel(); diff --git a/test/uitest/test_clip/ui_test_clip.h b/test/uitest/test_clip/ui_test_clip.h index 4aa3739821408dcfa33b7dc83b271eccca938c35..8984196c2e5dbd11ecd1f926cdf8190df4e3fb17 100644 --- a/test/uitest/test_clip/ui_test_clip.h +++ b/test/uitest/test_clip/ui_test_clip.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2021 Huawei Device Co., Ltd. + * Copyright (c) 2020-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -23,6 +23,10 @@ #include "ui_test.h" namespace OHOS { +constexpr char* UI_TEST_RADIUS_1 = "radius+1"; +constexpr char* UI_TEST_RADIUS_2 = "radius-1"; +constexpr char* UI_TEST_RADIUS_3 = "radius+5"; +constexpr char* UI_TEST_RADIUS_4 = "radius-5"; class UITestClip : public UITest, public UIView::OnClickListener { public: UITestClip() {} @@ -53,7 +57,7 @@ private: void CreateTitleLabel(const char* title); UIImageView* CreateImageView(); void ClipImage(UIImageView* imageView, ClipPath& path); - void SetUpButton(UILabelButton* btn, const char* title, int16_t x, int16_t y); + void SetUpButton(UILabelButton* btn, const char* title, int16_t x, int16_t y, const char* id = nullptr); UILabelButton* btnRadiusInc1_ = nullptr; UILabelButton* btnRadiusInc5_ = nullptr; diff --git a/test/framework/include/auto_test_app.h b/tools/qt/simulator/drivers/display/scoket_thread.h similarity index 53% rename from test/framework/include/auto_test_app.h rename to tools/qt/simulator/drivers/display/scoket_thread.h index a9262ac0868a7f98f4e83bf831396f819cff2746..6a0aed9b7531705dbf8c6e234846ca8aacc3eb3e 100644 --- a/test/framework/include/auto_test_app.h +++ b/tools/qt/simulator/drivers/display/scoket_thread.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,23 +13,33 @@ * limitations under the License. */ -#ifndef GRAPHIC_LITE_AUTO_TEST_APP_H -#define GRAPHIC_LITE_AUTO_TEST_APP_H +#ifndef GRAPHIC_LITE_SOCKET_THREAD_H +#define GRAPHIC_LITE_SOCKET_THREAD_H + +#include +#include + +#include "tcp_socket_manager.h" namespace OHOS { -class AutoTestApp { +class SocketThread : public QThread { + Q_OBJECT public: - static AutoTestApp* GetInstance(); - void Start(); + SocketThread(); + ~SocketThread(); -private: - AutoTestApp() {} - virtual ~AutoTestApp(); + void run() override; + void Quit(); - AutoTestApp(const AutoTestApp&) = delete; - AutoTestApp& operator=(const AutoTestApp&) = delete; - AutoTestApp(AutoTestApp&&) = delete; - AutoTestApp& operator=(AutoTestApp&&) = delete; + inline TcpSocketClientManager* GetClientManager() + { + return clientManager_; + }; + +private: + volatile bool taskQuitQry = false; + TcpSocketClientManager* clientManager_; }; } // namespace OHOS -#endif // GRAPHIC_LITE_AUTO_TEST_APP_H + +#endif // GRAPHIC_LITE_SOCKET_THREAD_H \ No newline at end of file diff --git a/tools/qt/simulator/drivers/display/socket_thread.cpp b/tools/qt/simulator/drivers/display/socket_thread.cpp new file mode 100644 index 0000000000000000000000000000000000000000..12a66ba204d063a19dce943f06f2a5a324fa1cb3 --- /dev/null +++ b/tools/qt/simulator/drivers/display/socket_thread.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "scoket_thread.h" + +namespace OHOS { +SocketThread::SocketThread() +{ + clientManager_ = TcpSocketClientManager::GetInstance(); +} + +SocketThread::~SocketThread() +{ + clientManager_ = nullptr; +} + +void SocketThread::run() +{ + taskQuitQry = false; + while (!taskQuitQry) { + TcpSocketClientManager::GetInstance()->DispatchMsg(); + Sleep(DEFAULT_TASK_PERIOD); + } +} + +void SocketThread::Quit() +{ + taskQuitQry = true; +} +} // namespace OHOS \ No newline at end of file diff --git a/tools/qt/simulator/test/test.pro b/tools/qt/simulator/test/test.pro old mode 100755 new mode 100644 index f194195a86df4814b75a10b15f2f79f51b6b0ec7..056c4830fd086669e95f9af3968b1d45b3b00da9 --- a/tools/qt/simulator/test/test.pro +++ b/tools/qt/simulator/test/test.pro @@ -95,12 +95,9 @@ SOURCES += \ ../../../../test/uitest/test_view_scale_rotate/ui_test_view_scale_rotate.cpp SOURCES += \ - ../../../../test/framework/src/auto_test_app.cpp \ - ../../../../test/framework/src/auto_test_case_group.cpp \ + ../../../../test/framework/src/auto_test_manager.cpp \ ../../../../test/framework/src/compare_tools.cpp \ ../../../../test/framework/src/ui_auto_test.cpp \ - ../../../../test/uitest/test_render/ui_auto_test_render.cpp \ - ../../../../test/uitest/test_layout/ui_auto_test_basic_layout.cpp HEADERS += \ ../../../../test/framework/common/ui_text_language.h \ @@ -117,7 +114,7 @@ HEADERS += \ ../../../../test/uitest/test_canvas/ui_test_canvas.h \ ../../../../test/uitest/test_chart/ui_test_chart_pillar.h \ ../../../../test/uitest/test_chart/ui_test_chart_polyline.h \ - ../../../../test/uitest/test_clip/ui_test_clip.cpp \ + ../../../../test/uitest/test_clip/ui_test_clip.h \ ../../../../test/uitest/test_dialog/ui_test_dialog.h \ ../../../../test/uitest/test_digital_clock/ui_test_digital_clock.h \ ../../../../test/uitest/test_draw_line/ui_test_draw_line.h \ @@ -156,12 +153,10 @@ HEADERS += \ ../../../../test/uitest/test_view_scale_rotate/ui_test_view_scale_rotate.h HEADERS += \ - ../../../../test/framework/include/auto_test_app.h \ - ../../../../test/framework/include/auto_test_case_group.h \ + ../../../../test/framework/include/auto_test_manager.h \ ../../../../test/framework/include/compare_tools.h \ ../../../../test/framework/include/ui_auto_test.h \ - ../../../../test/uitest/test_render/ui_auto_test_render.h \ - ../../../../test/uitest/test_layout/ui_auto_test_basic_layout.h + ../../../../test/framework/include/ui_test_message.h \ INCLUDEPATH += \ ../../../../frameworks \ diff --git a/tools/qt/simulator/uitest/UITest.pro b/tools/qt/simulator/uitest/UITest.pro old mode 100755 new mode 100644 index b039e5cd90fbb5a3ab840925685e64181443d9fe..35a2c2773ee5ee4d25804be60cd17261b645a5f6 --- a/tools/qt/simulator/uitest/UITest.pro +++ b/tools/qt/simulator/uitest/UITest.pro @@ -35,6 +35,9 @@ SOURCES += \ ../drivers/indev/key_input.cpp \ ../drivers/indev/mouse_input.cpp \ ../drivers/indev/mousewheel_input.cpp \ + ../drivers/display/socket_thread.cpp \ + tcp_socket.cpp \ + tcp_socket_manager.cpp \ main.cpp \ main_widget.cpp @@ -46,6 +49,9 @@ HEADERS += \ ../drivers/indev/key_input.h \ ../drivers/indev/mouse_input.h \ ../drivers/indev/mousewheel_input.h \ + ../drivers/display/scoket_thread.h \ + tcp_socket.h \ + tcp_socket_manager.h \ main_widget.h INCLUDEPATH += \ @@ -59,6 +65,7 @@ INCLUDEPATH += \ ../../../../../utils/interfaces/innerkits \ ../../../../../utils/interfaces/kits \ ../../../../../../../third_party/freetype/include \ + ../../../../test/framework/include \ ../../../../../../../third_party/bounds_checking_function/include LIBS += $$OUT_PWD/../libs/libui.dll diff --git a/tools/qt/simulator/uitest/main.cpp b/tools/qt/simulator/uitest/main.cpp index 38b2d46959b194b37895d09b36269d6f9fd4b24b..e1f41eba54fb6b42a850d3c7f47ae0f2fbd8622f 100644 --- a/tools/qt/simulator/uitest/main.cpp +++ b/tools/qt/simulator/uitest/main.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Copyright (c) 2020-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -27,6 +27,11 @@ int main(int argc, char* argv[]) OHOS::Monitor::GetInstance()->InitHal(); OHOS::Monitor::GetInstance()->InitFontEngine(); OHOS::Monitor::GetInstance()->InitImageDecodeAbility(); + + if (argv[1] != nullptr && strcmp(argv[1], "-f") == 0) { + OHOS::TcpSocketClientManager::GetInstance()->InitSocket(); + } + RunApp(); OHOS::MainWidget mainWidget; mainWidget.resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); diff --git a/tools/qt/simulator/uitest/main_widget.cpp b/tools/qt/simulator/uitest/main_widget.cpp index a85869e8146d5cc4815c536e15664c47af21784b..4b9db5c6a669ad194fec276fc9ab1715a69a970e 100644 --- a/tools/qt/simulator/uitest/main_widget.cpp +++ b/tools/qt/simulator/uitest/main_widget.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Copyright (c) 2020-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -22,6 +22,7 @@ MainWidget::MainWidget(QWidget* parent) : QWidget(parent), guiThread_(nullptr), ui_->setupUi(this); CreateGUIThread(); CreateTaskThread(); + CreateSocketThread(); } MainWidget::~MainWidget() @@ -37,6 +38,11 @@ MainWidget::~MainWidget() taskThread_->wait(); delete taskThread_; } + if (socketThread_ != nullptr) { + socketThread_->Quit(); + socketThread_->wait(); + delete socketThread_; + } } void MainWidget::CreateGUIThread() @@ -58,6 +64,17 @@ void MainWidget::CreateTaskThread() } } +void MainWidget::CreateSocketThread() +{ + socketThread_ = new SocketThread(); + if (socketThread_ != nullptr) { + socketThread_->start(); + qRegisterMetaType("size_t"); + connect(socketThread_->GetClientManager(), SIGNAL(SendMsgSignal(size_t)), this, + SLOT(SendMsgSlot(size_t))); + } +} + void MainWidget::paintEvent(QPaintEvent* event) { Q_UNUSED(event) diff --git a/tools/qt/simulator/uitest/main_widget.h b/tools/qt/simulator/uitest/main_widget.h index 8dd9879e9855b35cdcb93df7f6d7091dc2463c45..2138118230b87a5ffd3ffd04367e514dc62d82f1 100644 --- a/tools/qt/simulator/uitest/main_widget.h +++ b/tools/qt/simulator/uitest/main_widget.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Copyright (c) 2020-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -32,6 +32,7 @@ #include "monitor.h" #include "mouse_input.h" #include "mousewheel_input.h" +#include "scoket_thread.h" #include "task_thread.h" #include "ui_mainwidget.h" @@ -50,6 +51,7 @@ public: ~MainWidget(); void CreateGUIThread(); void CreateTaskThread(); + void CreateSocketThread(); protected: void mouseMoveEvent(QMouseEvent* event) override; @@ -67,6 +69,7 @@ private: uint32_t height_; GUIThread* guiThread_; TaskThread* taskThread_; + SocketThread* socketThread_; public slots: void UpdatePaintSlot(uint32_t* tftFb, uint32_t imgWidth, uint32_t imgHeight) @@ -80,6 +83,17 @@ public slots: } update(); }; + + void SendMsgSlot(size_t mainID) + { + TcpScoketClient* tcpSocket = OHOS::TcpSocketClientManager::GetInstance()->GetTcpSocket(); + if (tcpSocket) { + QString str = QString::number(mainID); + printf("SendMsgSlot----------str=[%s] \n", str.toStdString().c_str()); + fflush(stdout); + tcpSocket->OnSendMessage(str); + } + } }; } // namespace OHOS diff --git a/tools/qt/simulator/uitest/tcp_socket.cpp b/tools/qt/simulator/uitest/tcp_socket.cpp new file mode 100644 index 0000000000000000000000000000000000000000..259104e1a88ad17a2ecbfca0bd260baa699f7d28 --- /dev/null +++ b/tools/qt/simulator/uitest/tcp_socket.cpp @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "tcp_socket.h" + +namespace OHOS { +TcpScoketClient::TcpScoketClient() : tcpSocket_(nullptr) +{ +} + +TcpScoketClient::~TcpScoketClient() +{ + if (tcpSocket_) { + delete tcpSocket_; + tcpSocket_ = nullptr; + } +} + +void TcpScoketClient::CreateTCPScoket() +{ + if (tcpSocket_ == nullptr) { + tcpSocket_ = new QTcpSocket(this); + } + + if (tcpSocket_ == nullptr) { + return; + } + + connect(tcpSocket_, SIGNAL(connected()), this, SLOT(OnConnected())); + connect(tcpSocket_, SIGNAL(disconnected()), this, SLOT(OnDisconnected())); + connect(tcpSocket_, SIGNAL(stateChanged(QAbstractSocket::SocketState)), + this, SLOT(OnSocketStateChange(QAbstractSocket::SocketState))); + connect(tcpSocket_, SIGNAL(readyRead()), this, SLOT(OnSocketReadyRead())); +} + +void TcpScoketClient::ConnectSocket() +{ + if (tcpSocket_ == nullptr) { + return; + } + + tcpSocket_->connectToHost(IP, port); +} + +void TcpScoketClient::SetScoketManager(TcpSocketClientManager* tcpSocketManager) +{ + tcpSocketManager_ = tcpSocketManager; +} + +void TcpScoketClient::OnConnected() +{ + printf("TcpScoketClient::connected\n"); + fflush(stdout); +} + +void TcpScoketClient::OnDisconnected() +{ + printf("TcpScoketClient::onDisconnected\n"); +} + +void TcpScoketClient::OnSocketStateChange(QAbstractSocket::SocketState socketState) +{ + printf("TcpScoketClient::onSocketStateChange---socketState=[%d]\n", socketState); + switch (socketState) { + case QAbstractSocket::UnconnectedState: + break; + case QAbstractSocket::HostLookupState: + break; + case QAbstractSocket::ConnectingState: + break; + case QAbstractSocket::ConnectedState: + break; + case QAbstractSocket::BoundState: + break; + case QAbstractSocket::ClosingState: + break; + case QAbstractSocket::ListeningState: + break; + default: + break; + } +} + +void TcpScoketClient::OnSocketReadyRead() +{ + QByteArray recv = tcpSocket_->readAll(); + tcpSocketManager_->RecvMsg(recv); +} + +void TcpScoketClient::OnSendMessage(QString& message) +{ + QByteArray str = message.toUtf8(); + str.append('\n'); + tcpSocket_->write(str); +} +} diff --git a/tools/qt/simulator/uitest/tcp_socket.h b/tools/qt/simulator/uitest/tcp_socket.h new file mode 100644 index 0000000000000000000000000000000000000000..9869707cb740b2dd798dbb7dafc5e7ab0bdef142 --- /dev/null +++ b/tools/qt/simulator/uitest/tcp_socket.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef GRAPHIC_LITE_TCP_SOCKET_H +#define GRAPHIC_LITE_TCP_SOCKET_H + +#include +#include +#include +#include + +#include "tcp_socket_manager.h" + +const QString IP = "127.0.0.1"; +const quint16 port = 23495; + +namespace OHOS { +class TcpSocketClientManager; +class TcpScoketClient : public QObject { + Q_OBJECT + +public: + TcpScoketClient(); + virtual ~TcpScoketClient(); + void CreateTCPScoket(); + void SetScoketManager(TcpSocketClientManager* tcpSocketManager); + void OnSendMessage(QString& message); + void ConnectSocket(); + +private slots: + void OnConnected(); + void OnDisconnected(); + void OnSocketStateChange(QAbstractSocket::SocketState socketState); + void OnSocketReadyRead(); + +public: + +private: + QTcpSocket* tcpSocket_; + TcpSocketClientManager* tcpSocketManager_; +}; +} // namespace OHOS + +#endif // GRAPHIC_LITE_TCP_SOCKET_H diff --git a/tools/qt/simulator/uitest/tcp_socket_manager.cpp b/tools/qt/simulator/uitest/tcp_socket_manager.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a1ff39e155f07672b83a766de138f765ca2a7021 --- /dev/null +++ b/tools/qt/simulator/uitest/tcp_socket_manager.cpp @@ -0,0 +1,293 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "tcp_socket_manager.h" + +#include +#include +#include + +#include "main.cpp" +#include "auto_test_manager.h" + +namespace OHOS { +static void StartTest(std::vector> msgInfo) +{ + AutoTestManager::GetInstance()->StartTest(msgInfo); +} + +static void DipatchConfigMsg(std::shared_ptr configInfo) +{ + AutoTestManager::GetInstance()->SetConfigInfo(configInfo); +} + +static void DispatchComplete() +{ + AutoTestManager::GetInstance()->TestComplete(); +} + +static void SendTestMsg(size_t mainID) +{ + TcpSocketClientManager::GetInstance()->SendMsg(mainID); +} + +TcpSocketClientManager* TcpSocketClientManager::GetInstance() +{ + static TcpSocketClientManager instance; + return &instance; +} + +TcpSocketClientManager::~TcpSocketClientManager() +{ + if (tcpSocket_) { + delete tcpSocket_; + } +} + +void TcpSocketClientManager::InitSocket() +{ + if (tcpSocket_ == nullptr) { + tcpSocket_ = new TcpScoketClient(); + } + + tcpSocket_->CreateTCPScoket(); + tcpSocket_->SetScoketManager(GetInstance()); + + ConnectSocket(); + + SetDispatchFuncCallBack(std::bind(StartTest, std::placeholders::_1)); + SetDispatchConfigFuncCallBack(std::bind(DipatchConfigMsg, std::placeholders::_1)); + SetDispatchCompleteFuncCallBack(std::bind(DispatchComplete)); + AutoTestManager::GetInstance()->SetSendMsgFuncCallBack(std::bind(SendTestMsg, std::placeholders::_1)); +} + +void TcpSocketClientManager::ConnectSocket() +{ + if (tcpSocket_ == nullptr) { + return; + } + + tcpSocket_->ConnectSocket(); +} + +void TcpSocketClientManager::OnGetEventValue(QJsonArray array, std::vector& values) +{ + foreach (auto it, array) { + values.push_back(it.toInt()); + } +} + +void TcpSocketClientManager::OnGetPageNav(QJsonArray array, std::vector& pageNav) +{ + foreach (auto it, array) { + pageNav.push_back(it.toString().toStdString()); + } +} + +void TcpSocketClientManager::OnGetTestSetps(QJsonArray array, std::vector& steps) +{ + foreach (auto it, array) { + TestSteps testSteps; + QJsonObject arrobj = it.toObject(); + if (arrobj.contains(JSON_VALUE_VIEW_ID.c_str())) { + testSteps.viewID = arrobj.value(JSON_VALUE_VIEW_ID.c_str()).toString().toStdString(); + } + if (arrobj.contains(JSON_VALUE_EVENT_ID.c_str())) { + testSteps.eventID = static_cast(arrobj.value(JSON_VALUE_EVENT_ID.c_str()).toInt()); + } + if (arrobj.contains(JSON_VALUE_EVENT_VALUE.c_str())) { + QJsonValue arrays_value = arrobj.take(JSON_VALUE_EVENT_VALUE.c_str()); + if (arrays_value.isArray()) { + QJsonArray array = arrays_value.toArray(); + OnGetEventValue(array, testSteps.eventValue); + } + } + if (arrobj.contains(JSON_VALUE_SAVE_CHECK_POINT.c_str())) { + testSteps.saveCheckPoint = static_cast( + arrobj.value(JSON_VALUE_SAVE_CHECK_POINT.c_str()).toBool()); + } + steps.push_back(testSteps); + } +} + +void TcpSocketClientManager::RecvMsg(QByteArray recv) +{ + std::shared_ptr recvmsg = std::make_shared(recv); + QMutexLocker mutexLocker(&mutex_); + recv_.push_back(recvmsg); +} + +void TcpSocketClientManager::OnGetMsgInfo(const std::shared_ptr recv) +{ + QJsonParseError parseError; + QJsonDocument document = QJsonDocument::fromJson(recv->toStdString().data(), &parseError); + if (parseError.error != QJsonParseError::NoError) { + return; + } + + QJsonObject object; + if (document.isObject()) { + object = document.object(); + } + + size_t mainID = 0; + if (object.contains(JSON_VALUE_MAIN_ID.c_str())) { + mainID = static_cast(object.value(JSON_VALUE_MAIN_ID.c_str()).toInt()); + } + + printf("OnGetMsgInfo------mainID = [%zu]\n", mainID); + fflush(stdout); + switch (mainID) { + case S_C_MAIN_ID_SEND_CONFIG_INFO: + OnGetConfigInfo(object); + break; + case S_C_MAIN_ID_SEND_TEST_INFO: + OnGetTestInfo(object); + break; + case S_C_MAIN_ID_All_TESTS_COMPLETE: + dispatchCompleteFunc_(); + break; + default: + break; + } +} + +void TcpSocketClientManager::OnGetConfigInfo(const QJsonObject object) +{ + if (object.empty()) { + return; + } + + std::shared_ptr configInfo = std::make_shared(); + if (object.contains(JOSN_VALUE_TEST_MODE.c_str())) { + configInfo->testMode = static_cast(object.value(JOSN_VALUE_TEST_MODE.c_str()).toInt()); + } + + if (object.contains(JSON_VALUE_BASE_DIR.c_str())) { + configInfo->baseDir = object.value(JSON_VALUE_BASE_DIR.c_str()).toString().toStdString(); + } + + if (object.contains(JSON_VALUE_RUN_DIR.c_str())) { + configInfo->runDir = object.value(JSON_VALUE_RUN_DIR.c_str()).toString().toStdString(); + } + + if (object.contains(JSON_VALUE_LOG_DIR.c_str())) { + configInfo->logDir = object.value(JSON_VALUE_LOG_DIR.c_str()).toString().toStdString(); + } + + dispatchConfigFunc_(configInfo); +} + +void TcpSocketClientManager::OnGetTestInfo(QJsonObject object) +{ + if (object.empty()) { + return; + } + + std::vector> testMsgInfo; + if (object.contains(JSON_VALUE_TEST_INFO.c_str())) { + QJsonValue arrays_value = object.take(JSON_VALUE_TEST_INFO.c_str()); + if (!arrays_value.isArray()) { + return; + } + + QJsonArray assintArray = arrays_value.toArray(); + foreach(auto it, assintArray) { + std::shared_ptr msgInfo = std::make_shared(); + QJsonObject arrobj = it.toObject(); + OnGetTestInfo(arrobj, msgInfo); + testMsgInfo.push_back(msgInfo); + } + } + OnPrintTestInfo(testMsgInfo); + + dispatchFunc_(testMsgInfo); +} + +void TcpSocketClientManager::OnGetTestInfo(QJsonObject arrobj, std::shared_ptr& msgInfo) +{ + if (arrobj.contains(JSON_VALUE_CLASS_NAME.c_str())) { + msgInfo->className = arrobj.value(JSON_VALUE_CLASS_NAME.c_str()).toString().toStdString(); + } + + if (arrobj.contains(JSON_VALUE_PAGE_NAV.c_str())) { + QJsonValue value = arrobj.take(JSON_VALUE_PAGE_NAV.c_str()); + if (value.isArray()) { + QJsonArray array = value.toArray(); + OnGetPageNav(array, msgInfo->pageNav); + } + } + + if (arrobj.contains(JSON_VALUE_TEST_STEPS.c_str())) { + QJsonValue value = arrobj.take(JSON_VALUE_TEST_STEPS.c_str()); + if (value.isArray()) { + QJsonArray array = value.toArray(); + OnGetTestSetps(array, msgInfo->steps); + } + } +} + +void TcpSocketClientManager::OnPrintTestInfo(const std::vector> testMsgInfo) const +{ + for (auto it : testMsgInfo) { + printf("TcpSocketClientManager::OnRunRecvMsg()-className=[%s],---\n", it->className.c_str()); + fflush(stdout); + for (auto it2 : it->pageNav) { + printf("pageNav--%s----------", it2.c_str()); + } + printf("\n"); + for (auto it3: it->steps) { + printf("steps---viewID=[%s], eventID=[%d]", it3.viewID.c_str(), it3.eventID); + for (auto it4 : it3.eventValue) { + printf("steps---eventValue=[%d]", it4); + } + printf("steps---saveCheckPoint=[%d]--------\n", it3.saveCheckPoint); + } + } +} + +void TcpSocketClientManager::DispatchMsg() +{ + OnRunRecvMsg(); +} + +void TcpSocketClientManager::SetDispatchFuncCallBack(DispatchFunc dispatchFunc) +{ + dispatchFunc_ = dispatchFunc; +} + +void TcpSocketClientManager::SetDispatchConfigFuncCallBack(DispatchConfigFunc dispatchConfigFunc) +{ + dispatchConfigFunc_ = dispatchConfigFunc; +} + +void TcpSocketClientManager::SetDispatchCompleteFuncCallBack(DispatchCompleteFunc dispatchCompleteFunc) +{ + dispatchCompleteFunc_ = dispatchCompleteFunc; +} + +void TcpSocketClientManager::OnRunRecvMsg() +{ + if (recv_.empty()) { + return; + } + + QMutexLocker mutexLocker(&mutex_); + std::shared_ptr recv = recv_.front(); + recv_.pop_front(); + + OnGetMsgInfo(recv); +} +} // namespace OHOS diff --git a/tools/qt/simulator/uitest/tcp_socket_manager.h b/tools/qt/simulator/uitest/tcp_socket_manager.h new file mode 100644 index 0000000000000000000000000000000000000000..cd8368759af98539ac13067a3a4eb3e6b48a65a4 --- /dev/null +++ b/tools/qt/simulator/uitest/tcp_socket_manager.h @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef GRAPHIC_LITE_TCP_SOCKET_CLIENT_MANGER_H +#define GRAPHIC_LITE_TCP_SOCKET_CLIENT_MANGER_H + +#include +#include + +#include "common/task.h" +#include "gfx_utils/list.h" +#include "tcp_socket.h" +#include "ui_test_message.h" + +namespace OHOS { +class TcpScoketClient; +using DispatchFunc = std::function>)>; +using DispatchConfigFunc = std::function)>; +using DispatchCompleteFunc = std::function; +class TcpSocketClientManager : public QObject { + Q_OBJECT +public: + TcpSocketClientManager() = default; + ~TcpSocketClientManager(); + static TcpSocketClientManager* GetInstance(); + + void InitSocket(); + void ConnectSocket(); + void DispatchMsg(); + void RecvMsg(QByteArray recv); + void SetDispatchFuncCallBack(DispatchFunc dispatchFunc); + void SetDispatchConfigFuncCallBack(DispatchConfigFunc dispatchConfigFunc); + void SetDispatchCompleteFuncCallBack(DispatchCompleteFunc dispatchCompleteFunc); + + inline TcpScoketClient *GetTcpSocket() + { + return tcpSocket_; + } + +signals: + void SendMsgSignal(size_t mainID); +public: + void SendMsg(size_t mainID) + { + emit SendMsgSignal(mainID); + } + +private: + void OnRunRecvMsg(); + void OnGetMsgInfo(const std::shared_ptr recv); + void OnGetConfigInfo(const QJsonObject object); + void OnGetTestInfo(QJsonObject object); + void OnGetTestInfo(QJsonObject arrobj, std::shared_ptr& msgInfo); + + void OnGetPageNav(QJsonArray array, std::vector& pageNav); + void OnGetTestSetps(QJsonArray array, std::vector& steps); + void OnGetEventValue(QJsonArray array, std::vector& values); + void OnPrintTestInfo(const std::vector> testMsgInfo) const; +private: + TcpScoketClient *tcpSocket_; + DispatchFunc dispatchFunc_; + DispatchConfigFunc dispatchConfigFunc_; + DispatchCompleteFunc dispatchCompleteFunc_; + std::deque> recv_; + QMutex mutex_; +}; +} // namespace OHOS + +#endif // GRAPHIC_LITE_TCP_SOCKET_CLIENT_MANGER_H diff --git a/tools/server/config.json b/tools/server/config.json new file mode 100644 index 0000000000000000000000000000000000000000..f9b704052bcdd35601212134efac1b75a1a5b7d5 --- /dev/null +++ b/tools/server/config.json @@ -0,0 +1,25 @@ +{ + "start_test_time": "11:08", + "testGroup":[ + { + "test_mode" : 2, + "process_dir": "D:/WorkSpace/OpenHarmony/foundation/graphic/ui/tools/qt/build-simulator-Desktop_Qt_6_3_1_MinGW_64_bit-Debug/libs/", + "process_name": "UITest.exe", + "base_dir": "D:/WorkSpace/OpenHarmony/foundation/graphic/ui/tools/qt/simulator/config/auto_test/A/", + "run_dir": "D:/WorkSpace/OpenHarmony/foundation/graphic/ui/tools/qt/simulator/config/auto_test/B/", + "log_dir": "D:/WorkSpace/OpenHarmony/foundation/graphic/ui/tools/qt/simulator/config/auto_test/", + "test_case": [], + "test_case_dir": "D:/WorkSpace/Pyhton_demo/test_case" + }, + { + "test_mode" : 2, + "process_dir": "D:/WorkSpace/OpenHarmony/foundation/graphic/ui/tools/qt/build-simulator-Desktop_Qt_6_3_1_MinGW_64_bit-Debug/libs/", + "process_name": "UITest.exe", + "base_dir": "D:/WorkSpace/OpenHarmony/foundation/graphic/ui/tools/qt/simulator/config/auto_test/A/", + "run_dir": "D:/WorkSpace/OpenHarmony/foundation/graphic/ui/tools/qt/simulator/config/auto_test/B/", + "log_dir": "D:/WorkSpace/OpenHarmony/foundation/graphic/ui/tools/qt/simulator/config/auto_test/", + "test_case": [], + "test_case_dir": "D:/WorkSpace/Pyhton_demo/test_case" + } + ] +} \ No newline at end of file diff --git a/tools/server/main.py b/tools/server/main.py new file mode 100644 index 0000000000000000000000000000000000000000..a9b6d5540f368e6a43c181f9599d081a1a31e809 --- /dev/null +++ b/tools/server/main.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import time +import schedule +from tcp_server import TestServer + + +def main(): + tcp_servr = TestServer() + tcp_servr.start() + print(tcp_servr.config) + start_test_time = tcp_servr.config['start_test_time'] + schedule.every().day.at(start_test_time).do(tcp_servr.start_client_process) + + while True: + schedule.run_pending() + time.sleep(1) + + +if __name__ == "__main__": + main() diff --git a/tools/server/tcp_server.py b/tools/server/tcp_server.py new file mode 100644 index 0000000000000000000000000000000000000000..4b375e1cc447f15fa3359c4f3b7ac19f76dd867f --- /dev/null +++ b/tools/server/tcp_server.py @@ -0,0 +1,191 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import threading +import socket +import json +import time +import subprocess +import os +import shutil + + +class TestServer(threading.Thread): + + IP = '127.0.0.1' + + PORT = 23495 + + config_file_name = "config.json" + + # Run base_ Dir directory + TestModeBase = 1 + + # Run run_dir directory + TestModeRun = 2 + + # Send config information + S_C_MAIN_ID_SEND_CONFIG_INFO = 1 + + # Request to start test + C_S_MAIN_ID_REQUEST_TEST_INFO = 2 + + # Distribute test data + S_C_MAIN_ID_SEND_TEST_INFO = 3 + + # Test a set of data + C_S_MAIN_ID_TEST_FINISH_INFO = 4 + + # All tests completed + S_C_MAIN_ID_All_TESTS_COMPLETE = 5 + + + def __init__(self): + threading.Thread.__init__(self) + print("tcp_server_init__") + self.tcp_server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + self.tcp_server_socket.bind((self.IP, self.PORT)) + self.tcp_server_socket.listen(128) + + self.config = self.read_data_from_json(self.config_file_name) + self.test_group_index = 0 + + + def send_message(self, conn, info): + clientdata = json.dumps(info).encode("utf-8") + print('send msg: ', clientdata) + conn.send(clientdata) + + + def init_data(self): + self.test_case_index = 0 + self.test_case = self.config['testGroup'][self.test_group_index]['test_case'] + self.test_case_dir = self.config['testGroup'][self.test_group_index]['test_case_dir'] + + if len(self.config['testGroup'][self.test_group_index]['test_case']) <= 0: + self.test_case = self.traverasl_files(self.config['testGroup'][self.test_group_index]['test_case_dir']) + print(self.test_case) + + + def tcp_connect(self, conn, addr): + print(' Connected by: ', addr) + time.sleep(3) + + self.init_data() + self.start_test(conn) + while True: + data = conn.recv(1024) + data = (int)(data.decode("utf-8")) + print("recv msg: ", data) + if data == self.C_S_MAIN_ID_REQUEST_TEST_INFO: + print("begin test: ", data) + self.test_case_index = 0 + self.send_test_info(conn) + elif data == self.C_S_MAIN_ID_TEST_FINISH_INFO: + self.test_case_index += 1 + self.send_test_info(conn) + + + def send_all_test_finish(self, conn): + send_config = {'main_id':self.S_C_MAIN_ID_All_TESTS_COMPLETE} + self.send_message(conn, send_config) + + self.test_group_index += 1 + if self.test_group_index >= len(self.config['testGroup']): + self.test_group_index = 0 + return + + print("send_all_test_finish------test_group_index=", self.test_group_index,\ + "------len=", len(self.config['testGroup'])) + self.start_client_process() + + + def send_test_info(self, conn): + if len(self.test_case): + if self.test_case_index < len(self.test_case): + json_data = self.read_data_from_json(self.test_case_dir + '/' + self.test_case[self.test_case_index]) + json_data['main_id'] = self.S_C_MAIN_ID_SEND_TEST_INFO + print(json_data) + self.send_message(conn, json_data) + else: + self.send_all_test_finish(conn) + + + def start_test(self, conn): + send_config = self.config['testGroup'][self.test_group_index] + test_mode = send_config['test_mode'] + base_dir = send_config['base_dir'] + run_dir = send_config['run_dir'] + log_dir = send_config['log_dir'] + + if test_mode == self.TestModeBase: + self.clear_directory(base_dir) + elif test_mode == self.TestModeRun: + self.clear_directory(run_dir) + + send_config = {'main_id': self.S_C_MAIN_ID_SEND_CONFIG_INFO,\ + 'test_mode': test_mode,\ + 'base_dir': base_dir,\ + 'run_dir': run_dir,\ + 'log_dir': log_dir} + + self.send_message(conn, send_config) + + + def read_data_from_json(self, filename): + with open(filename, 'r') as json_file: + json_data = json.load(json_file) + + return json_data + + + def start_client_process(self): + print(time.time(), '----time is up') + process_dir = self.config['testGroup'][self.test_group_index]['process_dir'] + process_name = self.config['testGroup'][self.test_group_index]['process_name'] + + process = process_dir + process_name + ' -f' + subprocess.Popen(process, cwd=process_dir) + result = subprocess.getstatusoutput(process_dir) + print(result) + + + def traverasl_files(self, path): + self.filelist = [] + obj = os.scandir(path) + for entry in obj: + if entry.is_file(): + self.filelist.append(entry.name) + + return self.filelist + + + def clear_directory(self, filepath): + if not os.path.exists(filepath): + os.mkdir(filepath) + else: + shutil.rmtree(filepath) + os.mkdir(filepath) + + + def run(self): + print("TcpServer_run__") + while True: + conn, addr = self.tcp_server_socket.accept() + print("TcpServer_run__, conn, addr", conn, addr) + thread_recv = threading.Thread(target=self.tcp_connect, args=(conn, addr)) + thread_recv.start() + + self.tcp_server_socket.close() \ No newline at end of file diff --git a/tools/server/test_case/button_auto_test.json b/tools/server/test_case/button_auto_test.json new file mode 100644 index 0000000000000000000000000000000000000000..7a1e12f34b0115c3c900944125fd1ea782af62b2 --- /dev/null +++ b/tools/server/test_case/button_auto_test.json @@ -0,0 +1,22 @@ +{ + "testInfo": [ + { + "className": "clip_test_radius_01", + "pageNav": ["Clip"], + "testSteps": [ + { + "viewID": "radius+1", + "eventID": 0, + "eventValue": [1,2], + "saveCheckPoint": true + }, + { + "viewID": "radius-1", + "eventID": 0, + "eventValue": [1,2], + "saveCheckPoint": true + } + ] + } + ] +} \ No newline at end of file diff --git a/tools/server/test_case/clip_auto_test.json b/tools/server/test_case/clip_auto_test.json new file mode 100644 index 0000000000000000000000000000000000000000..9abd446b0072d4e2b01765fd74a6b2e48f36c1b7 --- /dev/null +++ b/tools/server/test_case/clip_auto_test.json @@ -0,0 +1,40 @@ +{ + "testInfo": [ + { + "className": "clip_test_radius_01", + "pageNav": ["Clip", "Next"], + "testSteps": [ + { + "viewID": "radius+5", + "eventID": 0, + "eventValue": [1,2], + "saveCheckPoint": true + }, + { + "viewID": "radius-5", + "eventID": 0, + "eventValue": [1,2], + "saveCheckPoint": true + } + ] + }, + { + "className": "clip_test_radius_01", + "pageNav": ["Clip"], + "testSteps": [ + { + "viewID": "radius+1", + "eventID": 0, + "eventValue": [1,2], + "saveCheckPoint": true + }, + { + "viewID": "radius-1", + "eventID": 0, + "eventValue": [1,2], + "saveCheckPoint": true + } + ] + } + ] +} \ No newline at end of file