jaroslav@1328: /** jaroslav@1328: * Back 2 Browser Bytecode Translator jaroslav@1328: * Copyright (C) 2012 Jaroslav Tulach jaroslav@1328: * jaroslav@1328: * This program is free software: you can redistribute it and/or modify jaroslav@1328: * it under the terms of the GNU General Public License as published by jaroslav@1328: * the Free Software Foundation, version 2 of the License. jaroslav@1328: * jaroslav@1328: * This program is distributed in the hope that it will be useful, jaroslav@1328: * but WITHOUT ANY WARRANTY; without even the implied warranty of jaroslav@1328: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the jaroslav@1328: * GNU General Public License for more details. jaroslav@1328: * jaroslav@1328: * You should have received a copy of the GNU General Public License jaroslav@1328: * along with this program. Look for COPYING file in the top folder. jaroslav@1328: * If not, see http://opensource.org/licenses/GPL-2.0. jaroslav@1328: */ jaroslav@1328: package org.apidesign.bck2brwsr.tck; jaroslav@1328: jaroslav@1416: import java.io.ByteArrayOutputStream; jaroslav@1416: import java.io.PrintStream; jaroslav@1417: import org.apidesign.bck2brwsr.core.ExtraJavaScript; jaroslav@1416: import org.apidesign.bck2brwsr.core.JavaScriptBody; jaroslav@1328: import org.apidesign.bck2brwsr.vmtest.Compare; jaroslav@1328: import org.apidesign.bck2brwsr.vmtest.VMTest; jaroslav@1328: import org.testng.annotations.Factory; jaroslav@1328: jaroslav@1328: /** jaroslav@1328: * jaroslav@1328: * @author Jaroslav Tulach jaroslav@1328: */ jaroslav@1417: @ExtraJavaScript(resource = "/org/apidesign/bck2brwsr/tck/console.js") jaroslav@1328: public class SystemTest { jaroslav@1328: @Compare public boolean nonNullOSName() { jaroslav@1328: return System.getProperty("os.name") != null; jaroslav@1328: } jaroslav@1328: jaroslav@1416: @Compare public String captureStdOut() throws Exception { jaroslav@1416: Object capture = initCapture(); jaroslav@1416: System.out.println("Ahoj"); jaroslav@1416: return textCapture(capture); jaroslav@1416: } jaroslav@1416: jaroslav@1416: @JavaScriptBody(args = {}, body = "" jaroslav@1416: + "var lines = [];" jaroslav@1416: + "console.log = function(l) { lines.push(l); };" jaroslav@1416: + "return lines;") jaroslav@1416: Object initCapture() { jaroslav@1416: ByteArrayOutputStream os = new ByteArrayOutputStream(); jaroslav@1416: PrintStream ps = new PrintStream(os); jaroslav@1416: jaroslav@1416: System.setOut(ps); jaroslav@1416: return os; jaroslav@1416: } jaroslav@1416: jaroslav@1416: @JavaScriptBody(args = { "o" }, body = "return o.join('');") jaroslav@1416: String textCapture(Object o) throws java.io.IOException { jaroslav@1416: ByteArrayOutputStream b = (ByteArrayOutputStream) o; jaroslav@1416: return new String(b.toByteArray(), "UTF-8"); jaroslav@1416: } jaroslav@1416: jaroslav@1328: @Factory public static Object[] create() { jaroslav@1328: return VMTest.create(SystemTest.class); jaroslav@1328: } jaroslav@1328: }