From: Caisking Date: Tue, 19 Aug 2025 10:21:25 +0000 (+0800) Subject: 增加产测测试项测试结果按键 X-Git-Tag: leiniao_debug_1.0.0_20250922_020716~152^2~24 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=3ac604969683f785b1a93bb3eef9b32ac1049bd9;p=mirrors%2FFD230.git 增加产测测试项测试结果按键 --- diff --git a/code/sdk/zhihui/UI/producttest/include/testModel.h b/code/sdk/zhihui/UI/producttest/include/testModel.h index 4e813a8ed..2dd2a5682 100644 --- a/code/sdk/zhihui/UI/producttest/include/testModel.h +++ b/code/sdk/zhihui/UI/producttest/include/testModel.h @@ -1,20 +1,87 @@ #ifndef TEST_MODEL_H #define TEST_MODEL_H - +#include +#include namespace OHOS { + //测试结果枚举 未测试 成功 失败 + enum test_status_enum { + TEST_STATUS_NONE, + TEST_STATUS_SUCCESS, + TEST_STATUS_ERROR + }; + + //测试结果结构体 + struct test_status_t { + int test_id; + test_status_enum status; + std::string test_result; + }; + + /* + // LCD测试结果 + // 触摸屏测试结果 + // 磁力计测试结果 + // 亮度测试结果 + // 亮度测试结果 + // 喇叭测试结果 + // 麦克风测试结果 + // 马达测试结果 + // 心率漏光测试结果 + // 重力加速度传感器 + // 4g测试结果 + // 按键测试结果 + // 蓝牙扫描测试结果 + // gps测试结果 + // 低功耗测试结果 + */ + + //测试项枚举 + enum test_item_enum { + LCD_TEST, + TP_TEST, + MAGETIC_TEST, + LUMINANCE_TEST, + BAT_TEST, + SPK_TEST, + MIC_TEST, + MOTOR_TEST, + HR_TEST, + GSENSOR_TEST, + CAT1_TEST, + KEY_TEST, + BUTTON_TEST, + BT_TEST, + APPI_TEST, + GPS_TEST, + // LOWPOWER_TEST, + MAX_TEST_ITEM, + }; class testModel { public: static testModel *GetInstance(void); void testModelupdata(int); + bool SetResult(int viewId, bool pass); + bool SetResult(std::string viewIdstr); + bool GetResult(int viewId); + std::string GetSummaryString(); + std::string GetViewId(int viewid); + private: testModel() = default; ~testModel(){} testModel(const testModel &) = delete; testModel &operator=(const testModel &) = delete; - + std::string m_summary;//测试结果总结 + std::string m_start_time;//开始时间str + std::string m_end_time;//结束时间str + bool is_first_test{true};//第一次测试标志 + uint32_t m_start_ts = 0;//开始时间戳 + uint32_t m_end_ts = 0;//结束时间 + uint32_t m_failed_tests = 0 ;//失败的测试项数 + uint32_t m_skipped_tests = 0;//跳过的测试项数 }; } diff --git a/code/sdk/zhihui/UI/producttest/include/testView.h b/code/sdk/zhihui/UI/producttest/include/testView.h index 57bbae165..5520e49c1 100644 --- a/code/sdk/zhihui/UI/producttest/include/testView.h +++ b/code/sdk/zhihui/UI/producttest/include/testView.h @@ -169,6 +169,12 @@ namespace OHOS }; extern test_ext Test_ViewMapper_t[]; + + + UILabelButtonExt *okBtn{nullptr}; + UILabelButtonExt *failBtn{nullptr}; + + } // namespace OHOS #endif \ No newline at end of file diff --git a/code/sdk/zhihui/UI/producttest/src/testModel.cpp b/code/sdk/zhihui/UI/producttest/src/testModel.cpp index b8a4d7887..9676f28ed 100644 --- a/code/sdk/zhihui/UI/producttest/src/testModel.cpp +++ b/code/sdk/zhihui/UI/producttest/src/testModel.cpp @@ -12,9 +12,152 @@ #include "producttest/include/testPresenter.h" #include "producttest/include/testLCDC.h" #include "producttest/include/testTPC.h" +#include "custom_utils.h" namespace OHOS { + //测试结果数组 + test_status_t test_status_list[MAX_TEST_ITEM] = { + { LCD_TEST, TEST_STATUS_NONE, "LCD_Test" }, + { TP_TEST, TEST_STATUS_NONE, "Touch_Panel_Test" }, + { MAGNETIC_TEST, TEST_STATUS_NONE, "Magnetic_Test" }, + { LUMINANCE_TEST, TEST_STATUS_NONE, "Luminance_Test" }, + { BAT_TEST, TEST_STATUS_NONE, "Battery_Charger_Test" }, + { SPK_TEST, TEST_STATUS_NONE, "Speaker_Test" }, + { KEY_TEST, TEST_STATUS_NONE, "Key_Test" }, + { MOTOR_TEST, TEST_STATUS_NONE, "Motor_Vibration_Test" }, + { HR_TEST, TEST_STATUS_NONE, "Heart_Rate_Sensor_Test" }, + { GSENSOR_TEST, TEST_STATUS_NONE, "G_Sensor_Test" }, + { CAT1_TEST, TEST_STATUS_NONE, "CAT1_Module_Test" }, + { BUTTON_TEST, TEST_STATUS_NONE, "Physical_Buttons_Test" }, + { BT_TEST, TEST_STATUS_NONE, "Bluetooth_Test" }, + { APPI_TEST, TEST_STATUS_NONE, "SE_Chip_Test" }, + { GPS_TEST, TEST_STATUS_NONE, "GPS_Position_Test" }, + // { LOWPOWER_TEST, TEST_STATUS_NONE, "Deep_Sleep_Current_Test" }, + }; + + //设置测试结果 + bool testModel::SetResult(int viewId, test_status_enum pass) + { + //判断viewId是否在测试项枚举范围内 + if(viewId < 0 || viewId >= MAX_TEST_ITEM) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "testModel::SetResult: viewId out of range"); + return false; + } + //记录开始时间 + if(is_first_test) + { + //设置测试开始时间 + char current_time[9]; // 分配内存给current_time + if (uapi_get_HHMMSS_Time(current_time, ':', true) != ERRCODE_SUCC) + { + return false; + } + m_start_time = current_time; + is_first_test = false; + } + //更新测试结果 + test_status_list[viewId].status = pass ? TEST_STATUS_SUCCESS : TEST_STATUS_ERROR; + return true; + } + + //通过测试项描述进行更新 + bool testModel::SetResult(std::string viewIdstr) + { + //解析执行结果 + test_status_enum status = TEST_STATUS_NONE; + if(strncmp(viewIdstr.c_str(), "TestOK", 6) == 0) + { + status = TEST_STATUS_SUCCESS; + } + else if(strncmp(viewIdstr.c_str(), "TestNO", 6) == 0) + { + status = TEST_STATUS_ERROR; + } + else + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "testModel::SetResult: invalid status string"); + return false; + } + + //提取测试项描述(跳过前面的"TestOK"或"TestNO") + std::string desc = viewIdstr.substr(6); + + //查找匹配的测试项并更新状态 + for(int i = 0; i < MAX_TEST_ITEM; i++) + { + if(strcmp(test_status_list[i].desc, desc.c_str()) == 0) + { + //记录开始时间(与ID更新方式保持一致) + if(is_first_test) + { + char current_time[9]; + if (uapi_get_HHMMSS_Time(current_time, ':', true) != ERRCODE_SUCC) + { + return false; + } + m_start_time = current_time; + is_first_test = false; + } + + //更新测试状态 + test_status_list[i].status = status; + return true; + } + } + + //未找到匹配的测试项 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "testModel::SetResult: test item not found - %s", desc.c_str()); + return false; + } + //获取测试结果 + test_status_enum testModel::GetResult(int viewId) + { + if(viewId < 0 || viewId >= MAX_TEST_ITEM) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "testModel::GetResult: viewId out of range"); + return false; + } + return test_status_list[viewId].status; + } + + //获取描述str + std::string testModel::GetViewId(int viewid) + { + if(viewId < 0 || viewId >= MAX_TEST_ITEM) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "testModel::GetResult: viewId out of range"); + return false; + } + return test_status_list[viewId].test_result; + } + + //汇总测试项结果 + std::string testModel::GetSummaryString() + { + //清空测试结果总结 + m_summary.clear(); + m_skipped_tests = 0; + m_failed_tests = 0; + + //进行编译 设置未测试的测试项;未通过的测试项; + for(int i = 0; i < MAX_TEST_ITEM; i++) + { + if(test_status_list[i].status == TEST_STATUS_NONE) + { + m_summary += test_status_list[i].test_result + "未测试\n"; + m_skipped_tests++; + } + else if(test_status_list[i].status == TEST_STATUS_ERROR) + { + m_summary += test_status_list[i].test_result + "未通过\n"; + m_failed_tests++; + } + } + + return m_summary; + } testModel *testModel::GetInstance(void) { diff --git a/code/sdk/zhihui/UI/producttest/src/testPresenter.cpp b/code/sdk/zhihui/UI/producttest/src/testPresenter.cpp index f7ea6ffac..a758058a6 100644 --- a/code/sdk/zhihui/UI/producttest/src/testPresenter.cpp +++ b/code/sdk/zhihui/UI/producttest/src/testPresenter.cpp @@ -222,19 +222,33 @@ namespace OHOS return true; } + // 处理各测试界面的 成功/失败 按钮 + if (strncmp(view.GetViewId(), "TestOK", 6) == 0 || strncmp(view.GetViewId(), "TestNO", 6) == 0) + { + std::string vid = view.GetViewId(); + + if(testModel::GetInstance()->SetResult(vid)) + { + return true; + } + return false; + } + for(int i=0;iChangeView(TESTVIEW, Test_ViewMapper_t[i].viewId); + if(Test_ViewMapper_t[i].enable_falg==true) { + testView::GetInstance()->ChangeView(TESTVIEW, Test_ViewMapper_t[i].viewId); + } return true; } if(strcmp(view.GetViewId(),Test_ViewMapper_t[i].viewid_str_next) == 0) { - if(Test_ViewMapper_t[i+1].enable_falg==true) - testView::GetInstance()->ChangeView(Test_ViewMapper_t[i].viewId, Test_ViewMapper_t[i+1].viewId); + if(Test_ViewMapper_t[i+1].enable_falg==true) { + testView::GetInstance()->ChangeView(Test_ViewMapper_t[i].viewId, Test_ViewMapper_t[i+1].viewId); + } return true; } diff --git a/code/sdk/zhihui/UI/producttest/src/testView.cpp b/code/sdk/zhihui/UI/producttest/src/testView.cpp index 917978621..14ccf1e92 100644 --- a/code/sdk/zhihui/UI/producttest/src/testView.cpp +++ b/code/sdk/zhihui/UI/producttest/src/testView.cpp @@ -1,5 +1,6 @@ #include "producttest/include/testView.h" #include "producttest/include/testPresenter.h" +#include "components/ui_label_button.h" #include "power_display_service.h" #include "wearable_log.h" #ifdef SUPPORT_CAT1_SERVICE @@ -118,6 +119,18 @@ namespace OHOS } } } + ///////////////////////// + if(okBtn) + { + delete okBtn; + okBtn = nullptr; + } + if(failBtn) + { + delete failBtn; + failBtn = nullptr; + } + ///////////////////////////// if (test_about_view) { delete test_about_view; // 1 @@ -369,6 +382,7 @@ namespace OHOS return false; } SystemScrollView[thisView] = test_LCD_view->testLCDInitIView(thisView); + AddResultButtons(SystemScrollView[thisView], LCD_TEST); group->Add(SystemScrollView[thisView]); } return true; @@ -386,6 +400,7 @@ namespace OHOS return false; } SystemScrollView[thisView] = test_TP_view->testTPInitIView(thisView); + AddResultButtons(SystemScrollView[thisView], TP_TEST); group->Add(SystemScrollView[thisView]); } return true; @@ -403,6 +418,7 @@ namespace OHOS return false; } SystemScrollView[thisView] = test_MG_view->testmagicInitIView(thisView); + AddResultButtons(SystemScrollView[thisView], MAGNETIC_TEST); group->Add(SystemScrollView[thisView]); } return true; @@ -420,6 +436,7 @@ namespace OHOS return false; } SystemScrollView[thisView] = test_lum_view->testLUMInitIView(thisView); + AddResultButtons(SystemScrollView[thisView], LUMINANCE_TEST); group->Add(SystemScrollView[thisView]); } return true; @@ -437,6 +454,7 @@ namespace OHOS return false; } SystemScrollView[thisView] = test_charging_view->testCHANINGInitIView(thisView); + AddResultButtons(SystemScrollView[thisView], BAT_TEST); group->Add(SystemScrollView[thisView]); } return true; @@ -454,6 +472,7 @@ namespace OHOS return false; } SystemScrollView[thisView] = test_speak_view->testSPEAKInitIView(thisView); + AddResultButtons(SystemScrollView[thisView], SPK_TEST); group->Add(SystemScrollView[thisView]); } return true; @@ -471,6 +490,7 @@ namespace OHOS return false; } SystemScrollView[thisView] = test_motor_view->testMOTORInitIView(thisView); + AddResultButtons(SystemScrollView[thisView], MOTOR_TEST); group->Add(SystemScrollView[thisView]); } return true; @@ -489,6 +509,7 @@ namespace OHOS return false; } SystemScrollView[thisView] = test_cat1_view->testcat1InitIView(thisView); + AddResultButtons(SystemScrollView[thisView], CAT1_TEST); group->Add(SystemScrollView[thisView]); } #endif @@ -524,6 +545,7 @@ namespace OHOS return false; } SystemScrollView[thisView] = test_MP_view->testmicrophoneInitIView(thisView); + // AddResultButtons(SystemScrollView[thisView], thisView); group->Add(SystemScrollView[thisView]); } return true; @@ -541,6 +563,7 @@ namespace OHOS return false; } SystemScrollView[thisView] = test_hr_view->testhrsensonInitIView(thisView); + AddResultButtons(SystemScrollView[thisView], HR_TEST); group->Add(SystemScrollView[thisView]); } return true; @@ -558,6 +581,7 @@ namespace OHOS return false; } SystemScrollView[thisView] = test_G_view->testGSENSONInitIView(thisView); + AddResultButtons(SystemScrollView[thisView], GSENSOR_TEST); group->Add(SystemScrollView[thisView]); } return true; @@ -594,6 +618,7 @@ namespace OHOS return false; } SystemScrollView[thisView] = test_BT_view->testBTInitIView(thisView); + AddResultButtons(SystemScrollView[thisView], BT_TEST); group->Add(SystemScrollView[thisView]); } return true; @@ -611,6 +636,7 @@ namespace OHOS return false; } SystemScrollView[thisView] = test_SEChip_view->SEChipInitIView(thisView); + AddResultButtons(SystemScrollView[thisView], APPI_TEST); group->Add(SystemScrollView[thisView]); } return true; @@ -646,6 +672,7 @@ namespace OHOS return false; } SystemScrollView[thisView] = test_GPS_view->testGPSInitIView((uint8_t)thisView); + AddResultButtons(SystemScrollView[thisView], GPS_TEST); group->Add(SystemScrollView[thisView]); } @@ -666,6 +693,7 @@ namespace OHOS return false; } SystemScrollView[thisView] = test_pressure_view->testpressureInitIView((uint8_t)thisView); + // AddResultButtons(SystemScrollView[thisView], thisView); group->Add(SystemScrollView[thisView]); } @@ -685,6 +713,7 @@ namespace OHOS return false; } SystemScrollView[thisView] = test_A5133_view->testA5133InitIView(thisView); + // AddResultButtons(SystemScrollView[thisView], thisView); group->Add(SystemScrollView[thisView]); } return true; @@ -941,4 +970,78 @@ namespace OHOS group->Add(SystemScrollView[TESTVIEW]); AddViewToRootContainer(group); } -} \ No newline at end of file + + int16_t testView::GetCurrentViewId() + { + return m_currentViewId; + } + + void testView::AddResultButtons(UIScrollView *scrollView, int16_t viewId) +{ + if (scrollView == nullptr) { + return; + } + + // 放到上方,避免被内容遮挡 + if(okBtn == nullptr) + okBtn = testAboutView::GetInstance()->init_button_next(40, 80, (char*)"TestOK"); + if(failBtn == nullptr) + failBtn = testAboutView::GetInstance()->init_button_next(220, 80, (char*)"TestNO"); + + // 获取当前测试项状态 + test_status_enum status = testModel::GetInstance()->GetResult(viewId); + // 获取测试项描述 + std::string viewDesc = testModel::GetInstance()->GetViewId(viewId); + + if (okBtn) { + okBtn->SetText("成功"); + okBtn->SetAlign(TEXT_ALIGNMENT_CENTER); + + // 根据状态设置按钮样式 + switch(status) + { + case TEST_STATUS_NONE: + okBtn->SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full); + break; + case TEST_STATUS_SUCCESS: + okBtn->SetStyle(STYLE_BACKGROUND_COLOR, Color::Green().full); + break; + case TEST_STATUS_ERROR: + okBtn->SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full); + break; + } + + // 设置按钮标识 + std::string okIdStr = "TestOK" + viewDesc; + okBtn->SetViewId(okIdStr.c_str()); + scrollView->Add(okBtn); + okBtn->SetOnClickListener(testPresenter::GetInstance()); + } + + if (failBtn) { + failBtn->SetText("失败"); + failBtn->SetAlign(TEXT_ALIGNMENT_CENTER); + + // 根据状态设置按钮样式 + switch(status) + { + case TEST_STATUS_NONE: + failBtn->SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full); + break; + case TEST_STATUS_SUCCESS: + failBtn->SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full); + break; + case TEST_STATUS_ERROR: + failBtn->SetStyle(STYLE_BACKGROUND_COLOR, Color::Red().full); + break; + } + + // 设置按钮标识(修复了原代码中的错误) + std::string failIdStr = "TestNO" + viewDesc; + failBtn->SetViewId(failIdStr.c_str()); + scrollView->Add(failBtn); + failBtn->SetOnClickListener(testPresenter::GetInstance()); + } +} + +} // namespace OHOS \ No newline at end of file