-
Notifications
You must be signed in to change notification settings - Fork 5
/
RunTests.ahk
executable file
·171 lines (119 loc) · 5.41 KB
/
RunTests.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#Include %A_ScriptDir%
#Include Yunit\Yunit.ahk
#Include Yunit\Window.ahk
#Include Yunit\Stdout.ahk
#Include MCL.ahk
Tester := Yunit.Use(YunitStdout, YunitWindow)
Read(File) {
return FileOpen(File, "r").Read()
}
class MCLTests {
class C {
Begin() {
SetWorkingDir, %A_ScriptDir%/Tests/C
}
ReturnSingleValue() {
pCode := MCL.FromC(Read("ReturnSingleValue.c"))
Result := DllCall(pCode, "CDecl Int")
Yunit.Assert(Result == 2390)
}
ManualFunctionImport() {
pCode := MCL.FromC(Read("ManualFunctionImport.c"))
Result := DllCall(pCode, "WStr", "2390", "CDecl Int")
Yunit.Assert(Result == 2390)
}
PassLotsOfParameters() {
pCode := MCL.FromC(Read("PassLotsOfParameters.c"))
Result := DllCall(pCode, "Int", 2000, "Int", 150, "Int", 150, "Int", 60, "Int", 30, "CDecl Int")
Yunit.Assert(Result == 2390)
Result := DllCall(pCode, "Int", 1000, "Int", 1000, "Int", 1000, "Int", 1000, "Int", 1000, "CDecl Int")
Yunit.Assert(Result == 5000)
}
BasicFloatMath() {
pCode := MCL.FromC(Read("BasicFloatMath.c"))
Result := DllCall(pCode, "Double", 3.1, "Double", 2.8, "CDecl Double")
Yunit.Assert(Abs(Result - 12.98) < 0.0001)
}
ReturnSingleValueWithHeader() {
pCode := MCL.FromC(Read("ReturnSingleValueWithHeader.c"))
Result := DllCall(pCode, "CDecl Int")
Yunit.Assert(Result == 2390)
}
AllocateMemoryAndWriteString() {
pCode := MCL.FromC(Read("AllocateMemoryAndWriteString.c"))
pResult := DllCall(pCode, "CDecl Ptr")
Yunit.Assert(StrGet(pResult, "UTF-8") == "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "C code generated incorrect string '" StrGet(pResult, "UTF-8") "'")
}
Library() {
Library := MCL.FromC(Read("Library.c"))
Yunit.Assert(IsObject(Library))
TestString := "ABC|DEF"
PipePosition := DllCall(Library.Find, "AStr", TestString, "Int", Chr("|"), "CDecl Int")
Yuint.Assert(PipePosition == 3)
ReferenceHash := DllCall(Library.Hash, "AStr", "DEF", "CDecl Int")
ActualHash := DllCall(Library.Hash, "AStr", SubStr(TestString, PipePosition), "CDecl Int")
Yuint.Assert(ReferenceHash == ActualHash)
}
Relocations() {
pCode := MCL.FromC(Read("Relocations.c"))
for k, String in ["Hello", "Goodbye", "dog", "cat"] {
pEntry := DllCall(pCode, "Int", k - 1, "CDecl Ptr")
pString := NumGet(pEntry + 0, 0, "Ptr")
Yunit.Assert(StrGet(pString, "UTF-8") = String)
}
}
GetSetGlobal() {
Code := MCL.FromC(Read("GetSetGlobalFromAHK.c"))
pResultString := DllCall(Code.Check, "Int", 20, "CDecl Ptr")
Yuint.Assert(StrGet(pResultString, "UTF-8") = "Oops, that's wrong")
ThePassword := NumGet(Code.Password, 0, "Int")
pResultString := DllCall(Code.Check, "Int", ThePassword, "CDecl Ptr")
Yuint.Assert(StrGet(pResultString, "UTF-8") = "You got the password right!")
NumPut(0, Code.Password, 0, "Int")
pResultString := DllCall(Code.Check, "Int", ThePassword, "CDecl Ptr")
Yuint.Assert(StrGet(pResultString, "UTF-8") = "Oops, that's wrong")
}
ImplicitExport() {
pCode := MCL.FromC(Read("ImplicitExport.c"))
Result := DllCall(pCode, "Int", 2, "Int", 9, "Int")
Yuint.Assert(Result = 0x400)
Result := DllCall(pCode, "Int", 0x10, "Int", 13, "Int")
Yuint.Assert(Result = 0x20000)
}
ImplicitAllocateMemoryAndWriteString() {
; The big difference between this test and the last one is that this one also pulls in the stdlib
; headers, which define a bunch of (static) functions of their own. If static functions aren't
; handled correctly then the main function can't be guessed and this test will fail.
; The proper behavior is that static functions aren't considered when trying to guess which function is
; the real main function.
pCode := MCL.FromC(Read("ImplicitAllocateMemoryAndWriteString.c"))
pResult := DllCall(pCode, "CDecl Ptr")
Yunit.Assert(StrGet(pResult, "UTF-8") == "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "C code generated incorrect string '" StrGet(pResult, "UTF-8") "'")
}
AHKFromIsFormattedCorrectly() {
CodeString := MCL.AHKFromC("int __main() {return 20;}", MCL.Options.DoNotFormat)
pCode := MCL.FromString(CodeString)
Result := DllCall(pCode, "Int")
Yuint.Assert(Result = 20)
}
}
class CPP {
Begin() {
SetWorkingDir, %A_ScriptDir%/Tests/CPP
}
New() {
pCode := MCL.FromCPP(Read("New.cpp"))
pPoint := DllCall(pCode, "Int", 20, "Int", 30, "CDecl Ptr")
Yunit.Assert(NumGet(pPoint+0, 0, "Int") = 20)
Yunit.Assert(NumGet(pPoint+0, 4, "Int") = 30)
}
Spooky() {
pCode := MCL.FromCPP(Read("Spooky.cpp"))
Success := DllCall(pCode, "CDecl Int")
Yunit.Assert(Success = -1)
}
}
class Packed {
}
}
Tester.Test(MCLTests)