2 *******************************************************************************
3 * Copyright (C) 2003-2011, 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 * Returns true if ICU_Version < major.minor.
19 static public boolean isICUVersionBefore(int major, int minor) {
20 return isICUVersionBefore(major, minor, 0);
24 * Returns true if ICU_Version < major.minor.milli.
26 static public boolean isICUVersionBefore(int major, int minor, int milli) {
27 return VersionInfo.ICU_VERSION.compareTo(VersionInfo.getInstance(major, minor, milli)) < 0;
31 * Returns true if ICU_Version >= major.minor.
33 static public boolean isICUVersionAtLeast(int major, int minor) {
34 return isICUVersionAtLeast(major, minor, 0);
38 * Returns true if ICU_Version >= major.minor.milli.
40 static public boolean isICUVersionAtLeast(int major, int minor, int milli) {
41 return !isICUVersionBefore(major, minor, milli);
47 public final void log(String message) {
48 msg(message, LOG, true, false);
52 * Add a message and newline.
54 public final void logln(String message) {
55 msg(message, LOG, true, true);
61 public final void err(String message) {
62 msg(message, ERR, true, false);
66 * Report an error and newline.
68 public final void errln(String message) {
69 msg(message, ERR, true, true);
73 * Report a warning (generally missing tests or data).
75 public final void warn(String message) {
76 msg(message, WARN, true, false);
80 * Report a warning (generally missing tests or data) and newline.
82 public final void warnln(String message) {
83 msg(message, WARN, true, true);
87 * Vector for logging. Callers can force the logging system to
88 * not increment the error or warning level by passing false for incCount.
90 * @param message the message to output.
91 * @param level the message level, either LOG, WARN, or ERR.
92 * @param incCount if true, increments the warning or error count
93 * @param newln if true, forces a newline after the message
95 public abstract void msg(String message, int level, boolean incCount, boolean newln);
98 * Not sure if this class is useful. This lets you log without first testing
99 * if logging is enabled. The Delegating log will either silently ignore the
100 * message, if the delegate is null, or forward it to the delegate.
102 public static final class DelegatingLog extends AbstractTestLog {
103 private TestLog delegate;
105 public DelegatingLog(TestLog delegate) {
106 this.delegate = delegate;
109 public void msg(String message, int level, boolean incCount, boolean newln) {
110 if (delegate != null) {
111 delegate.msg(message, level, incCount, newln);
115 public boolean isDateAtLeast(int year, int month, int day){
116 Date now = new Date();
117 Calendar c = new GregorianCalendar(year, month, day);
118 Date dt = c.getTime();
119 if(now.compareTo(dt)>=0){