< prev index next >

modules/graphics/src/test/java/com/sun/glass/ui/monocle/TestLogShim.java

Print this page
rev 9504 : need to fix test log and others

*** 23,40 **** * questions. */ package com.sun.glass.ui.monocle; - import junit.framework.AssertionFailedError; - import java.util.ArrayList; import java.util.Arrays; import java.util.Formatter; import java.util.List; ! public class TestLog { private static final boolean verbose = Boolean.getBoolean("verbose"); private static final double timeScale = Double.parseDouble( System.getProperty("timeScale", "1")); --- 23,38 ---- * questions. */ package com.sun.glass.ui.monocle; import java.util.ArrayList; import java.util.Arrays; import java.util.Formatter; import java.util.List; ! public class TestLogShim { private static final boolean verbose = Boolean.getBoolean("verbose"); private static final double timeScale = Double.parseDouble( System.getProperty("timeScale", "1"));
*** 43,52 **** --- 41,56 ---- private static final List<String> log = new ArrayList<>(); private static final Object lock = new Object(); private static long startTime = System.currentTimeMillis(); + public static class TestLogAssertion extends Exception { + public TestLogAssertion(String message) { + super(message); + } + } + public static void log(String s) { synchronized (lock) { if (verbose) { System.out.println(timestamp() + " TestLog: " + s); }
*** 153,187 **** public static boolean checkLogContaining(String s) { return checkLog(new String[] {s}, 0, false) != null; } ! public static void assertLog(String s) { synchronized (lock) { if (!checkLog(s)) { String err = "No line '" + s + "' in log"; if (verbose) { System.out.println(err); } ! throw new AssertionFailedError(err); } } } ! public static void assertLogContaining(String s) { synchronized (lock) { if (!checkLogContaining(s)) { String err = "No line containing '" + s + "' in log"; if (verbose) { System.out.println(err); } ! throw new AssertionFailedError(err); } } } ! private static String waitForLog(String[] s, long timeout, boolean exact) throws InterruptedException { long startTime = System.currentTimeMillis(); long timeNow = startTime; long endTime = timeNow + (long) (timeout * timeScale); String line; String logString = Arrays.toString(s).substring(1, Arrays.toString(s).length() - 1); --- 157,191 ---- public static boolean checkLogContaining(String s) { return checkLog(new String[] {s}, 0, false) != null; } ! public static void assertLog(String s) throws TestLogAssertion { synchronized (lock) { if (!checkLog(s)) { String err = "No line '" + s + "' in log"; if (verbose) { System.out.println(err); } ! throw new TestLogAssertion(err); } } } ! public static void assertLogContaining(String s) throws TestLogAssertion { synchronized (lock) { if (!checkLogContaining(s)) { String err = "No line containing '" + s + "' in log"; if (verbose) { System.out.println(err); } ! throw new TestLogAssertion(err); } } } ! private static String waitForLog(String[] s, long timeout, boolean exact) throws InterruptedException, TestLogAssertion { long startTime = System.currentTimeMillis(); long timeNow = startTime; long endTime = timeNow + (long) (timeout * timeScale); String line; String logString = Arrays.toString(s).substring(1, Arrays.toString(s).length() - 1);
*** 202,212 **** for (String logLine: log) { System.out.println(logLine); } } System.out.println(message); ! throw new AssertionFailedError(message); } } } long matchTime = System.currentTimeMillis() - startTime; if (verbose) { --- 206,216 ---- for (String logLine: log) { System.out.println(logLine); } } System.out.println(message); ! throw new TestLogAssertion(message); } } } long matchTime = System.currentTimeMillis() - startTime; if (verbose) {
*** 223,249 **** } } return line; } ! public static String waitForLog(String s, long timeout) throws InterruptedException { return waitForLog(new String [] {s}, timeout, true); } ! public static String waitForLogContaining(String s, long timeout) throws InterruptedException { return waitForLog(new String [] {s}, timeout, false); } ! public static String waitForLog(String format, Object... args) throws InterruptedException { return waitForLog(new Formatter().format(format, args).toString(), DEFAULT_TIMEOUT); } ! public static String waitForLogContaining(String format, Object... args) throws InterruptedException { return waitForLogContaining(new Formatter().format(format, args).toString(), DEFAULT_TIMEOUT); } ! public static String waitForLogContainingSubstrings(String... s) throws InterruptedException { return waitForLog(s, DEFAULT_TIMEOUT, false); } } --- 227,253 ---- } } return line; } ! public static String waitForLog(String s, long timeout) throws InterruptedException, TestLogAssertion { return waitForLog(new String [] {s}, timeout, true); } ! public static String waitForLogContaining(String s, long timeout) throws InterruptedException, TestLogAssertion { return waitForLog(new String [] {s}, timeout, false); } ! public static String waitForLog(String format, Object... args) throws InterruptedException, TestLogAssertion { return waitForLog(new Formatter().format(format, args).toString(), DEFAULT_TIMEOUT); } ! public static String waitForLogContaining(String format, Object... args) throws InterruptedException, TestLogAssertion { return waitForLogContaining(new Formatter().format(format, args).toString(), DEFAULT_TIMEOUT); } ! public static String waitForLogContainingSubstrings(String... s) throws InterruptedException, TestLogAssertion { return waitForLog(s, DEFAULT_TIMEOUT, false); } }
< prev index next >