// These are macros used 
alias ts_init "es_xsetinfo ts_count 0;es_xsetinfo ts_passes 0"
alias ts_alldone "es_dbgmsg 0 Tests Passed: server_var(ts_passes) of server_var(ts_count);if (server_var(ts_passes) = server_var(ts_count)) then es_dbgmsg 0 GREEN;else es_dbgmsg 0 RED"

alias ts_begin "es_xsetinfo ts_passed 0;es_xmath ts_count + 1"
alias ts_pass "es_xmath ts_passed + 1;es_xmath ts_passes + 1;es_log [Tests]: ."
alias ts_fail "es_dbgmsg 0 Test FAILED - server_var(ts_count) - server_var(ts_name)"
alias ts_end ";"


// Initialize the test cases
ts_init
// YOU PROBABLY DON'T NEED TO EDIT ABOVE THIS LINE



// All test cases must begin with a test name and the ts_begin
es_xsetinfo ts_name "Basic if test"
ts_begin
// do a test and call "ts_pass" if the test succeeds
if (server_var(ts_count) equalto 1) then ts_pass
// if the test fails, call ts_fail
if (server_var(ts_count) notequalto 1) then ts_fail
// after a test you must call ts_end
ts_end

// more if test
es_xsetinfo ts_name "if condition tests 1"
ts_begin
es_setinfo ift 33
es_setinfo failcheck 1
if (server_var(ift) equalto 33) then es_setinfo failcheck 0
if (server_var(ift) equalto 32) then es_setinfo failcheck 1
if (server_var(ift) lessthan 32) then es_setinfo failcheck 1
if (server_var(ift) greaterthan 34) then es_setinfo failcheck 1
if (server_var(ift) notequalto 33) then es_setinfo failcheck 1
if (server_var(ift) notgreaterthan 32) then es_setinfo failcheck 1
if (server_var(ift) notlessthan 34) then es_setinfo failcheck 1
if (server_var(failcheck) notequalto 1) then ts_pass
if (server_var(failcheck) equalto 1) then ts_fail
ts_end

// more if test
es_xsetinfo ts_name "if condition tests 2"
ts_begin
es_setinfo ift 33
es_setinfo failcheck 1
if (server_var(ift) = 33) then es_setinfo failcheck 0
if (server_var(ift) == 32) then es_setinfo failcheck 1
if (server_var(ift) < 32) then es_setinfo failcheck 1
if (server_var(ift) > 34) then es_setinfo failcheck 1
if (server_var(ift) != 33) then es_setinfo failcheck 1
if (server_var(ift) =< 32) then es_setinfo failcheck 1
if (server_var(ift) => 34) then es_setinfo failcheck 1
if (server_var(failcheck) notequalto 1) then ts_pass
if (server_var(failcheck) equalto 1) then ts_fail
ts_end


// Use this test case as an example for building your own tests
es_xsetinfo ts_name "Edit this text when you copy this"
ts_begin
// insert your code here
// test the success here somehow
if (1 equalto 1) then ts_pass
if (1 equalto 2) then ts_fail
ts_end


es_xsetinfo ts_name "Key Commands test"
ts_begin

// Set variables
es_xsetinfo failcheck 1
es_xsetinfo key_pass1 0
es_xsetinfo key_pass2 0
es_xsetinfo key_pass3 0

// Test group creation, list, and delete commands
es_keygroupdelete ts_group1
es_keygroupcreate ts_group1
es_keycreate ts_group1 ts_key1
es_keysetvalue ts_group1 ts_key1 pass 1
// TODO: Read screen: es_keygrouplist 
// TODO: Read screen: es_keylist ts_group1
es_keydelete ts_group1 ts_key1
es_set _oldesdebug server_var(eventscripts_debug)
es_set eventscripts_debug -1
es_keygetvalue key_pass1 ts_group1 ts_key1 pass
es_set eventscripts_debug server_var(_oldesdebug)

// Test foreach loop
es_keycreate ts_group1 ts_key1
alias execute "es_keysetvalue ts_group1 server_var(tmp) pass 1"
es_foreachkey tmp in ts_group1 execute
es_keygetvalue key_pass2 ts_group1 ts_key1 pass
es_keygroupsave ts_group1

// Test rename functions
es_keygroupdelete ts_group1
es_keygroupcreate ts_group1
es_keygroupload ts_group1
es_keygrouprename ts_group1 ts_group2
es_keyrename ts_group2 ts_key1 ts_key2
// TODO: Read screen: es_keygrouplist
// TODO: Read screen: es_keylist ts_group2
es_keygetvalue key_pass3 ts_group2 ts_key2 pass

// Confirm all tests passed
if (server_var(key_pass3) equalto 1) then es_xif (server_var(key_pass2) equalto 1) then es_xif (server_var(key_pass1) equalto 0) then es_xsetinfo failcheck 0
es_keygroupdelete ts_group2

// Test complete. Did it pass?
if (server_var(failcheck) equalto 0) then ts_pass
if (server_var(failcheck) equalto 1) then ts_fail
ts_end 


es_xsetinfo ts_name "XKey Commands test"
ts_begin

// Set variables
es_xsetinfo failcheck 1
es_xsetinfo key_pass1 0
es_xsetinfo key_pass2 0
es_xsetinfo key_pass3 0

// Test group creation, list, and delete commands
es_xkeygroupdelete ts_group1
es_xkeygroupcreate ts_group1
es_xkeycreate ts_group1 ts_key1
es_xkeysetvalue ts_group1 ts_key1 pass 1
// TODO: Read screen: es_xkeygrouplist
// TODO: Read screen: es_xkeylist ts_group1
es_xkeydelete ts_group1 ts_key1
es_set _oldesdebug server_var(eventscripts_debug)
es_set eventscripts_debug -1
es_xkeygetvalue key_pass1 ts_group1 ts_key1 pass
es_set eventscripts_debug server_var(_oldesdebug)

// Test foreach loop
es_xkeycreate ts_group1 ts_key1
alias execute "es_keysetvalue ts_group1 server_var(tmp) pass 1"
es_xforeachkey tmp in ts_group1 execute
es_xkeygetvalue key_pass2 ts_group1 ts_key1 pass
es_xkeygroupsave ts_group1

// Test rename functions
es_xkeygroupdelete ts_group1
es_xkeygroupcreate ts_group1
es_xkeygroupload ts_group1
es_xkeygrouprename ts_group1 ts_group2
es_xkeyrename ts_group2 ts_key1 ts_key2
// TODO: Read screen: es_xkeygrouplist
// TODO: Read screen: es_xkeylist ts_group2
es_xkeygetvalue key_pass3 ts_group2 ts_key2 pass

// Confirm all tests passed
if (server_var(key_pass3) equalto 1) then es_xif (server_var(key_pass2) equalto 1) then es_xif (server_var(key_pass1) equalto 0) then es_xsetinfo failcheck 0
es_xkeygroupdelete ts_group2

// Test complete. Did it pass?
if (server_var(failcheck) equalto 0) then ts_pass
if (server_var(failcheck) equalto 1) then ts_fail
ts_end 


// Use this test case as an example for building your own tests
es_xsetinfo ts_name "Sin: es_math"
ts_begin
es_setinfo ts2 45
es_math ts2 sin
if (0.850904 == server_var(ts2)) then ts_pass
if (0.850904 != server_var(ts2)) then ts_fail
ts_end


// Use this test case as an example for building your own tests
es_xsetinfo ts_name "Cos: es_math"
ts_begin
es_setinfo ts2 45
es_math ts2 cos
if (0.525322 == server_var(ts2)) then ts_pass
if (0.525322 != server_var(ts2)) then ts_fail
ts_end

// Use this test case as an example for building your own tests
es_xsetinfo ts_name "Tan: es_math"
ts_begin
es_setinfo ts2 45
es_math ts2 tan
if (1.619775 == server_var(ts2)) then ts_pass
if (1.619775 != server_var(ts2)) then ts_fail
ts_end


// Multiplication test
es_xsetinfo ts_name "Multiplication: es_math"
ts_begin
es_setinfo ts1 3
es_math ts1 * 7
if (server_var(ts1) equalto 21) then ts_pass
if (server_var(ts1) notequalto 21) then ts_fail
ts_end

es_xsetinfo ts_name "Addition: es_math"
ts_begin
es_setinfo ts1 3
es_math ts1 + 7
if (server_var(ts1) equalto 10) then ts_pass
if (server_var(ts1) notequalto 10) then ts_fail
ts_end

// string length check tests, numeric, text and alphanumeric
es_xsetinfo ts_name "check string length (numeric) test (es_format, es_string, es_section)"
ts_begin
es_setinfo input 1234567890
alias checklen "es_xsetinfo check 0; es_xsetinfo count_temp 0; es_xsetinfo count_temp_notnull 0; es_xsetinfo count -1; es_xsetinfo section 0; checklen_loop; es_dbgmsg 1 Count: server_var(count)"
alias checklen_loop "es_xmath count + 1; es_xmath section + 1; es_xcopy count_temp input; es_string count_temp section server_var(count) server_var(section); es_xcopy count_temp_notnull count_temp; es_xmath count_temp_notnull + 1; if (server_var(count_temp) equalto 0) then es_xif (server_var(count_temp_notnull) equalto 1) then checklen_loop; if (server_var(count_temp) notequalto 0) then checklen_loop"
checklen
if (server_var(count) equalto 10) then ts_pass
if (server_var(count) notequalto 10) then ts_fail
ts_end

es_xsetinfo ts_name "check string length (text) test (es_format, es_string, es_section)"
ts_begin
es_setinfo input akdfjidnkd
alias checklen "es_xsetinfo check 0; es_xsetinfo count_temp 0; es_xsetinfo count_temp_notnull 0; es_xsetinfo count -1; es_xsetinfo section 0; checklen_loop; es_dbgmsg 1 Count: server_var(count)"
alias checklen_loop "es_xmath count + 1; es_xmath section + 1; es_xcopy count_temp input; es_string count_temp section server_var(count) server_var(section); es_xcopy count_temp_notnull count_temp; es_xmath count_temp_notnull + 1; if (server_var(count_temp) equalto 0) then es_xif (server_var(count_temp_notnull) equalto 1) then checklen_loop; if (server_var(count_temp) notequalto 0) then checklen_loop"
checklen
if (server_var(count) equalto 10) then ts_pass
if (server_var(count) notequalto 10) then ts_fail
ts_end

es_xsetinfo ts_name "check string length (alphanumeric) test (es_format, es_string, es_section)"
ts_begin
es_setinfo input 1xa3g6g830
alias checklen "es_xsetinfo check 0; es_xsetinfo count_temp 0; es_xsetinfo count_temp_notnull 0; es_xsetinfo count -1; es_xsetinfo section 0; checklen_loop; es_dbgmsg 1 Count: server_var(count)"
alias checklen_loop "es_xmath count + 1; es_xmath section + 1; es_xcopy count_temp input; es_string count_temp section server_var(count) server_var(section); es_xcopy count_temp_notnull count_temp; es_xmath count_temp_notnull + 1; if (server_var(count_temp) equalto 0) then es_xif (server_var(count_temp_notnull) equalto 1) then checklen_loop; if (server_var(count_temp) notequalto 0) then checklen_loop"
checklen
if (server_var(count) equalto 10) then ts_pass
if (server_var(count) notequalto 10) then ts_fail
ts_end

es_xsetinfo ts_name "Power (float): es_math"
ts_begin
es_setinfo ts1 3.0
es_math ts1 power 7.0
if (server_var(ts1) equalto 2187) then ts_pass
if (server_var(ts1) notequalto 2187) then ts_fail
ts_end

es_xsetinfo ts_name "Power (int): es_math"
ts_begin
es_setinfo ts1 3
es_math ts1 power 7
if (server_var(ts1) equalto 2187) then ts_pass
if (server_var(ts1) notequalto 2187) then ts_fail
ts_end

es_xsetinfo ts_name "Root (float): es_math"
ts_begin
es_setinfo ts1 4.0
es_math ts1 root 2.0
if (server_var(ts1) equalto 2) then ts_pass
if (server_var(ts1) notequalto 2) then ts_fail
ts_end

es_xsetinfo ts_name "Root (int): es_math"
ts_begin
es_setinfo ts1 4
es_math ts1 root 2
if (server_var(ts1) equalto 2) then ts_pass
if (server_var(ts1) notequalto 2) then ts_fail
ts_end

es_xsetinfo ts_name "abs: es_math"
ts_begin
es_setinfo ts1 -5
es_math ts1 abs
if (server_var(ts1) equalto 5) then ts_pass
if (server_var(ts1) notequalto 5) then ts_fail
ts_end


es_xsetinfo ts_name "server_var: protected"
ts_begin
if (server_var(rcon_password) equalto "(protected)") then ts_pass
if (server_var(rcon_password) notequalto "(protected)") then ts_fail
ts_end


// Get commands test - Start
// THE FOLLOWING GET COMMANDS ARE COMMENTED OUT UNTIL 
// BOTS ARE ADDED TO THE TEST SCRIPT (i.e. this can't be run from autoexec.cfg)
//es_xsetinfo ts_testplayer "b" // Bots have an E in their name ;)
//// es_setinfo oldbotprefix server_var(bot_prefix)
//// es_setinfo oldbotjoin server_var(bot_join_after_player)
//// es_setinfo oldbotquota server_var(bot_quota)
//es_xsetinfo ts_name "Get commands test: es_getuserid"
//ts_begin
//es_xsetinfo ts_userid 0
//es_getuserid ts_userid server_var(ts_testplayer)
//if (server_var(ts_userid) greaterthan 0) then ts_pass
//if (server_var(ts_userid) equalto 0) then ts_fail
//if (server_var(ts_userid) lessthan 0) then ts_fail
//ts_end

//es_xsetinfo ts_name "Get commands test: es_getmoney"
//ts_begin
//es_xsetinfo ts_failcheck 0
//es_xsetinfo ts_money 20000
//if (server_var(ts_userid) greaterthan 0) then es_getmoney ts_money server_var(ts_userid)
//if (server_var(ts_money) equalto 0) then es_xsetinfo ts_failcheck 0
//if (server_var(ts_money) greaterthan 0) then if (server_var(ts_userid) lessthan 16000) then es_xsetinfo ts_failcheck 0
//if (server_var(ts_money) greaterthan 16000) then es_xsetinfo ts_failcheck 1
//if (server_var(ts_failcheck) equalto 0) then ts_pass
//if (server_var(ts_failcheck) equalto 1) then ts_fail
//ts_end

//es_xsetinfo ts_name "Get commands test: es_getplayercount"
//ts_begin
//es_xsetinfo ts_playercount 0
//es_getplayercount ts_playercount
//if (server_var(ts_playercount) greaterthan 1) then ts_fail
//if (server_var(ts_playercount) equalto 1) then ts_pass
//if (server_var(ts_playercount) lessthan 1) then ts_fail
//ts_end

//es_xsetinfo ts_name "Get commands test: es_isbot"
//ts_begin
//es_xsetinfo ts_bot 1
//if (server_var(ts_userid) greaterthan 0) then es_isbot ts_bot server_var(ts_userid)
//if (server_var(ts_bot) notequalto 0) then ts_fail
//if (server_var(ts_bot) equalto 0) then ts_pass
//ts_end

//es_xsetinfo ts_name "Get commands test: es_getplayername"
//ts_begin
//es_xsetinfo ts_uname 0
//if (server_var(ts_userid) greaterthan 0) then es_getplayername ts_uname server_var(ts_userid)
//if (server_var(ts_uname) equalto 0) then ts_fail
//if (server_var(ts_uname) notequalto 0) then ts_pass
//ts_end

//es_xsetinfo ts_name "Get commands test: es_getplayersteamid"
//ts_begin
//es_xsetinfo ts_steamid 0
//if (server_var(ts_userid) greaterthan 0) then es_getplayersteamid ts_steamid server_var(ts_userid)
//if (server_var(ts_steamid) equalto 0) then ts_fail
//if (server_var(ts_steamid) notequalto 0) then ts_pass
//ts_end

//es_xsetinfo ts_name "Get commands test: es_getplayerteam"
//ts_begin
//es_xsetinfo ts_uteam 0
//if (server_var(ts_userid) greaterthan 0) then es_getplayerteam ts_uteam server_var(ts_userid)
//if (server_var(ts_uteam) equalto 0) then ts_fail
//if (server_var(ts_uteam) greaterthan 0) then ts_pass
//ts_end

es_xsetinfo ts_name "Get commands test: es_gettimestring"
ts_begin
es_xsetinfo ts_timestring 0
es_gettimestring ts_timestring
if (server_var(ts_timestring) notequalto 0) then ts_pass
if (server_var(ts_timestring) equalto 0) then ts_fail
ts_end

es_xsetinfo ts_name "Get commands test: es_gettime"
ts_begin
es_xsetinfo ts_time 0
es_xsetinfo ts_later 0
es_gettime ts_time
if (server_var(ts_timestring) equalto 0) then ts_fail
if (server_var(ts_timestring) notequalto 0) then es_gettime ts_later
if (server_var(ts_timestring) notequalto 0) then if (server_var(ts_later) greaterthan server_var(ts_time)) then ts_pass
if (server_var(ts_timestring) notequalto 0) then if (server_var(ts_later) lessthan server_var(ts_time)) then ts_fail
if (server_var(ts_timestring) notequalto 0) then if (server_var(ts_later) equalto server_var(ts_time)) then ts_pass
ts_end
// Get commands test - End

// more if test
es_xsetinfo ts_name "if condition tests 1"
ts_begin
es_setinfo failcheck 1
if ("hello" notin "WAYGOAWAY") then es_setinfo failcheck 0
if ("hello" notin "WAYhelloGOAWAY") then es_setinfo failcheck 1
if (server_var(failcheck) notequalto 1) then ts_pass
if (server_var(failcheck) equalto 1) then ts_fail
ts_end


// run the script-based unit tests
es_xsetinfo ts_load 0
es_load unittest
es_xsetinfo ts_name "Script Addon: load event"
ts_begin
if (server_var(ts_load) equalto 1) then ts_pass
if (server_var(ts_load) notequalto 1) then ts_fail
ts_end

// YOU PROBABLY DON'T NEED TO EDIT BELOW THIS LINE
// This must stay at the very end of the test script
es_xevent initialize es_unittest_done
es_xevent fire es_unittest_done

//es_soon ts_alldone