|
| 1 | +VERSION 1.0 CLASS |
| 2 | +BEGIN |
| 3 | + MultiUse = -1 'True |
| 4 | +END |
| 5 | +Attribute VB_Name = "SQLlibStaticTests" |
| 6 | +Attribute VB_GlobalNameSpace = False |
| 7 | +Attribute VB_Creatable = False |
| 8 | +Attribute VB_PredeclaredId = False |
| 9 | +Attribute VB_Exposed = False |
| 10 | +Implements iTestCase |
| 11 | + |
| 12 | +Dim Interfaced As iSQLQuery |
| 13 | +Dim MyStatic As SQLStaticQuery |
| 14 | + |
| 15 | +Sub iTestCase_Setup() |
| 16 | + Set MyStatic = Create_SQLStaticQuery |
| 17 | + Set Interfaced = MyStatic |
| 18 | +End Sub |
| 19 | +Function iTestCase_GetAllTests() |
| 20 | + iTestCase_GetAllTests = Array("NoArgumentTest", "AddargumentMissingColonTest", "CorrectUseTest", _ |
| 21 | + "ChangeArgumentTest", "EscapeTextTest", "MultipleArgumentTest", "ClearArgumentsTest", _ |
| 22 | + "InsertArgumentInValueTest", "InsertArgumentInStringTest") |
| 23 | +End Function |
| 24 | + |
| 25 | +Function iTestCase_GetObject() |
| 26 | + Set iTestCase_GetObject = New SQLlibStaticTests |
| 27 | +End Function |
| 28 | + |
| 29 | +Function NoArgumentTest() |
| 30 | + MyStatic.Query = "DELETE FROM users" |
| 31 | + NoArgumentTest = AssertObjectStringEquals(Interfaced, "DELETE FROM users") |
| 32 | +End Function |
| 33 | + |
| 34 | +Function AddargumentMissingColonTest() |
| 35 | + MyStatic.Query = "SELECT name FROM users WHERE id=:id" |
| 36 | + MyStatic.AddArgument "id", 4 |
| 37 | + AddargumentMissingColonTest = AssertObjectStringEquals(Interfaced, "SELECT name FROM users WHERE id=:id") |
| 38 | +End Function |
| 39 | + |
| 40 | +Function CorrectUseTest() |
| 41 | + MyStatic.Query = "SELECT name FROM users WHERE id=:id" |
| 42 | + MyStatic.AddArgument ":id", 4 |
| 43 | + CorrectUseTest = AssertObjectStringEquals(Interfaced, "SELECT name FROM users WHERE id=4") |
| 44 | +End Function |
| 45 | + |
| 46 | +Function ChangeArgumentTest() |
| 47 | + MyStatic.Query = "SELECT name FROM users WHERE id=:id" |
| 48 | + MyStatic.AddArgument ":id", 4 |
| 49 | + MyStatic.AddArgument ":id", 40 |
| 50 | + ChangeArgumentTest = AssertObjectStringEquals(Interfaced, "SELECT name FROM users WHERE id=40") |
| 51 | +End Function |
| 52 | + |
| 53 | +Function EscapeTextTest() |
| 54 | + MyStatic.Query = "SELECT name FROM users WHERE id=:id" |
| 55 | + MyStatic.AddArgument ":id", "text" |
| 56 | + EscapeTextTest = AssertObjectStringEquals(Interfaced, "SELECT name FROM users WHERE id='text'") |
| 57 | +End Function |
| 58 | + |
| 59 | +Function MultipleArgumentTest() |
| 60 | + MyStatic.Query = "SELECT name FROM users WHERE id=:id AND type=:type" |
| 61 | + MyStatic.AddArgument ":type", "admin" |
| 62 | + MultipleArgumentTest = AssertObjectStringEquals(Interfaced, "SELECT name FROM users WHERE id=:id AND type='admin'") |
| 63 | +End Function |
| 64 | + |
| 65 | +Function ClearArgumentsTest() |
| 66 | + MyStatic.Query = "SELECT name FROM users WHERE id=:id AND type=:type" |
| 67 | + MyStatic.AddArgument ":type", "admin" |
| 68 | + MyStatic.ClearArguments |
| 69 | + MyStatic.AddArgument ":id", 4 |
| 70 | + ClearArgumentsTest = AssertObjectStringEquals(Interfaced, "SELECT name FROM users WHERE id=4 AND type=:type") |
| 71 | + MyStatic.AddArgument ":type", "admin" |
| 72 | + Call AssertObjectStringEquals(Interfaced, "SELECT name FROM users WHERE id=4 AND type='admin'") |
| 73 | +End Function |
| 74 | + |
| 75 | +' Function: InsertArgumentInValueTest |
| 76 | +' Ensure that argument replacement will not search within string literals and replace the substring |
| 77 | +Function InsertArgumentInValueTest() |
| 78 | + MyStatic.Query = "SELECT name FROM users WHERE id=:id AND type=:type" |
| 79 | + MyStatic.AddArgument ":id", "4:type" |
| 80 | + MyStatic.AddArgument ":type", ";DELETE FROM users;:id" |
| 81 | + InsertArgumentInValueTest = AssertObjectStringEquals(Interfaced, "SELECT name FROM users WHERE id='4:type' AND type=';DELETE FROM users;:id'") |
| 82 | +End Function |
| 83 | + |
| 84 | +' Function: InsertArgumentInValueTest |
| 85 | +' Ensure that argument replacement will not search within string literals and replace the substring |
| 86 | +Function InsertArgumentInStringTest() |
| 87 | + MyStatic.Query = "SELECT name FROM users WHERE id=:id AND type=':id'" |
| 88 | + MyStatic.AddArgument ":id", "4" |
| 89 | + InsertArgumentInStringTest = AssertObjectStringEquals(Interfaced, "SELECT name FROM users WHERE id='4' AND type=':id'") |
| 90 | +End Function |
0 commit comments