diff --git a/cScripts/CfgFunctions.hpp b/cScripts/CfgFunctions.hpp index 5698b0056..18888c0ea 100644 --- a/cScripts/CfgFunctions.hpp +++ b/cScripts/CfgFunctions.hpp @@ -240,9 +240,4 @@ class cScripts { class log {}; class warning {}; }; - class testing { - file = "cScripts\functions\testing"; - class testing_loadoutArrays {}; - class testing_equipmentUsed {}; - }; }; diff --git a/cScripts/_TESTING_/fn_test_all.sqf b/cScripts/_TESTING_/fn_test_all.sqf new file mode 100644 index 000000000..27f92fa81 --- /dev/null +++ b/cScripts/_TESTING_/fn_test_all.sqf @@ -0,0 +1,4 @@ +#include "script_component.hpp"; +// 0 spawn compile preprocessFileLineNumbers '_TESTING_\fn_test_all.sqf' + +RUN_TEST(fn_test_equipment) \ No newline at end of file diff --git a/cScripts/_TESTING_/fn_test_equipment.sqf b/cScripts/_TESTING_/fn_test_equipment.sqf new file mode 100644 index 000000000..11add463e --- /dev/null +++ b/cScripts/_TESTING_/fn_test_equipment.sqf @@ -0,0 +1,13 @@ +TEST_INIT(Equipment) +#include "script_component.hpp"; + +private _database = [true] call cScripts_fnc_logistics_getAllContainerItems; + + +private _configLoadouts = configProperties [missionconfigfile >> "CfgLoadouts", "getNumber (_x >> 'scope') >= 1", true]; + +{ + private _class = configName _x; + lOG_1("Testing loadout %1", _class); + +} forEach _configLoadouts \ No newline at end of file diff --git a/cScripts/_TESTING_/script_component.hpp b/cScripts/_TESTING_/script_component.hpp new file mode 100644 index 000000000..b1640fae6 --- /dev/null +++ b/cScripts/_TESTING_/script_component.hpp @@ -0,0 +1,4 @@ +#define PREFIX cScripts Unit +#define COMPONENT UNDEFINED + +#include "script_macros.hpp" diff --git a/cScripts/_TESTING_/script_macros.hpp b/cScripts/_TESTING_/script_macros.hpp new file mode 100644 index 000000000..093581c3e --- /dev/null +++ b/cScripts/_TESTING_/script_macros.hpp @@ -0,0 +1,97 @@ +//#include "\x\cba addons\main\script_macros_common.hpp" +//#include "\x\cba\addons\main\script_macros_mission.hpp" + +#define QUOTE(var) #var +#define DOUBLES(var1,var2) ##var1##_##var2 +#define TRIPLES(var1,var2,var3) ##var1##_##var2##_##var3 + +#define ARR_1(ARG1) ARG1 +#define ARR_2(ARG1,ARG2) ARG1, ARG2 +#define ARR_3(ARG1,ARG2,ARG3) ARG1, ARG2, ARG3 +#define ARR_4(ARG1,ARG2,ARG3,ARG4) ARG1, ARG2, ARG3, ARG4 +#define ARR_5(ARG1,ARG2,ARG3,ARG4,ARG5) ARG1, ARG2, ARG3, ARG4, ARG5 +#define ARR_6(ARG1,ARG2,ARG3,ARG4,ARG5,ARG6) ARG1, ARG2, ARG3, ARG4, ARG5, ARG6 +#define ARR_7(ARG1,ARG2,ARG3,ARG4,ARG5,ARG6,ARG7) ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7 +#define ARR_8(ARG1,ARG2,ARG3,ARG4,ARG5,ARG6,ARG7,ARG8) ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7, ARG8 + +#define GVAR(var1) DOUBLES(PREFIX,var1) +#define EGVAR(var1,var2) TRIPLES(PREFIX,var1,var2) +#define QGVAR(var1) QUOTE(GVAR(var1)) +#define QEGVAR(var1,var2) QUOTE(EGVAR(var1,var2)) +#define QQGVAR(var1) QUOTE(QGVAR(var1)) +#define QQEGVAR(var1,var2) QUOTE(QEGVAR(var1,var2)) + +#define FUNC(var) TRIPLES(PREFIX,fnc,var) +#define EFUNC(var1,var2) FUNC(DOUBLES(var1,var2)) +#define QFUNC(var) QUOTE(FUNC(var)) +#define QEFUNC(var1,var2) QUOTE(EFUNC(var1,var2)) + +#define GETVAR_SYS(var1,var2) getVariable [ARR_2(QUOTE(var1),var2)] +#define SETVAR_SYS(var1,var2) setVariable [ARR_2(QUOTE(var1),var2)] +#define SETPVAR_SYS(var1,var2) setVariable [ARR_3(QUOTE(var1),var2,true)] + +#define GETVAR(var1,var2,var3) (var1 GETVAR_SYS(var2,var3)) +#define GETMVAR(var1,var2) (missionNamespace GETVAR_SYS(var1,var2)) +#define GETUVAR(var1,var2) (uiNamespace GETVAR_SYS(var1,var2)) +#define GETPRVAR(var1,var2) (profileNamespace GETVAR_SYS(var1,var2)) +#define GETPAVAR(var1,var2) (parsingNamespace GETVAR_SYS(var1,var2)) + +#define SETVAR(var1,var2,var3) var1 SETVAR_SYS(var2,var3) +#define SETPVAR(var1,var2,var3) var1 SETPVAR_SYS(var2,var3) +#define SETMVAR(var1,var2) missionNamespace SETVAR_SYS(var1,var2) +#define SETUVAR(var1,var2) uiNamespace SETVAR_SYS(var1,var2) +#define SETPRVAR(var1,var2) profileNamespace SETVAR_SYS(var1,var2) +#define SETPAVAR(var1,var2) parsingNamespace SETVAR_SYS(var1,var2) + +#define GETGVAR(var1,var2) GETMVAR(GVAR(var1),var2) +#define GETEGVAR(var1,var2,var3) GETMVAR(EGVAR(var1,var2),var3) + +#define FORMAT_1(STR,ARG1) format[STR, ARG1] +#define FORMAT_2(STR,ARG1,ARG2) format[STR, ARG1, ARG2] +#define FORMAT_3(STR,ARG1,ARG2,ARG3) format[STR, ARG1, ARG2, ARG3] +#define FORMAT_4(STR,ARG1,ARG2,ARG3,ARG4) format[STR, ARG1, ARG2, ARG3, ARG4] +#define FORMAT_5(STR,ARG1,ARG2,ARG3,ARG4,ARG5) format[STR, ARG1, ARG2, ARG3, ARG4, ARG5] +#define FORMAT_6(STR,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6) format[STR, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6] +#define FORMAT_7(STR,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6,ARG7) format[STR, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7] +#define FORMAT_8(STR,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6,ARG7,ARG8) format[STR, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7, ARG8] + +/* TESTING */ +#define TEST_INIT(NAME) \ + #define COMPONANT NAME\ + diag_log text "================================================"; \ + diag_log FORMAT_1("TESTING: %1", NAME); \ + diag_log text "================================================" + + +#define RUN_TEST(FILE) 0 spawn compile preprocessFileLineNumbers QUOTE(_TESTING_\FILE.sqf) + + +/* LOGGING */ +#define LOG_SYS_FORMAT(LEVEL,MESSAGE) format ['%1 (%2) %3: %4', PREFIX, COMPONENT, LEVEL, MESSAGE] +#define LOG_SYS(LEVEL,MESSAGE) diag_log text LOG_SYS_FORMAT(LEVEL, MESSAGE) + +/* DEBUG LOG LOGGING */ +#ifdef DEBUG_MODE +#define LOG(MESSAGE) LOG_SYS('LOG', MESSAGE) +#define LOG_1(MESSAGE,ARG1) LOG(FORMAT_1(MESSAGE,ARG1)) +#define LOG_2(MESSAGE,ARG1,ARG2) LOG(FORMAT_2(MESSAGE,ARG1,ARG2)) +#define LOG_3(MESSAGE,ARG1,ARG2,ARG3) LOG(FORMAT_3(MESSAGE,ARG1,ARG2,ARG3)) +#define LOG_4(MESSAGE,ARG1,ARG2,ARG3,ARG4) LOG(FORMAT_4(MESSAGE,ARG1,ARG2,ARG3,ARG4)) +#define LOG_5(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5) LOG(FORMAT_5(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5)) +#define LOG_6(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6) LOG(FORMAT_6(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6)) +#define LOG_7(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6,ARG7) LOG(FORMAT_7(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6,ARG7)) +#define LOG_8(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6,ARG7,ARG8) LOG(FORMAT_8(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6,ARG7,ARG8)) + +#else + +#define LOG(MESSAGE) /* disabled */ +#define LOG_1(MESSAGE,ARG1) /* disabled */ +#define LOG_2(MESSAGE,ARG1,ARG2) /* disabled */ +#define LOG_3(MESSAGE,ARG1,ARG2,ARG3) /* disabled */ +#define LOG_4(MESSAGE,ARG1,ARG2,ARG3,ARG4) /* disabled */ +#define LOG_5(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5) /* disabled */ +#define LOG_6(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6) /* disabled */ +#define LOG_7(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6,ARG7) /* disabled */ +#define LOG_8(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6,ARG7,ARG8) /* disabled */ + +#endif diff --git a/cScripts/functions/testing/fn_testing_equipmentUsed.sqf b/cScripts/functions/testing/fn_testing_equipmentUsed.sqf deleted file mode 100644 index 39bb3ef8d..000000000 --- a/cScripts/functions/testing/fn_testing_equipmentUsed.sqf +++ /dev/null @@ -1,60 +0,0 @@ -#include "..\script_component.hpp" -/* - * Author: CPL.Brostrom.A - * This function test all loadout arrays - * - * Arguments: - * - * Return Value: - * True or False - * - * Example: - * call cScripts_fnc_testing_loadoutArrays - * 0 spawn compile preprocessFileLineNumbers 'cScripts\functions\testing\fn_testing_equipmentUsed.sqf' - * - */ - -diag_log text ""; -diag_log text "###############################################################################################################"; -diag_log text ""; -["STARTING UNIT TEST FOR LOADOUT ARRAYS", "INFO", true, false, "TESTING"] call FUNC(log); -["There should be no script errors when this function runs.", "INFO", true, false, "TESTING"] call FUNC(log); - -diag_log text ""; -diag_log text "###############################################################################################################"; -diag_log text ""; - -private _return = true; - -private _database = GVAR(DATABASE); - -private _faultyEquipment = []; - -["TESTING KEYS FROM DATABASE", "INFO", true, false, "TESTING"] call FUNC(log); -{ - //[format ["TESTING KEY '%1'", _x], "INFO", true, false, "TESTING"] call FUNC(log); - { - _x params ["_item"]; - //[format ["TESTING ITEM '%1'", _item], "INFO", false, false, "TESTING"] call FUNC(log);; - private _cfgMagazines = getText (configFile >> 'CfgMagazines' >> _item >> 'displayName'); - private _cfgWeapons = getText (configFile >> 'CfgWeapons' >> _item >> 'displayName'); - private _cfgVehicles = getText (configFile >> 'CfgVehicles' >> _item >> 'displayName'); - if (_cfgMagazines == "" && _cfgWeapons == "" && _cfgVehicles == "") then { - [format ["FAILED: '%1' does not exist in CfgMagazines, CfgWeapons or CfgVehicles.", _item], "INFO", true, false, "TESTING"] call FUNC(log); - _return = false - }; - } forEach _y; -} forEach _database; - -if (_return) then { - ["TEST SUCCESSFUL", "INFO", true, false, "TESTING"] call FUNC(log); -} else { - ["TEST FAILED", "INFO", true, false, "TESTING"] call FUNC(log); -}; - -["TEST COMPLETED", "INFO", true, false, "TESTING"] call FUNC(log); -diag_log text ""; -diag_log text "###############################################################################################################"; -diag_log text ""; - -_return; diff --git a/cScripts/functions/testing/fn_testing_loadoutArrays.sqf b/cScripts/functions/testing/fn_testing_loadoutArrays.sqf deleted file mode 100644 index 630ebdb98..000000000 --- a/cScripts/functions/testing/fn_testing_loadoutArrays.sqf +++ /dev/null @@ -1,145 +0,0 @@ -#include "..\script_component.hpp" -/* - * Author: CPL.Brostrom.A - * This function test all loadout arrays - * - * Arguments: - * - * Return Value: - * True or False - * - * Example: - * call cScripts_fnc_testing_loadoutArrays - * 0 spawn compile preprocessFileLineNumbers 'cScripts\functions\testing\fn_testing_loadoutArrays.sqf' - * - */ - -diag_log text ""; -diag_log text "###############################################################################################################"; -diag_log text ""; -["STARTING UNIT TEST FOR LOADOUT ARRAYS", "INFO", true, false, "TESTING"] call FUNC(log); -["There should be no script errors when this function runs.", "INFO", true, false, "TESTING"] call FUNC(log); - -diag_log text ""; -diag_log text "###############################################################################################################"; -diag_log text ""; - - -private _return = true; - -private _classnameList = configProperties [missionconfigfile >> "CfgLoadouts", "getNumber (_x >> 'scope') >= 2", true]; -{ - private _class = configName _x; - [format["Testing loadout %1", _class], "TEST START", false, false, "TESTING"] call FUNC(log); - - // Obtain loadout - ["Obtaining loadout array if there are a error in between here something is wrong...", "TEST", false, false, "TESTING"] call FUNC(log); - ["... Loadout array parse ...", "TEST", false, false, "TESTING"] call FUNC(log); - private _loadout = getText (missionConfigFile >> 'CfgLoadouts' >> _class >> "loadout"); - _loadout = parseSimpleArray _loadout; - ["... Loadout array parse ...", "TEST", false, false, "TESTING"] call FUNC(log); - - // Testing array size - ["Testing array size it should be 1", "TEST", false, false, "TESTING"] call FUNC(log); - private _arraySize = count [_loadout]; - if (_arraySize == 1) then { - [format["SUCCESS: Array size of loadout %1 size is %2", _class, _arraySize], "SUCCESS", false, false, "TESTING"] call FUNC(log); - } else { - [format["FAILED: Array size of loadout %1 size is %2", _class, _arraySize], "FAILED", true, false, "TESTING"] call FUNC(log); - _return = false; - }; - - // Testing loadout array structure - ["Testing loadout array structure", "TEST", false, false, "TESTING"] call FUNC(log); - switch (_forEachIndex) do { - private _element = _x; - case 0: { - if (!_element isEqualType []) then { - [format["FAILED: Loadout %1 Primary Weapon is not a array got %2", _class, _element], "FAILED", true, false, "TESTING"] call FUNC(log); - _return = false; - }; - }; - case 1: { - if (_element isEqualType []) then { - [format["FAILED: Loadout %1 Secondary Weapon is not a array got %2", _class, _element], "FAILED", true, false, "TESTING"] call FUNC(log); - _return = false; - }; - }; - case 2: { - if (_element isEqualType []) then { - [format["FAILED: Loadout %1 Handgun Weapon is not a array got %2", _class, _element], "FAILED", true, false, "TESTING"] call FUNC(log); - _return = false; - }; - }; - case 3: { - if (_element isEqualType []) then { - [format["FAILED: Loadout %1 Uniform is not a array got %2", _class, typeName _element], "FAILED", true, false, "TESTING"] call FUNC(log); - _return = false; - }; - }; - case 4: { - if (_element isEqualType []) then { - [format["FAILED: Loadout %1 Vest is not a array got %2", _class, typeName _element], "FAILED", true, false, "TESTING"] call FUNC(log); - _return = false; - }; - case 5: { - if (_element isEqualType []) then { - [format["FAILED: Loadout %1 Backpack is not a array got %2", _class, typeName _element], "FAILED", true, false, "TESTING"] call FUNC(log); - _return = false; - }; - }; - case 6: { - if (_element isEqualType "") then { - [format["FAILED: Loadout %1 Headgear is not a string got %1", _class, typeName _element], "FAILED", true, false, "TESTING"] call FUNC(log); - _return = false; - }; - }; - case 7: { - if (typeName _element != "") then { - [format["FAILED: Loadout %1 Goggles/Facewear is not a string got %1", _class, typeName _element], "FAILED", true, false, "TESTING"] call FUNC(log); - _return = false; - }; - }; - case 8: { - if (_element isEqualType []) then { - [format["FAILED: Loadout %1 Binoculars is not a array got %2", _class, typeName _element], "FAILED", true, false, "TESTING"] call FUNC(log); - _return = false; - }; - }; - case 9: { - if (_element isEqualType []) then { - [format["FAILED: Loadout %1 Assigned Items is not a array got %2", _class, typeName _element], "FAILED", true, false, "TESTING"] call FUNC(log); - _return = false; - }; - if (count _element != 6) then { - [format["FAILED: Loadout %1 Assigned Items size array is wrong expected 6 got %2", _class, count _element], "FAILED", true, false, "TESTING"] call FUNC(log); - _return = false; - }; - { - if (_element isEqualType "") then { - [format["FAILED: Loadout %1 Assigned Items expected item in string got %2", _class, typeName _x], "FAILED", true, false, "TESTING"] call FUNC(log); - _return = false; - } - } forEach _element; - }; - }; - } forEach _loadout; - - - [format["Testing loadout %1", _class], "TEST END", false, false, "TESTING"] call FUNC(log); - diag_log text ""; - -} forEach _classnameList; - - -if (_return) then { - ["TEST SUCCESSFUL", "INFO", true, false, "TESTING"] call FUNC(log); -} else { - ["TEST FAILED", "INFO", true, false, "TESTING"] call FUNC(log); -}; -["TEST COMPLETED", "INFO", true, false, "TESTING"] call FUNC(log); -diag_log text ""; -diag_log text "###############################################################################################################"; -diag_log text ""; - -_return; diff --git a/tools/config.json b/tools/config.json index fc900313e..a3d658067 100644 --- a/tools/config.json +++ b/tools/config.json @@ -2,6 +2,6 @@ "build" : { "scriptName": "cScripts", "version": "DevBuild", - "notlist": ["doc", "tools", "release", "resourses", "Compositions", "mission.sqm"] + "notlist": ["_TESTING_", "doc", "tools", "release", "resourses", "Compositions", "mission.sqm"] } }