code_production/code/base/test_base.cpp

440 lines
10 KiB
C++
Raw Normal View History

2022-12-08 10:10:19 +00:00
#include"test_base.h"
#include<string>
#include <stdio.h>
#include <windows.h>
#include <map>
#include <iostream>
2022-12-14 06:58:06 +00:00
#include "huagao/hgscanner_error.h"
2022-12-08 10:10:19 +00:00
2022-12-15 11:53:41 +00:00
class test
2022-12-08 10:10:19 +00:00
{
2022-12-15 11:53:41 +00:00
ui_helper* helper_;
public:
test(ui_helper* helper) :helper_(helper)
2022-12-23 02:39:07 +00:00
{
init_test_map_();
}
2022-12-15 11:53:41 +00:00
~test()
{}
2022-12-23 02:39:07 +00:00
struct ptrcmp
{
bool operator()(const wchar_t* name1, const wchar_t* name2)const
{
return wcscmp(name1, name2) < 0;
}
};
std::map<std::wstring, int(test::*)()> test_map_;
2022-12-15 11:53:41 +00:00
void init_test_map_()
{
2022-12-23 02:39:07 +00:00
test_map_[HGPDTTOOLDB_NAME_DIAL_SWITCH] = &test::test_dial_switch;
test_map_[HGPDTTOOLDB_NAME_ROCKER_SWITCH] = &test::test_pocker_switch;
test_map_[HGPDTTOOLDB_NAME_BOOT_STATUS] = &test::test_boot_status;
test_map_[HGPDTTOOLDB_NAME_LCD_DISPLAY] = &test::test_lcd_display;
test_map_[HGPDTTOOLDB_NAME_CLEAR_PAPER_PATH] = &test::tset_clear_paper_path;
test_map_[HGPDTTOOLDB_NAME_KEY_FUNCTION] = &test::test_key_funtion;
test_map_[HGPDTTOOLDB_NAME_COUNTING_MODE] = &test::test_count_mode;
test_map_[HGPDTTOOLDB_NAME_SKEW_DETECTION] = &test::test_skew_detection;
test_map_[HGPDTTOOLDB_NAME_SEPARATER_MOTOR] = &test::test_separater_motor;
test_map_[HGPDTTOOLDB_NAME_CIS_ORIGINAL_IMAGE] = &test::test_cis__original_image;
test_map_[HGPDTTOOLDB_NAME_HOST_FAN] = &test::test_host_fan;
test_map_[HGPDTTOOLDB_NAME_ULTRASONIC_MODULE] = &test::test_ultrasonic_module;
test_map_[HGPDTTOOLDB_NAME_LED_LIGHT] = &test::test_led_light;
test_map_[HGPDTTOOLDB_NAME_RESET] = &test::test_reset;
test_map_[HGPDTTOOLDB_NAME_PAPER_FEED] = &test::test_paper_feed;
test_map_[HGPDTTOOLDB_NAME_COVER_SENSOR] = &test::test_cover_sensor;
test_map_[HGPDTTOOLDB_NAME_SCANNING_SENSOR] = &test::test_scanning_sensor;
test_map_[HGPDTTOOLDB_NAME_CONFIGURE_SPEED_MODE] = &test::test_configure_speed_mode;
test_map_[HGPDTTOOLDB_NAME_PLACE_CORRECTION_PAPER] = &test::test_place_correction_paper;
test_map_[HGPDTTOOLDB_NAME_AUTO_FLAT_FIELD] = &test::test_auto_flat_field;
test_map_[HGPDTTOOLDB_NAME_REBOOT_DEVICE] = &test::test_reboot_device;
test_map_[HGPDTTOOLDB_NAME_IMAGE_QUALITY] = &test::test_image_quality;
test_map_[HGPDTTOOLDB_NAME_COLORCARD_IMAGEING_QUALITY] = &test::test_colorcard_imageing_quality;
test_map_[HGPDTTOOLDB_NAME_COLORCARD_BIAS_IMAGEING_QUALITY] = &test::test_colorcard_bias_imageing_quality;
test_map_[HGPDTTOOLDB_NAME_CLARITY_QUALITY] = &test::test_clarity_quality;
test_map_[HGPDTTOOLDB_NAME_DISTORTION] = &test::test_distortion;
test_map_[HGPDTTOOLDB_NAME_DORMANCY] = &test::test_dormancy;
test_map_[HGPDTTOOLDB_NAME_SKEW_GEAR] = &test::test_skew_gear;
test_map_[HGPDTTOOLDB_NAME_PAPER_SEPARATION_STRENGTH] = &test::test_paper_separation_strength;
test_map_[HGPDTTOOLDB_NAME_MECH_PAPER_FEEDING_INCLINATION] = &test::test_mech_paper_feeding_inclination;
test_map_[HGPDTTOOLDB_NAME_SINGLE_PAGE_TEST_1] = &test::test_single_page_test_1;
test_map_[HGPDTTOOLDB_NAME_SINGLE_PAGE_TEST_2] = &test::test_single_page_test_2;
test_map_[HGPDTTOOLDB_NAME_SINGLE_PAGE_TEST_3] = &test::test_single_page_test_3;
test_map_[HGPDTTOOLDB_NAME_PRESSUER_TEST] = &test::test_pressuer_test;
test_map_[HGPDTTOOLDB_NAME_CLEAR_ROLLER_COUNT] = &test::test_clear_roller_count;
}
int set_test(const wchar_t* str)
{
if (!str)
return SCANNER_ERR_NO_DATA;
ui_helper::test_event test_ev_;
int ret = SCANNER_ERR_OK;
std::wstring s = str;
//int count = test_map_.count(str) > 0;
wchar_t* start = (wchar_t*)L"START TEST ";
wchar_t* stop = (wchar_t*)L"STOP TEST ";
wchar_t ss[10];
wcscpy(ss,str);
/*if (!count)
{
ret = SCANNER_ERR_NO_DATA;
return ret;
}*/
//wcscat(start,str);
//helper_->test_callback(str, ui_helper::TEST_EVENT_TIPS, start, NULL);
auto it = test_map_.find(str);
if (it != test_map_.end())
{
ret = (this->*test_map_[str])();
}
else
{
return SCANNER_ERR_OK;
}
if (ret != SCANNER_ERR_OK)
{
helper_->test_callback(str, ui_helper::TEST_EVENT_TIPS, NULL, ret);
return ret;
}
helper_->test_callback(str, ui_helper::TEST_EVENT_TIPS, stop, ret);
return ret;
2022-12-15 11:53:41 +00:00
}
public:
/* <20><><EFBFBD><EFBFBD><EBBFAA>У<EFBFBD><D0A3> */
int test_dial_switch()
{
2022-12-23 02:39:07 +00:00
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
2022-12-15 11:53:41 +00:00
}
/* <20><><EFBFBD><EFBFBD>Ϳ<EFBFBD><CDBF>ع<EFBFBD><D8B9><EFBFBD> */
int test_pocker_switch()
{
2022-12-23 02:39:07 +00:00
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
2022-12-15 11:53:41 +00:00
}
/* <20><EFBFBD>ϵ粢<CFB5>۲쿪<DBB2><ECBFAA>״̬ */
int test_boot_status()
{
2022-12-23 02:39:07 +00:00
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
2022-12-15 11:53:41 +00:00
}
/* <20><><EFBFBD><EFBFBD>Һ<EFBFBD><D2BA><EFBFBD><EFBFBD>ʾ */
int test_lcd_display()
{
2022-12-23 02:39:07 +00:00
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
2022-12-15 11:53:41 +00:00
}
/* <20><><EFBFBD><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7> */
int tset_clear_paper_path()
{
2022-12-23 02:39:07 +00:00
ui_helper::test_event test_ev_ = ui_helper::TEST_EVENT_RESULT;
int ret = helper_->io_control(IO_CTRL_CODE_GET_CLEAN_PAPER_ROAD, NULL, NULL);
if (ret != SCANNER_ERR_OK)
{
helper_->test_callback(HGPDTTOOLDB_NAME_DIAL_SWITCH, test_ev_, NULL, ret);
}
return ret;
2022-12-15 11:53:41 +00:00
}
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܼ<EFBFBD><DCBC><EFBFBD> */
int test_key_funtion()
{
2022-12-23 02:39:07 +00:00
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
2022-12-15 11:53:41 +00:00
}
/* <20><><EFBFBD><EFBFBD>ģʽ<C4A3><CABD><EFBFBD><EFBFBD> */
int test_count_mode()
{
2022-12-23 02:39:07 +00:00
ui_helper::test_event test_ev_= ui_helper::TEST_EVENT_RESULT;
SANE_Bool ismode = false;
unsigned int len = sizeof(SANE_Bool);
int ret = helper_->io_control(IO_CTRL_CODE_GET_CLEAN_PAPER_ROAD, &ismode, &len);
if (ret != SCANNER_ERR_OK)
{
helper_->test_callback(HGPDTTOOLDB_NAME_DIAL_SWITCH, test_ev_, NULL, ret);
return ret;
}
helper_->test_callback(HGPDTTOOLDB_NAME_DIAL_SWITCH, test_ev_, NULL, ismode);
return ret;
2022-12-15 11:53:41 +00:00
}
/* <20><>б<EFBFBD><D0B1><EFBFBD><EFBFBD> */
int test_skew_detection()
{
2022-12-23 02:39:07 +00:00
ui_helper::test_event test_ev_ = ui_helper::TEST_EVENT_RESULT;
SANE_Bool ismode = true;
unsigned int len = sizeof(SANE_Bool);
int ret = helper_->io_control(IO_CTRL_CODE_SET_SKEW_CHECK, &ismode, &len);
if (ret != SCANNER_ERR_OK)
{
helper_->test_callback(HGPDTTOOLDB_NAME_SKEW_DETECTION, test_ev_, NULL, ret);
return ret;
}
int i = 5;
ret = helper_->io_control(IO_CTRL_CODE_SET_SKEW_CHECK_VAL, &i, &len);
ret = helper_->io_control(IO_CTRL_CODE_TEST_SINGLE, NULL, NULL);
helper_->test_callback(HGPDTTOOLDB_NAME_SKEW_DETECTION, test_ev_, NULL, ismode);
return ret;
2022-12-15 11:53:41 +00:00
return SCANNER_ERR_OK;
}
/* <20><>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
int test_separater_motor()
{
return SCANNER_ERR_OK;
}
/* cisԭͼ<D4AD><CDBC><EFBFBD><EFBFBD> */
int test_cis__original_image()
{
return SCANNER_ERR_OK;
}
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȹ<EFBFBD><C8B9>ܼ<EFBFBD><DCBC><EFBFBD> */
int test_host_fan()
{
return SCANNER_ERR_OK;
}
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
int test_ultrasonic_module()
{
return SCANNER_ERR_OK;
}
/* led<65><64>״̬<D7B4><CCAC><EFBFBD><EFBFBD> */
int test_led_light()
{
return SCANNER_ERR_OK;
}
/* <20><>λ<EFBFBD><CEBB><EFBFBD><EFBFBD> */
int test_reset()
{
return SCANNER_ERR_OK;
}
/* <20><>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD> */
int test_paper_feed()
{
return SCANNER_ERR_OK;
}
/* <20><><EFBFBD>Ǵ<EFBFBD><C7B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
int test_cover_sensor()
{
return SCANNER_ERR_OK;
}
/* ɨ<><EFBFBD><E8B4AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
int test_scanning_sensor()
{
return SCANNER_ERR_OK;
}
/* <20><><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD>ģʽ */
int test_configure_speed_mode()
{
return SCANNER_ERR_OK;
}
/* <20><><EFBFBD><EFBFBD>У<EFBFBD><D0A3>ֽ */
int test_place_correction_paper()
{
return SCANNER_ERR_OK;
}
/* <20>Զ<EFBFBD>ƽ<EFBFBD><C6BD>У<EFBFBD><D0A3> */
int test_auto_flat_field()
{
return SCANNER_ERR_OK;
}
/* <20><><EFBFBD><EFBFBD><EFBFBD>豸 */
int test_reboot_device()
{
2022-12-23 02:39:07 +00:00
return SCANNER_ERR_OK;
2022-12-15 11:53:41 +00:00
}
/* ɨ<><C9A8>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7> */
int test_image_quality()
{
2022-12-23 02:39:07 +00:00
return SCANNER_ERR_OK;
2022-12-15 11:53:41 +00:00
}
/* ɫ<><C9AB>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
int test_colorcard_imageing_quality()
{
2022-12-23 02:39:07 +00:00
return SCANNER_ERR_OK;
2022-12-15 11:53:41 +00:00
}
/* ɫ<><C9AB>ֽƫɫ<C6AB><C9AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
int test_colorcard_bias_imageing_quality()
{
2022-12-23 02:39:07 +00:00
return SCANNER_ERR_OK;
2022-12-15 11:53:41 +00:00
}
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
int test_clarity_quality()
{
2022-12-23 02:39:07 +00:00
return SCANNER_ERR_OK;
2022-12-15 11:53:41 +00:00
}
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
int test_distortion()
{
2022-12-23 02:39:07 +00:00
return SCANNER_ERR_OK;
2022-12-15 11:53:41 +00:00
}
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
int test_dormancy()
{
2022-12-23 02:39:07 +00:00
return SCANNER_ERR_OK;
2022-12-15 11:53:41 +00:00
}
/* <20><>б<EFBFBD><D0B1>λ<EFBFBD><CEBB><EFBFBD><EFBFBD> */
int test_skew_gear()
{
2022-12-23 02:39:07 +00:00
return SCANNER_ERR_OK;
2022-12-15 11:53:41 +00:00
}
/* <20><>ֽǿ<D6BD>ȼ<EFBFBD><C8BC><EFBFBD> */
int test_paper_separation_strength()
{
2022-12-23 02:39:07 +00:00
return SCANNER_ERR_OK;
2022-12-15 11:53:41 +00:00
}
/* <20><>е<EFBFBD><D0B5>ֽ<EFBFBD><D6BD>б<EFBFBD><D0B1><EFBFBD><EFBFBD> */
int test_mech_paper_feeding_inclination()
{
2022-12-23 02:39:07 +00:00
return SCANNER_ERR_OK;
2022-12-15 11:53:41 +00:00
}
/* <20><><EFBFBD>Ų<EFBFBD><C5B2><EFBFBD>1 */
int test_single_page_test_1()
{
2022-12-23 02:39:07 +00:00
return SCANNER_ERR_OK;
2022-12-15 11:53:41 +00:00
}
/* <20><><EFBFBD>Ų<EFBFBD><C5B2><EFBFBD>2 */
int test_single_page_test_2()
{
2022-12-23 02:39:07 +00:00
return SCANNER_ERR_OK;
2022-12-15 11:53:41 +00:00
}
/* <20><><EFBFBD>Ų<EFBFBD><C5B2><EFBFBD>3 */
int test_single_page_test_3()
{
2022-12-23 02:39:07 +00:00
return SCANNER_ERR_OK;
2022-12-15 11:53:41 +00:00
}
/* ѹ<><D1B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2<EFBFBD><32> */
int test_pressuer_test()
{
2022-12-23 02:39:07 +00:00
return SCANNER_ERR_OK;
2022-12-15 11:53:41 +00:00
}
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
int test_clear_roller_count()
{
2022-12-23 02:39:07 +00:00
return SCANNER_ERR_OK;
2022-12-15 11:53:41 +00:00
}
private:
2022-12-08 10:10:19 +00:00
};
2022-12-15 11:53:41 +00:00
2022-12-08 10:10:19 +00:00
//test
2022-12-14 06:58:06 +00:00
static std::string jsontext1("{\"1\":{\"name\":\"test-8\",\"ver\":1}}");
2022-12-23 02:39:07 +00:00
std::string ret_call_= "";
2022-12-15 11:53:41 +00:00
bool have_img_ = false;
2022-12-15 02:54:09 +00:00
int sane_ex_callback1(SANE_Handle hdev, int code, void* data, unsigned int* len, void* param)
2022-12-08 10:10:19 +00:00
{
switch (code)
{
case SANE_EVENT_WORKING:
{
2022-12-23 02:39:07 +00:00
ret_call_ = (char*)data;
2022-12-08 10:10:19 +00:00
}
break;
case SANE_EVENT_SCAN_FINISHED:
{
2022-12-23 02:39:07 +00:00
ret_call_ = (char*)data;
2022-12-08 10:10:19 +00:00
}
break;
case SANE_EVENT_STATUS:
{
2022-12-23 02:39:07 +00:00
ret_call_ = (char*)data;
2022-12-08 10:10:19 +00:00
}
break;
case SANE_EVENT_ERROR:
{
2022-12-23 02:39:07 +00:00
ret_call_ = (char*)data;
2022-12-08 10:10:19 +00:00
}
break;
case SANE_EVENT_IMAGE_OK:
{
SANE_Image* sane_img = (SANE_Image*)data;
2022-12-15 11:53:41 +00:00
have_img_ = true;
2022-12-08 10:10:19 +00:00
}
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; //ȥ<><C8A5>ִ<EFBFBD>е<EFBFBD><D0B5>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
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;
}
2022-12-15 02:54:09 +00:00
2022-12-15 06:39:32 +00:00
DECL_API(int) func_test_init(void* init)
2022-12-08 10:10:19 +00:00
{
return 0;
}
2022-12-15 06:39:32 +00:00
DECL_API(int) func_test_get_list(wchar_t* buf, size_t* len)
2022-12-08 10:10:19 +00:00
{
2022-12-14 06:58:06 +00:00
return str_to_wchar(jsontext1, buf, len);
2022-12-08 10:10:19 +00:00
}
2022-12-15 06:39:32 +00:00
DECL_API(int) func_test_go(const wchar_t* name, const wchar_t* oper, ui_helper* helper)
2022-12-08 10:10:19 +00:00
{
if (!name || !oper || !helper)
{
return -1;
}
2022-12-15 02:54:09 +00:00
//helper->add_ref();
helper->register_sane_callback(sane_ex_callback1, NULL);
2022-12-08 10:10:19 +00:00
int ret = 0;
2022-12-23 02:39:07 +00:00
test ts(helper);
ret = ts.set_test(name);
2022-12-08 10:10:19 +00:00
2022-12-23 02:39:07 +00:00
ret = helper->io_control(IO_CTRL_CODE_RESTORE_SETTINGS, NULL, NULL);//<2F><><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD>Ĭ<EFBFBD><C4AC>
return ret;
2022-12-08 10:10:19 +00:00
}
2022-12-15 06:39:32 +00:00
DECL_API(int) func_test_uninit(void* uninit)
2022-12-08 10:10:19 +00:00
{
return 0;
}