jdk/test/tools/launcher/DefaultLocaleTest.java
author prr
Tue, 01 Jul 2014 10:20:56 -0700
changeset 25211 2476da7d73bf
parent 14342 8435a30053c1
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
14342
8435a30053c1 7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents: 11364
diff changeset
     2
 * Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
11364
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 5506
diff changeset
    24
import java.io.BufferedReader;
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 5506
diff changeset
    25
import java.io.BufferedWriter;
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 5506
diff changeset
    26
import java.io.File;
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 5506
diff changeset
    27
import java.io.IOException;
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 5506
diff changeset
    28
import java.nio.charset.Charset;
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 5506
diff changeset
    29
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 5506
diff changeset
    30
import static java.nio.file.Files.*;
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 5506
diff changeset
    31
import static java.nio.file.StandardOpenOption.*;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
public class DefaultLocaleTest {
11364
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 5506
diff changeset
    34
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 5506
diff changeset
    35
    static final String setting =
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
            "language:"   + System.getProperty("user.language") + "_" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
            "country:"    + System.getProperty("user.country")  + "_" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
            "encoding:"   + System.getProperty("file.encoding") + "_" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
            "jnuEncoding:"+ System.getProperty("sun.jnu.encoding");
11364
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 5506
diff changeset
    40
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 5506
diff changeset
    41
    public static void main(String[] args) throws IOException {
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 5506
diff changeset
    42
        if (args != null && args.length > 1) {
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 5506
diff changeset
    43
            File f = new File(args[1]);
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 5506
diff changeset
    44
            switch (args[0]) {
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 5506
diff changeset
    45
                case "-r":
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 5506
diff changeset
    46
                    System.out.println("reading file: " + args[1]);
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 5506
diff changeset
    47
                    String str = null;
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 5506
diff changeset
    48
                    try (BufferedReader in = newBufferedReader(f.toPath(),
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 5506
diff changeset
    49
                                    Charset.defaultCharset())) {
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 5506
diff changeset
    50
                        str = in.readLine().trim();
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 5506
diff changeset
    51
                    }
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 5506
diff changeset
    52
                    if (setting.equals(str)) {
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 5506
diff changeset
    53
                        System.out.println("Compared ok");
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 5506
diff changeset
    54
                    } else {
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 5506
diff changeset
    55
                        System.out.println("Compare fails");
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 5506
diff changeset
    56
                        System.out.println("EXPECTED: " + setting);
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 5506
diff changeset
    57
                        System.out.println("OBTAINED: " + str);
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 5506
diff changeset
    58
                        throw new RuntimeException("Test fails: compare failed");
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 5506
diff changeset
    59
                    }
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 5506
diff changeset
    60
                    break;
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 5506
diff changeset
    61
                case "-w":
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 5506
diff changeset
    62
                    System.out.println("writing file: " + args[1]);
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 5506
diff changeset
    63
                    try (BufferedWriter out = newBufferedWriter(f.toPath(),
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 5506
diff changeset
    64
                                    Charset.defaultCharset(), CREATE_NEW)) {
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 5506
diff changeset
    65
                        out.write(setting);
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 5506
diff changeset
    66
                    }
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 5506
diff changeset
    67
                    break;
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 5506
diff changeset
    68
                default:
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 5506
diff changeset
    69
                    throw new RuntimeException("ERROR: invalid arguments");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        } else {
11364
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 5506
diff changeset
    72
            throw new RuntimeException("ERROR: invalid arguments");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        }
11364
7907324fed4f 7124443: (launcher) test DefaultsLocaleTest fails with Windows shells.
ksrini
parents: 5506
diff changeset
    74
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
}