< prev index next >

test/jdk/java/util/Formatter/BasicShortObject.java

Print this page




  35 import java.math.BigInteger;
  36 import java.text.DateFormatSymbols;
  37 import java.util.*;
  38 
  39 import static java.util.Calendar.*;
  40 
  41 
  42 
  43 
  44 
  45 public class BasicShortObject extends Basic {
  46 
  47     private static void test(String fs, String exp, Object ... args) {
  48         Formatter f = new Formatter(new StringBuilder(), Locale.US);
  49         f.format(fs, args);
  50         ck(fs, exp, f.toString());
  51 
  52         f = new Formatter(new StringBuilder(), Locale.US);
  53         f.format("foo " + fs + " bar", args);
  54         ck(fs, "foo " + exp + " bar", f.toString());



  55     }
  56 
  57     private static void test(Locale l, String fs, String exp, Object ... args)
  58     {
  59         Formatter f = new Formatter(new StringBuilder(), l);
  60         f.format(fs, args);
  61         ck(fs, exp, f.toString());
  62 
  63         f = new Formatter(new StringBuilder(), l);
  64         f.format("foo " + fs + " bar", args);
  65         ck(fs, "foo " + exp + " bar", f.toString());



  66     }
  67 
  68     private static void test(String fs, Object ... args) {
  69         Formatter f = new Formatter(new StringBuilder(), Locale.US);
  70         f.format(fs, args);
  71         ck(fs, "fail", f.toString());
  72     }
  73 
  74     private static void test(String fs) {
  75         Formatter f = new Formatter(new StringBuilder(), Locale.US);
  76         f.format(fs, "fail");
  77         ck(fs, "fail", f.toString());
  78     }
  79 
  80     private static void testSysOut(String fs, String exp, Object ... args) {
  81         FileOutputStream fos = null;
  82         FileInputStream fis = null;
  83         try {
  84             PrintStream saveOut = System.out;
  85             fos = new FileOutputStream("testSysOut");


 107                 if (fis != null)
 108                     fis.close();
 109             } catch (IOException ex) {
 110                 fail(fs, ex.getClass());
 111             }
 112         }
 113     }
 114 
 115     private static void tryCatch(String fs, Class<?> ex) {
 116         boolean caught = false;
 117         try {
 118             test(fs);
 119         } catch (Throwable x) {
 120             if (ex.isAssignableFrom(x.getClass()))
 121                 caught = true;
 122         }
 123         if (!caught)
 124             fail(fs, ex);
 125         else
 126             pass();


 127     }
 128 
 129     private static void tryCatch(String fs, Class<?> ex, Object ... args) {
 130         boolean caught = false;
 131         try {
 132             test(fs, args);






























 133         } catch (Throwable x) {
 134             if (ex.isAssignableFrom(x.getClass()))
 135                 caught = true;
 136         }
 137         if (!caught)
 138             fail(fs, ex);
 139         else
 140             pass();
 141     }
 142 
 143 
 144 
 145 
 146 
 147 
 148 
 149 
 150 
 151 
 152 




  35 import java.math.BigInteger;
  36 import java.text.DateFormatSymbols;
  37 import java.util.*;
  38 
  39 import static java.util.Calendar.*;
  40 
  41 
  42 
  43 
  44 
  45 public class BasicShortObject extends Basic {
  46 
  47     private static void test(String fs, String exp, Object ... args) {
  48         Formatter f = new Formatter(new StringBuilder(), Locale.US);
  49         f.format(fs, args);
  50         ck(fs, exp, f.toString());
  51 
  52         f = new Formatter(new StringBuilder(), Locale.US);
  53         f.format("foo " + fs + " bar", args);
  54         ck(fs, "foo " + exp + " bar", f.toString());
  55 
  56         JavacIntrinsicsSupport.formatAndCheck(fs, exp, Locale.US, args);
  57         JavacIntrinsicsSupport.formatAndCheck("foo " + fs + " bar", "foo " + exp + " bar", Locale.US, args);
  58     }
  59 
  60     private static void test(Locale l, String fs, String exp, Object ... args)
  61     {
  62         Formatter f = new Formatter(new StringBuilder(), l);
  63         f.format(fs, args);
  64         ck(fs, exp, f.toString());
  65 
  66         f = new Formatter(new StringBuilder(), l);
  67         f.format("foo " + fs + " bar", args);
  68         ck(fs, "foo " + exp + " bar", f.toString());
  69 
  70         JavacIntrinsicsSupport.formatAndCheck(fs, exp, l, args);
  71         JavacIntrinsicsSupport.formatAndCheck("foo " + fs + " bar", "foo " + exp + " bar", l, args);
  72     }
  73 
  74     private static void test(String fs, Object ... args) {
  75         Formatter f = new Formatter(new StringBuilder(), Locale.US);
  76         f.format(fs, args);
  77         ck(fs, "fail", f.toString());
  78     }
  79 
  80     private static void test(String fs) {
  81         Formatter f = new Formatter(new StringBuilder(), Locale.US);
  82         f.format(fs, "fail");
  83         ck(fs, "fail", f.toString());
  84     }
  85 
  86     private static void testSysOut(String fs, String exp, Object ... args) {
  87         FileOutputStream fos = null;
  88         FileInputStream fis = null;
  89         try {
  90             PrintStream saveOut = System.out;
  91             fos = new FileOutputStream("testSysOut");


 113                 if (fis != null)
 114                     fis.close();
 115             } catch (IOException ex) {
 116                 fail(fs, ex.getClass());
 117             }
 118         }
 119     }
 120 
 121     private static void tryCatch(String fs, Class<?> ex) {
 122         boolean caught = false;
 123         try {
 124             test(fs);
 125         } catch (Throwable x) {
 126             if (ex.isAssignableFrom(x.getClass()))
 127                 caught = true;
 128         }
 129         if (!caught)
 130             fail(fs, ex);
 131         else
 132             pass();
 133 
 134         tryCatchIntrinsic(fs, ex);
 135     }
 136 
 137     private static void tryCatch(String fs, Class<?> ex, Object ... args) {
 138         boolean caught = false;
 139         try {
 140             test(fs, args);
 141         } catch (Throwable x) {
 142             if (ex.isAssignableFrom(x.getClass()))
 143                 caught = true;
 144         }
 145         if (!caught)
 146             fail(fs, ex);
 147         else
 148             pass();
 149 
 150         tryCatchIntrinsic(fs, ex, args);
 151     }
 152 
 153     private static void tryCatchIntrinsic(String fs, Class<?> ex) {
 154         boolean caught = false;
 155         try {
 156             JavacIntrinsicsSupport.formatAndCheck(fs, "fail", Locale.US, "fail");
 157         } catch (Throwable x) {
 158             if (ex.isAssignableFrom(x.getClass()))
 159                 caught = true;
 160         }
 161         if (!caught)
 162             fail(fs, ex);
 163         else
 164             pass();
 165     }
 166 
 167     private static void tryCatchIntrinsic(String fs, Class<?> ex, Object ... args) {
 168         boolean caught = false;
 169         try {
 170             JavacIntrinsicsSupport.formatAndCheck(fs, "fail", Locale.US, args);
 171         } catch (Throwable x) {
 172             if (ex.isAssignableFrom(x.getClass()))
 173                 caught = true;
 174         }
 175         if (!caught)
 176             fail(fs, ex);
 177         else
 178             pass();
 179     }
 180 
 181 
 182 
 183 
 184 
 185 
 186 
 187 
 188 
 189 
 190 


< prev index next >