diff --git a/addons/arrays/test_filter.sqf b/addons/arrays/test_filter.sqf index 18d22d787..c9cf003bf 100644 --- a/addons/arrays/test_filter.sqf +++ b/addons/arrays/test_filter.sqf @@ -9,45 +9,45 @@ SCRIPT(test_filter); private ["_original", "_expected", "_result", "_fn"]; _fn = "CBA_fnc_filter"; -ASSERT_DEFINED("CBA_fnc_filter",""); - LOG("Testing " + _fn); +TEST_DEFINED("CBA_fnc_filter",""); + // Filter to new array. _original = []; _result = [[], { _x * 10 }] call CBA_fnc_filter; _expected = []; -ASSERT_OP(str _result,==,str _expected,_fn); -ASSERT_OP(str _original,==,str _expected,_fn); +TEST_OP(str _result,==,str _expected,_fn); +TEST_OP(str _original,==,str _expected,_fn); _original = [1, 2, 3]; _result = [_original, { _x + 1 }] call CBA_fnc_filter; _expected = [2, 3, 4]; -ASSERT_OP(str _result,==,str _expected,_fn); -ASSERT_OP(str _original,!=,str _expected,_fn); +TEST_OP(str _result,==,str _expected,_fn); +TEST_OP(str _original,!=,str _expected,_fn); _original = [1, 2, 3]; _result = [_original, { _x }, false] call CBA_fnc_filter; _expected = [1, 2, 3]; -ASSERT_OP(str _result,==,str _expected,_fn); +TEST_OP(str _result,==,str _expected,_fn); // Filter in place. _original = []; _result = [_original, { _x * 10 }, true] call CBA_fnc_filter; _expected = []; -ASSERT_OP(str _original,==,str _expected,_fn); -ASSERT_OP(str _result,==,str _expected,_fn); +TEST_OP(str _original,==,str _expected,_fn); +TEST_OP(str _result,==,str _expected,_fn); _original = [1, 2, 3]; _result = [_original, { _x + 1 }, true] call CBA_fnc_filter; _expected = [2, 3, 4]; -ASSERT_OP(str _original,==,str _expected,_fn); -ASSERT_OP(str _result,==,str _expected,_fn); +TEST_OP(str _original,==,str _expected,_fn); +TEST_OP(str _result,==,str _expected,_fn); _original = [1, 2, 3]; _result = [_original, { _x }, true] call CBA_fnc_filter; _expected = [1, 2, 3]; -ASSERT_OP(str _original,==,str _expected,_fn); -ASSERT_OP(str _result,==,str _expected,_fn); +TEST_OP(str _original,==,str _expected,_fn); +TEST_OP(str _result,==,str _expected,_fn); nil; diff --git a/addons/arrays/test_inject.sqf b/addons/arrays/test_inject.sqf index f83b2ac6e..052f66643 100644 --- a/addons/arrays/test_inject.sqf +++ b/addons/arrays/test_inject.sqf @@ -9,24 +9,24 @@ SCRIPT(test_inject); private ["_expected", "_result", "_fn"]; _fn = "CBA_fnc_inject"; -ASSERT_DEFINED("CBA_fnc_inject",""); - LOG("Testing " + _fn); +TEST_DEFINED("CBA_fnc_inject",""); + _result = [[], "", { _accumulator + (str _x) }] call CBA_fnc_inject; _expected = ""; -ASSERT_OP(_result,==,_expected,_fn); +TEST_OP(_result,==,_expected,_fn); _result = [[1, 2, 3], "", { _accumulator + (str _x) }] call CBA_fnc_inject; _expected = "123"; -ASSERT_OP(_result,==,_expected,_fn); +TEST_OP(_result,==,_expected,_fn); _result = [[1, 2, 3], " frogs", { (str _x) + _accumulator }] call CBA_fnc_inject; _expected = "321 frogs"; -ASSERT_OP(_result,==,_expected,_fn); +TEST_OP(_result,==,_expected,_fn); _result = [[1, 2, 3], 0, { _accumulator + _x }] call CBA_fnc_inject; _expected = 6; -ASSERT_OP(_result,==,_expected,_fn); +TEST_OP(_result,==,_expected,_fn); nil; diff --git a/addons/arrays/test_join.sqf b/addons/arrays/test_join.sqf index c524b72ee..219533d2d 100644 --- a/addons/arrays/test_join.sqf +++ b/addons/arrays/test_join.sqf @@ -9,32 +9,32 @@ SCRIPT(test_join); private ["_expected", "_result", "_fn"]; _fn = "CBA_fnc_join"; -ASSERT_DEFINED("CBA_fnc_join",""); - LOG("Testing " + _fn); +TEST_DEFINED("CBA_fnc_join",""); + _result = [[], "x"] call CBA_fnc_join; _expected = ""; -ASSERT_OP(_result,==,_expected,_fn); +TEST_OP(_result,==,_expected,_fn); _result = [[""], "x"] call CBA_fnc_join; _expected = ""; -ASSERT_OP(_result,==,_expected,_fn); +TEST_OP(_result,==,_expected,_fn); _result = [["frog"], "x"] call CBA_fnc_join; _expected = "frog"; -ASSERT_OP(_result,==,_expected,_fn); +TEST_OP(_result,==,_expected,_fn); _result = [["", ""], "x"] call CBA_fnc_join; _expected = "x"; -ASSERT_OP(_result,==,_expected,_fn); +TEST_OP(_result,==,_expected,_fn); _result = [["a","b","c"], "x"] call CBA_fnc_join; _expected = "axbxc"; -ASSERT_OP(_result,==,_expected,_fn); +TEST_OP(_result,==,_expected,_fn); _result = [["a",1,[objNull]], "x^x"] call CBA_fnc_join; _expected = "ax^x1x^x[]"; -ASSERT_OP(_result,==,_expected,_fn); +TEST_OP(_result,==,_expected,_fn); nil; diff --git a/addons/arrays/test_shuffle.sqf b/addons/arrays/test_shuffle.sqf index 62300830d..5e9f74007 100644 --- a/addons/arrays/test_shuffle.sqf +++ b/addons/arrays/test_shuffle.sqf @@ -9,30 +9,30 @@ SCRIPT(test_shuffle); private ["_expected", "_result", "_fn"]; _fn = "CBA_fnc_shuffle"; -ASSERT_DEFINED("CBA_fnc_shuffle",""); - LOG("Testing " + _fn); +TEST_DEFINED("CBA_fnc_shuffle",""); + _original = [1, 2, 3]; _result = [_original] call CBA_fnc_shuffle; -ASSERT_OP(count _result,==,count _original,_fn); +TEST_OP(count _result,==,count _original,_fn); { - ASSERT_OP(_x,in,_original,_fn); + TEST_OP(_x,in,_original,_fn); } forEach _result; // Test depecated version. _original = [1, 2, 3]; _result = _original call CBA_fnc_shuffle; -ASSERT_OP(count _result,==,count _original,_fn); +TEST_OP(count _result,==,count _original,_fn); { - ASSERT_OP(_x,in,_original,_fn); + TEST_OP(_x,in,_original,_fn); } forEach _result; // Test depecated version. _original = []; _result = _original call CBA_fnc_shuffle; -ASSERT_OP(count _result,==,count _original,_fn); +TEST_OP(count _result,==,count _original,_fn); nil; diff --git a/addons/common/test.sqf b/addons/common/test.sqf index 93821f0cd..edaedeefe 100644 --- a/addons/common/test.sqf +++ b/addons/common/test.sqf @@ -2,7 +2,7 @@ // Automatically generated by 'functions_config.rb' // DO NOT MANUALLY EDIT THIS FILE! // ----------------------------------------------------------------------------- - +#define DEBUG_MODE_FULL #include "script_component.hpp" #define TESTS ["inheritsFrom", "parseYaml"] diff --git a/addons/common/test_inheritsFrom.sqf b/addons/common/test_inheritsFrom.sqf index 920046d3d..09f25bef6 100644 --- a/addons/common/test_inheritsFrom.sqf +++ b/addons/common/test_inheritsFrom.sqf @@ -9,10 +9,10 @@ SCRIPT(test_inheritsFrom); private ["_class", "_base", "_expected", "_result", "_fn", "_game", "_clssname"]; _fn = "CBA_fnc_inheritsFrom"; -ASSERT_DEFINED("CBA_fnc_inheritsFrom",""); - LOG("Testing " + _fn); +TEST_DEFINED("CBA_fnc_inheritsFrom",""); + /* Game as integer from SLX_XEH_MACHINE 0 = Arma2 @@ -23,8 +23,8 @@ Game as integer from SLX_XEH_MACHINE _game = SLX_XEH_MACHINE select 14; if (_game > 3) then { - LOG ("FIXME! - Unknown game " + (SLX_XEH_MACHINE select 15) + ". All assert tests will fail! " + _fn); //Sanity check and reminder - Diag_log ("FIXME! - Unknown game " + (SLX_XEH_MACHINE select 15) + ". All assert tests will fail! " + _fn); + LOG ("FIXME! - Unknown game " + (SLX_XEH_MACHINE select 15) + ". All TEST tests will fail! " + _fn); //Sanity check and reminder + Diag_log ("FIXME! - Unknown game " + (SLX_XEH_MACHINE select 15) + ". All TEST tests will fail! " + _fn); }; if (_game < 2) then { @@ -40,16 +40,16 @@ if (_game < 2) then { _class = configFile >> "CfgWeapons" >> _clssname; _base = configFile >> "CfgWeapons" >> "RifleCore"; _result = [_class, _base] call CBA_fnc_inheritsFrom; -ASSERT_TRUE(_result,_fn); +TEST_TRUE(_result,_fn); _class = configFile >> "CfgWeapons" >> "RifleCore"; _base = configFile >> "CfgWeapons" >> _clssname; _result = [_class, _base] call CBA_fnc_inheritsFrom; -ASSERT_FALSE(_result,_fn); +TEST_FALSE(_result,_fn); _class = configFile >> "CfgWeapons" >> _clssname; _base = configFile >> "CfgWeapons" >> "PistolCore"; _result = [_class, _base] call CBA_fnc_inheritsFrom; -ASSERT_FALSE(_result,_fn); +TEST_FALSE(_result,_fn); nil; diff --git a/addons/common/test_parseYaml.sqf b/addons/common/test_parseYaml.sqf index 3b884c084..0292c85b1 100644 --- a/addons/common/test_parseYaml.sqf +++ b/addons/common/test_parseYaml.sqf @@ -9,24 +9,24 @@ SCRIPT(test_parseYaml); private ["_expected", "_result", "_fn", "_data"]; _fn = "CBA_fnc_parseYaml"; -ASSERT_DEFINED("CBA_fnc_parseYaml",_fn); - LOG("Testing " + _fn); +TEST_DEFINED("CBA_fnc_parseYaml",_fn); + _data = ["\x\cba\addons\common\test_parseYaml_config.yml"] call CBA_fnc_parseYaml; -ASSERT_TRUE([_data] call CBA_fnc_isHash,_fn); +TEST_TRUE([_data] call CBA_fnc_isHash,_fn); _result = [_data, "anotherNumber"] call CBA_fnc_hashGet; _expected = "42"; -ASSERT_OP(_result,==,_expected,_fn); +TEST_OP(_result,==,_expected,_fn); _result = ([_data, "nestedArray"] call CBA_fnc_hashGet) select 0; _expected = "first"; -ASSERT_OP(_result,==,_expected,_fn); +TEST_OP(_result,==,_expected,_fn); _result = (([_data, "nestedArray"] call CBA_fnc_hashGet) select 2) select 1; _expected = "3.2"; -ASSERT_OP(_result,==,_expected,_fn); +TEST_OP(_result,==,_expected,_fn); nil; diff --git a/addons/diagnostic/test.sqf b/addons/diagnostic/test.sqf index 7ef6fcde2..ca4bdbcea 100644 --- a/addons/diagnostic/test.sqf +++ b/addons/diagnostic/test.sqf @@ -2,7 +2,7 @@ // Automatically generated by 'functions_config.rb' // DO NOT MANUALLY EDIT THIS FILE! // ----------------------------------------------------------------------------- - +#define DEBUG_MODE_FULL #include "script_component.hpp" #define TESTS ["assertions", "parameters"] diff --git a/addons/diagnostic/test_parameters.sqf b/addons/diagnostic/test_parameters.sqf index ec9414c7d..b700e9a9b 100644 --- a/addons/diagnostic/test_parameters.sqf +++ b/addons/diagnostic/test_parameters.sqf @@ -8,33 +8,33 @@ SCRIPT(test_parameters); LOG("Testing parameters"); -private ["_expected"]; +private ["_expected","_result","_this"]; // Test default params. _this = [5]; DEFAULT_PARAM(0,_result,12); _expected = 5; -ASSERT_OP(_result,==,_expected,"DEFAULT_PARAM"); +TEST_OP(_result,==,_expected,"DEFAULT_PARAM"); _result = nil; _this = []; DEFAULT_PARAM(0,_result,12); _expected = 12; -ASSERT_OP(_result,==,_expected,"DEFAULT_PARAM"); +TEST_OP(_result,==,_expected,"DEFAULT_PARAM"); _result = nil; _this = [nil]; DEFAULT_PARAM(0,_result,12); _expected = 12; -ASSERT_OP(_result,==,_expected,"DEFAULT_PARAM"); +TEST_OP(_result,==,_expected,"DEFAULT_PARAM"); _result = nil; _this = nil; DEFAULT_PARAM(0,_result,12); _expected = 12; -ASSERT_OP(_result,==,_expected,"DEFAULT_PARAM"); +TEST_OP(_result,==,_expected,"DEFAULT_PARAM"); nil; diff --git a/addons/hashes/test_hashEachPair.sqf b/addons/hashes/test_hashEachPair.sqf index f82a7122e..0f8624b09 100644 --- a/addons/hashes/test_hashEachPair.sqf +++ b/addons/hashes/test_hashEachPair.sqf @@ -11,9 +11,7 @@ private ["_hash", "_expected", "_sumKeys", "_sumValues", "_totalIterations"]; _fn = "CBA_fnc_hashEachPair"; LOG("Testing " + _fn); -ASSERT_DEFINED("CBA_fnc_hashEachPair",""); - -Diag_log [diag_frameNo, diag_tickTime, time, ("Testing " + _fn)]; +TEST_DEFINED("CBA_fnc_hashEachPair",""); _hash = [[[1, 12], [5, 25]], 88] call CBA_fnc_hashCreate; @@ -29,10 +27,10 @@ _totalIterations = 0; }] call CBA_fnc_hashEachPair; _expected = 6; -ASSERT_OP(_sumKeys,==,_expected,""); +TEST_OP(_sumKeys,==,_expected,""); _expected = 37; -ASSERT_OP(_sumValues,==,_expected,""); +TEST_OP(_sumValues,==,_expected,""); _expected = 2; -ASSERT_OP(_totalIterations,==,_expected,""); +TEST_OP(_totalIterations,==,_expected,""); diff --git a/addons/hashes/test_hashes.sqf b/addons/hashes/test_hashes.sqf index ea5d00b56..bb9c6e4ea 100644 --- a/addons/hashes/test_hashes.sqf +++ b/addons/hashes/test_hashes.sqf @@ -11,74 +11,74 @@ private ["_hash", "_expected", "_result"]; LOG("Testing Hashes"); // UNIT TESTS (initStrings.sqf - stringJoin) -ASSERT_DEFINED("CBA_fnc_hashCreate",""); -ASSERT_DEFINED("CBA_fnc_hashGet",""); -ASSERT_DEFINED("CBA_fnc_hashSet",""); -ASSERT_DEFINED("CBA_fnc_hashHasKey",""); -ASSERT_DEFINED("CBA_fnc_isHash",""); +TEST_DEFINED("CBA_fnc_hashCreate",""); +TEST_DEFINED("CBA_fnc_hashGet",""); +TEST_DEFINED("CBA_fnc_hashSet",""); +TEST_DEFINED("CBA_fnc_hashHasKey",""); +TEST_DEFINED("CBA_fnc_isHash",""); -ASSERT_FALSE([[]] call CBA_fnc_isHash,"CBA_fnc_isHash"); +TEST_FALSE([[]] call CBA_fnc_isHash,"CBA_fnc_isHash"); _hash = [5, [4], [1], 2]; // Not a real hash. -ASSERT_FALSE([_hash] call CBA_fnc_isHash,"CBA_fnc_isHash"); -ASSERT_FALSE([5] call CBA_fnc_isHash,"CBA_fnc_isHash"); +TEST_FALSE([_hash] call CBA_fnc_isHash,"CBA_fnc_isHash"); +TEST_FALSE([5] call CBA_fnc_isHash,"CBA_fnc_isHash"); // Putting in and retrieving values. _hash = [] call CBA_fnc_hashCreate; -ASSERT_DEFINED("_hash","hashSet/Get"); -ASSERT_TRUE([_hash] call CBA_fnc_isHash,"CBA_fnc_isHash"); +TEST_DEFINED("_hash","hashSet/Get"); +TEST_TRUE([_hash] call CBA_fnc_isHash,"CBA_fnc_isHash"); _result = [_hash, "frog"] call CBA_fnc_hashHasKey; -ASSERT_FALSE(_result,"hashHashKey"); +TEST_FALSE(_result,"hashHashKey"); [_hash, "frog", 12] call CBA_fnc_hashSet; -ASSERT_TRUE([_hash] call CBA_fnc_isHash,"CBA_fnc_isHash"); +TEST_TRUE([_hash] call CBA_fnc_isHash,"CBA_fnc_isHash"); _result = [_hash, "frog"] call CBA_fnc_hashGet; -ASSERT_OP(_result,==,12,"hashSet/Get"); +TEST_OP(_result,==,12,"hashSet/Get"); _result = [_hash, "frog"] call CBA_fnc_hashHasKey; -ASSERT_TRUE(_result,"hashHashKey"); +TEST_TRUE(_result,"hashHashKey"); _result = [_hash, "fish"] call CBA_fnc_hashHasKey; -ASSERT_FALSE(_result,"hashHashKey"); +TEST_FALSE(_result,"hashHashKey"); // Unsetting a value [_hash, "frog", nil] call CBA_fnc_hashSet; _result = [_hash, "frog"] call CBA_fnc_hashGet; -ASSERT_TRUE(isNil "_result","hashSet/Get"); +TEST_TRUE(isNil "_result","hashSet/Get"); // Value never put in is nil. _result = [_hash, "fish"] call CBA_fnc_hashGet; -ASSERT_TRUE(isNil "_result","hashSet/Get"); +TEST_TRUE(isNil "_result","hashSet/Get"); // Reading in from array _hash = [[["fish", 7], ["frog", 99]]] call CBA_fnc_hashCreate; -ASSERT_TRUE([_hash] call CBA_fnc_isHash,"CBA_fnc_isHash"); +TEST_TRUE([_hash] call CBA_fnc_isHash,"CBA_fnc_isHash"); _result = [_hash, "frog"] call CBA_fnc_hashGet; -ASSERT_DEFINED("_result","hashSet/Get"); -ASSERT_OP(_result,==,99,"hashSet/Get"); +TEST_DEFINED("_result","hashSet/Get"); +TEST_OP(_result,==,99,"hashSet/Get"); // Alternative defaults. _hash = [[["frog", -8]], 0] call CBA_fnc_hashCreate; -ASSERT_TRUE([_hash] call CBA_fnc_isHash,"CBA_fnc_isHash"); +TEST_TRUE([_hash] call CBA_fnc_isHash,"CBA_fnc_isHash"); _result = [_hash, "frog"] call CBA_fnc_hashGet; -ASSERT_DEFINED("_result","hashSet/Get"); -ASSERT_OP(_result,==,-8,"hashSet/Get"); +TEST_DEFINED("_result","hashSet/Get"); +TEST_OP(_result,==,-8,"hashSet/Get"); _result = [_hash, "fish"] call CBA_fnc_hashGet; -ASSERT_DEFINED("_result","hashSet/Get"); -ASSERT_OP(_result,==,0,"hashSet/Get"); +TEST_DEFINED("_result","hashSet/Get"); +TEST_OP(_result,==,0,"hashSet/Get"); [_hash, "frog", 1] call CBA_fnc_hashSet; _result = [_hash, "frog"] call CBA_fnc_hashGet; -ASSERT_DEFINED("_result","hashSet/Get"); -ASSERT_OP(_result,==,1,"hashSet/Get"); +TEST_DEFINED("_result","hashSet/Get"); +TEST_OP(_result,==,1,"hashSet/Get"); [_hash, "frog", nil] call CBA_fnc_hashSet; _result = [_hash, "frog"] call CBA_fnc_hashGet; -ASSERT_TRUE(isNil "_result","hashSet/Get"); +TEST_TRUE(isNil "_result","hashSet/Get"); nil; diff --git a/addons/main/script_macros_common.hpp b/addons/main/script_macros_common.hpp index 384cd7c14..3a9ed10b8 100644 --- a/addons/main/script_macros_common.hpp +++ b/addons/main/script_macros_common.hpp @@ -232,6 +232,25 @@ Macro: ERROR_WITH_TITLE() #define ERROR_WITH_TITLE(TITLE,MESSAGE) \ [THIS_FILE_, __LINE__, TITLE, MESSAGE] call CBA_fnc_error; +/* ------------------------------------------- +Macro: MESSAGE_WITH_TITLE() + Record a single line, timestamped log entry in the RPT log. + +Parameters: + TITLE - Title of log message [String] + MESSAGE - Body of message [String] + +Example: + (begin example) + MESSAGE_WITH_TITLE("Value found","Value of frog found in config "); + (end) + +Author: + Killswitch +------------------------------------------- */ +#define MESSAGE_WITH_TITLE(TITLE,MESSAGE) \ + [THIS_FILE_, __LINE__, TITLE + ': ' + (MESSAGE)] call CBA_fnc_log; + /* ------------------------------------------- Macro: RETNIL() If a variable is undefined, return the value nil. Otherwise, return the @@ -1151,6 +1170,122 @@ Macro: ASSERT_DEFINED() ASSERTION_ERROR('Assertion (VARIABLE is defined) failed!\n\n' + (MESSAGE)); \ } +/* ------------------------------------------- +Group: Unit tests +------------------------------------------- */ +#define TEST_SUCCESS(MESSAGE) MESSAGE_WITH_TITLE("Test OK",MESSAGE) +#define TEST_FAIL(MESSAGE) ERROR_WITH_TITLE("Test FAIL",MESSAGE) + +/* ------------------------------------------- +Macro: TEST_TRUE() + Tests that a CONDITION is true. + If the condition is not true, an error is raised with the given MESSAGE. + +Parameters: + CONDITION - Condition to assert as true [Boolean] + MESSSAGE - Message to display if (A OPERATOR B) is false [String] + +Example: + (begin example) + TEST_TRUE(_frogIsDead,"The frog is alive"); + (end) + +Author: + Killswitch +------------------------------------------- */ +#define TEST_TRUE(CONDITION, MESSAGE) \ + if (CONDITION) then \ + { \ + TEST_SUCCESS('(CONDITION)'); \ + } \ + else \ + { \ + TEST_FAIL('(CONDITION) ' + (MESSAGE)); \ + } + +/* ------------------------------------------- +Macro: TEST_FALSE() + Tests that a CONDITION is false. + If the condition is not false, an error is raised with the given MESSAGE. + +Parameters: + CONDITION - Condition to test as false [Boolean] + MESSSAGE - Message to display if (A OPERATOR B) is true [String] + +Example: + (begin example) + TEST_FALSE(_frogIsDead,"The frog died"); + (end) + +Author: + Killswitch +------------------------------------------- */ +#define TEST_FALSE(CONDITION, MESSAGE) \ + if (not (CONDITION)) then \ + { \ + TEST_SUCCESS('(not (CONDITION))'); \ + } \ + else \ + { \ + TEST_FAIL('(not (CONDITION)) ' + (MESSAGE)); \ + } + +/* ------------------------------------------- +Macro: TEST_OP() + Tests that (A OPERATOR B) is true. + If the test fails, an error is raised with the given MESSAGE. + +Parameters: + A - First value [Any] + OPERATOR - Binary operator to use [Operator] + B - Second value [Any] + MESSSAGE - Message to display if (A OPERATOR B) is false. [String] + +Example: + (begin example) + TEST_OP(_fish,>,5,"Too few fish!"); + (end) + +Author: + Killswitch +------------------------------------------- */ +#define TEST_OP(A,OPERATOR,B,MESSAGE) \ + if ((A) OPERATOR (B)) then \ + { \ + TEST_SUCCESS('(A OPERATOR B)') \ + } \ + else \ + { \ + TEST_FAIL('(A OPERATOR B)') \ + }; + +/* ------------------------------------------- +Macro: TEST_DEFINED() + Tests that a VARIABLE is defined. + +Parameters: + VARIABLE - Variable to test if defined [String or Function]. + MESSAGE - Message to display if variable is undefined [String]. + +Examples: + (begin example) + TEST_DEFINED("_anUndefinedVar","Too few fish!"); + TEST_DEFINED({ obj getVariable "anUndefinedVar" },"Too many fish!"); + (end) + +Author: + Killswitch +------------------------------------------- */ +#define TEST_DEFINED(VARIABLE,MESSAGE) \ + if (not isNil VARIABLE) then \ + { \ + TEST_SUCCESS('(' + VARIABLE + ' is defined)'); \ + } \ + else \ + { \ + TEST_FAIL('(' + VARIABLE + ' is not defined)' + (MESSAGE)); \ + } + /* ------------------------------------------- Group: Managing Deprecation ------------------------------------------- */ diff --git a/addons/strings/test_strings.sqf b/addons/strings/test_strings.sqf index b11a93087..68f2fcd1d 100644 --- a/addons/strings/test_strings.sqf +++ b/addons/strings/test_strings.sqf @@ -12,252 +12,252 @@ LOG('Testing Strings'); // UNIT TESTS (stringFind) _fn = "CBA_fnc_find"; -ASSERT_DEFINED("CBA_fnc_find",""); +TEST_DEFINED("CBA_fnc_find",""); _pos = ["frog", "f"] call CBA_fnc_find; -ASSERT_OP(_pos,==,0,_fn); +TEST_OP(_pos,==,0,_fn); _pos = ["frog", "g"] call CBA_fnc_find; -ASSERT_OP(_pos,==,3,_fn); +TEST_OP(_pos,==,3,_fn); _pos = ["frog", "z"] call CBA_fnc_find; -ASSERT_OP(_pos,==,-1,_fn); +TEST_OP(_pos,==,-1,_fn); _pos = ["bullfrog", "frog"] call CBA_fnc_find; -ASSERT_OP(_pos,==,4,_fn); +TEST_OP(_pos,==,4,_fn); _pos = ["bullfrog", "frogs"] call CBA_fnc_find; -ASSERT_OP(_pos,==,-1,_fn); +TEST_OP(_pos,==,-1,_fn); _pos = ["frofrog", "frog"] call CBA_fnc_find; -ASSERT_OP(_pos,==,3,_fn); +TEST_OP(_pos,==,3,_fn); // ---------------------------------------------------------------------------- // UNIT TESTS (stringSplit) _fn = "CBA_fnc_split"; -ASSERT_DEFINED("CBA_fnc_split",""); +TEST_DEFINED("CBA_fnc_split",""); _array = ["", "\"] call CBA_fnc_split; _expected = []; -ASSERT_OP(str _array, ==, str _expected, _fn); +TEST_OP(str _array, ==, str _expected, _fn); _array = ["\", "\"] call CBA_fnc_split; _expected = ["", ""]; -ASSERT_OP(str _array, ==, str _expected, _fn); +TEST_OP(str _array, ==, str _expected, _fn); _array = ["\frog", "\"] call CBA_fnc_split; _expected = ["", "frog"]; -ASSERT_OP(str _array, ==, str _expected, _fn); +TEST_OP(str _array, ==, str _expected, _fn); _array = ["\frog\", "\"] call CBA_fnc_split; _expected = ["", "frog", ""]; -ASSERT_OP(str _array, ==, str _expected, _fn); +TEST_OP(str _array, ==, str _expected, _fn); _array = ["cheese\frog\fish", "\"] call CBA_fnc_split; _expected = ["cheese", "frog", "fish"]; -ASSERT_OP(str _array, ==, str _expected, _fn); +TEST_OP(str _array, ==, str _expected, _fn); _array = ["peas", ""] call CBA_fnc_split; _expected = ["p", "e", "a", "s"]; -ASSERT_OP(str _array, ==, str _expected, _fn); +TEST_OP(str _array, ==, str _expected, _fn); // ---------------------------------------------------------------------------- // UNIT TESTS (stringReplace) _fn = "CBA_fnc_replace"; -ASSERT_DEFINED("CBA_fnc_replace",""); +TEST_DEFINED("CBA_fnc_replace",""); _str = ["", "", ""] call CBA_fnc_replace; -ASSERT_OP(_str,==,"",_fn); +TEST_OP(_str,==,"",_fn); _str = ["", "frog", "fish"] call CBA_fnc_replace; -ASSERT_OP(_str,==,"",_fn); +TEST_OP(_str,==,"",_fn); _str = ["frog", "fish", "cheese"] call CBA_fnc_replace; -ASSERT_OP(_str,==,"frog",_fn); +TEST_OP(_str,==,"frog",_fn); _str = ["frog", "o", "a"] call CBA_fnc_replace; -ASSERT_OP(_str,==,"frag",_fn); +TEST_OP(_str,==,"frag",_fn); _str = ["frodo", "o", "ai"] call CBA_fnc_replace; -ASSERT_OP(_str,==,"fraidai",_fn); +TEST_OP(_str,==,"fraidai",_fn); // ---------------------------------------------------------------------------- // UNIT TESTS (leftTrim) _fn = "CBA_fnc_leftTrim"; -ASSERT_DEFINED("CBA_fnc_leftTrim",""); +TEST_DEFINED("CBA_fnc_leftTrim",""); _str = [""] call CBA_fnc_leftTrim; -ASSERT_OP(_str,==,"",_fn); +TEST_OP(_str,==,"",_fn); _str = ["frog"] call CBA_fnc_leftTrim; -ASSERT_OP(_str,==,"frog",_fn); +TEST_OP(_str,==,"frog",_fn); _str = [" frog"] call CBA_fnc_leftTrim; -ASSERT_OP(_str,==,"frog",_fn); +TEST_OP(_str,==,"frog",_fn); _str = [" frog"] call CBA_fnc_leftTrim; // spaces -ASSERT_OP(_str,==,"frog",_fn); +TEST_OP(_str,==,"frog",_fn); _str = [" frog"] call CBA_fnc_leftTrim; // tab -ASSERT_OP(_str,==,"frog",_fn); +TEST_OP(_str,==,"frog",_fn); _str = [" "] call CBA_fnc_leftTrim; -ASSERT_OP(_str,==,"",_fn); +TEST_OP(_str,==,"",_fn); _str = [" x "] call CBA_fnc_leftTrim; -ASSERT_OP(_str,==,"x ",_fn); +TEST_OP(_str,==,"x ",_fn); // ---------------------------------------------------------------------------- // UNIT TESTS (rightTrim) _fn = "CBA_fnc_rightTrim"; -ASSERT_DEFINED("CBA_fnc_rightTrim",""); +TEST_DEFINED("CBA_fnc_rightTrim",""); _str = [""] call CBA_fnc_rightTrim; -ASSERT_OP(_str,==,"",_fn); +TEST_OP(_str,==,"",_fn); _str = ["frog"] call CBA_fnc_rightTrim; -ASSERT_OP(_str,==,"frog",_fn); +TEST_OP(_str,==,"frog",_fn); _str = ["frog "] call CBA_fnc_rightTrim; -ASSERT_OP(_str,==,"frog",_fn); +TEST_OP(_str,==,"frog",_fn); _str = ["frog "] call CBA_fnc_rightTrim; -ASSERT_OP(_str,==,"frog",_fn); +TEST_OP(_str,==,"frog",_fn); _str = ["frog "] call CBA_fnc_rightTrim; // including tabs -ASSERT_OP(_str,==,"frog",_fn); +TEST_OP(_str,==,"frog",_fn); _str = [" "] call CBA_fnc_rightTrim; -ASSERT_OP(_str,==,"",_fn); +TEST_OP(_str,==,"",_fn); _str = [" "] call CBA_fnc_rightTrim; // including tabs -ASSERT_OP(_str,==,"",_fn); +TEST_OP(_str,==,"",_fn); _str = [" x "] call CBA_fnc_rightTrim; -ASSERT_OP(_str,==," x",_fn); +TEST_OP(_str,==," x",_fn); // ---------------------------------------------------------------------------- // UNIT TESTS (trim) _fn = "CBA_fnc_trim"; -ASSERT_DEFINED("CBA_fnc_trim",""); +TEST_DEFINED("CBA_fnc_trim",""); _str = [""] call CBA_fnc_trim; -ASSERT_OP(_str,==,"",_fn); +TEST_OP(_str,==,"",_fn); _str = [" x "] call CBA_fnc_trim; -ASSERT_OP(_str,==,"x",_fn); +TEST_OP(_str,==,"x",_fn); // ---------------------------------------------------------------------------- // UNIT TESTS (capitalize) _fn = "CBA_fnc_capitalize"; -ASSERT_DEFINED("CBA_fnc_capitalize",""); +TEST_DEFINED("CBA_fnc_capitalize",""); _str = [""] call CBA_fnc_capitalize; -ASSERT_OP(_str,==,"",_fn); +TEST_OP(_str,==,"",_fn); _str = ["a"] call CBA_fnc_capitalize; -ASSERT_OP(_str,==,"A",_fn); +TEST_OP(_str,==,"A",_fn); _str = ["frog"] call CBA_fnc_capitalize; -ASSERT_OP(_str,==,"Frog",_fn); +TEST_OP(_str,==,"Frog",_fn); _str = ["Frog"] call CBA_fnc_capitalize; -ASSERT_OP(_str,==,"Frog",_fn); +TEST_OP(_str,==,"Frog",_fn); // ---------------------------------------------------------------------------- // UNIT TESTS (CBA_fnc_formatNumber) _fn = "CBA_fnc_formatNumber"; -ASSERT_DEFINED("CBA_fnc_formatNumber",""); +TEST_DEFINED("CBA_fnc_formatNumber",""); _str = [0.0001, 1, 3] call CBA_fnc_formatNumber; -ASSERT_OP(_str,==,"0.000",_fn); +TEST_OP(_str,==,"0.000",_fn); _str = [0.0005, 1, 3] call CBA_fnc_formatNumber; -ASSERT_OP(_str,==,"0.001",_fn); +TEST_OP(_str,==,"0.001",_fn); _str = [12345, 1, 0, true] call CBA_fnc_formatNumber; _expected = "12,345"; -ASSERT_OP(_str,==,_expected,_fn); +TEST_OP(_str,==,_expected,_fn); _str = [12345.67, 1, 1, true] call CBA_fnc_formatNumber; _expected = "12,345.7"; -ASSERT_OP(_str,==,_expected,_fn); +TEST_OP(_str,==,_expected,_fn); _str = [0.1, 1] call CBA_fnc_formatNumber; -ASSERT_OP(_str,==,"0",_fn); +TEST_OP(_str,==,"0",_fn); _str = [0.1, 3, 1] call CBA_fnc_formatNumber; -ASSERT_OP(_str,==,"000.1",_fn); +TEST_OP(_str,==,"000.1",_fn); _str = [0.1, 0, 2] call CBA_fnc_formatNumber; -ASSERT_OP(_str,==,".10",_fn); +TEST_OP(_str,==,".10",_fn); _str = [12, 0] call CBA_fnc_formatNumber; -ASSERT_OP(_str,==,"12",_fn); +TEST_OP(_str,==,"12",_fn); _str = [12, 3] call CBA_fnc_formatNumber; -ASSERT_OP(_str,==,"012",_fn); +TEST_OP(_str,==,"012",_fn); _str = [-12] call CBA_fnc_formatNumber; -ASSERT_OP(_str,==,"-12",_fn); +TEST_OP(_str,==,"-12",_fn); // ---------------------------------------------------------------------------- // UNIT TESTS (elaspsedTime) _fn = "CBA_fnc_formatElapsedTime"; -ASSERT_DEFINED("CBA_fnc_formatElapsedTime",""); +TEST_DEFINED("CBA_fnc_formatElapsedTime",""); _str = [0, "H:MM:SS"] call CBA_fnc_formatElapsedTime; _expected = "0:00:00"; -ASSERT_OP(_str,==,_expected,_fn); +TEST_OP(_str,==,_expected,_fn); _str = [0, "M:SS"] call CBA_fnc_formatElapsedTime; _expected = "0:00"; -ASSERT_OP(_str,==,_expected,_fn); +TEST_OP(_str,==,_expected,_fn); _str = [0, "H:MM:SS.mmm"] call CBA_fnc_formatElapsedTime; _expected = "0:00:00.000"; -ASSERT_OP(_str,==,_expected,_fn); +TEST_OP(_str,==,_expected,_fn); _str = [0, "M:SS.mmm"] call CBA_fnc_formatElapsedTime; _expected = "0:00.000"; -ASSERT_OP(_str,==,_expected,_fn); +TEST_OP(_str,==,_expected,_fn); // ---------------------------------------------------------------------------- // UNIT TESTS (compareStrings) /* Function ISN'T implemented. _fn = "CBA_fnc_compare"; -ASSERT_DEFINED("CBA_fnc_compare",""); +TEST_DEFINED("CBA_fnc_compare",""); _result = ["", ""] call CBA_fnc_compare; -ASSERT_OP(_result, ==, 0, _fn); +TEST_OP(_result, ==, 0, _fn); _result = ["", "a"] call CBA_fnc_compare; -ASSERT_OP(_result, ==, -1, _fn); +TEST_OP(_result, ==, -1, _fn); _result = ["a", ""] call CBA_fnc_compare; -ASSERT_OP(_result, ==, +1, _fn); +TEST_OP(_result, ==, +1, _fn); _result = ["a", "a"] call CBA_fnc_compare; -ASSERT_OP(_result, ==, 0, _fn); +TEST_OP(_result, ==, 0, _fn); _result = ["a", "b"] call CBA_fnc_compare; -ASSERT_OP(_result, ==, -1, _fn); +TEST_OP(_result, ==, -1, _fn); _result = ["b", "a"] call CBA_fnc_compare; -ASSERT_OP(_result, ==, +1, _fn); +TEST_OP(_result, ==, +1, _fn); _result = ["aardvark", "aardwolf"] call CBA_fnc_compare; -ASSERT_OP(_result, ==, -1, _fn); +TEST_OP(_result, ==, -1, _fn); _result = ["aardwolf", "aardvark"] call CBA_fnc_compare; -ASSERT_OP(_result, ==, +1, _fn); +TEST_OP(_result, ==, +1, _fn); */ nil;