2 *******************************************************************************
3 * Copyright (C) 2003-2010, International Business Machines Corporation and *
4 * others. All Rights Reserved. *
5 *******************************************************************************
7 package com.ibm.icu.dev.test;
9 import java.util.Calendar;
10 import java.util.Date;
11 import java.util.GregorianCalendar;
13 import com.ibm.icu.util.VersionInfo;
15 public abstract class AbstractTestLog implements TestLog {
17 public static boolean dontSkipForVersion = false;
19 * Returns true if the current ICU version is before, or equal to, the specified major.minor.micro version.
20 * TODO: Why is this called "before" when it returns true for "before or equal"? Can we fix it?
22 public boolean skipIfBeforeICU(int major, int minor, int micro) {
23 if (dontSkipForVersion || VersionInfo.ICU_VERSION.compareTo(VersionInfo.getInstance(major, minor, micro)) > 0) {
26 logln("Test skipped before ICU release " + major + "." + minor + "." + micro);
34 public final void log(String message) {
35 msg(message, LOG, true, false);
39 * Add a message and newline.
41 public final void logln(String message) {
42 msg(message, LOG, true, true);
48 public final void err(String message) {
49 msg(message, ERR, true, false);
53 * Report an error and newline.
55 public final void errln(String message) {
56 msg(message, ERR, true, true);
60 * Report a warning (generally missing tests or data).
62 public final void warn(String message) {
63 msg(message, WARN, true, false);
67 * Report a warning (generally missing tests or data) and newline.
69 public final void warnln(String message) {
70 msg(message, WARN, true, true);
74 * Vector for logging. Callers can force the logging system to
75 * not increment the error or warning level by passing false for incCount.
77 * @param message the message to output.
78 * @param level the message level, either LOG, WARN, or ERR.
79 * @param incCount if true, increments the warning or error count
80 * @param newln if true, forces a newline after the message
82 public abstract void msg(String message, int level, boolean incCount, boolean newln);
85 * Not sure if this class is useful. This lets you log without first testing
86 * if logging is enabled. The Delegating log will either silently ignore the
87 * message, if the delegate is null, or forward it to the delegate.
89 public static final class DelegatingLog extends AbstractTestLog {
90 private TestLog delegate;
92 public DelegatingLog(TestLog delegate) {
93 this.delegate = delegate;
96 public void msg(String message, int level, boolean incCount, boolean newln) {
97 if (delegate != null) {
98 delegate.msg(message, level, incCount, newln);
102 public boolean isDateAtLeast(int year, int month, int day){
103 Date now = new Date();
104 Calendar c = new GregorianCalendar(year, month, day);
105 Date dt = c.getTime();
106 if(now.compareTo(dt)>=0){