提交 629d78a0 编写于 作者: Y youbing

Description: automatic testing

IssueNo: https://gitee.com/openharmony/graphic_ui/issues/I5PBAM
Feature or Bugfix: Bugfix
Binary Source:No
Signed-off-by: youbing54<youbing3@huawei.com>
上级 9225f0c6
...@@ -82,10 +82,6 @@ if (enable_video_component) { ...@@ -82,10 +82,6 @@ if (enable_video_component) {
} }
auto_test_sources = [ 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/compare_tools.cpp",
"src/ui_auto_test.cpp", "src/ui_auto_test.cpp",
] ]
......
/*
* 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<void(size_t)>;
class AutoTestManager {
public:
AutoTestManager();
virtual ~AutoTestManager();
static AutoTestManager* GetInstance();
void SetUpTestCase();
void TearDownTestCase();
void SendMsg(size_t mainID);
void StartTest(std::vector<std::shared_ptr<TestMsgInfo>> msgInfo);
void SetSendMsgFuncCallBack(SendMsgFunc sendMsgFunc);
void SetConfigInfo(const std::shared_ptr<TestConfigInfo> configInfo);
std::shared_ptr<TestConfigInfo> GetConfigInfo();
void TestComplete();
private:
std::shared_ptr<UIAutoTest> autoTest_;
SendMsgFunc sendMsgFunc_;
std::shared_ptr<TestConfigInfo> configInfo_;
};
} // namespace OHOS
#endif // GRAPHIC_LITE_AUTO_TEST_MANAGER_H
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#define GRAPHIC_LITE_COMPARE_TOOLS_H #define GRAPHIC_LITE_COMPARE_TOOLS_H
#include "graphic_config.h" #include "graphic_config.h"
#include <string>
#ifdef _WIN32 #ifdef _WIN32
#include <Windows.h> #include <Windows.h>
#else #else
...@@ -25,7 +26,7 @@ ...@@ -25,7 +26,7 @@
namespace OHOS { namespace OHOS {
namespace { 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 size_t DEFAULT_FILE_NAME_MAX_LENGTH = 256;
constexpr uint8_t BITMAP_HEADER_SIZE = 54; constexpr uint8_t BITMAP_HEADER_SIZE = 54;
} }
...@@ -56,12 +57,16 @@ public: ...@@ -56,12 +57,16 @@ public:
static bool CheckFileExist(const char* filePath, size_t length); static bool CheckFileExist(const char* filePath, size_t length);
static void SetLogPath(const char* filePath, size_t length); static void SetLogPath(const char* filePath, size_t length);
static void UnsetLogPath(); 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: private:
CompareTools() {} CompareTools() {}
virtual ~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 CompareByBit(uint32_t fd);
static bool SaveByBit(uint32_t fd); static bool SaveByBit(uint32_t fd);
static bool enableLog_; static bool enableLog_;
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
...@@ -13,24 +13,42 @@ ...@@ -13,24 +13,42 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef GRAPHIC_LITE_UI_AUTO_TEST_H #ifndef GRAPHIC_LITE_AUTO_TEST_H
#define GRAPHIC_LITE_UI_AUTO_TEST_H #define GRAPHIC_LITE_AUTO_TEST_H
#include "auto_test_case_group.h"
#include "components/ui_view.h" #include "components/ui_view.h"
#include "compare_tools.h"
#include "ui_test_message.h"
namespace OHOS { namespace OHOS {
class UIAutoTest : public AutoTestCaseGroup::AutoTestCase { class UIAutoTest {
public: public:
UIAutoTest() {} UIAutoTest();
virtual ~UIAutoTest() {} virtual ~UIAutoTest();
static void SetUpTestCase();
void ResetMainMenu() const; void ResetMainMenu() const;
void Reset(std::string testID) const;
void RunTest(std::vector<std::shared_ptr<TestMsgInfo>> msgInfo);
void TestComplete() const;
void EnterSubMenu(const char* id) const; void EnterSubMenu(const char* id) const;
void ClickViewById(const char* id) const; void ClickViewById(const char* id) const;
void DragViewToHead(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<TestMsgInfo> info);
void OnEnterPage(std::vector<std::string> pageNav);
void OnTestBySteps(std::vector<TestSteps> 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<std::string> fileNames_;
}; };
} // namespace OHOS } // namespace OHOS
#endif // GRAPHIC_LITE_UI_AUTO_TEST_H #endif // GRAPHIC_LITE_AUTO_TEST_H
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
...@@ -13,14 +13,13 @@ ...@@ -13,14 +13,13 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef UI_TEST_APP_LIST_H #ifndef GRAPHIC_LITE_TEST_APP_H
#define UI_TEST_APP_LIST_H #define GRAPHIC_LITE_TEST_APP_H
#include "components/root_view.h" #include "components/root_view.h"
#include "components/ui_label.h" #include "components/ui_label.h"
#include "components/ui_label_button.h" #include "components/ui_label_button.h"
#include "components/ui_list.h" #include "components/ui_list.h"
#include "graphic_thread.h"
#include "test_case_list_adapter.h" #include "test_case_list_adapter.h"
namespace OHOS { namespace OHOS {
...@@ -28,11 +27,6 @@ namespace { ...@@ -28,11 +27,6 @@ namespace {
constexpr char* UI_TEST_MAIN_LIST_ID = "main_list"; constexpr char* UI_TEST_MAIN_LIST_ID = "main_list";
constexpr char* UI_TEST_BACK_BUTTON_ID = "back_button"; 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 { class UITestApp {
public: public:
static UITestApp* GetInstance(); static UITestApp* GetInstance();
...@@ -61,4 +55,4 @@ private: ...@@ -61,4 +55,4 @@ private:
UIViewGroup* mainMenu_ = nullptr; UIViewGroup* mainMenu_ = nullptr;
}; };
} // namespace OHOS } // namespace OHOS
#endif #endif // GRAPHIC_LITE_TEST_APP_H
/*
* 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 <algorithm>
#include <functional>
#include <list>
#include <memory>
#include <string>
#include <vector>
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<int> eventValue;
bool saveCheckPoint;
};
struct TestMsgInfo {
std::string className;
std::vector<std::string> pageNav;
std::vector<TestSteps> 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
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
...@@ -13,43 +13,52 @@ ...@@ -13,43 +13,52 @@
* limitations under the License. * limitations under the License.
*/ */
#include "auto_test_app.h" #include "auto_test_manager.h"
#include "auto_test_case_group.h"
#include "compare_tools.h" #include <iostream>
#include <memory>
#include "dfx/event_injector.h" #include "dfx/event_injector.h"
#if ENABLE_WINDOW
#include "window/window.h"
#endif
namespace OHOS { namespace OHOS {
AutoTestApp* AutoTestApp::GetInstance() AutoTestManager::AutoTestManager()
{
SetUpTestCase();
}
AutoTestManager::~AutoTestManager()
{
TearDownTestCase();
}
AutoTestManager* AutoTestManager::GetInstance()
{ {
static AutoTestApp instance; static AutoTestManager instance;
return &instance; return &instance;
} }
void AutoTestApp::Start() void AutoTestManager::SetUpTestCase()
{ {
autoTest_ = std::make_shared<UIAutoTest>();
#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::POINT_TYPE);
EventInjector::GetInstance()->RegisterEventInjector(EventDataType::KEY_TYPE); EventInjector::GetInstance()->RegisterEventInjector(EventDataType::KEY_TYPE);
#if ENABLE_WINDOW #if ENABLE_WINDOW
Window* window = RootView::GetInstance()->GetBoundWindow(); Window* window = RootView::GetInstance()->GetBoundWindow();
if (window != nullptr) { if (window != nullptr) {
EventInjector::GetInstance()->SetWindowId(window->GetWindowId()); EventInjector::GetInstance()->SetWindowId(window->GetWindowId());
} }
#endif #endif
CompareTools::WaitSuspend();
ListNode<AutoTestCaseGroup::AutoTestCase*>* node = AutoTestCaseGroup::GetTestCase().Begin();
while (node != AutoTestCaseGroup::GetTestCase().End()) {
node->data_->RunTestList();
node->data_->ResetMainMenu();
node = node->next_;
}
} }
AutoTestApp::~AutoTestApp() void AutoTestManager::TearDownTestCase()
{ {
if (EventInjector::GetInstance()->IsEventInjectorRegistered(EventDataType::POINT_TYPE)) { if (EventInjector::GetInstance()->IsEventInjectorRegistered(EventDataType::POINT_TYPE)) {
EventInjector::GetInstance()->UnregisterEventInjector(EventDataType::POINT_TYPE); EventInjector::GetInstance()->UnregisterEventInjector(EventDataType::POINT_TYPE);
...@@ -57,6 +66,50 @@ AutoTestApp::~AutoTestApp() ...@@ -57,6 +66,50 @@ AutoTestApp::~AutoTestApp()
if (EventInjector::GetInstance()->IsEventInjectorRegistered(EventDataType::KEY_TYPE)) { if (EventInjector::GetInstance()->IsEventInjectorRegistered(EventDataType::KEY_TYPE)) {
EventInjector::GetInstance()->UnregisterEventInjector(EventDataType::KEY_TYPE); EventInjector::GetInstance()->UnregisterEventInjector(EventDataType::KEY_TYPE);
} }
AutoTestCaseGroup::TearDownTestCase();
} }
} // namespace OHOS
void AutoTestManager::SendMsg(size_t mainID)
{
sendMsgFunc_(mainID);
}
void AutoTestManager::SetSendMsgFuncCallBack(SendMsgFunc sendMsgFunc)
{
sendMsgFunc_ = sendMsgFunc;
}
void AutoTestManager::StartTest(std::vector<std::shared_ptr<TestMsgInfo>> 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<TestConfigInfo> 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<TestConfigInfo> AutoTestManager::GetConfigInfo()
{
return configInfo_;
}
}
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
...@@ -103,6 +103,102 @@ bool CompareTools::CompareByBit(uint32_t fd) ...@@ -103,6 +103,102 @@ bool CompareTools::CompareByBit(uint32_t fd)
return flag; 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) bool CompareTools::CompareFile(const char* filePath, size_t length)
{ {
if ((filePath == nullptr) || (length > DEFAULT_FILE_NAME_MAX_LENGTH)) { if ((filePath == nullptr) || (length > DEFAULT_FILE_NAME_MAX_LENGTH)) {
...@@ -169,6 +265,15 @@ bool CompareTools::SaveByBit(uint32_t fd) ...@@ -169,6 +265,15 @@ bool CompareTools::SaveByBit(uint32_t fd)
return flag; 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) bool CompareTools::SaveFile(const char* filePath, size_t length)
{ {
if ((filePath == nullptr) || (length > DEFAULT_FILE_NAME_MAX_LENGTH)) { if ((filePath == nullptr) || (length > DEFAULT_FILE_NAME_MAX_LENGTH)) {
...@@ -184,25 +289,6 @@ bool CompareTools::SaveFile(const char* filePath, size_t length) ...@@ -184,25 +289,6 @@ bool CompareTools::SaveFile(const char* filePath, size_t length)
} }
bool flag = SaveByBit(fd); bool flag = SaveByBit(fd);
close(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; return flag;
} }
...@@ -243,12 +329,18 @@ void CompareTools::UnsetLogPath() ...@@ -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; 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) { if (logFd == -1) {
GRAPHIC_LOGE("open log failed"); GRAPHIC_LOGE("open log failed");
return false; return false;
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
...@@ -19,8 +19,4 @@ ...@@ -19,8 +19,4 @@
void RunApp() void RunApp()
{ {
OHOS::UITestApp::GetInstance()->Start(); OHOS::UITestApp::GetInstance()->Start();
#if ENABEL_UI_AUTO_TEST
ThreadAttr attr;
ThreadCreate(OHOS::AutoTestThread, nullptr, &attr);
#endif // ENABEL_UI_AUTO_TEST
} }
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
...@@ -15,17 +15,28 @@ ...@@ -15,17 +15,28 @@
#include "ui_auto_test.h" #include "ui_auto_test.h"
#include "compare_tools.h" #include "auto_test_manager.h"
#include "components/root_view.h" #include "components/root_view.h"
#include "components/ui_list.h"
#include "components/ui_view_group.h" #include "components/ui_view_group.h"
#include "dfx/event_injector.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_app.h"
#include "ui_test_group.h" #include "ui_test_group.h"
namespace OHOS { namespace OHOS {
UIAutoTest::UIAutoTest()
{
}
UIAutoTest::~UIAutoTest()
{
}
void UIAutoTest::Reset(std::string testID) const
{
ResetMainMenu();
ClickViewById(testID.c_str());
}
void UIAutoTest::ResetMainMenu() const void UIAutoTest::ResetMainMenu() const
{ {
while (RootView::GetInstance()->GetChildById(UI_TEST_MAIN_LIST_ID) == nullptr) { while (RootView::GetInstance()->GetChildById(UI_TEST_MAIN_LIST_ID) == nullptr) {
...@@ -38,6 +49,7 @@ void UIAutoTest::EnterSubMenu(const char* id) const ...@@ -38,6 +49,7 @@ void UIAutoTest::EnterSubMenu(const char* id) const
if (id == nullptr) { if (id == nullptr) {
return; return;
} }
UIView* view = RootView::GetInstance()->GetChildById(id); UIView* view = RootView::GetInstance()->GetChildById(id);
if (view == nullptr) { if (view == nullptr) {
UIView* view = RootView::GetInstance()->GetChildById(UI_TEST_MAIN_LIST_ID); UIView* view = RootView::GetInstance()->GetChildById(UI_TEST_MAIN_LIST_ID);
...@@ -56,6 +68,7 @@ void UIAutoTest::EnterSubMenu(const char* id) const ...@@ -56,6 +68,7 @@ void UIAutoTest::EnterSubMenu(const char* id) const
reinterpret_cast<UIList*>(view)->RefreshList(); reinterpret_cast<UIList*>(view)->RefreshList();
CompareTools::WaitSuspend(); CompareTools::WaitSuspend();
} }
ClickViewById(id); ClickViewById(id);
} }
...@@ -95,23 +108,169 @@ void UIAutoTest::DragViewToHead(const char* id) const ...@@ -95,23 +108,169 @@ void UIAutoTest::DragViewToHead(const char* id) const
CompareTools::WaitSuspend(); 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; 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}; char filePath[DEFAULT_FILE_NAME_MAX_LENGTH] = {0};
CompareTools::StrnCatPath(filePath, DEFAULT_FILE_NAME_MAX_LENGTH, fileName, strlen(fileName)); CompareTools::StrnCatPath(filePath, DEFAULT_FILE_NAME_MAX_LENGTH, fileName, strlen(fileName));
if (CompareTools::CheckFileExist(filePath, sizeof(filePath))) { if (CompareTools::CheckFileExist(filePath, sizeof(filePath))) {
CompareTools::CompareFile(filePath, sizeof(filePath)); return CompareTools::CompareFile(filePath, sizeof(filePath));
} else { } else {
CompareTools::SaveFile(filePath, sizeof(filePath)); return CompareTools::SaveFile(filePath, sizeof(filePath));
}
}
void UIAutoTest::RunTest(std::vector<std::shared_ptr<TestMsgInfo>> 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<TestMsgInfo> info)
{
ResetMainMenu();
OnEnterPage(info->pageNav);
OnTestBySteps(info->steps, info->className);
}
void UIAutoTest::OnTestBySteps(std::vector<TestSteps> 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()); if (step.eventID == TestEventID::TEST_CLICK_EVENT) {
AutoTestCaseGroup::AddTestCase(new UIAutoTestBasicLayout()); 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<int16_t>(step.eventValue[0]);
int16_t y = static_cast<int16_t>(step.eventValue[1]);
DrageToView(step.viewID.c_str(), x, y);
}
if (step.saveCheckPoint) {
OnSaveFile(className, step.viewID, stepIndex);
}
}
void UIAutoTest::OnEnterPage(std::vector<std::string> 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<TestConfigInfo> 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<TestConfigInfo> 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<TestConfigInfo> 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 } // namespace OHOS
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
...@@ -15,34 +15,12 @@ ...@@ -15,34 +15,12 @@
#include "ui_test_app.h" #include "ui_test_app.h"
#include "auto_test_app.h"
#include "compare_tools.h" #include "compare_tools.h"
#include "test_resource_config.h" #include "test_resource_config.h"
#include "ui_auto_test.h"
#include "ui_test.h" #include "ui_test.h"
#include "ui_test_group.h" #include "ui_test_group.h"
namespace OHOS { 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();
}
UITestApp* UITestApp::GetInstance() UITestApp* UITestApp::GetInstance()
{ {
static UITestApp instance; static UITestApp instance;
...@@ -72,8 +50,6 @@ public: ...@@ -72,8 +50,6 @@ public:
bool OnClick(UIView& view, const ClickEvent& event) override bool OnClick(UIView& view, const ClickEvent& event) override
{ {
ThreadCreate(AutoTestThread, nullptr, nullptr);
return true;
} }
}; };
...@@ -110,6 +86,7 @@ void UITestApp::InitMainMenu() ...@@ -110,6 +86,7 @@ void UITestApp::InitMainMenu()
autoTestBtn_->SetStyleForState(STYLE_BACKGROUND_OPA, 0, UIButton::RELEASED); autoTestBtn_->SetStyleForState(STYLE_BACKGROUND_OPA, 0, UIButton::RELEASED);
autoTestBtn_->SetStyleForState(STYLE_BACKGROUND_OPA, 0, UIButton::PRESSED); autoTestBtn_->SetStyleForState(STYLE_BACKGROUND_OPA, 0, UIButton::PRESSED);
autoTestBtn_->SetStyleForState(STYLE_BACKGROUND_OPA, 0, UIButton::INACTIVE); autoTestBtn_->SetStyleForState(STYLE_BACKGROUND_OPA, 0, UIButton::INACTIVE);
autoTestBtn_->SetVisible(false);
mainMenu_->Add(autoTestBtn_); mainMenu_->Add(autoTestBtn_);
} }
if ((mainList_ == nullptr) && (adapter_ == nullptr)) { if ((mainList_ == nullptr) && (adapter_ == nullptr)) {
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "ui_test_clip.h" #include "ui_test_clip.h"
#include <cmath> #include <cmath>
#include "common/image.h" #include "common/image.h"
#include "draw/clip_utils.h" #include "draw/clip_utils.h"
#include "gfx_utils/graphic_math.h" #include "gfx_utils/graphic_math.h"
...@@ -137,7 +138,7 @@ UIImageView* UITestClip::CreateImageView() ...@@ -137,7 +138,7 @@ UIImageView* UITestClip::CreateImageView()
return imageVIew; 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) { if (btn == nullptr) {
return; return;
...@@ -147,6 +148,7 @@ void UITestClip::SetUpButton(UILabelButton* btn, const char* title, int16_t x, i ...@@ -147,6 +148,7 @@ void UITestClip::SetUpButton(UILabelButton* btn, const char* title, int16_t x, i
btn->SetText(title); btn->SetText(title);
btn->SetFont(DEFAULT_VECTOR_FONT_FILENAME, BUTTON_LABEL_SIZE); btn->SetFont(DEFAULT_VECTOR_FONT_FILENAME, BUTTON_LABEL_SIZE);
btn->SetOnClickListener(this); 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::RELEASED);
btn->SetStyleForState(STYLE_BORDER_RADIUS, BUTTON_STYLE_BORDER_RADIUS_VALUE, UIButton::PRESSED); btn->SetStyleForState(STYLE_BORDER_RADIUS, BUTTON_STYLE_BORDER_RADIUS_VALUE, UIButton::PRESSED);
btn->SetStyleForState(STYLE_BORDER_RADIUS, BUTTON_STYLE_BORDER_RADIUS_VALUE, UIButton::INACTIVE); btn->SetStyleForState(STYLE_BORDER_RADIUS, BUTTON_STYLE_BORDER_RADIUS_VALUE, UIButton::INACTIVE);
...@@ -171,14 +173,14 @@ void UITestClip::UIKitClipTest001() ...@@ -171,14 +173,14 @@ void UITestClip::UIKitClipTest001()
int16_t x = VIEW_DISTANCE_TO_LEFT_SIDE + BLOCK_WIDTH + GAP; int16_t x = VIEW_DISTANCE_TO_LEFT_SIDE + BLOCK_WIDTH + GAP;
int16_t y = positionY_; int16_t y = positionY_;
btnRadiusInc1_ = new UILabelButton(); btnRadiusInc1_ = new UILabelButton();
SetUpButton(btnRadiusInc1_, "半径+1", x, y); SetUpButton(btnRadiusInc1_, "半径+1", x, y, UI_TEST_RADIUS_1);
btnRadiusDec1_ = new UILabelButton(); 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(); btnRadiusInc5_ = new UILabelButton();
y += BUTTON_HEIGHT2 + GAP; y += BUTTON_HEIGHT2 + GAP;
SetUpButton(btnRadiusInc5_, "半径+5", x, y); SetUpButton(btnRadiusInc5_, "半径+5", x, y, UI_TEST_RADIUS_3);
btnRadiusDec5_ = new UILabelButton(); 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; y += BUTTON_HEIGHT2 + GAP;
radiusText_ = new UILabel(); radiusText_ = new UILabel();
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
...@@ -23,6 +23,10 @@ ...@@ -23,6 +23,10 @@
#include "ui_test.h" #include "ui_test.h"
namespace OHOS { 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 { class UITestClip : public UITest, public UIView::OnClickListener {
public: public:
UITestClip() {} UITestClip() {}
...@@ -53,7 +57,7 @@ private: ...@@ -53,7 +57,7 @@ private:
void CreateTitleLabel(const char* title); void CreateTitleLabel(const char* title);
UIImageView* CreateImageView(); UIImageView* CreateImageView();
void ClipImage(UIImageView* imageView, ClipPath& path); 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* btnRadiusInc1_ = nullptr;
UILabelButton* btnRadiusInc5_ = nullptr; UILabelButton* btnRadiusInc5_ = nullptr;
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
...@@ -13,23 +13,33 @@ ...@@ -13,23 +13,33 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef GRAPHIC_LITE_AUTO_TEST_APP_H #ifndef GRAPHIC_LITE_SOCKET_THREAD_H
#define GRAPHIC_LITE_AUTO_TEST_APP_H #define GRAPHIC_LITE_SOCKET_THREAD_H
#include <QThread>
#include <windows.h>
#include "tcp_socket_manager.h"
namespace OHOS { namespace OHOS {
class AutoTestApp { class SocketThread : public QThread {
Q_OBJECT
public: public:
static AutoTestApp* GetInstance(); SocketThread();
void Start(); ~SocketThread();
private: void run() override;
AutoTestApp() {} void Quit();
virtual ~AutoTestApp();
AutoTestApp(const AutoTestApp&) = delete; inline TcpSocketClientManager* GetClientManager()
AutoTestApp& operator=(const AutoTestApp&) = delete; {
AutoTestApp(AutoTestApp&&) = delete; return clientManager_;
AutoTestApp& operator=(AutoTestApp&&) = delete; };
private:
volatile bool taskQuitQry = false;
TcpSocketClientManager* clientManager_;
}; };
} // namespace OHOS } // namespace OHOS
#endif // GRAPHIC_LITE_AUTO_TEST_APP_H
#endif // GRAPHIC_LITE_SOCKET_THREAD_H
\ No newline at end of file
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
...@@ -13,32 +13,30 @@ ...@@ -13,32 +13,30 @@
* limitations under the License. * limitations under the License.
*/ */
#include "auto_test_case_group.h" #include "scoket_thread.h"
#include "graphic_config.h"
namespace OHOS { namespace OHOS {
List<AutoTestCaseGroup::AutoTestCase*> AutoTestCaseGroup::testCaseList_; SocketThread::SocketThread()
{
clientManager_ = TcpSocketClientManager::GetInstance();
}
List<AutoTestCaseGroup::AutoTestCase*>& AutoTestCaseGroup::GetTestCase() SocketThread::~SocketThread()
{ {
return testCaseList_; clientManager_ = nullptr;
} }
void AutoTestCaseGroup::TearDownTestCase() void SocketThread::run()
{ {
ListNode<AutoTestCase*>* node = testCaseList_.Begin(); taskQuitQry = false;
while (node != testCaseList_.End()) { while (!taskQuitQry) {
delete node->data_; TcpSocketClientManager::GetInstance()->DispatchMsg();
node->data_ = nullptr; Sleep(DEFAULT_TASK_PERIOD);
node = node->next_;
} }
testCaseList_.Clear();
} }
void AutoTestCaseGroup::AddTestCase(AutoTestCase* testCaseInfo) void SocketThread::Quit()
{ {
if (testCaseInfo != nullptr) { taskQuitQry = true;
testCaseList_.PushBack(testCaseInfo);
}
} }
} // namespace OHOS } // namespace OHOS
\ No newline at end of file
...@@ -95,12 +95,9 @@ SOURCES += \ ...@@ -95,12 +95,9 @@ SOURCES += \
../../../../test/uitest/test_view_scale_rotate/ui_test_view_scale_rotate.cpp ../../../../test/uitest/test_view_scale_rotate/ui_test_view_scale_rotate.cpp
SOURCES += \ SOURCES += \
../../../../test/framework/src/auto_test_app.cpp \ ../../../../test/framework/src/auto_test_manager.cpp \
../../../../test/framework/src/auto_test_case_group.cpp \
../../../../test/framework/src/compare_tools.cpp \ ../../../../test/framework/src/compare_tools.cpp \
../../../../test/framework/src/ui_auto_test.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 += \ HEADERS += \
../../../../test/framework/common/ui_text_language.h \ ../../../../test/framework/common/ui_text_language.h \
...@@ -117,7 +114,7 @@ HEADERS += \ ...@@ -117,7 +114,7 @@ HEADERS += \
../../../../test/uitest/test_canvas/ui_test_canvas.h \ ../../../../test/uitest/test_canvas/ui_test_canvas.h \
../../../../test/uitest/test_chart/ui_test_chart_pillar.h \ ../../../../test/uitest/test_chart/ui_test_chart_pillar.h \
../../../../test/uitest/test_chart/ui_test_chart_polyline.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_dialog/ui_test_dialog.h \
../../../../test/uitest/test_digital_clock/ui_test_digital_clock.h \ ../../../../test/uitest/test_digital_clock/ui_test_digital_clock.h \
../../../../test/uitest/test_draw_line/ui_test_draw_line.h \ ../../../../test/uitest/test_draw_line/ui_test_draw_line.h \
...@@ -156,12 +153,10 @@ HEADERS += \ ...@@ -156,12 +153,10 @@ HEADERS += \
../../../../test/uitest/test_view_scale_rotate/ui_test_view_scale_rotate.h ../../../../test/uitest/test_view_scale_rotate/ui_test_view_scale_rotate.h
HEADERS += \ HEADERS += \
../../../../test/framework/include/auto_test_app.h \ ../../../../test/framework/include/auto_test_manager.h \
../../../../test/framework/include/auto_test_case_group.h \
../../../../test/framework/include/compare_tools.h \ ../../../../test/framework/include/compare_tools.h \
../../../../test/framework/include/ui_auto_test.h \ ../../../../test/framework/include/ui_auto_test.h \
../../../../test/uitest/test_render/ui_auto_test_render.h \ ../../../../test/framework/include/ui_test_message.h \
../../../../test/uitest/test_layout/ui_auto_test_basic_layout.h
INCLUDEPATH += \ INCLUDEPATH += \
../../../../frameworks \ ../../../../frameworks \
......
...@@ -35,6 +35,9 @@ SOURCES += \ ...@@ -35,6 +35,9 @@ SOURCES += \
../drivers/indev/key_input.cpp \ ../drivers/indev/key_input.cpp \
../drivers/indev/mouse_input.cpp \ ../drivers/indev/mouse_input.cpp \
../drivers/indev/mousewheel_input.cpp \ ../drivers/indev/mousewheel_input.cpp \
../drivers/display/socket_thread.cpp \
tcp_socket.cpp \
tcp_socket_manager.cpp \
main.cpp \ main.cpp \
main_widget.cpp main_widget.cpp
...@@ -46,6 +49,9 @@ HEADERS += \ ...@@ -46,6 +49,9 @@ HEADERS += \
../drivers/indev/key_input.h \ ../drivers/indev/key_input.h \
../drivers/indev/mouse_input.h \ ../drivers/indev/mouse_input.h \
../drivers/indev/mousewheel_input.h \ ../drivers/indev/mousewheel_input.h \
../drivers/display/scoket_thread.h \
tcp_socket.h \
tcp_socket_manager.h \
main_widget.h main_widget.h
INCLUDEPATH += \ INCLUDEPATH += \
...@@ -59,6 +65,7 @@ INCLUDEPATH += \ ...@@ -59,6 +65,7 @@ INCLUDEPATH += \
../../../../../utils/interfaces/innerkits \ ../../../../../utils/interfaces/innerkits \
../../../../../utils/interfaces/kits \ ../../../../../utils/interfaces/kits \
../../../../../../../third_party/freetype/include \ ../../../../../../../third_party/freetype/include \
../../../../test/framework/include \
LIBS += $$OUT_PWD/../libs/libui.dll LIBS += $$OUT_PWD/../libs/libui.dll
LIBS += $$OUT_PWD/../libs/test.dll LIBS += $$OUT_PWD/../libs/test.dll
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
...@@ -27,6 +27,11 @@ int main(int argc, char* argv[]) ...@@ -27,6 +27,11 @@ int main(int argc, char* argv[])
OHOS::Monitor::GetInstance()->InitHal(); OHOS::Monitor::GetInstance()->InitHal();
OHOS::Monitor::GetInstance()->InitFontEngine(); OHOS::Monitor::GetInstance()->InitFontEngine();
OHOS::Monitor::GetInstance()->InitImageDecodeAbility(); OHOS::Monitor::GetInstance()->InitImageDecodeAbility();
if (argv[1] != nullptr && strcmp(argv[1], "-f") == 0) {
OHOS::TcpSocketClientManager::GetInstance()->InitSocket();
}
RunApp(); RunApp();
OHOS::MainWidget mainWidget; OHOS::MainWidget mainWidget;
mainWidget.resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); mainWidget.resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION);
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
...@@ -22,6 +22,7 @@ MainWidget::MainWidget(QWidget* parent) : QWidget(parent), guiThread_(nullptr), ...@@ -22,6 +22,7 @@ MainWidget::MainWidget(QWidget* parent) : QWidget(parent), guiThread_(nullptr),
ui_->setupUi(this); ui_->setupUi(this);
CreateGUIThread(); CreateGUIThread();
CreateTaskThread(); CreateTaskThread();
CreateSocketThread();
} }
MainWidget::~MainWidget() MainWidget::~MainWidget()
...@@ -37,6 +38,11 @@ MainWidget::~MainWidget() ...@@ -37,6 +38,11 @@ MainWidget::~MainWidget()
taskThread_->wait(); taskThread_->wait();
delete taskThread_; delete taskThread_;
} }
if (socketThread_ != nullptr) {
socketThread_->Quit();
socketThread_->wait();
delete socketThread_;
}
} }
void MainWidget::CreateGUIThread() void MainWidget::CreateGUIThread()
...@@ -58,6 +64,17 @@ void MainWidget::CreateTaskThread() ...@@ -58,6 +64,17 @@ void MainWidget::CreateTaskThread()
} }
} }
void MainWidget::CreateSocketThread()
{
socketThread_ = new SocketThread();
if (socketThread_ != nullptr) {
socketThread_->start();
qRegisterMetaType<size_t>("size_t");
connect(socketThread_->GetClientManager(), SIGNAL(SendMsgSignal(size_t)), this,
SLOT(SendMsgSlot(size_t)));
}
}
void MainWidget::paintEvent(QPaintEvent* event) void MainWidget::paintEvent(QPaintEvent* event)
{ {
Q_UNUSED(event) Q_UNUSED(event)
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include "monitor.h" #include "monitor.h"
#include "mouse_input.h" #include "mouse_input.h"
#include "mousewheel_input.h" #include "mousewheel_input.h"
#include "scoket_thread.h"
#include "task_thread.h" #include "task_thread.h"
#include "ui_mainwidget.h" #include "ui_mainwidget.h"
...@@ -50,6 +51,7 @@ public: ...@@ -50,6 +51,7 @@ public:
~MainWidget(); ~MainWidget();
void CreateGUIThread(); void CreateGUIThread();
void CreateTaskThread(); void CreateTaskThread();
void CreateSocketThread();
protected: protected:
void mouseMoveEvent(QMouseEvent* event) override; void mouseMoveEvent(QMouseEvent* event) override;
...@@ -67,6 +69,7 @@ private: ...@@ -67,6 +69,7 @@ private:
uint32_t height_; uint32_t height_;
GUIThread* guiThread_; GUIThread* guiThread_;
TaskThread* taskThread_; TaskThread* taskThread_;
SocketThread* socketThread_;
public slots: public slots:
void UpdatePaintSlot(uint32_t* tftFb, uint32_t imgWidth, uint32_t imgHeight) void UpdatePaintSlot(uint32_t* tftFb, uint32_t imgWidth, uint32_t imgHeight)
...@@ -80,6 +83,17 @@ public slots: ...@@ -80,6 +83,17 @@ public slots:
} }
update(); 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 } // namespace OHOS
......
/*
* 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);
}
}
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
...@@ -13,29 +13,44 @@ ...@@ -13,29 +13,44 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef GRAPHIC_LITE_AUTO_TEST_CASE_GROUP_H #ifndef GRAPHIC_LITE_TCP_SOCKET_H
#define GRAPHIC_LITE_AUTO_TEST_CASE_GROUP_H #define GRAPHIC_LITE_TCP_SOCKET_H
#include "gfx_utils/list.h" #include <QtCore/qobject.h>
#include <QTcpServer>
#include <QTcpSocket>
#include <QHostAddress>
#include "tcp_socket_manager.h"
const QString IP = "127.0.0.1";
const quint16 port = 23495;
namespace OHOS { namespace OHOS {
class AutoTestCaseGroup { 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: public:
class AutoTestCase {
public:
AutoTestCase() {}
virtual ~AutoTestCase() {}
virtual void RunTestList() = 0;
virtual void Reset() const = 0;
virtual void ResetMainMenu() const = 0;
};
static List<AutoTestCase*>& GetTestCase();
static void TearDownTestCase();
static void AddTestCase(AutoTestCase* testCaseInfo);
private: private:
static List<AutoTestCase*> testCaseList_; QTcpSocket* tcpSocket_;
TcpSocketClientManager* tcpSocketManager_;
}; };
} // namespace OHOS } // namespace OHOS
#endif // GRAPHIC_LITE_AUTO_TEST_CASE_GROUP_H
#endif // GRAPHIC_LITE_TCP_SOCKET_H
/*
* 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 <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include "main.cpp"
#include "auto_test_manager.h"
namespace OHOS {
static void StartTest(std::vector<std::shared_ptr<TestMsgInfo>> msgInfo)
{
AutoTestManager::GetInstance()->StartTest(msgInfo);
}
static void DipatchConfigMsg(std::shared_ptr<TestConfigInfo> 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<int>& values)
{
foreach (auto it, array) {
values.push_back(it.toInt());
}
}
void TcpSocketClientManager::OnGetPageNav(QJsonArray array, std::vector<std::string>& pageNav)
{
foreach (auto it, array) {
pageNav.push_back(it.toString().toStdString());
}
}
void TcpSocketClientManager::OnGetTestSetps(QJsonArray array, std::vector<TestSteps>& 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<TestEventID>(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<bool>(
arrobj.value(JSON_VALUE_SAVE_CHECK_POINT.c_str()).toBool());
}
steps.push_back(testSteps);
}
}
void TcpSocketClientManager::RecvMsg(QByteArray recv)
{
std::shared_ptr<QByteArray> recvmsg = std::make_shared<QByteArray>(recv);
QMutexLocker mutexLocker(&mutex_);
recv_.push_back(recvmsg);
}
void TcpSocketClientManager::OnGetMsgInfo(const std::shared_ptr<QByteArray> 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<size_t>(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<TestConfigInfo> configInfo = std::make_shared<TestConfigInfo>();
if (object.contains(JOSN_VALUE_TEST_MODE.c_str())) {
configInfo->testMode = static_cast<TestMode>(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<std::shared_ptr<TestMsgInfo>> 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<TestMsgInfo> msgInfo = std::make_shared<TestMsgInfo>();
QJsonObject arrobj = it.toObject();
OnGetTestInfo(arrobj, msgInfo);
testMsgInfo.push_back(msgInfo);
}
}
OnPrintTestInfo(testMsgInfo);
dispatchFunc_(testMsgInfo);
}
void TcpSocketClientManager::OnGetTestInfo(QJsonObject arrobj, std::shared_ptr<TestMsgInfo>& 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<std::shared_ptr<TestMsgInfo>> 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<QByteArray> recv = recv_.front();
recv_.pop_front();
OnGetMsgInfo(recv);
}
} // namespace OHOS
/*
* 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 <queue>
#include <QMutex>
#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<void(std::vector<std::shared_ptr<TestMsgInfo>>)>;
using DispatchConfigFunc = std::function<void(std::shared_ptr<TestConfigInfo>)>;
using DispatchCompleteFunc = std::function<void()>;
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<QByteArray> recv);
void OnGetConfigInfo(const QJsonObject object);
void OnGetTestInfo(QJsonObject object);
void OnGetTestInfo(QJsonObject arrobj, std::shared_ptr<TestMsgInfo>& msgInfo);
void OnGetPageNav(QJsonArray array, std::vector<std::string>& pageNav);
void OnGetTestSetps(QJsonArray array, std::vector<TestSteps>& steps);
void OnGetEventValue(QJsonArray array, std::vector<int>& values);
void OnPrintTestInfo(const std::vector<std::shared_ptr<TestMsgInfo>> testMsgInfo) const;
private:
TcpScoketClient *tcpSocket_;
DispatchFunc dispatchFunc_;
DispatchConfigFunc dispatchConfigFunc_;
DispatchCompleteFunc dispatchCompleteFunc_;
std::deque<std::shared_ptr<QByteArray>> recv_;
QMutex mutex_;
};
} // namespace OHOS
#endif // GRAPHIC_LITE_TCP_SOCKET_CLIENT_MANGER_H
{
"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
#!/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()
#!/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
{
"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
{
"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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册