From 993b6feee4e125bf6acda4e56b4b8a497b210c03 Mon Sep 17 00:00:00 2001 From: zontreck Date: Sat, 5 Oct 2024 02:10:41 -0700 Subject: [PATCH] test(updater): copy over and port tests to nusystem All testsuites have been copied over from SynthOS updater and syntax has been corrected for the most part in the various testsuites. Signed-off-by: zontreck --- src/includes/Functions.lsl | 6 +- src/includes/Variables.lsl | 1 + src/raw/updater/tests/1-scan_servers.lsl | 24 +++++ src/raw/updater/tests/2-connect.lsl | 33 +++++++ src/raw/updater/tests/3-get_versions.lsl | 44 +++++++++ src/raw/updater/tests/4-check_version.lsl | 100 +++++++++++++++++++++ src/raw/updater/tests/5-test_delivery.lsl | 104 ++++++++++++++++++++++ src/raw/updater/tests/test_manifest.txt | 6 ++ 8 files changed, 317 insertions(+), 1 deletion(-) create mode 100644 src/raw/updater/tests/1-scan_servers.lsl create mode 100644 src/raw/updater/tests/2-connect.lsl create mode 100644 src/raw/updater/tests/3-get_versions.lsl create mode 100644 src/raw/updater/tests/4-check_version.lsl create mode 100644 src/raw/updater/tests/5-test_delivery.lsl create mode 100644 src/raw/updater/tests/test_manifest.txt diff --git a/src/includes/Functions.lsl b/src/includes/Functions.lsl index 859df33..afa1358 100644 --- a/src/includes/Functions.lsl +++ b/src/includes/Functions.lsl @@ -16,7 +16,11 @@ CancelCallback(string sTimerID) { } string BuildPacket(string sOperation, list lParams) { - return llList2Json(JSON_OBJECT, lParams + ["op", sOperation]); + return llList2Json(JSON_OBJECT, lParams + ["op", sOperation, "info", BuildInfoPacket()]); +} + +string BuildInfoPacket() { + return llList2Json(JSON_OBJECT, ["script", llGetScriptName(), "time", llGetUnixTime()]); } diff --git a/src/includes/Variables.lsl b/src/includes/Variables.lsl index 54465a5..aa7d393 100644 --- a/src/includes/Variables.lsl +++ b/src/includes/Variables.lsl @@ -29,6 +29,7 @@ string VERSION = "0.3.0-dev"; integer UPDATER_CHANNEL = 0xABCDE0; +integer PACKAGE_SERVER_CHANNEL = 0xAACEA; // AriA's CrEAtions diff --git a/src/raw/updater/tests/1-scan_servers.lsl b/src/raw/updater/tests/1-scan_servers.lsl new file mode 100644 index 0000000..ba55e35 --- /dev/null +++ b/src/raw/updater/tests/1-scan_servers.lsl @@ -0,0 +1,24 @@ +#include "Variables.lsl" +#include "Functions.lsl" +#include "Version.lsl" +#include "../external/AriasCreations/Common.lsl" +#include "../external/AriasCreations/Helpers.lsl" + +// When used in combination with the Test manifest +// {"op":"package_server_reply","info":{"origin":"New Script","time":1667966332},"server":"Test Server"} +// +// Test status: PASS +default +{ + state_entry() + { + g_iServerListener = llListen(PACKAGE_SERVER_CHANNEL, "", "", ""); + + llRegionSay(PACKAGE_SERVER_CHANNEL, BuildPacket("check_package_servers",[])); + } + + listen(integer c,string n,key i,string m) + { + llSay(0, "REPLIES: "+m); + } +} \ No newline at end of file diff --git a/src/raw/updater/tests/2-connect.lsl b/src/raw/updater/tests/2-connect.lsl new file mode 100644 index 0000000..e36a029 --- /dev/null +++ b/src/raw/updater/tests/2-connect.lsl @@ -0,0 +1,33 @@ +#include "Variables.lsl" +#include "Functions.lsl" +#include "Version.lsl" +#include "../external/AriasCreations/Common.lsl" +#include "../external/AriasCreations/Helpers.lsl" + +// When used in combination with the Test manifest +// {"op":"package_list","info":{"origin":"New Script","time":1667966574},"packages":["Test"]} +// +// Test status: PASS +default +{ + state_entry() + { + g_iServerListener = llListen(PACKAGE_SERVER_CHANNEL, "", "", ""); + + llRegionSay(PACKAGE_SERVER_CHANNEL, BuildPacket("check_package_servers",[])); + } + + listen(integer c,string n,key i,string m) + { + if(llJsonGetValue(m,["op"]) == "package_server_reply") + { + if(llJsonGetValue(m,["server"]) == "Test Server") + { + llRegionSayTo(i,c,Build("connect", [])); + } + }else if(llJsonGetValue(m,["op"]) == "package_list") + { + llSay(0, "REPLY: "+m); + } + } +} \ No newline at end of file diff --git a/src/raw/updater/tests/3-get_versions.lsl b/src/raw/updater/tests/3-get_versions.lsl new file mode 100644 index 0000000..6c744e3 --- /dev/null +++ b/src/raw/updater/tests/3-get_versions.lsl @@ -0,0 +1,44 @@ +#include "Variables.lsl" +#include "Functions.lsl" +#include "Version.lsl" +#include "../external/AriasCreations/Common.lsl" +#include "../external/AriasCreations/Helpers.lsl" + +// When used in combination with the Test manifest +// {"op":"package_versions","info":{"origin":"New Script","time":1667967045},"Test":["0.1.0.0","0.1.0.1"]} +// +// Test status: PASS +default +{ + state_entry() + { + g_iServerListener = llListen(PACKAGE_SERVER_CHANNEL, "", "", ""); + + llRegionSay(PACKAGE_SERVER_CHANNEL, BuildPacket("check_package_servers",[])); + } + + listen(integer c,string n,key i,string m) + { + if(llJsonGetValue(m,["op"]) == "package_server_reply") + { + if(llJsonGetValue(m,["server"]) == "Test Server") + { + llRegionSayTo(i,c,BuildPacket("connect", [])); + }else { + //llSay(0, "FATAL ERROR IN PACKAGE SERVER REPLY"); + } + }else if(llJsonGetValue(m,["op"]) == "package_list") + { + string sPkgs = llJsonGetValue(m,["packages"]); + if(sPkgs == "[\"Test\"]") + { + llRegionSayTo(i,c,BuildPacket("check_package", ["pkg", "Test"])); + }else { + llSay(0, "FATAL ERROR IN PACKAGE SERVER LISTING"); + } + } else if(llJsonGetValue(m,["op"]) == "package_versions") + { + llSay(0, "VERSIONS: "+m); + } + } +} \ No newline at end of file diff --git a/src/raw/updater/tests/4-check_version.lsl b/src/raw/updater/tests/4-check_version.lsl new file mode 100644 index 0000000..f22fc09 --- /dev/null +++ b/src/raw/updater/tests/4-check_version.lsl @@ -0,0 +1,100 @@ +#include "Variables.lsl" +#include "Functions.lsl" +#include "Version.lsl" +#include "../external/AriasCreations/Common.lsl" +#include "../external/AriasCreations/Helpers.lsl" + + +// When used in combination with the Test manifest +/* + +CHECK 1: {"op":"version_back","info":{"origin":"New Script","time":1667970061},"same":0,"newer":1,"compatible":1} + +CHECK 2: {"op":"version_back","info":{"origin":"New Script","time":1667970061},"same":0,"newer":1,"compatible":0} + +CHECK 3: {"op":"version_back","info":{"origin":"New Script","time":1667970061},"same":0,"newer":1,"compatible":1} + +CHECK 4: {"op":"version_back","info":{"origin":"New Script","time":1667970199},"same":1,"newer":0,"compatible":1} + +*/ +// +// Test status: PASS + + +integer g_iChecks=0; +default +{ + state_entry() + { + VERSION = "0.0.1.0"; + + g_iServerListener = llListen(PACKAGE_SERVER_CHANNEL, "", "", ""); + + llRegionSay(PACKAGE_SERVER_CHANNEL, BuildPacket("check_package_servers",[])); + } + + listen(integer c,string n,key i,string m) + { + if(llJsonGetValue(m,["op"]) == "package_server_reply") + { + if(llJsonGetValue(m,["server"]) == "Test Server") + { + llRegionSayTo(i,c,BuildPacket("connect", [])); + }else { + llSay(0, "FATAL ERROR IN PACKAGE SERVER REPLY"); + } + }else if(llJsonGetValue(m,["op"]) == "package_list") + { + string sPkgs = llJsonGetValue(m,["packages"]); + if(sPkgs == "[\"Test\"]") + { + llRegionSayTo(i,c,BuildPacket("check_package", ["pkg", "Test"])); + }else { + llSay(0, "FATAL ERROR IN PACKAGE SERVER LISTING"); + } + } else if(llJsonGetValue(m,["op"]) == "package_versions") + { + g_iChecks=0; + llRegionSayTo(i,c,BuildPacket("check_version", ["pkg","Test","ver", "0.1.0.0", "cur", VERSION])); + } else if(llJsonGetValue(m,["op"]) == "version_back") + { + // Test 1 we check 0.1.0.0 + // Test 2 we check 0.1.0.1 + + // Testsuite A will only check with version number 0.0.0.1-EXTRA + // Testsuite B will test with its version number being 1.0.0.0 + + if(!(g_iChecks & 1)) + { + g_iChecks++; + llSay(0, "CHECK 1: "+m); + + llRegionSayTo(i,c,BuildPacket("check_version", ["pkg","Test", "ver", "0.1.0.1", "cur", VERSION])); + } else if(!(g_iChecks & 2)) + { + g_iChecks = g_iChecks << 1; + llSay(0, "CHECK 2: "+m); + + // We are updating! + VERSION = "0.1.0.0"; + g_iChecks++; + llRegionSayTo(i,c,BuildPacket("check_version", ["pkg", "Test", "ver", "0.1.0.1", "cur", VERSION])); + }else if(!(g_iChecks & 4)) + { + g_iChecks = g_iChecks << 1; + llSay(0, "CHECK 3: "+m); + g_iChecks++; + + // Check the same version to us + llRegionSayTo(i,c,BuildPacket("check_version", ["pkg", "Test", "ver", "0.1.0.0", "cur", VERSION])); + } else if(!(g_iChecks & 8)) + { + g_iChecks = g_iChecks<<1; + g_iChecks++; + llSay(0, "CHECK 4: "+m); + + + } + } + } +} \ No newline at end of file diff --git a/src/raw/updater/tests/5-test_delivery.lsl b/src/raw/updater/tests/5-test_delivery.lsl new file mode 100644 index 0000000..7e144ed --- /dev/null +++ b/src/raw/updater/tests/5-test_delivery.lsl @@ -0,0 +1,104 @@ +#include "Variables.lsl" +#include "Functions.lsl" +#include "Version.lsl" +#include "../external/AriasCreations/Common.lsl" +#include "../external/AriasCreations/Helpers.lsl" + + +// When used in combination with the Test manifest +/* + +[21:10:16] Object: Send_back received +[21:10:16] Object: Item 'Test0100' is in the inventory + +*/ +// +// Test status: PASS + + +integer g_iChecks=0; +default +{ + state_entry() + { + VERSION = "0.0.1.0"; + + g_iServerListener = llListen(PACKAGE_SERVER_CHANNEL, "", "", ""); + + llRegionSay(PACKAGE_SERVER_CHANNEL, BuildPacket("check_package_servers",[])); + } + + listen(integer c,string n,key i,string m) + { + if(llJsonGetValue(m,["op"]) == "package_server_reply") + { + if(llJsonGetValue(m,["server"]) == "Test Server") + { + llRegionSayTo(i,c,BuildPacket("connect", [])); + }else { + llSay(0, "FATAL ERROR IN PACKAGE SERVER REPLY"); + } + }else if(llJsonGetValue(m,["op"]) == "package_list") + { + string sPkgs = llJsonGetValue(m,["packages"]); + if(sPkgs == "[\"Test\"]") + { + llRegionSayTo(i,c,BuildPacket("check_package", ["pkg", "Test"])); + }else { + llSay(0, "FATAL ERROR IN PACKAGE SERVER LISTING"); + } + } else if(llJsonGetValue(m,["op"]) == "package_versions") + { + g_iChecks=0; + llRegionSayTo(i,c,BuildPacket("check_version", ["pkg","Test","ver", "0.1.0.0", "cur", VERSION])); + } else if(llJsonGetValue(m,["op"]) == "version_back") + { + // Test 1 we check 0.1.0.0 + // Test 2 we check 0.1.0.1 + + // Testsuite A will only check with version number 0.0.0.1-EXTRA + // Testsuite B will test with its version number being 1.0.0.0 + + if(!(g_iChecks & 1)) + { + g_iChecks++; + + llRegionSayTo(i,c,BuildPacket("check_version", ["pkg","Test", "ver", "0.1.0.1", "cur", VERSION])); + } else if(!(g_iChecks & 2)) + { + g_iChecks = g_iChecks << 1; + + // We are updating! + VERSION = "0.1.0.0"; + g_iChecks++; + llRegionSayTo(i,c,BuildPacket("check_version", ["pkg", "Test", "ver", "0.1.0.1", "cur", VERSION])); + }else if(!(g_iChecks & 4)) + { + g_iChecks = g_iChecks << 1; + g_iChecks++; + + // Check the same version to us + llRegionSayTo(i,c,BuildPacket("check_version", ["pkg", "Test", "ver", "0.1.0.0", "cur", VERSION])); + } else if(!(g_iChecks & 8)) + { + g_iChecks = g_iChecks<<1; + g_iChecks++; + + if(llGetOwnerKey(i)!=llGetOwner())llAllowInventoryDrop(TRUE); + + llRegionSayTo(i,c,BuildPacket("send", ["pkg", "Test", "ver", "0.1.0.0", "dest", llGetKey()])); + } + } else if(llJsonGetValue(m,["op"]) == "send_back") + { + llAllowInventoryDrop(FALSE); + llSay(0, "Send_back received"); + + if(llGetInventoryType(llJsonGetValue(m,["item"])) != INVENTORY_NONE) + { + llSay(0, "Item '"+llJsonGetValue(m,["item"])+"' is in the inventory"); + } else{ + llSay(0, "Item from server not found"); + } + } + } +} \ No newline at end of file diff --git a/src/raw/updater/tests/test_manifest.txt b/src/raw/updater/tests/test_manifest.txt new file mode 100644 index 0000000..5dacc78 --- /dev/null +++ b/src/raw/updater/tests/test_manifest.txt @@ -0,0 +1,6 @@ +SERVER_NAME Test Server +BEGIN Test +LATEST 0.1.0.1 +0.1.0.0|Test0100|0.0.1.0 +0.1.0.1|Test0101|0.1.0.0 +END \ No newline at end of file