code_production/code/base/test_base.cpp

344 lines
6.2 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include"test_base.h"
#include<string>
#include <stdio.h>
#include <windows.h>
#include <map>
#include <iostream>
#include "huagao/hgscanner_error.h"
class test
{
ui_helper* helper_;
public:
test(ui_helper* helper) :helper_(helper)
{}
~test()
{}
std::map<const wchar_t*, test> test_map_;
void init_test_map_()
{
// test_map_[HGPDTTOOLDB_NAME_DIAL_SWITCH] = &test::test_dial_switch;
}
public:
/* 拨码开关校验 */
int test_dial_switch()
{
ui_helper::test_event ev = ui_helper::TEST_EVENT_TIPS;
int ret = helper_->io_control(IO_CTRL_CODE_BASE, NULL, NULL);
helper_->test_callback(HGPDTTOOLDB_NAME_DIAL_SWITCH, ev, NULL, ret);
return SCANNER_ERR_OK;
}
/* 检查船型开关功能 */
int test_pocker_switch()
{
return SCANNER_ERR_OK;
}
/* 设备上电并观察开机状态 */
int test_boot_status()
{
return SCANNER_ERR_OK;
}
/* 检查液晶显示 */
int test_lcd_display()
{
return SCANNER_ERR_OK;
}
/* 清理纸道功能确认 */
int tset_clear_paper_path()
{
return SCANNER_ERR_OK;
}
/* 按键功能检测 */
int test_key_funtion()
{
return SCANNER_ERR_OK;
}
/* 计数模式检测 */
int test_count_mode()
{
return SCANNER_ERR_OK;
}
/* 歪斜检测 */
int test_skew_detection()
{
return SCANNER_ERR_OK;
}
/* 分纸电机检测 */
int test_separater_motor()
{
return SCANNER_ERR_OK;
}
/* cis原图初检 */
int test_cis__original_image()
{
return SCANNER_ERR_OK;
}
/* 主机风扇功能检测 */
int test_host_fan()
{
return SCANNER_ERR_OK;
}
/* 超声波模块检验 */
int test_ultrasonic_module()
{
return SCANNER_ERR_OK;
}
/* led灯状态检查 */
int test_led_light()
{
return SCANNER_ERR_OK;
}
/* 复位检查 */
int test_reset()
{
return SCANNER_ERR_OK;
}
/* 走纸检查 */
int test_paper_feed()
{
return SCANNER_ERR_OK;
}
/* 开盖传感器检查 */
int test_cover_sensor()
{
return SCANNER_ERR_OK;
}
/* 扫描传感器检查 */
int test_scanning_sensor()
{
return SCANNER_ERR_OK;
}
/* 配置速度模式 */
int test_configure_speed_mode()
{
return SCANNER_ERR_OK;
}
/* 放置校正纸 */
int test_place_correction_paper()
{
return SCANNER_ERR_OK;
}
/* 自动平场校正 */
int test_auto_flat_field()
{
return SCANNER_ERR_OK;
}
/* 重启设备 */
int test_reboot_device()
{
}
/* 扫描图像质量确认 */
int test_image_quality()
{
}
/* 色卡纸成像质量评估 */
int test_colorcard_imageing_quality()
{
}
/* 色卡纸偏色成像质量评估 */
int test_colorcard_bias_imageing_quality()
{
}
/* 清晰度质量评估 */
int test_clarity_quality()
{
}
/* 畸变修正 */
int test_distortion()
{
}
/* 设置休眠 */
int test_dormancy()
{
}
/* 歪斜挡位检测 */
int test_skew_gear()
{
}
/* 分纸强度检测 */
int test_paper_separation_strength()
{
}
/* 机械走纸倾斜检测 */
int test_mech_paper_feeding_inclination()
{
}
/* 单张测试1 */
int test_single_page_test_1()
{
}
/* 单张测试2 */
int test_single_page_test_2()
{
}
/* 单张测试3 */
int test_single_page_test_3()
{
}
/* 压力测试2轮 */
int test_pressuer_test()
{
}
/* 清除滚轴计数 */
int test_clear_roller_count()
{
}
private:
};
//test
static std::string jsontext1("{\"1\":{\"name\":\"test-8\",\"ver\":1}}");
std::string str_ret_call_= "";
bool have_img_ = false;
int sane_ex_callback1(SANE_Handle hdev, int code, void* data, unsigned int* len, void* param)
{
switch (code)
{
case SANE_EVENT_WORKING:
{
str_ret_call_ = (char*)data;
}
break;
case SANE_EVENT_SCAN_FINISHED:
{
str_ret_call_ = (char*)data;
}
break;
case SANE_EVENT_STATUS:
{
str_ret_call_ = (char*)data;
}
break;
case SANE_EVENT_ERROR:
{
str_ret_call_ = (char*)data;
}
break;
case SANE_EVENT_IMAGE_OK:
{
SANE_Image* sane_img = (SANE_Image*)data;
have_img_ = true;
}
break;
}
return 0;
}
int str_to_wchar(std::string str, wchar_t* s, size_t* strlen)
{
if (str.empty())
return ERROR_INSUFFICIENT_BUFFER;
size_t size = str.length();
int len = 0;
len = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, NULL, 0);
if (*strlen < len)
{
*strlen = len;
return ERROR_INSUFFICIENT_BUFFER;
}
MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, s, len);
return 0;
}
int get_json_config_file()
{
int len = 0;
char exePath[256];
char* buf = NULL;
GetModuleFileNameA(NULL, exePath, 255);
(strrchr(exePath, '\\'))[1] = 0; //去掉执行的文件名。
strcat(exePath, "DLLs\\G302.hsc");
FILE* fp = fopen(exePath, "rb");
if (fp == NULL)
{
return -1;
}
fseek(fp, 0, SEEK_END);
len = ftell(fp);
fseek(fp, 0, SEEK_SET);
buf = new char[len];
if (!buf)
{
fclose(fp);
return -1;
}
memset(buf, 0, len);
fread(buf, len, 1, fp);
fclose(fp);
std::cout << buf << std::endl;
}
DECL_API(int) func_test_init(void* init)
{
return 0;
}
DECL_API(int) func_test_get_list(wchar_t* buf, size_t* len)
{
return str_to_wchar(jsontext1, buf, len);
}
DECL_API(int) func_test_go(const wchar_t* name, const wchar_t* oper, ui_helper* helper)
{
if (!name || !oper || !helper)
{
return -1;
}
//helper->add_ref();
helper->register_sane_callback(sane_ex_callback1, NULL);
bool flag = false;
wchar_t* des = NULL;
int ret = 0;
size_t map_bool_len = sizeof(Test_Map_Bool) / sizeof(Test_Map_Bool[0]);
size_t map_str_len = sizeof(Test_Map_String) / sizeof(Test_Map_String[0]);
size_t map_int_len = sizeof(Test_Map_Int) / sizeof(Test_Map_Int[0]);
ui_helper::test_event ev = ui_helper::TEST_EVENT_TIPS; //项目测试设置TEST_EVENT_TIPS测试结果设置TEST_EVENT_RESULT
for (size_t i = 0; i < map_bool_len; i++)
{
des = (wchar_t*)Test_Map_Bool[i].title;
if (wcscmp(name, Test_Map_Bool[i].name) == 0) //理论上手动处理的事项是不会传下来
{
SANE_Bool map_bool = true;
unsigned int len = sizeof(SANE_Bool);
ret = helper->io_control(Test_Map_Bool[i].num,(void *)&map_bool, &len);
ev = ui_helper::TEST_EVENT_RESULT;
helper->test_callback(Test_Map_Bool[i].name, ev, NULL, ret);
return SCANNER_ERR_OK;
}
/*else if(wcscmp(name, Test_Map_String[i].name) == 0)
{
return SCANNER_ERR_OK;
}
else if (wcscmp(name, Test_Map_Int[i].name) == 0)
{
return SCANNER_ERR_OK;
}*/
}
ret = helper->io_control(IO_CTRL_CODE_RESTORE_SETTINGS, NULL, NULL);
//helper->release();
//helper->unregister_sane_callback(sane_ex_callback);
if (!helper)
{
return SCANNER_ERR_NO_DATA;
}
//test ts(helper);
return SCANNER_ERR_OK;
}
DECL_API(int) func_test_uninit(void* uninit)
{
return 0;
}