%REM Copyright 2022-2023 HCL America, Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License %END REM %REM Agent BasicTester Created Mar 14, 2022 by Paul Withers Description: Tests core functionality of a VoltScript Testing Framework, no custom tester, no before/after code %END REM Option Public Option Declare Use "VoltScriptTesting" Sub Initialize Dim runner As TestRunner ' All tests are in subs, one for each test suite Set runner = New TestRunner(|BasicTester|) runner.setOutputFormat("BOTH") Call testBooleansAndStrings(runner) Call testNumbers(runner) Call testPrimitives(runner) Call testVariants(runner) Call testVariantArrays(runner) Call testNotEqual(runner) End Sub %REM testPrimitive Runs tests for all primitive types against assertEqualsPrimitive %END REM Sub testPrimitives(runner As TestRunner) Dim testSuite As New TestSuite(|Primitive Tests|) Dim a As Integer, b As Double, c As Single, d As Long, e As Boolean Call runner.addTestSuite(testSuite) a = 1 Call testSuite.describe(|Test integers, matching|).assertEqualsPrimitive(a, 1) Call testSuite.describe(|Test integers, not matching|).assertEqualsPrimitive(a, 2) b = 2.5 Call testSuite.describe(|Test doubles, matching|).assertEqualsPrimitive(b, 2.5) Call testSuite.describe(|Test doubles, not matching|).assertEqualsPrimitive(b, 3.5) c = 6.02E23 Call testSuite.describe(|Test singles, matching|).assertEqualsPrimitive(c, 6.02E23) Call testSuite.describe(|Test singles, not matching|).assertEqualsPrimitive(c, 6.12E23) d = 2094070921 Call testSuite.describe(|Test longs, matching|).assertEqualsPrimitive(d, 2094070921) Call testSuite.describe(|Test longs, not matching|).assertEqualsPrimitive(d, 2094070922) e = True Call testSuite.describe(|Test booleans, matching|).assertEqualsPrimitive(e, True) Call testSuite.describe(|Test booleans, not matching|).assertEqualsPrimitive(e, False) Call testSuite.describe(|Test strings, matching|).assertEqualsPrimitive(|foo|, |foo|) Call testSuite.describe(|Test strings, not matching|).assertEqualsPrimitive(|foo|, |bar|) End Sub %REM Function testFoo Description: Comments for Function %END REM Function doTestError() As Boolean Dim doc As Variant doTestError = doc.Isdeleted End Function %REM Sub testNumbers Runs all numeric tests %END REM Sub testNumbers(runner As TestRunner) Dim testSuite As New TestSuite(|Number Tests|) Dim a As Integer, b As Double, c As Single, d As Long Call runner.addTestSuite(testSuite) a = 1 Call testSuite.describe(|Test integers, matching|).assertEqualsInteger(a, 1) Call testSuite.describe(|Test integers, not matching|).assertEqualsInteger(a, 2) b = 2.5 Call testSuite.describe(|Test doubles, matching|).assertEqualsDouble(b, 2.5) Call testSuite.describe(|Test doubles, not matching|).assertEqualsDouble(b, 3.5) Call testSuite.describe(|Test doubles with calculations|).assertEqualsDouble(b, 0.5 * 25 / 5) Call testSuite.describe(|Test complex recurring doubles|).assertEqualsDouble(10 / 3 * 10, 200 / 6) Call testSuite.describe(|Test more complex recurring doubles|).assertEqualsDouble(10 / 3 * 2 * 10, 100 - (100 / 3)) c = 6.02E23 Call testSuite.describe(|Test singles, matching|).assertEqualsSingle(c, 6.02E23) Call testSuite.describe(|Test singles, not matching|).assertEqualsSingle(c, 6.12E23) d = 2094070921 Call testSuite.describe(|Test longs, matching|).assertEqualsLong(d, 2094070921) Call testSuite.describe(|Test longs, not matching|).assertEqualsLong(d, 2094070922) Call testSuite.describe(|Test numeric, not matching|).assertEqualsNumeric(a, b) b = 1.0 Call testSuite.describe(|Test numeric, matching|).assertEqualsNumeric(a, b) End Sub %REM Sub testVariantArrays Description: Tests variant arrays %END REM Sub testVariantArrays(runner As TestRunner) Dim testSuite As New TestSuite(|Variant Array Tests|) Dim a(7) As Variant, b() As Variant Dim i As integer Call runner.addTestSuite(testSuite) For i = 0 To UBound(a) a(i) = i Next Call testSuite.describe(|Test array and not array|).assertEqualsPrimitiveOrPrimitiveArray(a, 1) ReDim b(0) b(0) = 0 Call testSuite.describe(|Test unequal array length|).assertEqualsPrimitiveOrPrimitiveArray(a, b) ReDim b(i - 1) For i = 0 To UBound(b) b(i) = i Next Call testSuite.describe(|Test equal arrays|).assertEqualsPrimitiveOrPrimitiveArray(a, b) b(0) = 1 Call testSuite.describe(|Test first element different|).assertEqualsPrimitiveOrPrimitiveArray(a, b) b(2) = 1 Call testSuite.describe(|Test first and third elements different|).assertEqualsPrimitiveOrPrimitiveArray(a, b) b(3) = 1 b(4) = 1 b(5) = 1 b(6) = 1 b(7) = 1 Call testSuite.describe(|Test lots of elements different|).assertEqualsPrimitiveOrPrimitiveArray(a, b) End Sub %REM Function doTest Description: Comments for Function %END REM Function doTest As Boolean doTest = doTestError End Function %REM Sub testVariants Description: Tests all primitive variants %END REM Sub testVariants(runner As TestRunner) Dim testSuite As New TestSuite(|Complex Variants Tests|) Dim a As Variant, b As Variant Call runner.addTestSuite(testSuite) a = 1.0 b = true Call testSuite.describe(|Test 1.0 = true|).assertEqualsPrimitive(a, b) a = 1 Call testSuite.describe(|Test 1 = true|).assertEqualsPrimitive(a, b) a = -1.0 Call testSuite.describe(|Test -1.0 = true|).assertEqualsPrimitive(a, b) a = -1 Call testSuite.describe(|Test -1 = true|).assertEqualsPrimitive(a, b) Call testSuite.describe(|Test True = 1|).assertEqualsPrimitive(b, -1) Call testSuite.describe(|Test True = -1|).assertEqualsPrimitive(b, 1) Call testSuite.describe(|Test True = 2|).assertEqualsPrimitive(b, 2) Call testSuite.describe(|Test False = 0|).assertEqualsPrimitive(False, 0) a = -1.0 b = "True" Call testSuite.describe(|Test -1.0 = "True"|).assertEqualsPrimitive(a, b) b = "Foo" Call testSuite.describe(|Test 1.0 = "Foo"|).assertEqualsPrimitive(a, b) Call testSuite.describe(|Test a is Double|).assertIs(|DOUBLE|, a) Call testSuite.describe(|Test a is String|).assertIs(|STRING|, a) End Sub %REM Sub testBooleansAndStrings Description: Tests against booleans and strings %END REM Sub testBooleansAndStrings(runner As TestRunner) Dim testSuite As New TestSuite(|Boolean and String Tests|) Dim a As Boolean Call runner.addTestSuite(testSuite) testSuite.describe("Test fail basic boolean true").assertTrue(a) testSuite.describe("Test fail basic boolean false").assertFalse(a) a = True testSuite.describe("Test true basic boolean false").assertFalse(a) testSuite.describe("Test true basic boolean true").assertTrue(a) Call testSuite.describe("Test error") On Error Goto catchTrueError Call testSuite.assertTrue(doTest()) nextTest: On Error Resume Next Call testSuite.describe("Test string equals pass").assertEqualsString("Foo", "Foo", False) Call testSuite.describe("Test string equals fail").assertEqualsString("Foo", "foo", False) Call testSuite.describe("Test string equals insensitive pass").assertEqualsString("Foo", "foo", True) Call testSuite.describe("Test string equals insensitive fail").assertEqualsString("Foo", "Bar", True) catchTrueError: Call testSuite.addError(testSuite.getErrorMsg, GetThreadInfo(12)) Resume nextTest End Sub %REM Sub testNotEqual Runs all assertNot... tests %END REM Sub testNotEqual(runner As TestRunner) Dim testSuite As New TestSuite(|Not Equal|) Dim a As Integer, b As Double, c As Single, d As Long Dim e As Variant, f(2) As Variant, g(2) As Variant Call runner.addTestSuite(testSuite) Call testSuite.describe(|Test foo not equal to bar|).assertNotEqualString(|Foo|, |Bar|) Call testSuite.describe(|Test foo not equal to foo|).assertNotEqualString(|Foo|, |Foo|) Call testSuite.describe(|Test 1 not equal to 2|).assertNotEqualInteger(1, 2) Call testSuite.describe(|Test 1 not equal to 1|).assertNotEqualInteger(1, 1) Call testSuite.describe(|Test 1 not equal to 2|).assertNotEqualInteger(1, 2) Call testSuite.describe(|Test 1 not equal to 1|).assertNotEqualInteger(1, 1) a = 1 Call testSuite.describe(|Test integers, not equal|).assertNotEqualInteger(a, 2) Call testSuite.describe(|Test integers, not equal fails|).assertNotEqualInteger(a, 1) b = 2.5 Call testSuite.describe(|Test doubles, not equal|).assertNotEqualDouble(b, 3.5) Call testSuite.describe(|Test doubles, not equal fails|).assertNotEqualDouble(b, 2.5) c = 6.02E23 Call testSuite.describe(|Test singles, not equal|).assertNotEqualSingle(c, 6.12E23) Call testSuite.describe(|Test singles, not equal fails|).assertNotEqualSingle(c, 6.02E23) d = 2094070921 Call testSuite.describe(|Test longs, not equal|).assertNotEqualLong(d, 2094070922) Call testSuite.describe(|Test longs, not equal fails|).assertNotEqualLong(d, 2094070921) Call testSuite.describe(|Test numeric, not equal|).assertNotEqualNumeric(a, b) b = 1.0 Call testSuite.describe(|Test numeric, not equal fails|).assertNotEqualNumeric(a, b) Call testSuite.describe(|Test a is not Integer|).assertIsNot(|INTEGER|, a) Call testSuite.describe(|Test a is not String|).assertIsNot(|STRING|, a) e = 1 f(0) = 0 f(1) = 1 f(2) = 2 g(0) = 0 g(1) = 2 g(2) = 2 Call testSuite.describe(|Test primitive not matches|).assertNotEqualPrimitiveOrPrimitiveArray(e, 2) Call testSuite.describe(|Test primitive not matches fails|).assertNotEqualPrimitiveOrPrimitiveArray(e, e) Call testSuite.describe(|Test primitive not matches array|).assertNotEqualPrimitiveOrPrimitiveArray(e, f) Call testSuite.describe(|Test array not matches|).assertNotEqualPrimitiveOrPrimitiveArray(f, g) Call testSuite.describe(|Test array not matches fails|).assertNotEqualPrimitiveOrPrimitiveArray(f, f) End Sub