< prev index next >

test/java/util/Currency/CheckDataVersion.java

Print this page


   1 /*
   2  * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 /**
  24  *
  25  *
  26  * Check the consistency between the regression tests and the currency data in the JRE
  27  */
  28 
  29 import java.io.*;
  30 import java.lang.reflect.*;


  31 import java.security.*;
  32 import java.util.Currency;
  33 
  34 class CheckDataVersion {
  35     static final String datafile = "tablea1.txt";
  36     static final String FILEVERSIONKEY = "FILEVERSION=";
  37     static final String DATAVERSIONKEY = "DATAVERSION=";
  38     static String fileVersion;
  39     static String dataVersion;
  40     static boolean checked = false;
  41 
  42     static void check() {
  43         if (!checked) {
  44             try {
  45                 FileReader fr = new FileReader(new File(System.getProperty("test.src", "."), datafile));
  46                 BufferedReader in = new BufferedReader(fr);
  47                 String line;
  48 
  49                 while ((line = in.readLine()) != null) {
  50                     if (line.startsWith(FILEVERSIONKEY)) {
  51                         fileVersion = line.substring(FILEVERSIONKEY.length());
  52                     }
  53                     if (line.startsWith(DATAVERSIONKEY)) {
  54                         dataVersion = line.substring(DATAVERSIONKEY.length());
  55                     }
  56                     if (fileVersion != null && dataVersion != null) {
  57                         break;
  58                     }
  59                 }
  60             } catch (IOException ioe) {
  61                 throw new RuntimeException(ioe);
  62             }
  63 
  64             AccessController.doPrivileged(new PrivilegedAction<Object>() {
  65                 public Object run() {
  66                     try {
  67                         InputStream in = Currency.class.getModule().getResourceAsStream("java/util/currency.data");
  68                         String sep = File.separator;
  69                         DataInputStream dis = new DataInputStream(in);

  70                         int magic = dis.readInt();
  71                         if (magic != 0x43757244) {
  72                             throw new RuntimeException("The magic number in the JRE's currency data is incorrect.  Expected: 0x43757244, Got: 0x"+magic);
  73                         }
  74                         int fileVerNumber = dis.readInt();
  75                         int dataVerNumber = dis.readInt();
  76                         if (Integer.parseInt(fileVersion) != fileVerNumber ||
  77                             Integer.parseInt(dataVersion) != dataVerNumber) {
  78                             throw new RuntimeException("Test data and JRE's currency data are inconsistent.  test: (file: "+fileVersion+" data: "+dataVersion+"), JRE: (file: "+fileVerNumber+" data: "+dataVerNumber+")");
  79                         }
  80 System.out.println("test: (file: "+fileVersion+" data: "+dataVersion+"), JRE: (file: "+fileVerNumber+" data: "+dataVerNumber+")");
  81                     } catch (IOException ioe) {
  82                         throw new RuntimeException(ioe);
  83                     }
  84                     return null;
  85                 }
  86             });
  87             checked = true;
  88         }
  89     }
   1 /*
   2  * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 /**
  24  *
  25  *
  26  * Check the consistency between the regression tests and the currency data in the JRE
  27  */
  28 
  29 import java.io.*;
  30 import java.lang.reflect.*;
  31 import java.nio.file.Files;
  32 import java.nio.file.Paths;
  33 import java.security.*;
  34 import java.util.Currency;
  35 
  36 class CheckDataVersion {
  37     static final String datafile = "tablea1.txt";
  38     static final String FILEVERSIONKEY = "FILEVERSION=";
  39     static final String DATAVERSIONKEY = "DATAVERSION=";
  40     static String fileVersion;
  41     static String dataVersion;
  42     static boolean checked = false;
  43 
  44     static void check() {
  45         if (!checked) {
  46             try {
  47                 FileReader fr = new FileReader(new File(System.getProperty("test.src", "."), datafile));
  48                 BufferedReader in = new BufferedReader(fr);
  49                 String line;
  50 
  51                 while ((line = in.readLine()) != null) {
  52                     if (line.startsWith(FILEVERSIONKEY)) {
  53                         fileVersion = line.substring(FILEVERSIONKEY.length());
  54                     }
  55                     if (line.startsWith(DATAVERSIONKEY)) {
  56                         dataVersion = line.substring(DATAVERSIONKEY.length());
  57                     }
  58                     if (fileVersion != null && dataVersion != null) {
  59                         break;
  60                     }
  61                 }
  62             } catch (IOException ioe) {
  63                 throw new RuntimeException(ioe);
  64             }
  65 
  66             AccessController.doPrivileged(new PrivilegedAction<Object>() {
  67                 public Object run() {
  68                     try {
  69                         DataInputStream dis = new DataInputStream(
  70                                 new BufferedInputStream(Files.newInputStream(
  71                                         Paths.get(System.getProperty("java.home"),
  72                                                 "lib", "currency.data"))));
  73                         int magic = dis.readInt();
  74                         if (magic != 0x43757244) {
  75                             throw new RuntimeException("The magic number in the JRE's currency data is incorrect.  Expected: 0x43757244, Got: 0x"+magic);
  76                         }
  77                         int fileVerNumber = dis.readInt();
  78                         int dataVerNumber = dis.readInt();
  79                         if (Integer.parseInt(fileVersion) != fileVerNumber ||
  80                             Integer.parseInt(dataVersion) != dataVerNumber) {
  81                             throw new RuntimeException("Test data and JRE's currency data are inconsistent.  test: (file: "+fileVersion+" data: "+dataVersion+"), JRE: (file: "+fileVerNumber+" data: "+dataVerNumber+")");
  82                         }
  83 System.out.println("test: (file: "+fileVersion+" data: "+dataVersion+"), JRE: (file: "+fileVerNumber+" data: "+dataVerNumber+")");
  84                     } catch (IOException ioe) {
  85                         throw new RuntimeException(ioe);
  86                     }
  87                     return null;
  88                 }
  89             });
  90             checked = true;
  91         }
  92     }
< prev index next >