527 lines
16 KiB
C
527 lines
16 KiB
C
|
#pragma once
|
|||
|
#include "string"
|
|||
|
#include "sane/sane_ex.h"
|
|||
|
//////////////////////////////////////TITLE//////////////////////////////////////
|
|||
|
/* 拨码开关校验 */
|
|||
|
#define HGPDTTOOLDB_TITLE_DIAL_SWITCH L"拨码开关校验"
|
|||
|
/* 检查船型开关功能 */
|
|||
|
#define HGPDTTOOLDB_TITLE_ROCKER_SWITCH L"检查船型开关功能"
|
|||
|
/* 设备上电并观察开机状态 */
|
|||
|
#define HGPDTTOOLDB_TITLE_BOOT_STATUS L"设备上电并观察开机状态"
|
|||
|
/* 检查液晶显示 */
|
|||
|
#define HGPDTTOOLDB_TITLE_LCD_DISPLAY L"检查液晶显示"
|
|||
|
/* 清理纸道功能确认 */
|
|||
|
#define HGPDTTOOLDB_TITLE_CLEAR_PAPER_PATH L"清理纸道功能确认"
|
|||
|
/* 按键功能检测 */
|
|||
|
#define HGPDTTOOLDB_TITLE_KEY_FUNCTION L"按键功能检测"
|
|||
|
/* 计数模式检测 */
|
|||
|
#define HGPDTTOOLDB_TITLE_COUNTING_MODE L"计数模式检测"
|
|||
|
/* 歪斜检测 */
|
|||
|
#define HGPDTTOOLDB_TITLE_SKEW_DETECTION L"歪斜检测"
|
|||
|
/* 分纸电机检测 */
|
|||
|
#define HGPDTTOOLDB_TITLE_SEPARATER_MOTOR L"分纸电机检测"
|
|||
|
/* CIS原图初检 */
|
|||
|
#define HGPDTTOOLDB_TITLE_CIS_ORIGINAL_IMAGE L"CIS原图初检"
|
|||
|
/* 主机风扇功能检测 */
|
|||
|
#define HGPDTTOOLDB_TITLE_HOST_FAN L"主机风扇功能检测"
|
|||
|
/* 超声波模块检验 */
|
|||
|
#define HGPDTTOOLDB_TITLE_ULTRASONIC_MODULE L"超声波模块检验"
|
|||
|
/* LED灯状态检查 */
|
|||
|
#define HGPDTTOOLDB_TITLE_LED_LIGHT L"LED灯状态检查"
|
|||
|
/* 复位检查 */
|
|||
|
#define HGPDTTOOLDB_TITLE_RESET L"复位检查"
|
|||
|
/* 走纸检查 */
|
|||
|
#define HGPDTTOOLDB_TITLE_PAPER_FEED L"走纸检查"
|
|||
|
/* 开盖传感器检查 */
|
|||
|
#define HGPDTTOOLDB_TITLE_COVER_SENSOR L"开盖传感器检查"
|
|||
|
/* 扫描传感器检查 */
|
|||
|
#define HGPDTTOOLDB_TITLE_SCANNING_SENSOR L"扫描传感器检查"
|
|||
|
/* 配置速度模式 */
|
|||
|
#define HGPDTTOOLDB_TITLE_CONFIGURE_SPEED_MODE L"配置速度模式"
|
|||
|
/* 放置校正纸 */
|
|||
|
#define HGPDTTOOLDB_TITLE_PLACE_CORRECTION_PAPER L"放置校正纸"
|
|||
|
/* 自动平场校正 */
|
|||
|
#define HGPDTTOOLDB_TITLE_AUTO_FLAT_FIELD L"自动平场校正"
|
|||
|
/* 重启设备 */
|
|||
|
#define HGPDTTOOLDB_TITLE_REBOOT_DEVICE L"重启设备"
|
|||
|
/* 扫描图像质量确认 */
|
|||
|
#define HGPDTTOOLDB_TITLE_IMAGE_QUALITY L"扫描图像质量确认"
|
|||
|
/* 色卡纸成像质量评估 */
|
|||
|
#define HGPDTTOOLDB_TITLE_COLORCARD_IMAGEING_QUALITY L"色卡纸成像质量评估"
|
|||
|
/* 色卡纸偏色成像质量评估 */
|
|||
|
#define HGPDTTOOLDB_TITLE_COLORCARD_BIAS_IMAGEING_QUALITY L"色卡纸偏色成像质量评估"
|
|||
|
/* 清晰度质量评估 */
|
|||
|
#define HGPDTTOOLDB_TITLE_CLARITY_QUALITY L"清晰度质量评估"
|
|||
|
/* 畸变修正 */
|
|||
|
#define HGPDTTOOLDB_TITLE_DISTORTION L"畸变修正"
|
|||
|
/* 设置休眠 */
|
|||
|
#define HGPDTTOOLDB_TITLE_DORMANCY L"设置休眠"
|
|||
|
/* 歪斜挡位检测 */
|
|||
|
#define HGPDTTOOLDB_TITLE_SKEW_GEAR L"歪斜挡位检测"
|
|||
|
/* 分纸强度检测 */
|
|||
|
#define HGPDTTOOLDB_TITLE_PAPER_SEPARATION_STRENGTH L"分纸强度检测"
|
|||
|
/* 机械走纸倾斜检测 */
|
|||
|
#define HGPDTTOOLDB_TITLE_MECH_PAPER_FEEDING_INCLINATION L"机械走纸倾斜检测"
|
|||
|
/* 单张测试1 */
|
|||
|
#define HGPDTTOOLDB_TITLE_SINGLE_PAGE_TEST_1 L"单张测试1"
|
|||
|
/* 单张测试2 */
|
|||
|
#define HGPDTTOOLDB_TITLE_SINGLE_PAGE_TEST_2 L"单张测试2"
|
|||
|
/* 单张测试3 */
|
|||
|
#define HGPDTTOOLDB_TITLE_SINGLE_PAGE_TEST_3 L"单张测试3"
|
|||
|
/* 压力测试2轮 */
|
|||
|
#define HGPDTTOOLDB_TITLE_PRESSUER_TEST L"压力测试2轮"
|
|||
|
/* 清除滚轴计数 */
|
|||
|
#define HGPDTTOOLDB_TITLE_CLEAR_ROLLER_COUNT L"清除滚轴计数"
|
|||
|
//////////////////////////////////////NAME//////////////////////////////////////
|
|||
|
/* 拨码开关校验 */
|
|||
|
#define HGPDTTOOLDB_NAME_DIAL_SWITCH L"test-1"
|
|||
|
/* 检查船型开关功能 */
|
|||
|
#define HGPDTTOOLDB_NAME_ROCKER_SWITCH L"test-2"
|
|||
|
/* 设备上电并观察开机状态 */
|
|||
|
#define HGPDTTOOLDB_NAME_BOOT_STATUS L"test-3"
|
|||
|
/* 检查液晶显示 */
|
|||
|
#define HGPDTTOOLDB_NAME_LCD_DISPLAY L"test-4"
|
|||
|
/* 清理纸道功能确认 */
|
|||
|
#define HGPDTTOOLDB_NAME_CLEAR_PAPER_PATH L"test-5"
|
|||
|
/* 按键功能检测 */
|
|||
|
#define HGPDTTOOLDB_NAME_KEY_FUNCTION L"test-6"
|
|||
|
/* 计数模式检测 */
|
|||
|
#define HGPDTTOOLDB_NAME_COUNTING_MODE L"test-7"
|
|||
|
/* 歪斜检测 */
|
|||
|
#define HGPDTTOOLDB_NAME_SKEW_DETECTION L"test-8"
|
|||
|
/* 分纸电机检测 */
|
|||
|
#define HGPDTTOOLDB_NAME_SEPARATER_MOTOR L"test-9"
|
|||
|
/* CIS原图初检 */
|
|||
|
#define HGPDTTOOLDB_NAME_CIS_ORIGINAL_IMAGE L"test-10"
|
|||
|
/* 主机风扇功能检测 */
|
|||
|
#define HGPDTTOOLDB_NAME_HOST_FAN L"test-11"
|
|||
|
/* 超声波模块检验 */
|
|||
|
#define HGPDTTOOLDB_NAME_ULTRASONIC_MODULE L"test-12"
|
|||
|
/* LED灯状态检查 */
|
|||
|
#define HGPDTTOOLDB_NAME_LED_LIGHT L"test-13"
|
|||
|
/* 复位检查 */
|
|||
|
#define HGPDTTOOLDB_NAME_RESET L"test-14"
|
|||
|
/* 走纸检查 */
|
|||
|
#define HGPDTTOOLDB_NAME_PAPER_FEED L"test-15"
|
|||
|
/* 开盖传感器检查 */
|
|||
|
#define HGPDTTOOLDB_NAME_COVER_SENSOR L"test-16"
|
|||
|
/* 扫描传感器检查 */
|
|||
|
#define HGPDTTOOLDB_NAME_SCANNING_SENSOR L"test-17"
|
|||
|
|
|||
|
/* 配置速度模式 */
|
|||
|
#define HGPDTTOOLDB_NAME_CONFIGURE_SPEED_MODE L"test-18"
|
|||
|
/* 放置校正纸 */
|
|||
|
#define HGPDTTOOLDB_NAME_PLACE_CORRECTION_PAPER L"test-19"
|
|||
|
/* 自动平场校正 */
|
|||
|
#define HGPDTTOOLDB_NAME_AUTO_FLAT_FIELD L"test-20"
|
|||
|
/* 重启设备 */
|
|||
|
#define HGPDTTOOLDB_NAME_REBOOT_DEVICE L"test-21"
|
|||
|
/* 扫描图像质量确认 */
|
|||
|
#define HGPDTTOOLDB_NAME_IMAGE_QUALITY L"test-22"
|
|||
|
/* 色卡纸成像质量评估 */
|
|||
|
#define HGPDTTOOLDB_NAME_COLORCARD_IMAGEING_QUALITY L"test-23"
|
|||
|
/* 色卡纸偏色成像质量评估 */
|
|||
|
#define HGPDTTOOLDB_NAME_COLORCARD_BIAS_IMAGEING_QUALITY L"test-24"
|
|||
|
/* 清晰度质量评估 */
|
|||
|
#define HGPDTTOOLDB_NAME_CLARITY_QUALITY L"test-25"
|
|||
|
/* 畸变修正 */
|
|||
|
#define HGPDTTOOLDB_NAME_DISTORTION L"test-26"
|
|||
|
/* 设置休眠 */
|
|||
|
#define HGPDTTOOLDB_NAME_DORMANCY L"test-27"
|
|||
|
/* 歪斜挡位检测 */
|
|||
|
#define HGPDTTOOLDB_NAME_SKEW_GEAR L"test-28"
|
|||
|
/* 分纸强度检测 */
|
|||
|
#define HGPDTTOOLDB_NAME_PAPER_SEPARATION_STRENGTH L"test-29"
|
|||
|
/* 机械走纸倾斜检测 */
|
|||
|
#define HGPDTTOOLDB_NAME_MECH_PAPER_FEEDING_INCLINATION L"test-30"
|
|||
|
/* 单张测试1 */
|
|||
|
#define HGPDTTOOLDB_NAME_SINGLE_PAGE_TEST_1 L"test-31"
|
|||
|
/* 单张测试2 */
|
|||
|
#define HGPDTTOOLDB_NAME_SINGLE_PAGE_TEST_2 L"test-32"
|
|||
|
/* 单张测试3 */
|
|||
|
#define HGPDTTOOLDB_NAME_SINGLE_PAGE_TEST_3 L"test-33"
|
|||
|
/* 压力测试2轮 */
|
|||
|
#define HGPDTTOOLDB_NAME_PRESSUER_TEST L"test-34"
|
|||
|
/* 清除滚轴计数 */
|
|||
|
#define HGPDTTOOLDB_NAME_CLEAR_ROLLER_COUNT L"test-35"
|
|||
|
enum scanner_err
|
|||
|
{
|
|||
|
SCANNER_ERR_OK = 0, // 成功,正常状态
|
|||
|
|
|||
|
// 1:软件逻辑错误
|
|||
|
SCANNER_ERR_INVALID_PARAMETER = 0x100, // 非法的参数调用
|
|||
|
SCANNER_ERR_USER_CANCELED, // 用户取消了操作
|
|||
|
SCANNER_ERR_INSUFFICIENT_MEMORY, // 分配的内存不足
|
|||
|
SCANNER_ERR_ACCESS_DENIED, // 访问被拒绝
|
|||
|
SCANNER_ERR_IO_PENDING, // 异步访问,数据稍后返回
|
|||
|
SCANNER_ERR_NOT_EXACT, // 数据不精确,精确的数据已经在同一缓存中返回
|
|||
|
SCANNER_ERR_CONFIGURATION_CHANGED, // 设备的配置项发生改变,需要重新加载显示
|
|||
|
SCANNER_ERR_NOT_OPEN, // 设备未打开
|
|||
|
SCANNER_ERR_NOT_START, // 设备没有启动
|
|||
|
SCANNER_ERR_NOT_ANY_MORE, // 用于回调返回,在本次扫描中,对相同操作不再回调
|
|||
|
SCANNER_ERR_NO_DATA, // 没有数据
|
|||
|
SCANNER_ERR_HAS_DATA_YET, // 有数据未被读取(异步操作中)
|
|||
|
SCANNER_ERR_OUT_OF_RANGE, // 相关操作超出范围
|
|||
|
SCANNER_ERR_IO, // IO错误
|
|||
|
SCANNER_ERR_TIMEOUT, // 超时错误
|
|||
|
SCANNER_ERR_OPEN_FILE_FAILED, // 打开本地文件失败
|
|||
|
SCANNER_ERR_CREATE_FILE_FAILED, // 创建本地文件失败
|
|||
|
SCANNER_ERR_WRITE_FILE_FAILED, // 写本地文件失败
|
|||
|
SCANNER_ERR_DATA_DAMAGED, // 数据损坏(内置资源数据损坏)
|
|||
|
SCANNER_ERR_OPENED_BY_OTHER_PROCESS, // 设备已经被其它进程打开占用
|
|||
|
|
|||
|
// 2:USB错误
|
|||
|
SCANNER_ERR_USB_INIT_FAILED = 0x5b00, // libusb_init 失败
|
|||
|
SCANNER_ERR_USB_REGISTER_PNP_FAILED, // 注册USB监听事件失败
|
|||
|
SCANNER_ERR_USB_CLAIM_INTERFACE_FAILED, // failed in calling libusb_claim_interface
|
|||
|
|
|||
|
// 3:硬件错误
|
|||
|
SCANNER_ERR_DEVICE_NOT_FOUND = 0x0de00, // 设备未找到
|
|||
|
SCANNER_ERR_DEVICE_NOT_SUPPORT, // 设备不支持该操作
|
|||
|
SCANNER_ERR_DEVICE_BUSY, // 设备正忙,不能响应该操作
|
|||
|
SCANNER_ERR_DEVICE_SLEEPING, // 设备处于睡眠状态
|
|||
|
SCANNER_ERR_DEVICE_COUNT_MODE, // 设备处于计数扫描状态?
|
|||
|
SCANNER_ERR_DEVICE_STOPPED, // 扫描停止
|
|||
|
SCANNER_ERR_DEVICE_COVER_OPENNED, // 扫描仪盖板呈打开状态
|
|||
|
SCANNER_ERR_DEVICE_NO_PAPER, // 没有纸张输入
|
|||
|
SCANNER_ERR_DEVICE_FEEDING_PAPER, // 搓纸失败
|
|||
|
SCANNER_ERR_DEVICE_DOUBLE_FEEDING, // 双张检测
|
|||
|
SCANNER_ERR_DEVICE_PAPER_JAMMED, // 卡纸
|
|||
|
SCANNER_ERR_DEVICE_STAPLE_ON, // 有钉书钉
|
|||
|
SCANNER_ERR_DEVICE_PAPER_SKEW, // 纸张倾斜
|
|||
|
SCANNER_ERR_DEVICE_SIZE_CHECK, // 尺寸检测错误
|
|||
|
SCANNER_ERR_DEVICE_DOGEAR, // 纸张有折角
|
|||
|
SCANNER_ERR_DEVICE_NO_IMAGE, // 设备没取到图
|
|||
|
SCANNER_ERR_DEVICE_SCANN_ERROR, // 设备扫图失败
|
|||
|
SCANNER_ERR_DEVICE_PC_BUSY, // PC繁忙或出错
|
|||
|
SCANNER_ERR_DEVICE_ISLOCK, // 设备被锁定
|
|||
|
SCANNER_ERR_DEVICE_UPGRADE_SUCCESSFUL, // 固件升级成功
|
|||
|
SCANNER_ERR_DEVICE_UPGRADE_FAIL // 固件升级失败
|
|||
|
};
|
|||
|
|
|||
|
class ref
|
|||
|
{
|
|||
|
volatile long ref_;
|
|||
|
public:
|
|||
|
ref() : ref_(1)
|
|||
|
{}
|
|||
|
|
|||
|
protected:
|
|||
|
virtual ~ref()
|
|||
|
{}
|
|||
|
|
|||
|
public:
|
|||
|
long add_ref(void)
|
|||
|
{
|
|||
|
return _InterlockedIncrement(&ref_);
|
|||
|
}
|
|||
|
long release(void)
|
|||
|
{
|
|||
|
long r = _InterlockedDecrement(&ref_);
|
|||
|
|
|||
|
if (r == 0)
|
|||
|
delete this;
|
|||
|
|
|||
|
return r;
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
class parameter : public ref
|
|||
|
{
|
|||
|
public:
|
|||
|
parameter()
|
|||
|
{}
|
|||
|
|
|||
|
protected:
|
|||
|
virtual ~parameter()
|
|||
|
{}
|
|||
|
|
|||
|
public:
|
|||
|
virtual size_t get_size(void) = 0;
|
|||
|
virtual void* get_data(void) = 0; // return data pointer, bool*, int*, double*, (wchar_t*)
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
class ui_helper : public ref
|
|||
|
{
|
|||
|
public:
|
|||
|
ui_helper()
|
|||
|
{}
|
|||
|
protected:
|
|||
|
virtual ~ui_helper()
|
|||
|
{}
|
|||
|
|
|||
|
public:
|
|||
|
enum data_from
|
|||
|
{
|
|||
|
DATA_FROM_KNOWN = 0, // pre-defined data name, i.e. resulotion, paper, bright, ...
|
|||
|
DATA_FROM_USER, // need a window for user inputing
|
|||
|
};
|
|||
|
enum value_type
|
|||
|
{
|
|||
|
VAL_TYPE_BOOL = 0,
|
|||
|
VAL_TYPE_INT,
|
|||
|
VAL_TYPE_FLOAT,
|
|||
|
VAL_TYPE_STRING,
|
|||
|
VAL_TYPE_CUSTOM, // custom data, such as gamma table ...
|
|||
|
};
|
|||
|
|
|||
|
// get testing parameter ...
|
|||
|
virtual parameter* get_user_input(data_from from, value_type type
|
|||
|
, const wchar_t* title // window title when from == DATA_FROM_USER, or parameter name when from == DATA_FROM_KNOWN
|
|||
|
, const wchar_t* desc = NULL // description of the parameter if from was DATA_FROM_USER, unused in DATA_FROM_KNOWN
|
|||
|
) = 0;
|
|||
|
|
|||
|
enum test_event
|
|||
|
{
|
|||
|
TEST_EVENT_TIPS = 0, // messages in testing process, data is (wchar_t*), flag is unused
|
|||
|
TEST_EVENT_xxx, // should be complemented ...
|
|||
|
TEST_EVENT_RESULT, // test result, data is (wchar_t*)description, flag is (bool)result, true - test pass
|
|||
|
};
|
|||
|
virtual void test_callback(const wchar_t* name/*test name*/, test_event ev, void* data, size_t flag) = 0;
|
|||
|
|
|||
|
// register/unregister sane callback, the sane_callback in UI module should dispatch the events to these registered callback
|
|||
|
virtual int register_sane_callback(sane_callback cb, void* param) = 0;
|
|||
|
virtual int unregister_sane_callback(sane_callback cb) = 0;
|
|||
|
|
|||
|
// All IO operations are blocking
|
|||
|
virtual int io_control(unsigned long code, void* data, unsigned* len) = 0;
|
|||
|
};
|
|||
|
|
|||
|
#ifdef TEST_DLL
|
|||
|
#define DECL_API(ret) __declspec(dllexport) ret __stdcall
|
|||
|
#else
|
|||
|
#define DECL_API(ret) __declspec(dllimport) ret __stdcall
|
|||
|
#endif
|
|||
|
|
|||
|
// Function: initialize module
|
|||
|
DECL_API(int) func_test_init(void*);
|
|||
|
|
|||
|
// Function: to get testing function list supported by this module/DLL
|
|||
|
//
|
|||
|
// Parameter: buf - to receive the list JSON
|
|||
|
//
|
|||
|
// len - [in] space of 'buf' in words, [out] words copied in buf, or less buffer size in words if return ERROR_INSUFFICIENT_BUFFER
|
|||
|
//
|
|||
|
// Return: ERROR_SUCCESS - JSON configuration has copied into buf
|
|||
|
// ERROR_INSUFFICIENT_BUFFER - buffer is too small, and the minium size in words is stored in 'len'
|
|||
|
// ERROR_INVALID_PARAMETER - NULL for parameter 'len' is not acceptable
|
|||
|
DECL_API(int) func_test_get_list(wchar_t* buf // to receive the JSON text
|
|||
|
, size_t* len); // [in] space of 'buf' in words, [out] words copied in buf, or less buffer size in words if return ERROR_INSUFFICIENT_BUFFER
|
|||
|
|
|||
|
// Function: do ONE function test
|
|||
|
//
|
|||
|
// Parameter: name - function name
|
|||
|
//
|
|||
|
// oper - test operation, "start", "pause", "resume", "stop", ...
|
|||
|
//
|
|||
|
// helper - parameter and testing process callback
|
|||
|
//
|
|||
|
// Return: error code
|
|||
|
DECL_API(int) func_test_go(const wchar_t* name // test name
|
|||
|
, const wchar_t* oper // test oper - "start", "pause", "resume", "stop", ...
|
|||
|
, ui_helper* helper);
|
|||
|
|
|||
|
// Function: uninitialize module
|
|||
|
DECL_API(int) func_test_uninit(void*);
|
|||
|
|
|||
|
|
|||
|
|
|||
|
//////////////////////////////////////////////////////////////////////////////////////////////////
|
|||
|
/*/ testing-DLL load code ...
|
|||
|
#include <vector>
|
|||
|
#include <string>
|
|||
|
#include <algorithm>
|
|||
|
#include <Windows.h>
|
|||
|
|
|||
|
class json : public ref
|
|||
|
{
|
|||
|
public:
|
|||
|
json();
|
|||
|
|
|||
|
protected:
|
|||
|
~json();
|
|||
|
|
|||
|
public:
|
|||
|
bool attach(const wchar_t* text);
|
|||
|
bool get_value(const wchar_t* key, int& val);
|
|||
|
bool get_value(const wchar_t* key, std::wstring& val);
|
|||
|
bool get_value(const wchar_t* key, json*& val);
|
|||
|
};
|
|||
|
|
|||
|
class test_factory
|
|||
|
{
|
|||
|
typedef struct _test_func
|
|||
|
{
|
|||
|
std::wstring name;
|
|||
|
int ver;
|
|||
|
int(__stdcall* test_api)(const wchar_t*, const wchar_t*, ui_helper*);
|
|||
|
|
|||
|
struct _test_func()
|
|||
|
{
|
|||
|
name = L"";
|
|||
|
ver = 0;
|
|||
|
test_api = NULL;
|
|||
|
}
|
|||
|
bool operator==(const wchar_t* n)
|
|||
|
{
|
|||
|
return name == n;
|
|||
|
}
|
|||
|
}TESTFUNC, *LPTESTFUNC;
|
|||
|
std::vector<TESTFUNC> test_;
|
|||
|
|
|||
|
void add_api(const wchar_t* name, int ver, int(__stdcall* test_api)(const wchar_t*, const wchar_t*, ui_helper*))
|
|||
|
{
|
|||
|
std::vector<TESTFUNC>::iterator it = std::find(test_.begin(), test_.end(), name);
|
|||
|
|
|||
|
if (it == test_.end())
|
|||
|
{
|
|||
|
TESTFUNC tf;
|
|||
|
|
|||
|
tf.name = name;
|
|||
|
tf.ver = ver;
|
|||
|
tf.test_api = test_api;
|
|||
|
test_.push_back(tf);
|
|||
|
}
|
|||
|
else if (ver > it->ver)
|
|||
|
{
|
|||
|
it->test_api = test_api;
|
|||
|
it->ver = ver;
|
|||
|
}
|
|||
|
}
|
|||
|
void load_test_dll(const wchar_t* path_dll)
|
|||
|
{
|
|||
|
HMODULE mod = LoadLibraryW(path_dll);
|
|||
|
int(__stdcall * init)(void*) = NULL;
|
|||
|
int(__stdcall * get)(void*, size_t*) = NULL;
|
|||
|
int(__stdcall * go)(const wchar_t*, const wchar_t*, ui_helper*) = NULL;
|
|||
|
FARPROC* api = (FARPROC*)&init;
|
|||
|
wchar_t* buf = NULL;
|
|||
|
size_t len = 0;
|
|||
|
json* root = NULL, * child = NULL;
|
|||
|
|
|||
|
if (!mod)
|
|||
|
return;
|
|||
|
|
|||
|
*api = GetProcAddress(mod, "func_test_init");
|
|||
|
if (!api)
|
|||
|
{
|
|||
|
FreeLibrary(mod);
|
|||
|
return;
|
|||
|
}
|
|||
|
init(NULL);
|
|||
|
|
|||
|
api = (FARPROC*)&get;
|
|||
|
*api = GetProcAddress(mod, "func_test_get_list");
|
|||
|
if(!api)
|
|||
|
{
|
|||
|
FreeLibrary(mod);
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
api = (FARPROC*)&go;
|
|||
|
*api = GetProcAddress(mod, "func_test_go");
|
|||
|
if (!api)
|
|||
|
{
|
|||
|
FreeLibrary(mod);
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
if(get(buf, &len) != ERROR_INSUFFICIENT_BUFFER)
|
|||
|
{
|
|||
|
FreeLibrary(mod);
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
buf = new wchar_t[len + 8];
|
|||
|
memset(buf, 0, (len + 8) * 2);
|
|||
|
if (get(buf, &len))
|
|||
|
{
|
|||
|
delete[] buf;
|
|||
|
FreeLibrary(mod);
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
// parse json ...
|
|||
|
len = 0;
|
|||
|
root = new json();
|
|||
|
if (root->attach(buf))
|
|||
|
{
|
|||
|
for (int i = 1; 1; ++i)
|
|||
|
{
|
|||
|
swprintf_s(buf, 20, L"%d", i);
|
|||
|
if (!root->get_value(buf, child) || !child)
|
|||
|
break;
|
|||
|
|
|||
|
std::wstring name(L"");
|
|||
|
int ver = 0;
|
|||
|
if (child->get_value(L"name", name) && child->get_value(L"ver", ver))
|
|||
|
{
|
|||
|
add_api(name.c_str(), ver, go);
|
|||
|
len++;
|
|||
|
}
|
|||
|
child->release();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
root->release();
|
|||
|
delete[] buf;
|
|||
|
if (len == 0)
|
|||
|
FreeLibrary(mod);
|
|||
|
}
|
|||
|
void init(void)
|
|||
|
{
|
|||
|
wchar_t path[MAX_PATH] = { 0 };
|
|||
|
std::wstring dir(L"");
|
|||
|
size_t pos = 0;
|
|||
|
HANDLE hf = INVALID_HANDLE_VALUE;
|
|||
|
WIN32_FIND_DATAW fd = { 0 };
|
|||
|
|
|||
|
GetModuleFileNameW(NULL, path, _countof(path) - 1);
|
|||
|
dir = pos;
|
|||
|
pos = dir.rfind(L'\\');
|
|||
|
if (pos++ == std::wstring::npos)
|
|||
|
return;
|
|||
|
|
|||
|
dir.erase(pos);
|
|||
|
dir += L"dlls\\";
|
|||
|
hf = FindFirstFileW((dir + L"*.dll").c_str(), &fd);
|
|||
|
if (hf != INVALID_HANDLE_VALUE)
|
|||
|
{
|
|||
|
do
|
|||
|
{
|
|||
|
load_test_dll((dir + fd.cFileName).c_str());
|
|||
|
} while (FindNextFileW(hf, &fd));
|
|||
|
|
|||
|
FindClose(hf);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public:
|
|||
|
test_factory()
|
|||
|
{
|
|||
|
init();
|
|||
|
}
|
|||
|
~test_factory()
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
public:
|
|||
|
bool is_test_available(const wchar_t* name) // check if the test item with name 'name' is supported
|
|||
|
{
|
|||
|
std::vector<TESTFUNC>::iterator it = std::find(test_.begin(), test_.end(), name);
|
|||
|
|
|||
|
return it != test_.end();
|
|||
|
}
|
|||
|
int test(const wchar_t* name, ui_helper* ui, const wchar_t* oper = L"start")
|
|||
|
{
|
|||
|
std::vector<TESTFUNC>::iterator it = std::find(test_.begin(), test_.end(), name);
|
|||
|
|
|||
|
if (it == test_.end())
|
|||
|
return ERROR_NOT_SUPPORTED;
|
|||
|
|
|||
|
return it->test_api(name, oper, ui);
|
|||
|
}
|
|||
|
};
|
|||
|
/////////////////////////*////////////////////////////////////////////////////////////////////////
|