function print_r(arr, level) {
    var print_red_text = "";
    if(!level) level = 0;
    var level_padding = "";
    for(var j=0; j<level+1; j++) level_padding += "    ";
    if(typeof(arr) == 'object') {
        for(var item in arr) {
            var value = arr[item];
            if(typeof(value) == 'object') {
                print_red_text += level_padding + "'" + item + "' :\n";
                print_red_text += print_r(value,level+1);
		} 
            else 
                print_red_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
        }
    } 

    else  print_red_text = "===>"+arr+"<===("+typeof(arr)+")";
    return print_red_text;
}

inc("../SQLite.js");

setTimeout(function (){
	
	//get_VEN
	echo('get_VEN');
	test(get_VEN('123123123123'),false);
	test(get_VEN('ACPI\\DLL054A'),false);
	test(get_VEN('NMWCD\\VID_0421&PID_0103&IF_LC'),false);
	test(get_VEN('PCI\\VEN_10DE&DEV_1234'),'10DE');
	test(get_VEN('PCI\\VEN_1002&DEV_95C5&SUBSYS_3003148C'),'1002');
	test(get_VEN('USB\\VID_0438&PID_AC14'),'0438');
	test(get_VEN('USB\\VID_0FCE&PID_D087&MI_03&OS_NT'),'0FCE');
	test(get_VEN('HDAUDIO\\FUNC_01&VEN_10DE&DEV_0003&SUBSYS_10DE0101'),'10DE');
	
	
	//get_DEV
	echo('get_DEV');
	test(get_DEV('123123123123'),false);
	test(get_DEV('ACPI\\DLL054A'),false);
	test(get_DEV('NMWCD\\VID_0421&PID_0103&IF_LC'),false);
	test(get_DEV('PCI\\VEN_10DE&DEV_1234'),'1234');
	test(get_DEV('PCI\\VEN_1002&DEV_95C5&SUBSYS_3003148C'),'95C5');
	test(get_DEV('USB\\VID_0438&PID_AC14'),'AC14');
	test(get_DEV('USB\\VID_0FCE&PID_D087&MI_03&OS_NT'),'D087');
	test(get_DEV('HDAUDIO\\FUNC_01&VEN_10DE&DEV_0003&SUBSYS_10DE0101'),'0003');
	
	//get_Other
	echo('get_Other');
	test(get_Other('123123123123'),'123123123123');
	test(get_Other('ACPI\\DLL054A'),'ACPI\\DLL054A');
	test(get_Other('NMWCD\\VID_0421&PID_0103&IF_LC'),'NMWCD\\VID_0421&PID_0103&IF_LC');
	test(get_Other('PCI\\VEN_10DE&DEV_1234'),false);
	test(get_Other('PCI\\VEN_1002&DEV_95C5&SUBSYS_3003148C'),'&SUBSYS_3003148C');
	test(get_Other('USB\\VID_0438&PID_AC14'),false);
	test(get_Other('USB\\VID_0FCE&PID_D087&MI_03&OS_NT'),'&MI_03&OS_NT');
	test(get_Other('HDAUDIO\\FUNC_01&VEN_10DE&DEV_0003&SUBSYS_10DE0101'),'&SUBSYS_10DE0101');
	
	
	//devidToHEX
	echo('devidToHEX');
	test(devidToHEX('4318'),'10DE');
	test(devidToHEX('4098'),'1002');
	test(devidToHEX('53383'),'D087');
	test(devidToDEC('false'),'');
	test(devidToDEC(false),'');
	
	//devidToDEC
	echo('devidToDEC');
	test(devidToDEC('10DE'),'4318');
	test(devidToDEC('1002'),'4098');
	test(devidToDEC('D087'),'53383');
	test(devidToDEC('false'),'');
	test(devidToDEC(false),'');
	
	
	//get_devtype
	echo('get_devtype');
	test(get_devtype('123123123123'),'OTH');
	test(get_devtype('ACPI\\DLL054A'),'OTH');
	test(get_devtype('NMWCD\\VID_0421&PID_0103&IF_LC'),'OTH');
	test(get_devtype('PCI\\VEN_10DE&DEV_1234'),'PCI');
	test(get_devtype('PCI\\VEN_1002&DEV_95C5&SUBSYS_3003148C'),'PCI');
	test(get_devtype('USB\\VID_0438&PID_AC14'),'USB');
	test(get_devtype('USB\\VID_0FCE&PID_D087&MI_03&OS_NT'),'USB');
	test(get_devtype('HDAUDIO\\FUNC_01&VEN_10DE&DEV_0003&SUBSYS_10DE0101'),'HDA');
	
	
	//sql_devid
	echo('sql_devid');
	devid = [];
	devid[0] = 'HDAUDIO\\FUNC_01&VEN_2003&DEV_5678&SUBSYS_00000000&REV_0000';
	devid[1] = 'PCI\\VEN_8086&DEV_27D8';
	test(sql_devid(devid),"SELECT * FROM device WHERE (device_type = 'HDA' AND VEN = '8195' AND DEV = '22136' AND Other = '&SUBSYS_00000000&REV_0000') OR (device_type = 'PCI' AND VEN = '32902' AND DEV = '10200' AND Other = '');");
	test(sql_devid('USB\\VID_0438&PID_AC14'),"SELECT * FROM device WHERE (device_type = 'USB' AND VEN = '1080' AND DEV = '44052' AND Other = '');");
	
	
	//devidBuild
	echo('devidBuild');
	test(devidBuild('4318','53383','','PCI'),'PCI\\VEN_10DE&DEV_D087');
	test(devidBuild('4318','53383','','USB'),'USB\\VID_10DE&PID_D087');
	test(devidBuild('4318','53383','','HDA'),'HDAUDIO\\VEN_10DE&DEV_D087');
	test(devidBuild('','','ACPI\\DLL054A','OTH'),'ACPI\\DLL054A');
	
	//sql_query
	//echo('Test sql_query:');
	//echo(print_r(sql_query('select * from driverpacks;'))); //Ошибка возникает из-за разницы в относительных путях

	
	
	
},1000);
