diff --git a/regression/CMakeLists.txt b/regression/CMakeLists.txt index 340e29c2d9..a02a538e17 100644 --- a/regression/CMakeLists.txt +++ b/regression/CMakeLists.txt @@ -22,3 +22,4 @@ add_subdirectory(regression) add_subdirectory(stationlist) + add_subdirectory(gs) diff --git a/regression/gs/CMakeLists.txt b/regression/gs/CMakeLists.txt new file mode 100644 index 0000000000..e25b8642b0 --- /dev/null +++ b/regression/gs/CMakeLists.txt @@ -0,0 +1,8 @@ +include(CreateRegression) +create_regression("game" + ${CMAKE_CURRENT_SOURCE_DIR}/info.nut + ${CMAKE_CURRENT_SOURCE_DIR}/main.nut + ${CMAKE_CURRENT_SOURCE_DIR}/require.nut + ${CMAKE_CURRENT_SOURCE_DIR}/result.txt + ${CMAKE_CURRENT_SOURCE_DIR}/test.sav +) diff --git a/regression/gs/info.nut b/regression/gs/info.nut new file mode 100644 index 0000000000..57647bc67c --- /dev/null +++ b/regression/gs/info.nut @@ -0,0 +1,14 @@ +class Regression extends GSInfo { + function GetAuthor() { return "OpenTTD GS Developers Team"; } + function GetName() { return "Regression"; } + function GetShortName() { return "REGR"; } + function GetDescription() { return "This runs regression-tests on some commands. On the same map the result should always be the same."; } + function GetVersion() { return 1; } + function GetAPIVersion() { return "16"; } + function GetDate() { return "2026-05-19"; } + function CreateInstance() { return "Regression"; } + function UseAsRandomAI() { return false; } +} + +RegisterGS(Regression()); + diff --git a/regression/gs/main.nut b/regression/gs/main.nut new file mode 100644 index 0000000000..0a991ee5fb --- /dev/null +++ b/regression/gs/main.nut @@ -0,0 +1,83 @@ +class Regression extends GSController { + function Start(); +}; + + + +function Regression::TestInit() +{ + print(""); + print("--TestInit--"); + print(" Ops: " + this.GetOpsTillSuspend()); + print(" TickTest: " + this.GetTick()); + this.Sleep(1); + print(" TickTest: " + this.GetTick()); + print(" Ops: " + this.GetOpsTillSuspend()); + print(" SetCommandDelay: " + GSController.SetCommandDelay(1)); + print(" IsValid(vehicle.plane_speed): " + GSGameSettings.IsValid("vehicle.plane_speed")); + print(" vehicle.plane_speed: " + GSGameSettings.GetValue("vehicle.plane_speed")); + require("require.nut"); + print(" TestEnum.value1: " + ::TestEnum.value1); + print(" test_constant: " + ::test_constant); + print(" TestEnum.value2: " + TestEnum.value2); + print(" test_constant: " + test_constant); + print(" min(6, 3): " + min(6, 3)); + print(" min(3, 6): " + min(3, 6)); + print(" max(6, 3): " + max(6, 3)); + print(" max(3, 6): " + max(3, 6)); +} + +function Regression::Company() +{ + print(""); + print("--Company--"); + + /* Test GSXXXMode() in scopes */ + { + local test = GSTestMode(); + print(" SetName(): " + GSCompany.SetName("Regression")); + print(" SetName(): " + GSCompany.SetName("Regression")); + { + local exec = GSExecMode(); + print(" SetName(): " + GSCompany.SetName("Regression")); + print(" SetName(): " + GSCompany.SetName("Regression")); + print(" GetLastErrorString(): " + GSError.GetLastErrorString()); + } + } + + print(" GetName(): " + GSCompany.GetName(GSCompany.COMPANY_SELF)); + print(" GetPresidentName(): " + GSCompany.GetPresidentName(GSCompany.COMPANY_SELF)); + print(" SetPresidentName(): " + GSCompany.SetPresidentName("Regression GS")); + print(" GetPresidentName(): " + GSCompany.GetPresidentName(GSCompany.COMPANY_SELF)); + + print(""); + print("--CompanyMode--"); + + local company = GSCompanyMode(GSCompany.COMPANY_FIRST); + { + local test = GSTestMode(); + print(" SetName(): " + GSCompany.SetName("Regression")); + print(" SetName(): " + GSCompany.SetName("Regression")); + { + local exec = GSExecMode(); + print(" SetName(): " + GSCompany.SetName("Regression")); + print(" SetName(): " + GSCompany.SetName("Regression")); + print(" GetLastErrorString(): " + GSError.GetLastErrorString()); + } + } + + print(" GetName(): " + GSCompany.GetName(GSCompany.COMPANY_SELF)); + print(" GetPresidentName(): " + GSCompany.GetPresidentName(GSCompany.COMPANY_SELF)); + print(" SetPresidentName(): " + GSCompany.SetPresidentName("Regression GS")); + print(" GetPresidentName(): " + GSCompany.GetPresidentName(GSCompany.COMPANY_SELF)); +} + +function Regression::Start() +{ + this.TestInit(); + this.Company(); + + print(""); + print("Done..."); + print(""); +} diff --git a/regression/gs/require.nut b/regression/gs/require.nut new file mode 100644 index 0000000000..872a929a5f --- /dev/null +++ b/regression/gs/require.nut @@ -0,0 +1,9 @@ +print(" Required this file"); + +const test_constant = 1; + +enum TestEnum { + value0, + value1, + value2 +}; diff --git a/regression/gs/result.txt b/regression/gs/result.txt new file mode 100644 index 0000000000..03cd98fb1b --- /dev/null +++ b/regression/gs/result.txt @@ -0,0 +1,44 @@ + +--TestInit-- + Ops: 9988 + TickTest: 1 + TickTest: 2 + Ops: 9990 + SetCommandDelay: (null : 0x00000000) + IsValid(vehicle.plane_speed): true + vehicle.plane_speed: 4 + Required this file + TestEnum.value1: 1 + test_constant: 1 + TestEnum.value2: 2 + test_constant: 1 + min(6, 3): 3 + min(3, 6): 3 + max(6, 3): 6 + max(3, 6): 6 + +--Company-- + SetName(): false + SetName(): false + SetName(): false + SetName(): false + GetLastErrorString(): ERR_PRECONDITION_INVALID_COMPANY + GetName(): (null : 0x00000000) + GetPresidentName(): (null : 0x00000000) + SetPresidentName(): false + GetPresidentName(): (null : 0x00000000) + +--CompanyMode-- + SetName(): true + SetName(): true + SetName(): true + SetName(): false + GetLastErrorString(): ERR_NAME_IS_NOT_UNIQUE + GetName(): Regression + GetPresidentName(): S. G. Bloggs + SetPresidentName(): true + GetPresidentName(): Regression GS + +Done... + +ERROR: The script died unexpectedly. diff --git a/regression/gs/test.sav b/regression/gs/test.sav new file mode 100644 index 0000000000..ff654e0cd4 Binary files /dev/null and b/regression/gs/test.sav differ