1PREFIX="@prefix@"
2
3' run with cscript
4if instr(lcase(WScript.FullName),"cscript")=0 Then
5	WScript.Echo("Please run:  cscript /nologo testall.vbs")
6	WScript.Quit
7end if
8
9' dbs and apis to test
10testdbs=Array(@TESTDBS@)
11testapis=Array(@TESTAPIS@)
12
13' create file system object
14set fso=CreateObject("Scripting.FileSystemObject")
15
16' create shell object
17set WshShell=WScript.CreateObject("WScript.Shell")
18
19' get hostname
20COMPUTERNAME=WshShell.ExpandEnvironmentStrings("%COMPUTERNAME%")
21
22' stop any existing instances
23WshShell.Exec(PREFIX & "\bin\sqlr-stop")
24WScript.Sleep(2000)
25
26' for each database/configuration...
27for each db in testdbs
28
29	' testing...
30	WScript.Echo("testing " & db & " (from " & COMPUTERNAME & ")...")
31
32	' for the router test, start the master/slave instances
33	if db="router" then
34		WshShell.Exec(PREFIX & "\bin\sqlr-start -id routermaster")
35		WScript.Sleep(2000)
36
37		WshShell.Exec(PREFIX & "\bin\sqlr-start -id routerslave")
38		WScript.Sleep(2000)
39	end if
40
41	' start the instance
42	WshShell.Exec(PREFIX & "\bin\sqlr-start -id " & db & "test")
43	WScript.Sleep(2000)
44
45	' make sure that the instance is up
46	PING=""
47	for i=1 to 15
48
49		WScript.Echo("")
50		WScript.Echo("pinging " & db & "...")
51		sqlrsh=""
52		if db="extensions" then
53			sqlrsh=PREFIX & "\bin\sqlrsh -host localhost -user test -password test -command ping"
54		else
55			sqlrsh=PREFIX & "\bin\sqlrsh -id " & db & "test -command ping"
56		end if
57		set cmd=WshShell.Exec(sqlrsh)
58
59		' get the output/error
60		set re = new RegExp
61		re.Pattern = "^\s*"
62		re.Multiline = False
63		PING=""
64		do until cmd.StdOut.AtEndOfStream
65			PING=PING & re.Replace(cmd.StdOut.ReadLine(),"")
66		loop
67		pingerr=""
68		do until cmd.StdErr.AtEndOfStream
69			pingerr=pingerr & re.Replace(cmd.StdErr.ReadLine(),"")
70		loop
71
72		Wscript.Echo(PING)
73		Wscript.Echo(pingerr)
74
75		if pingerr="0:Couldn't connect to the listener." then
76			WScript.Sleep(5000)
77		else
78			exit for
79		end if
80	next
81
82	' run the tests
83	if PING="The database is up." then
84		WScript.Echo("")
85		WScript.Echo("success...")
86		WScript.Echo("")
87		for each api in testapis
88			runapitest db,api
89		next
90	else
91		WScript.Echo("")
92		WScript.Echo("failed to start " & db & "test")
93		WScript.Echo("")
94		WScript.Echo("hit enter to continue or ctrl-c to stop...")
95		Wscript.StdIn.ReadLine()
96	end if
97
98	' shut down the instance(s)
99	if db="router" then
100		WScript.Sleep(2000)
101		WshShell.Exec(PREFIX & "\bin\sqlr-stop -id routermaster")
102		WScript.Sleep(2000)
103		WshShell.Exec(PREFIX & "\bin\sqlr-stop -id routerslave")
104	end if
105	WScript.Sleep(2000)
106	WshShell.Exec(PREFIX & "\bin\sqlr-stop -id " & db & "test")
107	WScript.Sleep(2000)
108
109	WScript.Echo("")
110	WScript.Echo("================================================================================")
111	WScript.Echo("")
112next
113
114function runapitest(db,api)
115
116	WScript.echo("testing in " & api)
117	WScript.echo("")
118	WshShell.CurrentDirectory=api
119
120	TEST=""
121	TESTFILE=""
122	select case api
123		case "c"
124			TEST=db & ".exe"
125			TESTFILE=db & ".exe"
126		case "c++"
127			TEST=db & ".exe"
128			TESTFILE=db & ".exe"
129		case "cs"
130			TEST=db & ".exe"
131			TESTFILE=db & ".exe"
132		case "java"
133			TEST="run.bat " & db
134			TESTFILE=db & ".class"
135		case "nodejs"
136			TEST="node " & db & ".js"
137			TESTFILE=db & ".js"
138		case "perl"
139			TEST="perl " & db & ".pl"
140			TESTFILE=db & ".pl"
141		case "perldbi"
142			TEST="perl " & db & ".pl"
143			TESTFILE=db & ".pl"
144		case "php"
145			TEST="php " & db & ".php"
146			TESTFILE=db & ".php"
147		case "phppdo"
148			TEST="php " & db & ".php"
149			TESTFILE=db & ".php"
150		case "python"
151			TEST="python " & db & ".py"
152			TESTFILE=db & ".py"
153		case "pythondb"
154			TEST="python " & db & ".py"
155			TESTFILE=db & ".py"
156		case "ruby"
157			TEST="ruby " & db & ".rb"
158			TESTFILE=db & ".rb"
159		case "tcl"
160			TEST="tclsh " & db & ".tcl"
161			TESTFILE=db & ".tcl"
162	end select
163
164	if fso.FileExists(TESTFILE) then
165		set cmd=WshShell.Exec(TEST)
166		do until cmd.StdOut.AtEndOfStream
167			WScript.Echo(cmd.StdOut.ReadLine())
168		loop
169		if cmd.ExitCode=1 then
170			WScript.echo("")
171			WScript.echo("")
172			WScript.echo(db & " failed in " & api)
173			WScript.StdIn.ReadLine()
174		else
175			WScript.echo("")
176			WScript.echo("test complete")
177		end if
178	else
179		WScript.echo("no test found for " & db & " in " & api)
180	end if
181
182	WScript.echo("")
183	WScript.echo("================================================================================")
184	WScript.echo("")
185
186	WshShell.CurrentDirectory=".."
187end function
188