]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-4_8_1_1/main/tests/framework/src/com/ibm/icu/dev/test/AbstractTestLog.java
Added flags.
[Dictionary.git] / jars / icu4j-4_8_1_1 / main / tests / framework / src / com / ibm / icu / dev / test / AbstractTestLog.java
1 /**
2  *******************************************************************************
3  * Copyright (C) 2003-2010, International Business Machines Corporation and         *
4  * others. All Rights Reserved.                                                *
5  *******************************************************************************
6  */
7 package com.ibm.icu.dev.test;
8
9 import java.util.Calendar;
10 import java.util.Date;
11 import java.util.GregorianCalendar;
12
13 import com.ibm.icu.util.VersionInfo;
14
15 public abstract class AbstractTestLog implements TestLog {
16
17     public static boolean dontSkipForVersion = false;
18     /**
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?
21      */
22     public boolean skipIfBeforeICU(int major, int minor, int micro) {
23         if (dontSkipForVersion || VersionInfo.ICU_VERSION.compareTo(VersionInfo.getInstance(major, minor, micro)) > 0) {
24             return false;
25         } 
26         logln("Test skipped before ICU release " + major + "." + minor + "." + micro);
27         return true;
28     }
29
30     
31     /**
32      * Add a message.
33      */
34     public final void log(String message) {
35         msg(message, LOG, true, false);
36     }
37
38     /**
39      * Add a message and newline.
40      */
41     public final void logln(String message) {
42         msg(message, LOG, true, true);
43     }
44
45     /**
46      * Report an error.
47      */
48     public final void err(String message) {
49         msg(message, ERR, true, false);
50     }
51
52     /**
53      * Report an error and newline.
54      */
55     public final void errln(String message) {
56         msg(message, ERR, true, true);
57     }
58
59     /**
60      * Report a warning (generally missing tests or data).
61      */
62     public final void warn(String message) {
63         msg(message, WARN, true, false);
64     }
65
66     /**
67      * Report a warning (generally missing tests or data) and newline.
68      */
69     public final void warnln(String message) {
70         msg(message, WARN, true, true);
71     }
72
73     /**
74      * Vector for logging.  Callers can force the logging system to
75      * not increment the error or warning level by passing false for incCount.
76      *
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
81      */
82     public abstract void msg(String message, int level, boolean incCount, boolean newln);
83
84     /**
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.
88      */
89     public static final class DelegatingLog extends AbstractTestLog {
90         private TestLog delegate;
91
92         public DelegatingLog(TestLog delegate) {
93             this.delegate = delegate;
94         }
95
96         public void msg(String message, int level, boolean incCount, boolean newln) {
97             if (delegate != null) {
98                 delegate.msg(message, level, incCount, newln);
99             }
100         }
101     }
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){
107             return true;
108         }
109         return false;
110     }
111 }