test/jdk/java/util/logging/FileHandlerPatternGeneration.java
author mikael
Mon, 29 Jul 2019 09:59:04 -0700
changeset 57584 9d82a35b6ff7
parent 47725 a4fb389ca61a
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47725
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
     1
/*
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
     4
 *
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
     7
 * published by the Free Software Foundation.
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
     8
 *
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    13
 * accompanied this code).
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    14
 *
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    18
 *
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    21
 * questions.
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    22
 */
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    23
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    24
import java.io.ByteArrayInputStream;
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    25
import java.io.ByteArrayOutputStream;
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    26
import java.io.File;
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    27
import java.io.IOException;
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    28
import java.lang.reflect.InvocationTargetException;
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    29
import java.lang.reflect.Method;
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    30
import java.nio.file.Files;
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    31
import java.nio.file.Paths;
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    32
import java.security.*;
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    33
import java.util.*;
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    34
import java.util.concurrent.atomic.AtomicBoolean;
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    35
import java.util.logging.FileHandler;
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    36
import java.util.logging.LogManager;
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    37
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    38
/**
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    39
 * @test
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    40
 * @bug 8189953
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    41
 * @summary tests the pattern generation algorithm
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    42
 * @modules java.logging/java.util.logging:open
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    43
 * @run main/othervm FileHandlerPatternGeneration
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    44
 * @author danielfuchs
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    45
 */
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    46
public class FileHandlerPatternGeneration {
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    47
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    48
    /**
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    49
     * An array of strings where the elements at even indices are the input
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    50
     * to give to FileHandler::generate(pattern, count, generation, unique),
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    51
     * and the elements at the next odd index are a partially computed expected
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    52
     * output, where %t, %h, %u, %g and file separator still need to be replaced.
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    53
     * The final expected output is obtained by passing the partially computed
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    54
     * output to FileHandlerPatternGeneration::generateExpected
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    55
     * <p>
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    56
     * The test verifies that {@code
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    57
     *    FileHandler.generate(PATTERN[i], c, g, u).toString()
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    58
     * }
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    59
     * is equal to {@code
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    60
     *    FileHandlerPatternGeneration.generateExpected(PATTERN[i],
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    61
     *                                                  PATTERN[i+1],
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    62
     *                                                  c, g, u)
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    63
     * }
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    64
     */
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    65
    static final String[] PATTERNS = {
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    66
            "C:/Workspace/hoge.log",         "C:/Workspace/hoge.log",
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    67
            "C:/Workspace%g/hoge.log",       "C:/Workspace%g/hoge.log",
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    68
            "C:/%uWorkspace/hoge.log",       "C:/%uWorkspace/hoge.log",
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    69
            "C:/%uWorkspace%g/hoge.log",     "C:/%uWorkspace%g/hoge.log",
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    70
            "C:/Workspace/%ghoge.log",       "C:/Workspace/%ghoge.log",
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    71
            "C:/Workspace/%ghoge%u.log",     "C:/Workspace/%ghoge%u.log",
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    72
            "C:/Workspace-%g/hoge.log",      "C:/Workspace-%g/hoge.log",
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    73
            "C:/Work%hspace/hoge.log",       "%h/space/hoge.log",
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    74
            "C:/Works%tpace%g/hoge.log",     "%t/pace%g/hoge.log",
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    75
            "C:/%uWork%hspace/hoge.log",     "%h/space/hoge.log",
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    76
            "C:/%uWorkspace%g/%thoge.log",   "%t/hoge.log",
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    77
            "C:/Workspace/%g%h%%hoge.log",   "%h/%%hoge.log",
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    78
            "C:/Work%h%%hspace/hoge.log",    "%h/%%hspace/hoge.log",
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    79
            "C:/Works%t%%hpace%g/hoge.log",  "%t/%%hpace%g/hoge.log",
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    80
            "C:/%uWork%h%%tspace/hoge.log",  "%h/%%tspace/hoge.log",
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    81
            "C:/%uWorkspace%g/%t%%hoge.log", "%t/%%hoge.log",
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    82
            "C:/Workspace/%g%h%%hoge.log",   "%h/%%hoge.log",
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    83
            "ahaha",                         "ahaha",
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    84
            "ahaha/ahabe",                   "ahaha/ahabe",
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    85
            "../ahaha/ahabe",                "../ahaha/ahabe",
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    86
            "/x%ty/w/hoge.log",              "%t/y/w/hoge.log",
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    87
            "/x/%ty/w/hoge.log",             "%t/y/w/hoge.log",
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    88
            "/x%t/y/w/hoge.log",             "%t/y/w/hoge.log",
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    89
            "/x/%t/y/w/hoge.log",            "%t/y/w/hoge.log",
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    90
            "%ty/w/hoge.log",                "%t/y/w/hoge.log",
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    91
            "%t/y/w/hoge.log",               "%t/y/w/hoge.log",
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    92
            "/x%hy/w/hoge.log",              "%h/y/w/hoge.log",
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    93
            "/x/%hy/w/hoge.log",             "%h/y/w/hoge.log",
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    94
            "/x%h/y/w/hoge.log",             "%h/y/w/hoge.log",
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    95
            "/x/%h/y/w/hoge.log",            "%h/y/w/hoge.log",
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    96
            "%hy/w/hoge.log",                "%h/y/w/hoge.log",
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    97
            "%h/y/w/hoge.log",               "%h/y/w/hoge.log",
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    98
            "ahaha-%u-%g",                   "ahaha-%u-%g",
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
    99
            "ahaha-%g/ahabe-%u",             "ahaha-%g/ahabe-%u",
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   100
            "../ahaha-%u/ahabe",             "../ahaha-%u/ahabe",
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   101
            "/x%ty/w/hoge-%g.log",           "%t/y/w/hoge-%g.log",
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   102
            "/x/%ty/w/hoge-%u.log",          "%t/y/w/hoge-%u.log",
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   103
            "%u-%g/x%t/y/w/hoge.log",        "%t/y/w/hoge.log",
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   104
            "/x/%g%t%u/y/w/hoge.log",        "%t/%u/y/w/hoge.log",
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   105
            "%ty/w-%g/hoge.log",             "%t/y/w-%g/hoge.log",
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   106
            "%t/y/w-%u/hoge.log",            "%t/y/w-%u/hoge.log",
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   107
            "/x%hy/%u-%g-w/hoge.log",        "%h/y/%u-%g-w/hoge.log",
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   108
            "/x/%hy/w-%u-%g/hoge.log",       "%h/y/w-%u-%g/hoge.log",
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   109
            "/x%h/y/w/%u-%ghoge.log",        "%h/y/w/%u-%ghoge.log",
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   110
            "/x/%h/y/w/hoge-%u-%g.log",      "%h/y/w/hoge-%u-%g.log",
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   111
            "%hy/w/%u-%g-hoge.log",          "%h/y/w/%u-%g-hoge.log",
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   112
            "%h/y/w/hoge-%u-%g.log",         "%h/y/w/hoge-%u-%g.log",
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   113
            "/x/y/z/hoge-%u.log",            "/x/y/z/hoge-%u.log",
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   114
    };
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   115
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   116
    // the (count, generation, unique) parameters to pass to
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   117
    // FileHandler.generate(pattern, count, generation, unique)
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   118
    static final int[][] GENERATIONS = {
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   119
        {0, 0, 0},
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   120
        {0, 1, 0},
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   121
        {0, 1, 1},
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   122
        {1, 1, 0},
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   123
        {1, 1, 1},
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   124
        {1, 1, 2},
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   125
        {1, 2, 3},
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   126
        {3, 4, 0},
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   127
        {3, 4, 1},
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   128
        {3, 4, 2},
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   129
        {3, 0, 5},
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   130
        {3, 1, 5},
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   131
        {3, 2, 5},
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   132
    };
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   133
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   134
    static final Class<FileHandler> FILE_HANDLER_CLASS = FileHandler.class;
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   135
    static final Method GENERATE;
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   136
    static final String USER_HOME;
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   137
    static final String TMP;
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   138
    static {
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   139
        Method generate;
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   140
        try {
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   141
           generate = FILE_HANDLER_CLASS.getDeclaredMethod("generate",
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   142
                                                            String.class,
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   143
                                                            int.class,
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   144
                                                            int.class,
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   145
                                                            int.class);
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   146
           generate.setAccessible(true);
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   147
        } catch (Exception e) {
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   148
            throw new ExceptionInInitializerError(e);
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   149
        }
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   150
        GENERATE = generate;
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   151
        USER_HOME = System.getProperty("user.home");
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   152
        TMP = System.getProperty("java.io.tmpdir", USER_HOME);
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   153
    }
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   154
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   155
    public static void main(String... args) throws Throwable {
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   156
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   157
        for (int i=0; i < PATTERNS.length; i+=2) {
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   158
            String s = PATTERNS[i];
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   159
            String partial = PATTERNS[i+1];
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   160
            System.out.println("generate: " + s);
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   161
            for (int[] gen : GENERATIONS) {
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   162
                String expected = generateExpected(s, partial, gen[0], gen[1], gen[2]);
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   163
                String output = generate(s, gen[0], gen[1], gen[2]).toString();
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   164
                System.out.println("\t" + Arrays.toString(gen)+ ": " + output);
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   165
                if (!expected.equals(output)) {
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   166
                    throw new RuntimeException("test failed for \""
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   167
                            + s +"\" " + Arrays.toString(gen) + ": "
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   168
                            + "\n\tgenerated: \"" + output +"\""
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   169
                            + "\n\t expected: \"" + expected +"\"");
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   170
                }
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   171
            }
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   172
        }
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   173
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   174
    }
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   175
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   176
    // Strip the trailing separator from the string, if present
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   177
    static String stripTrailingSeparator(String s) {
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   178
        if (s.endsWith("/")) {
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   179
            return s.substring(0, s.length() -1);
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   180
        } else if (s.endsWith(File.separator)) {
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   181
            return s.substring(0, s.length() - File.separator.length());
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   182
        } else {
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   183
            return s;
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   184
        }
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   185
    }
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   186
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   187
    /**
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   188
     * Compute the final expected output from a partially computed output found
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   189
     * at PATTERNS[i+1]
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   190
     * @param s           The pattern string, found at PATTERN[i]
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   191
     *                    (with i % 2 == 0)
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   192
     * @param partial     The partially computed output, found at PATTERN[i+1]
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   193
     * @param count       The count parameter given to FileHandler::generate
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   194
     * @param generation  The generation parameter given to FileHandler::generate
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   195
     * @param unique      The unique parameter given to FileHandler::generate
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   196
     * @return  The expected output that FileHandler.generate(s, count, gen, unique)
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   197
     *          should produce.
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   198
     */
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   199
    static String generateExpected(String s, String partial,
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   200
                                   int count, int generation, int unique)
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   201
    {
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   202
        boolean sawu = s.replace("%%", "$$$$").contains("%u");
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   203
        boolean sawg = s.replace("%%", "$$$$").contains("%g");
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   204
        String result = partial.replace("%%", "$$$$");
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   205
        String tmp = stripTrailingSeparator(TMP);
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   206
        String home = stripTrailingSeparator(USER_HOME);
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   207
        result = result.replace("%h", home);
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   208
        result = result.replace("%t", tmp);
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   209
        result = result.replace("%g", String.valueOf(generation));
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   210
        result = result.replace("%u", String.valueOf(unique));
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   211
        result = result.replace("$$$$", "%");
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   212
        result = result.replace("/", File.separator);
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   213
        if (count > 1 && !sawg) {
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   214
            result = result + "." + generation;
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   215
        }
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   216
        if (unique > 0 && !sawu) {
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   217
            result = result + "." + unique;
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   218
        }
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   219
        return result;
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   220
    }
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   221
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   222
    // Calls FileHandler.generate(s, count, generation, unique) through reflection
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   223
    static File generate(String s, int count, int generation, int unique)
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   224
            throws Throwable
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   225
    {
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   226
        try {
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   227
            return (File) GENERATE.invoke(null, s, count, generation, unique);
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   228
        } catch (InvocationTargetException e) {
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   229
            throw e.getCause();
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   230
        }
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   231
    }
a4fb389ca61a 8189953: FileHandler constructor throws NoSuchFileException with absolute path
dfuchs
parents:
diff changeset
   232
}