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 
  33 class CheckDataVersion {
  34     static final String datafile = "tablea1.txt";
  35     static final String FILEVERSIONKEY = "FILEVERSION=";
  36     static final String DATAVERSIONKEY = "DATAVERSION=";
  37     static String fileVersion;
  38     static String dataVersion;
  39     static boolean checked = false;
  40 
  41     static void check() {
  42         if (!checked) {
  43             try {
  44                 FileReader fr = new FileReader(new File(System.getProperty("test.src", "."), datafile));
  45                 BufferedReader in = new BufferedReader(fr);
  46                 String line;
  47 
  48                 while ((line = in.readLine()) != null) {
  49                     if (line.startsWith(FILEVERSIONKEY)) {
  50                         fileVersion = line.substring(FILEVERSIONKEY.length());
  51                     }
  52                     if (line.startsWith(DATAVERSIONKEY)) {
  53                         dataVersion = line.substring(DATAVERSIONKEY.length());
  54                     }
  55                     if (fileVersion != null && dataVersion != null) {
  56                         break;
  57                     }
  58                 }
  59             } catch (IOException ioe) {
  60                 throw new RuntimeException(ioe);
  61             }
  62 
  63             AccessController.doPrivileged(new PrivilegedAction<Object>() {
  64                 public Object run() {
  65                     try {
  66                         String sep = File.separator;
  67                         DataInputStream dis = new DataInputStream(new FileInputStream(System.getProperty("java.home")+sep+"lib"+sep+"currency.data"));
  68                         int magic = dis.readInt();
  69                         if (magic != 0x43757244) {
  70                             throw new RuntimeException("The magic number in the JRE's currency data is incorrect.  Expected: 0x43757244, Got: 0x"+magic);
  71                         }
  72                         int fileVerNumber = dis.readInt();
  73                         int dataVerNumber = dis.readInt();
  74                         if (Integer.parseInt(fileVersion) != fileVerNumber ||
  75                             Integer.parseInt(dataVersion) != dataVerNumber) {
  76                             throw new RuntimeException("Test data and JRE's currency data are inconsistent.  test: (file: "+fileVersion+" data: "+dataVersion+"), JRE: (file: "+fileVerNumber+" data: "+dataVerNumber+")");
  77                         }
  78 System.out.println("test: (file: "+fileVersion+" data: "+dataVersion+"), JRE: (file: "+fileVerNumber+" data: "+dataVerNumber+")");
  79                     } catch (IOException ioe) {
  80                         throw new RuntimeException(ioe);
  81                     }
  82                     return null;
  83                 }
  84             });
  85             checked = true;
  86         }
  87     }
  88 }