diff --git a/test/framework/include/compare_tools.h b/test/framework/include/compare_tools.h new file mode 100644 index 0000000000000000000000000000000000000000..05532952bfc0c89ae40aafcd7b0c079860df46b9 --- /dev/null +++ b/test/framework/include/compare_tools.h @@ -0,0 +1,55 @@ +/* + * 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_COMPARE_TOOLS_H +#define GRAPHIC_LITE_COMPARE_TOOLS_H + +#include "graphic_config.h" +#ifdef _WIN32 +#include +#else +#include +#endif // _WIN32 + +#ifdef _WIN32 +#define UI_AUTO_TEST_RESOURCE_PATH "..\\simulator\\config\\auto_test\\" +#else +#define UI_AUTO_TEST_RESOURCE_PATH (RESOURCE_DIR "auto_test/") +#endif + +namespace OHOS { +namespace { + constexpr uint16_t DEFAULT_WAIT_TIME_MS = 300; + constexpr size_t DEFAULT_FILE_NAME_MAX_LENGTH = 256; +} +class CompareTools { +public: + enum CompareMode : uint8_t { + COMPARE_BINARY, + COMPARE_IMAGE + }; + + static void WaitSuspend(); + static bool StrnCatPath(char* filePath, size_t pathMax, const char* fileName, size_t count); + static bool CompareFile(const char* filePath, size_t length, uint8_t flag); + static bool SaveFile(const char* filePath, size_t length, uint8_t flag); + static bool CheckFileExist(const char* filePath, size_t length); + +private: + static bool CompareBinary(const char* filePath, size_t length); + static bool SaveFrameBuffToBinary(const char* filePath, size_t length); +}; +} // namespace OHOS +#endif // GRAPHIC_LITE_COMPARE_TOOLS_H diff --git a/test/framework/include/ui_auto_test.h b/test/framework/include/ui_auto_test.h new file mode 100644 index 0000000000000000000000000000000000000000..f9ae5c63b9dfa150e526d93d52148ac90e05cd71 --- /dev/null +++ b/test/framework/include/ui_auto_test.h @@ -0,0 +1,37 @@ +/* + * 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_UI_AUTO_TEST_H +#define GRAPHIC_LITE_UI_AUTO_TEST_H + +#include "components/ui_view.h" + +namespace OHOS { +class UIAutoTest { +public: + UIAutoTest() {} + virtual ~UIAutoTest() {} + + virtual void RunTestList() = 0; + virtual void Reset() const = 0; + + void ResetMainMenu() 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; +}; +} // namespace OHOS +#endif // GRAPHIC_LITE_UI_AUTO_TEST_H diff --git a/test/framework/include/ui_auto_test_group.h b/test/framework/include/ui_auto_test_group.h new file mode 100644 index 0000000000000000000000000000000000000000..3b9f84e1d6d6496f6889ad297898ed6dc7f16f2d --- /dev/null +++ b/test/framework/include/ui_auto_test_group.h @@ -0,0 +1,33 @@ +/* + * 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_UI_AUTO_TEST_GROUP_H +#define GRAPHIC_LITE_UI_AUTO_TEST_GROUP_H + +#include "gfx_utils/list.h" +#include "ui_auto_test.h" + +namespace OHOS { +class UIAutoTestGroup { +public: + static void SetUpTestCase(); + static List& GetTestCase(); + static void TearDownTestCase(); + +private: + static List testCaseList_; +}; +} // namespace OHOS +#endif // GRAPHIC_LITE_UI_AUTO_TEST_GROUP_H \ No newline at end of file diff --git a/test/framework/include/ui_test_app.h b/test/framework/include/ui_test_app.h index 164b45266ebfb7e6e5981aa7b99f7dafeb01cd1f..39a06903e1737b7e6c5db26edb65e8ce3a5938a4 100755 --- a/test/framework/include/ui_test_app.h +++ b/test/framework/include/ui_test_app.h @@ -22,7 +22,12 @@ #include "components/ui_list.h" #include "test_case_list_adapter.h" +#define ENABEL_UI_AUTO_TEST 0 namespace OHOS { +namespace { + constexpr char* UI_TEST_MAIN_LIST_ID = "main_list"; + constexpr char* UI_TEST_BACK_BUTTON_ID = "back_button"; +} class UITestApp { public: static UITestApp* GetInstance() @@ -49,5 +54,25 @@ private: UILabel* testCaseLabel_ = nullptr; UILabel* testLabel_ = nullptr; }; + +#if ENABEL_UI_AUTO_TEST +class UIAutoTestApp { +public: + static UIAutoTestApp* GetInstance() + { + static UIAutoTestApp instance; + return &instance; + } + void Start(); +private: + UIAutoTestApp() {} + ~UIAutoTestApp() {} + + UIAutoTestApp(const UIAutoTestApp&) = delete; + UIAutoTestApp& operator=(const UIAutoTestApp&) = delete; + UIAutoTestApp(UIAutoTestApp&&) = delete; + UIAutoTestApp& operator=(UIAutoTestApp&&) = delete; +}; +#endif // ENABEL_UI_AUTO_TEST } // namespace OHOS -#endif \ No newline at end of file +#endif diff --git a/test/framework/src/compare_tools.cpp b/test/framework/src/compare_tools.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8cbdf097ed60b44b33977f4683939f5e5f86401f --- /dev/null +++ b/test/framework/src/compare_tools.cpp @@ -0,0 +1,140 @@ +/* + * 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 "compare_tools.h" +#include "dock/screen_device_proxy.h" +#include "draw/draw_utils.h" +#include "file.h" +#include "gfx_utils/graphic_log.h" +#include "graphic_config.h" +#include "securec.h" + +namespace OHOS { +void CompareTools::WaitSuspend() +{ +#ifdef _WIN32 + Sleep(DEFAULT_WAIT_TIME_MS); +#else + usleep(1000 * DEFAULT_WAIT_TIME_MS); // 1000: us to ms +#endif // _WIN32 +} + +bool CompareTools::StrnCatPath(char* filePath, size_t pathMax, const char* fileName, size_t count) +{ + if ((filePath == nullptr) || (pathMax > DEFAULT_FILE_NAME_MAX_LENGTH)) { + return false; + } + char dest[DEFAULT_FILE_NAME_MAX_LENGTH] = UI_AUTO_TEST_RESOURCE_PATH; + if (strncat_s(dest, DEFAULT_FILE_NAME_MAX_LENGTH, fileName, count) != EOK) { + return false; + } + if (memcpy_s(static_cast(filePath), pathMax, dest, DEFAULT_FILE_NAME_MAX_LENGTH) != EOK) { + return false; + } + return true; +} + +bool CompareTools::CompareFile(const char* src, size_t length, uint8_t flag) +{ + switch (flag) { + case COMPARE_BINARY: + return CompareBinary(src, length); + case COMPARE_IMAGE: + // Unrealized : image for comparison + break; + default: + break; + } + return false; +} + +bool CompareTools::SaveFile(const char* src, size_t length, uint8_t flag) +{ + switch (flag) { + case COMPARE_BINARY: + return SaveFrameBuffToBinary(src, length); + case COMPARE_IMAGE: + // Unrealized : save frame buff as image + break; + default: + break; + } + return false; +} + +bool CompareTools::CompareBinary(const char* filePath, size_t length) +{ + if ((filePath == nullptr) || (length > DEFAULT_FILE_NAME_MAX_LENGTH)) { + return false; + } + FILE* fd = fopen(filePath, "rb"); + if (fd == nullptr) { + return false; + } + uint8_t* frameBuf = ScreenDeviceProxy::GetInstance()->GetBuffer(); + uint8_t sizeByColorMode = DrawUtils::GetByteSizeByColorMode(ScreenDeviceProxy::GetInstance()->GetBufferMode()); + uint32_t buffSize = HORIZONTAL_RESOLUTION * VERTICAL_RESOLUTION * sizeByColorMode; + uint8_t* readBuf = reinterpret_cast(malloc(buffSize)); + if (fread(readBuf, buffSize, sizeof(uint8_t), fd) < 0) { + fclose(fd); + free(readBuf); + return false; + } + for (int32_t i = 0; i < (buffSize / sizeof(uint8_t)); i++) { + if (readBuf[i] != frameBuf[i]) { + GRAPHIC_LOGE("[DIFF]:fileName=%s, read[%d]=%x, write[%d]=%x", filePath, i, readBuf[i], frameBuf[i]); + fclose(fd); + free(readBuf); + return false; + } + } + fclose(fd); + free(readBuf); + return true; +} + +bool CompareTools::SaveFrameBuffToBinary(const char* filePath, size_t length) +{ + if ((filePath == nullptr) || (length > DEFAULT_FILE_NAME_MAX_LENGTH)) { + return false; + } + FILE* fd = fopen(filePath, "wb+"); + if (fd == nullptr) { + return false; + } + uint8_t* frameBuf = ScreenDeviceProxy::GetInstance()->GetBuffer(); + uint8_t sizeByColorMode = DrawUtils::GetByteSizeByColorMode(ScreenDeviceProxy::GetInstance()->GetBufferMode()); + uint32_t buffSize = HORIZONTAL_RESOLUTION * VERTICAL_RESOLUTION * sizeByColorMode; + if (fwrite(frameBuf, buffSize, sizeof(uint8_t), fd) < 0) { + fclose(fd); + return false; + } + fclose(fd); + return true; +} + +bool CompareTools::CheckFileExist(const char* filePath, size_t length) +{ + if ((filePath == nullptr) || (length > DEFAULT_FILE_NAME_MAX_LENGTH)) { + return false; + } + FILE* fd = fopen(filePath, "r"); + if (fd == nullptr) { + return false; + } + fclose(fd); + return true; +} +} // namespace OHOS \ No newline at end of file diff --git a/test/framework/src/test_ability.cpp b/test/framework/src/test_ability.cpp index 066e56bd39f009f3bbd0a27d7945d2723e215958..32135cfa20c06bf96ba32967c76a903bec264513 100755 --- a/test/framework/src/test_ability.cpp +++ b/test/framework/src/test_ability.cpp @@ -14,8 +14,24 @@ */ #include "ui_test_app.h" +#if ENABEL_UI_AUTO_TEST +#ifdef _WIN32 +#include +#endif // _WIN32 + +void* AutoTestThread() +{ + OHOS::UIAutoTestApp::GetInstance()->Start(); +} +#endif // ENABEL_UI_AUTO_TEST void RunApp() { OHOS::UITestApp::GetInstance()->Start(); -} \ No newline at end of file +#if ENABEL_UI_AUTO_TEST +#ifdef _WIN32 + std::thread autoTestPthread(AutoTestThread); + autoTestPthread.detach(); +#endif // _WIN32 +#endif // ENABEL_UI_AUTO_TEST +} diff --git a/test/framework/src/test_case_list_adapter.cpp b/test/framework/src/test_case_list_adapter.cpp index 5f7ab43d48d8d280a5f119d78f472c0a32cf0f6a..ccde74354f9c8f0195a783c8c366efdcc5cdb6f6 100755 --- a/test/framework/src/test_case_list_adapter.cpp +++ b/test/framework/src/test_case_list_adapter.cpp @@ -179,6 +179,7 @@ UIView* TestCaseListAdapter::GetView(UIView* inView, int16_t index) listener = new BtnOnClickUiTestListener(rootView_, mainList_, backBtn_, &node->data_, testCaseLabel_, testLabel_); item->SetOnClickListener(listener); item->SetText(node->data_.sliceId); + item->SetViewId(node->data_.sliceId); item->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 24); // 24: means font size item->SetViewIndex(index); item->SetAlign(TEXT_ALIGNMENT_LEFT); diff --git a/test/framework/src/ui_auto_test.cpp b/test/framework/src/ui_auto_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d640becdd01091fdb41aa6614a26b4da3fa1f53f --- /dev/null +++ b/test/framework/src/ui_auto_test.cpp @@ -0,0 +1,108 @@ +/* + * 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 "ui_auto_test.h" +#include "compare_tools.h" +#include "components/root_view.h" +#include "components/ui_list.h" +#include "components/ui_view_group.h" +#include "dfx/event_injector.h" +#include "ui_test_app.h" +#include "ui_test_group.h" + +namespace OHOS { +void UIAutoTest::ResetMainMenu() const +{ + while (RootView::GetInstance()->GetChildById(UI_TEST_MAIN_LIST_ID) == nullptr) { + ClickViewById(UI_TEST_BACK_BUTTON_ID); + } +} + +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); + if (view == nullptr) { + return; + } + ListNode* node = UITestGroup::GetTestCase().Begin(); + while (node != UITestGroup::GetTestCase().End()) { + if ((node->data_.sliceId != nullptr) && (strcmp(id, node->data_.sliceId) == 0)) { + UITestGroup::GetTestCase().PushFront(node->data_); + UITestGroup::GetTestCase().Remove(node); + break; + } + node = node->next_; + } + reinterpret_cast(view)->RefreshList(); + CompareTools::WaitSuspend(); + } + ClickViewById(id); +} + +void UIAutoTest::ClickViewById(const char* id) const +{ + if (id == nullptr) { + return; + } + UIView* view = RootView::GetInstance()->GetChildById(id); + if (view == nullptr) { + return; + } + Point point; + point.x = view->GetOrigRect().GetX(); + point.y = view->GetOrigRect().GetY(); + EventInjector::GetInstance()->SetClickEvent(point); + CompareTools::WaitSuspend(); +} + +void UIAutoTest::DragViewToHead(const char* id) const +{ + 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 = 50; // 50 :end point x position; + endPoint.y = 80; // 80 :end point y position; + EventInjector::GetInstance()->SetDragEvent(startPoint, endPoint, 80); // 80: drag time + CompareTools::WaitSuspend(); +} + +void UIAutoTest::CompareByBinary(const char* fileName) const +{ + if (fileName == nullptr) { + return; + } + 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), CompareTools::CompareMode::COMPARE_BINARY); + } else { + CompareTools::SaveFile(filePath, sizeof(filePath), CompareTools::CompareMode::COMPARE_BINARY); + } +} +} // namespace OHOS diff --git a/test/framework/src/ui_auto_test_group.cpp b/test/framework/src/ui_auto_test_group.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ce0ceb1b13254c6c3d10cd430f3c75d821f81699 --- /dev/null +++ b/test/framework/src/ui_auto_test_group.cpp @@ -0,0 +1,42 @@ +/* + * 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 "ui_auto_test_group.h" +#include "graphic_config.h" +#include "test_render/ui_auto_test_render.h" + +namespace OHOS { +List UIAutoTestGroup::testCaseList_; + +void UIAutoTestGroup::SetUpTestCase() +{ + testCaseList_.PushBack(new UIAutoTestRender()); +} + +List& UIAutoTestGroup::GetTestCase() +{ + return testCaseList_; +} + +void UIAutoTestGroup::TearDownTestCase() +{ + ListNode* node = testCaseList_.Begin(); + while (node != testCaseList_.End()) { + delete node->data_; + node = node->next_; + } + testCaseList_.Clear(); +} +} // namespace OHOS diff --git a/test/framework/src/ui_test_app.cpp b/test/framework/src/ui_test_app.cpp index 5444a84d8cfeab2ca8e305675b3e759428d39e0f..ffcfc33955815c3cbe0ec5418b4d529de34ad492 100755 --- a/test/framework/src/ui_test_app.cpp +++ b/test/framework/src/ui_test_app.cpp @@ -18,6 +18,12 @@ #include "test_resource_config.h" #include "ui_test.h" #include "ui_test_group.h" +#if ENABEL_UI_AUTO_TEST +#include "compare_tools.h" +#include "dfx/event_injector.h" +#include "ui_auto_test_group.h" +#include "ui_auto_test.h" +#endif // ENABEL_UI_AUTO_TEST namespace OHOS { void UITestApp::Start() @@ -37,6 +43,7 @@ void UITestApp::Init() backBtn_->SetPosition(0, 0); backBtn_->Resize(163, 64); // 163: button width; 64: button height backBtn_->SetText("Back"); + backBtn_->SetViewId(UI_TEST_BACK_BUTTON_ID); backBtn_->SetLablePosition(72, 0); // 72: button label x-coordinate backBtn_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 24); // 24: means font size backBtn_->SetImageSrc(TEST_BACK_LEFT_ARROW, TEST_BACK_LEFT_ARROW); @@ -71,6 +78,7 @@ void UITestApp::Init() mainList_->SetPosition(24, deltaHeight); // 24: x-coordinate mainList_->Resize(Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight() - deltaHeight); mainList_->SetThrowDrag(true); + mainList_->SetViewId(UI_TEST_MAIN_LIST_ID); adapter_ = new TestCaseListAdapter(rootView_, mainList_, backBtn_, testCaseLabel_, testLabel_); UITestGroup::SetUpTestCase(); mainList_->SetAdapter(adapter_); @@ -97,4 +105,20 @@ UITestApp::~UITestApp() rootView_ = nullptr; } } -} // namespace OHOS \ No newline at end of file + +#if ENABEL_UI_AUTO_TEST +void UIAutoTestApp::Start() +{ + EventInjector::GetInstance()->RegisterEventInjector(EventDataType::POINT_TYPE); + EventInjector::GetInstance()->RegisterEventInjector(EventDataType::KEY_TYPE); + CompareTools::WaitSuspend(); + UIAutoTestGroup::SetUpTestCase(); + ListNode* node = UIAutoTestGroup::GetTestCase().Begin(); + while (node != UIAutoTestGroup::GetTestCase().End()) { + node->data_->RunTestList(); + node->data_->ResetMainMenu(); + node = node->next_; + } +} +#endif // ENABEL_UI_AUTO_TEST +} // namespace OHOS diff --git a/test/framework/src/ui_test_group.cpp b/test/framework/src/ui_test_group.cpp index 31e29663c2ea821249f7bf5fb208b3c1f6db33ed..b613f5c504f31a845dfe616ac180251c9a928d77 100755 --- a/test/framework/src/ui_test_group.cpp +++ b/test/framework/src/ui_test_group.cpp @@ -103,7 +103,7 @@ void UITestGroup::SetUpTestCase() testCaseList_.PushBack(TestCaseInfo{"Canvas", new UITestCanvas()}); testCaseList_.PushBack(TestCaseInfo{"Draw_Rect", new UITestDrawRect()}); testCaseList_.PushBack(TestCaseInfo{"Draw_Line", new UITestDrawLine()}); - testCaseList_.PushBack(TestCaseInfo{"Render", new UITestRender()}); + testCaseList_.PushBack(TestCaseInfo{UI_TEST_RENDER_ID, new UITestRender()}); testCaseList_.PushBack(TestCaseInfo{"Anti_Aliasing", new UITestAntiAliasing()}); testCaseList_.PushBack(TestCaseInfo{"UIList", new UITestUIList()}); testCaseList_.PushBack(TestCaseInfo{"UISwipeView", new UITestUISwipeView()}); diff --git a/test/uitest/test_render/ui_auto_test_render.cpp b/test/uitest/test_render/ui_auto_test_render.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a05a6f143e0f6032911e1cced3429d99fbd03829 --- /dev/null +++ b/test/uitest/test_render/ui_auto_test_render.cpp @@ -0,0 +1,45 @@ +/* + * 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 "ui_auto_test_render.h" +#include "ui_test_render.h" + +namespace OHOS { +void UIAutoTestRender::Reset() const +{ + ResetMainMenu(); + EnterSubMenu(UI_TEST_RENDER_ID); +} + +void UIAutoTestRender::RunTestList() +{ + Reset(); + UIKitRenderTestRender001(); + UIKitRenderTestRenderMeasure001(); +} + +void UIAutoTestRender::UIKitRenderTestRender001() const +{ + const char* fileName = "ui_test_render_001.bin"; + CompareByBinary(fileName); +} + +void UIAutoTestRender::UIKitRenderTestRenderMeasure001() const +{ + ClickViewById(UI_TEST_RENDER_UPDATA_BUTTON_ID_01); + const char* fileName = "ui_test_render_measure_001.bin"; + CompareByBinary(fileName); +} +} // namespace OHOS diff --git a/test/uitest/test_render/ui_auto_test_render.h b/test/uitest/test_render/ui_auto_test_render.h new file mode 100644 index 0000000000000000000000000000000000000000..2feb97d73e3bdbeea659c55330a4cd1855fc0157 --- /dev/null +++ b/test/uitest/test_render/ui_auto_test_render.h @@ -0,0 +1,34 @@ +/* + * 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_UI_AUTO_TEST_RENDER_H +#define GRAPHIC_LITE_UI_AUTO_TEST_RENDER_H + +#include "ui_auto_test.h" + +namespace OHOS { +class UIAutoTestRender : public UIAutoTest { +public: + UIAutoTestRender() {} + ~UIAutoTestRender() {} + + void Reset() const; + void RunTestList(); + + void UIKitRenderTestRender001() const; + void UIKitRenderTestRenderMeasure001() const; +}; +} // namespace OHOS +#endif // GRAPHIC_LITE_UI_AUTO_TEST_RENDER_H \ No newline at end of file diff --git a/test/uitest/test_render/ui_test_render.cpp b/test/uitest/test_render/ui_test_render.cpp index ac145ad96370fcbf5272de2244aa82806251817d..d32262aa469bdf73a9e66431f04e792de1fe020a 100755 --- a/test/uitest/test_render/ui_test_render.cpp +++ b/test/uitest/test_render/ui_test_render.cpp @@ -133,6 +133,7 @@ void UITestRender::UIKit_Render_Test_RenderMeasure_001() group->Add(labelButton_); labelButton_->Resize(BUTTON_WIDHT3, BUTTON_HEIGHT3); labelButton_->SetText("更新label"); + labelButton_->SetViewId(UI_TEST_RENDER_UPDATA_BUTTON_ID_01); labelButton_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); labelButton_->SetStyleForState(STYLE_BORDER_RADIUS, BUTTON_STYLE_BORDER_RADIUS_VALUE, UIButton::RELEASED); labelButton_->SetStyleForState(STYLE_BORDER_RADIUS, BUTTON_STYLE_BORDER_RADIUS_VALUE, UIButton::PRESSED); diff --git a/test/uitest/test_render/ui_test_render.h b/test/uitest/test_render/ui_test_render.h index 94a2e8dd17f75cfec2068f2caf64a19e5eb9fddb..cb10ee2cf4ec3d87a3d776a0a0b771b94358454f 100755 --- a/test/uitest/test_render/ui_test_render.h +++ b/test/uitest/test_render/ui_test_render.h @@ -22,6 +22,10 @@ #include "ui_test.h" namespace OHOS { +namespace { + constexpr char* UI_TEST_RENDER_ID = "Render"; + constexpr char* UI_TEST_RENDER_UPDATA_BUTTON_ID_01 = "test_render_updata_buttin_01"; +} class UITestRender : public UITest, public UIView::OnClickListener { public: UITestRender() : container_(nullptr) {} diff --git a/tools/qt/simulator/test/test.pro b/tools/qt/simulator/test/test.pro index 220b3a94b214669ff705fd46e873d7669037136f..38c5342411bfa1b375898e973931c3c2dd018ed2 100644 --- a/tools/qt/simulator/test/test.pro +++ b/tools/qt/simulator/test/test.pro @@ -65,6 +65,12 @@ SOURCES += \ ../../../../test/uitest/test_view_percent/ui_test_view_percent.cpp \ ../../../../test/uitest/test_view_scale_rotate/ui_test_view_scale_rotate.cpp +SOURCES += \ + ../../../../test/framework/src/ui_auto_test.cpp \ + ../../../../test/framework/src/ui_auto_test_group.cpp \ + ../../../../test/framework/src/compare_tools.cpp \ + ../../../../test/uitest/test_render/ui_auto_test_render.cpp \ + HEADERS += \ ../../../../test/framework/include/test_case_list_adapter.h \ ../../../../test/framework/include/ui_test_app.h \ @@ -111,6 +117,12 @@ HEADERS += \ ../../../../test/uitest/test_view_percent/ui_test_view_percent.h \ ../../../../test/uitest/test_view_scale_rotate/ui_test_view_scale_rotate.h +HEADERS += \ + ../../../../test/framework/include/ui_auto_test.h \ + ../../../../test/framework/include/ui_auto_test_group.h \ + ../../../../test/framework/include/compare_tools.h \ + ../../../../test/uitest/test_render/ui_auto_test_render.h + INCLUDEPATH += \ ../../../../frameworks \ ../../../../../utils/frameworks/windows \