author | Jaroslav Tulach <jaroslav.tulach@apidesign.org> |
Wed, 19 Nov 2014 19:32:00 +0100 | |
changeset 1723 | 3a1f262311cf |
parent 1417 | rt/emul/compact/src/test/java/org/apidesign/bck2brwsr/tck/SystemTest.java@f45b7126d21d |
child 1787 | ea12a3bb4b33 |
permissions | -rw-r--r-- |
jaroslav@1328 | 1 |
/** |
jaroslav@1328 | 2 |
* Back 2 Browser Bytecode Translator |
jaroslav@1328 | 3 |
* Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org> |
jaroslav@1328 | 4 |
* |
jaroslav@1328 | 5 |
* This program is free software: you can redistribute it and/or modify |
jaroslav@1328 | 6 |
* it under the terms of the GNU General Public License as published by |
jaroslav@1328 | 7 |
* the Free Software Foundation, version 2 of the License. |
jaroslav@1328 | 8 |
* |
jaroslav@1328 | 9 |
* This program is distributed in the hope that it will be useful, |
jaroslav@1328 | 10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
jaroslav@1328 | 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
jaroslav@1328 | 12 |
* GNU General Public License for more details. |
jaroslav@1328 | 13 |
* |
jaroslav@1328 | 14 |
* You should have received a copy of the GNU General Public License |
jaroslav@1328 | 15 |
* along with this program. Look for COPYING file in the top folder. |
jaroslav@1328 | 16 |
* If not, see http://opensource.org/licenses/GPL-2.0. |
jaroslav@1328 | 17 |
*/ |
jaroslav@1328 | 18 |
package org.apidesign.bck2brwsr.tck; |
jaroslav@1328 | 19 |
|
jaroslav@1416 | 20 |
import java.io.ByteArrayOutputStream; |
jaroslav@1416 | 21 |
import java.io.PrintStream; |
jaroslav@1417 | 22 |
import org.apidesign.bck2brwsr.core.ExtraJavaScript; |
jaroslav@1416 | 23 |
import org.apidesign.bck2brwsr.core.JavaScriptBody; |
jaroslav@1328 | 24 |
import org.apidesign.bck2brwsr.vmtest.Compare; |
jaroslav@1328 | 25 |
import org.apidesign.bck2brwsr.vmtest.VMTest; |
jaroslav@1328 | 26 |
import org.testng.annotations.Factory; |
jaroslav@1328 | 27 |
|
jaroslav@1328 | 28 |
/** |
jaroslav@1328 | 29 |
* |
jaroslav@1328 | 30 |
* @author Jaroslav Tulach <jtulach@netbeans.org> |
jaroslav@1328 | 31 |
*/ |
jaroslav@1417 | 32 |
@ExtraJavaScript(resource = "/org/apidesign/bck2brwsr/tck/console.js") |
jaroslav@1328 | 33 |
public class SystemTest { |
jaroslav@1328 | 34 |
@Compare public boolean nonNullOSName() { |
jaroslav@1328 | 35 |
return System.getProperty("os.name") != null; |
jaroslav@1328 | 36 |
} |
jaroslav@1328 | 37 |
|
jaroslav@1416 | 38 |
@Compare public String captureStdOut() throws Exception { |
jaroslav@1416 | 39 |
Object capture = initCapture(); |
jaroslav@1416 | 40 |
System.out.println("Ahoj"); |
jaroslav@1416 | 41 |
return textCapture(capture); |
jaroslav@1416 | 42 |
} |
jaroslav@1416 | 43 |
|
jaroslav@1416 | 44 |
@JavaScriptBody(args = {}, body = "" |
jaroslav@1416 | 45 |
+ "var lines = [];" |
jaroslav@1416 | 46 |
+ "console.log = function(l) { lines.push(l); };" |
jaroslav@1416 | 47 |
+ "return lines;") |
jaroslav@1416 | 48 |
Object initCapture() { |
jaroslav@1416 | 49 |
ByteArrayOutputStream os = new ByteArrayOutputStream(); |
jaroslav@1416 | 50 |
PrintStream ps = new PrintStream(os); |
jaroslav@1416 | 51 |
|
jaroslav@1416 | 52 |
System.setOut(ps); |
jaroslav@1416 | 53 |
return os; |
jaroslav@1416 | 54 |
} |
jaroslav@1416 | 55 |
|
jaroslav@1416 | 56 |
@JavaScriptBody(args = { "o" }, body = "return o.join('');") |
jaroslav@1416 | 57 |
String textCapture(Object o) throws java.io.IOException { |
jaroslav@1416 | 58 |
ByteArrayOutputStream b = (ByteArrayOutputStream) o; |
jaroslav@1416 | 59 |
return new String(b.toByteArray(), "UTF-8"); |
jaroslav@1416 | 60 |
} |
jaroslav@1416 | 61 |
|
jaroslav@1328 | 62 |
@Factory public static Object[] create() { |
jaroslav@1328 | 63 |
return VMTest.create(SystemTest.class); |
jaroslav@1328 | 64 |
} |
jaroslav@1328 | 65 |
} |