| | @@ -4,10 +4,11 @@ |
| 4 | 4 | //'http://fjson/cgi-bin/fossil-json.cgi' |
| 5 | 5 | //'http://192.168.1.62:8080' |
| 6 | 6 | //'http://fossil.wanderinghorse.net/repos/fossil-json-java/index.cgi' |
| 7 | 7 | , |
| 8 | 8 | verbose:false, |
| 9 | + fossilBinary:'fossil', |
| 9 | 10 | wiki:{} |
| 10 | 11 | }; |
| 11 | 12 | (function bootstrap() { |
| 12 | 13 | var srcdir = '../js/'; |
| 13 | 14 | var includes = [srcdir+'json2.js', |
| | @@ -19,11 +20,12 @@ |
| 19 | 20 | } |
| 20 | 21 | WhAjaj.Connector.prototype.sendImpl = WhAjaj.Connector.sendImpls.rhino; |
| 21 | 22 | TestApp.fossil = new FossilAjaj({ |
| 22 | 23 | asynchronous:false, /* rhino-based impl doesn't support async or timeout. */ |
| 23 | 24 | timeout:0, |
| 24 | | - url:TestApp.serverUrl |
| 25 | + url:TestApp.serverUrl, |
| 26 | + fossilBinary:TestApp.fossilBinary |
| 25 | 27 | }); |
| 26 | 28 | var cb = TestApp.fossil.ajaj.callbacks; |
| 27 | 29 | cb.beforeSend = function(req,opt){ |
| 28 | 30 | if(!TestApp.verbose) return; |
| 29 | 31 | print("SENDING REQUEST: AJAJ options="+JSON.stringify(opt)); |
| | @@ -55,11 +57,11 @@ |
| 55 | 57 | throw new Error("Assertion failed: "+descr); |
| 56 | 58 | // aarrgghh. Exceptions are of course swallowed by |
| 57 | 59 | // the AJAX layer, to keep from killing a browser's |
| 58 | 60 | // script environment. |
| 59 | 61 | }else{ |
| 60 | | - print("Assertion OK: "+descr); |
| 62 | + if(TestApp.verbose) print("Assertion OK: "+descr); |
| 61 | 63 | } |
| 62 | 64 | } |
| 63 | 65 | |
| 64 | 66 | /** |
| 65 | 67 | Calls func() in a try/catch block and throws an exception if |
| | @@ -74,11 +76,11 @@ |
| 74 | 76 | ex = e; |
| 75 | 77 | } |
| 76 | 78 | if(!ex){ |
| 77 | 79 | throw new Error("Function did not throw (as expected): "+descr); |
| 78 | 80 | }else{ |
| 79 | | - print("Function threw (as expected): "+descr+": "+ex); |
| 81 | + if(TestApp.verbose) print("Function threw (as expected): "+descr+": "+ex); |
| 80 | 82 | } |
| 81 | 83 | } |
| 82 | 84 | |
| 83 | 85 | /** |
| 84 | 86 | Convenience form of TestApp.fossil.sendCommand(command,payload,ajajOpt). |
| | @@ -187,28 +189,72 @@ |
| 187 | 189 | }); |
| 188 | 190 | assertResponseError(rs); |
| 189 | 191 | } |
| 190 | 192 | testAnonLogout.description = 'Log out anonymous user.'; |
| 191 | 193 | |
| 194 | +function testExternalProcess(){ |
| 195 | + |
| 196 | + var req = { command:"HAI", requestId:'testExternalProcess()' }; |
| 197 | + var args = [TestApp.fossilBinary, 'json', '--json-input', '-']; |
| 198 | + var p = java.lang.Runtime.getRuntime().exec(args); |
| 199 | + var outs = p.getOutputStream(); |
| 200 | + var osr = new java.io.OutputStreamWriter(outs); |
| 201 | + var osb = new java.io.BufferedWriter(osr); |
| 202 | + var json = JSON.stringify(req); |
| 203 | + osb.write(json,0, json.length); |
| 204 | + //osb.flush(); |
| 205 | + osb.close(); |
| 206 | + var ins = p.getInputStream(); |
| 207 | + var isr = new java.io.InputStreamReader(ins); |
| 208 | + var br = new java.io.BufferedReader(isr); |
| 209 | + var line; |
| 210 | + |
| 211 | + while( null !== (line=br.readLine())){ |
| 212 | + print(line); |
| 213 | + } |
| 214 | + //outs.close(); |
| 215 | + ins.close(); |
| 216 | +} |
| 217 | +testExternalProcess.description = 'Run fossil as external process.'; |
| 218 | + |
| 219 | +function testExternalProcessHandler(){ |
| 220 | + var aj = TestApp.fossil.ajaj; |
| 221 | + var oldImpl = aj.sendImpl; |
| 222 | + aj.sendImpl = FossilAjaj.rhinoLocalBinarySendImpl; |
| 223 | + var rs; |
| 224 | + TestApp.fossil.sendCommand('/json/HAI',undefined,{ |
| 225 | + onResponse:function(resp,opt){ |
| 226 | + rs = resp; |
| 227 | + } |
| 228 | + }); |
| 229 | + aj.sendImpl = oldImpl; |
| 230 | + assertResponseOK(rs); |
| 231 | + print("Using local fossil binary via AJAX interface, we fetched: "+ |
| 232 | + WhAjaj.stringify(rs)); |
| 233 | +} |
| 234 | +testExternalProcessHandler.description = 'Try local fossil binary via AJAX interface.'; |
| 235 | + |
| 192 | 236 | (function runAllTests(){ |
| 193 | 237 | var testList = [ |
| 194 | 238 | testHAI, |
| 195 | 239 | testIAmNobody, |
| 196 | 240 | testAnonymousLogin, |
| 197 | 241 | testAnonWiki, |
| 198 | | - testAnonLogout |
| 242 | + testAnonLogout, |
| 243 | + //testExternalProcess, |
| 244 | + testExternalProcessHandler |
| 199 | 245 | ]; |
| 200 | 246 | var i, f; |
| 201 | 247 | for( i = 0; i < testList.length; ++i ){ |
| 202 | 248 | f = testList[i]; |
| 203 | 249 | try{ |
| 204 | 250 | print("Running test #"+(i+1)+": "+(f.description || "no description.")); |
| 205 | 251 | f(); |
| 206 | 252 | }catch(e){ |
| 207 | | - print("Test failed: "+e); |
| 253 | + print("Test #"+(i+1)+" failed: "+e); |
| 208 | 254 | throw e; |
| 209 | 255 | } |
| 210 | 256 | } |
| 211 | 257 | |
| 212 | 258 | })(); |
| 213 | 259 | |
| 214 | | -print("Done!"); |
| 260 | +print("Done! If you don't see an exception message in the last few lines, you win!"); |
| 215 | 261 | |