#ifndef TEST_MODEL_H
#define TEST_MODEL_H
-
+#include <stdint.h>
+#include <string>
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;//跳过的测试项数
};
}
};\r
extern test_ext Test_ViewMapper_t[];\r
\r
+\r
+ \r
+ UILabelButtonExt *okBtn{nullptr};\r
+ UILabelButtonExt *failBtn{nullptr};\r
+\r
+\r
} // namespace OHOS\r
\r
#endif
\ No newline at end of file
#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)
{
return true;\r
}\r
\r
+ // 处理各测试界面的 成功/失败 按钮\r
+ if (strncmp(view.GetViewId(), "TestOK", 6) == 0 || strncmp(view.GetViewId(), "TestNO", 6) == 0)\r
+ {\r
+ std::string vid = view.GetViewId();\r
+\r
+ if(testModel::GetInstance()->SetResult(vid))\r
+ {\r
+ return true;\r
+ }\r
+ return false;\r
+ }\r
+\r
\r
for(int i=0;i<len;i++)\r
{\r
if(strcmp(view.GetViewId(),Test_ViewMapper_t[i].viewid_str) == 0)\r
{\r
- if(Test_ViewMapper_t[i].enable_falg==true)\r
- testView::GetInstance()->ChangeView(TESTVIEW, Test_ViewMapper_t[i].viewId);\r
+ if(Test_ViewMapper_t[i].enable_falg==true) {\r
+ testView::GetInstance()->ChangeView(TESTVIEW, Test_ViewMapper_t[i].viewId);\r
+ }\r
return true;\r
}\r
if(strcmp(view.GetViewId(),Test_ViewMapper_t[i].viewid_str_next) == 0)\r
{\r
- if(Test_ViewMapper_t[i+1].enable_falg==true)\r
- testView::GetInstance()->ChangeView(Test_ViewMapper_t[i].viewId, Test_ViewMapper_t[i+1].viewId);\r
+ if(Test_ViewMapper_t[i+1].enable_falg==true) {\r
+ testView::GetInstance()->ChangeView(Test_ViewMapper_t[i].viewId, Test_ViewMapper_t[i+1].viewId);\r
+ }\r
return true;\r
}\r
\r
#include "producttest/include/testView.h"\r
#include "producttest/include/testPresenter.h"\r
+#include "components/ui_label_button.h"\r
#include "power_display_service.h"\r
#include "wearable_log.h"\r
#ifdef SUPPORT_CAT1_SERVICE\r
}\r
}\r
}\r
+ /////////////////////////\r
+ if(okBtn)\r
+ { \r
+ delete okBtn; \r
+ okBtn = nullptr;\r
+ }\r
+ if(failBtn)\r
+ { \r
+ delete failBtn; \r
+ failBtn = nullptr;\r
+ }\r
+ /////////////////////////////\r
if (test_about_view)\r
{\r
delete test_about_view; // 1\r
return false;\r
}\r
SystemScrollView[thisView] = test_LCD_view->testLCDInitIView(thisView);\r
+ AddResultButtons(SystemScrollView[thisView], LCD_TEST);\r
group->Add(SystemScrollView[thisView]);\r
}\r
return true;\r
return false;\r
}\r
SystemScrollView[thisView] = test_TP_view->testTPInitIView(thisView);\r
+ AddResultButtons(SystemScrollView[thisView], TP_TEST);\r
group->Add(SystemScrollView[thisView]);\r
}\r
return true;\r
return false;\r
}\r
SystemScrollView[thisView] = test_MG_view->testmagicInitIView(thisView);\r
+ AddResultButtons(SystemScrollView[thisView], MAGNETIC_TEST);\r
group->Add(SystemScrollView[thisView]);\r
}\r
return true;\r
return false;\r
}\r
SystemScrollView[thisView] = test_lum_view->testLUMInitIView(thisView);\r
+ AddResultButtons(SystemScrollView[thisView], LUMINANCE_TEST);\r
group->Add(SystemScrollView[thisView]);\r
}\r
return true;\r
return false;\r
}\r
SystemScrollView[thisView] = test_charging_view->testCHANINGInitIView(thisView);\r
+ AddResultButtons(SystemScrollView[thisView], BAT_TEST);\r
group->Add(SystemScrollView[thisView]);\r
}\r
return true;\r
return false;\r
}\r
SystemScrollView[thisView] = test_speak_view->testSPEAKInitIView(thisView);\r
+ AddResultButtons(SystemScrollView[thisView], SPK_TEST);\r
group->Add(SystemScrollView[thisView]);\r
}\r
return true;\r
return false;\r
}\r
SystemScrollView[thisView] = test_motor_view->testMOTORInitIView(thisView);\r
+ AddResultButtons(SystemScrollView[thisView], MOTOR_TEST);\r
group->Add(SystemScrollView[thisView]);\r
}\r
return true;\r
return false;\r
}\r
SystemScrollView[thisView] = test_cat1_view->testcat1InitIView(thisView);\r
+ AddResultButtons(SystemScrollView[thisView], CAT1_TEST);\r
group->Add(SystemScrollView[thisView]);\r
}\r
#endif\r
return false;\r
}\r
SystemScrollView[thisView] = test_MP_view->testmicrophoneInitIView(thisView);\r
+ // AddResultButtons(SystemScrollView[thisView], thisView);\r
group->Add(SystemScrollView[thisView]);\r
}\r
return true;\r
return false;\r
}\r
SystemScrollView[thisView] = test_hr_view->testhrsensonInitIView(thisView);\r
+ AddResultButtons(SystemScrollView[thisView], HR_TEST);\r
group->Add(SystemScrollView[thisView]);\r
}\r
return true;\r
return false;\r
}\r
SystemScrollView[thisView] = test_G_view->testGSENSONInitIView(thisView);\r
+ AddResultButtons(SystemScrollView[thisView], GSENSOR_TEST);\r
group->Add(SystemScrollView[thisView]);\r
}\r
return true;\r
return false;\r
}\r
SystemScrollView[thisView] = test_BT_view->testBTInitIView(thisView);\r
+ AddResultButtons(SystemScrollView[thisView], BT_TEST);\r
group->Add(SystemScrollView[thisView]);\r
}\r
return true;\r
return false;\r
}\r
SystemScrollView[thisView] = test_SEChip_view->SEChipInitIView(thisView);\r
+ AddResultButtons(SystemScrollView[thisView], APPI_TEST);\r
group->Add(SystemScrollView[thisView]);\r
}\r
return true;\r
return false;\r
}\r
SystemScrollView[thisView] = test_GPS_view->testGPSInitIView((uint8_t)thisView);\r
+ AddResultButtons(SystemScrollView[thisView], GPS_TEST);\r
group->Add(SystemScrollView[thisView]);\r
}\r
\r
return false;\r
}\r
SystemScrollView[thisView] = test_pressure_view->testpressureInitIView((uint8_t)thisView);\r
+ // AddResultButtons(SystemScrollView[thisView], thisView);\r
group->Add(SystemScrollView[thisView]);\r
}\r
\r
return false;\r
}\r
SystemScrollView[thisView] = test_A5133_view->testA5133InitIView(thisView);\r
+ // AddResultButtons(SystemScrollView[thisView], thisView);\r
group->Add(SystemScrollView[thisView]);\r
}\r
return true;\r
group->Add(SystemScrollView[TESTVIEW]);\r
AddViewToRootContainer(group);\r
}\r
-}
\ No newline at end of file
+\r
+ int16_t testView::GetCurrentViewId()\r
+ {\r
+ return m_currentViewId;\r
+ }\r
+\r
+ void testView::AddResultButtons(UIScrollView *scrollView, int16_t viewId)\r
+{\r
+ if (scrollView == nullptr) {\r
+ return;\r
+ }\r
+\r
+ // 放到上方,避免被内容遮挡\r
+ if(okBtn == nullptr)\r
+ okBtn = testAboutView::GetInstance()->init_button_next(40, 80, (char*)"TestOK");\r
+ if(failBtn == nullptr)\r
+ failBtn = testAboutView::GetInstance()->init_button_next(220, 80, (char*)"TestNO");\r
+ \r
+ // 获取当前测试项状态\r
+ test_status_enum status = testModel::GetInstance()->GetResult(viewId);\r
+ // 获取测试项描述\r
+ std::string viewDesc = testModel::GetInstance()->GetViewId(viewId);\r
+ \r
+ if (okBtn) {\r
+ okBtn->SetText("成功");\r
+ okBtn->SetAlign(TEXT_ALIGNMENT_CENTER);\r
+ \r
+ // 根据状态设置按钮样式\r
+ switch(status)\r
+ {\r
+ case TEST_STATUS_NONE:\r
+ okBtn->SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full);\r
+ break;\r
+ case TEST_STATUS_SUCCESS:\r
+ okBtn->SetStyle(STYLE_BACKGROUND_COLOR, Color::Green().full);\r
+ break;\r
+ case TEST_STATUS_ERROR:\r
+ okBtn->SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full);\r
+ break;\r
+ }\r
+ \r
+ // 设置按钮标识\r
+ std::string okIdStr = "TestOK" + viewDesc;\r
+ okBtn->SetViewId(okIdStr.c_str());\r
+ scrollView->Add(okBtn);\r
+ okBtn->SetOnClickListener(testPresenter::GetInstance());\r
+ }\r
+ \r
+ if (failBtn) {\r
+ failBtn->SetText("失败");\r
+ failBtn->SetAlign(TEXT_ALIGNMENT_CENTER);\r
+ \r
+ // 根据状态设置按钮样式\r
+ switch(status)\r
+ {\r
+ case TEST_STATUS_NONE:\r
+ failBtn->SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full);\r
+ break;\r
+ case TEST_STATUS_SUCCESS:\r
+ failBtn->SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full);\r
+ break;\r
+ case TEST_STATUS_ERROR:\r
+ failBtn->SetStyle(STYLE_BACKGROUND_COLOR, Color::Red().full);\r
+ break;\r
+ }\r
+ \r
+ // 设置按钮标识(修复了原代码中的错误)\r
+ std::string failIdStr = "TestNO" + viewDesc;\r
+ failBtn->SetViewId(failIdStr.c_str());\r
+ scrollView->Add(failBtn);\r
+ failBtn->SetOnClickListener(testPresenter::GetInstance());\r
+ }\r
+}\r
+\r
+} // namespace OHOS
\ No newline at end of file