Home | History | Annotate | Download | only in test
      1 /**
      2  *******************************************************************************
      3  * Copyright (C) 2001-2009, International Business Machines Corporation and    *
      4  * others. All Rights Reserved.                                                *
      5  *******************************************************************************
      6  */
      7 package com.ibm.icu.dev.test;
      8 
      9 import java.util.Iterator;
     10 
     11 /**
     12  * Represents a collection of test data described in a file.
     13  *
     14  */
     15 public interface TestDataModule {
     16     /**
     17      * Return the name of this test data module.
     18      */
     19     public String getName();
     20 
     21     /**
     22      * Get additional data related to the module, e.g. DESCRIPTION,
     23      * global settings.  Might be null.
     24      */
     25     public DataMap getInfo();
     26 
     27     /**
     28      * Returns the TestData corresponding to name, or null if name not
     29      * found in this module.  Throw error if name is not found.
     30      * @throws DataModuleFormatError
     31      */
     32     public TestData getTestData(String name) throws DataModuleFormatError;
     33 
     34     /**
     35      * @return Iterator<TestData>
     36      */
     37     public Iterator getTestDataIterator();
     38 
     39     public static class Factory{
     40 
     41         static final TestDataModule get(String baseName, String localeName) throws DataModuleFormatError {
     42             return new ResourceModule(baseName, localeName);
     43         }
     44     }
     45 
     46     public static class DataModuleFormatError extends Exception{
     47         /**
     48          * For serialization
     49          */
     50         private static final long serialVersionUID = 4312521272388482529L;
     51         public DataModuleFormatError(String msg){
     52             super(msg);
     53         }
     54         public DataModuleFormatError(String msg, Throwable cause){
     55             super(msg, cause);
     56         }
     57         public DataModuleFormatError(Throwable cause) {
     58             super(cause);
     59         }
     60     }
     61 
     62     /**
     63      * Represents a single test in the module.
     64      */
     65     public static interface TestData {
     66         public String getName();
     67         /**
     68          * Get additional data related to the test data, e.g. DESCRIPTION,
     69          * global settings.  Might be null.
     70          */
     71         public DataMap getInfo();
     72         /**
     73          * @return Iterator<DataMap>
     74          */
     75         public Iterator getSettingsIterator();
     76         /**
     77          * @return Iterator<DataMap>
     78          */
     79         public Iterator getDataIterator();
     80     }
     81 
     82     /**
     83      * Map-like interface for accessing key-value pairs by key.
     84      * If the vaule is not found by given key, return null.
     85      * The behavior is analogous the get() method of the Map interface.
     86      *
     87      * @author Raymond Yang
     88      */
     89     public interface DataMap {
     90 //    public abstract boolean    isDefined(String key);
     91 //
     92     public abstract Object     getObject(String key);
     93     public abstract String     getString(String key);
     94 //    public abstract char       getChar(String key);
     95 //    public abstract int        getInt(String key);
     96 //    public abstract byte       getByte(String key);
     97 //    public abstract boolean    getBoolean(String key);
     98 //
     99 //    public abstract Object[]   getObjectArray(String key);
    100 //    public abstract String[]   getStringArray(String key);
    101 //    public abstract char[]     getCharArray(String key);
    102 //    public abstract int[]      getIntArray(String key);
    103 //    public abstract byte[]     getByteArray(String key);
    104 //    public abstract boolean[]  getBooleanArray(String key);
    105     }
    106 }
    107 
    108