test/tools/javac/annotations/repeatingAnnotations/combo/TestCaseGenerator.java

changeset 1661
cfb65ca92082
parent 1633
35cef52b0023
parent 1660
28e466e9cd34
child 1662
4a48f3173534
child 1671
46d2f144ebbd
     1.1 --- a/test/tools/javac/annotations/repeatingAnnotations/combo/TestCaseGenerator.java	Thu Mar 28 10:55:14 2013 -0700
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,191 +0,0 @@
     1.4 -/*
     1.5 - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
     1.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 - *
     1.8 - * This code is free software; you can redistribute it and/or modify it
     1.9 - * under the terms of the GNU General Public License version 2 only, as
    1.10 - * published by the Free Software Foundation.
    1.11 - *
    1.12 - * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 - * version 2 for more details (a copy is included in the LICENSE file that
    1.16 - * accompanied this code).
    1.17 - *
    1.18 - * You should have received a copy of the GNU General Public License version
    1.19 - * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 - *
    1.22 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 - * or visit www.oracle.com if you need additional information or have any
    1.24 - * questions.
    1.25 - */
    1.26 -
    1.27 -import java.util.ArrayList;
    1.28 -import java.util.HashSet;
    1.29 -import java.util.List;
    1.30 -import java.util.Random;
    1.31 -
    1.32 -/* System properties:
    1.33 - * NumberOfTests, TestMode, and TestCaseNum are mutually exclusive
    1.34 - * TestSeed will be used only with NumberOfTests or TestMode, otherwise it will be ignored
    1.35 - * -DNumberOfTests=[0 to 2^20+2^11+1]
    1.36 - * -DTestMode=[FULL|DEFAULT]
    1.37 - * -DTestSeed=[seedNumber]
    1.38 - * -DTestCaseNum=[0 to 2^20+2^11+1]
    1.39 - */
    1.40 -public class TestCaseGenerator {
    1.41 -    // Total number of tests to be run
    1.42 -    int numberOfTests = -1;
    1.43 -    //Single test case
    1.44 -    int testCaseNum = -1;
    1.45 -    //Seed used to generate test cases
    1.46 -    int testSeed;
    1.47 -
    1.48 -    int maxTestNum;
    1.49 -    Random randNum;
    1.50 -
    1.51 -    // used in getNextTestCase
    1.52 -    int curTestNum;
    1.53 -    int testCompletedCount;
    1.54 -    HashSet<Integer> uniqueTestSet;
    1.55 -
    1.56 -    static final int DEFAULT_TEST_COUNT = 250;
    1.57 -
    1.58 -    /*
    1.59 -     *  Get parameter values from command line to set numberOfTests, testCaseNum,
    1.60 -     *  and testSeed
    1.61 -     */
    1.62 -    public TestCaseGenerator(int maxTestNum) {
    1.63 -        this.maxTestNum = maxTestNum;
    1.64 -
    1.65 -        // Set values for variables based on input from command line
    1.66 -
    1.67 -        // TestMode system property
    1.68 -        String testModeVal = System.getProperty("TestMode");
    1.69 -        if(testModeVal != null && !testModeVal.isEmpty()) {
    1.70 -            switch (testModeVal.toUpperCase()) {
    1.71 -            case "FULL":
    1.72 -                numberOfTests = maxTestNum;
    1.73 -                break;
    1.74 -            case "DEFAULT":
    1.75 -                numberOfTests = DEFAULT_TEST_COUNT;
    1.76 -                break;
    1.77 -            default:
    1.78 -                System.out.println("Invalid property value " + testModeVal +
    1.79 -                        " for numberOfTests. Possible range: 0 to " +
    1.80 -                        maxTestNum + ". Ignoring property");
    1.81 -                numberOfTests = -1;
    1.82 -            }
    1.83 -        }
    1.84 -
    1.85 -        // NumberOfTests system property
    1.86 -        String numTestsStr = System.getProperty("NumberOfTests");
    1.87 -        if(numTestsStr != null && !numTestsStr.isEmpty()) {
    1.88 -            int numTests = -1;
    1.89 -            try {
    1.90 -                numTests = Integer.parseInt(numTestsStr);
    1.91 -                if (numTests < 0 || numTests > maxTestNum) {
    1.92 -                    throw new NumberFormatException();
    1.93 -                }
    1.94 -            } catch(NumberFormatException nfe) {
    1.95 -                System.out.println("Invalid NumberOfTests property value " +
    1.96 -                        numTestsStr + ". Possible range: 0 to " + maxTestNum +
    1.97 -                        "Reset to default: " + DEFAULT_TEST_COUNT);
    1.98 -                numTests = DEFAULT_TEST_COUNT;
    1.99 -            }
   1.100 -
   1.101 -            if (numberOfTests != -1 && numTests != -1) {
   1.102 -                System.out.println("TestMode and NumberOfTests cannot be set together. Ignoring TestMode.");
   1.103 -            }
   1.104 -            numberOfTests = numTests;
   1.105 -        }
   1.106 -
   1.107 -        // TestSeed system property
   1.108 -        String seedVal = System.getProperty("TestSeed");
   1.109 -        if(seedVal != null && !seedVal.isEmpty()) {
   1.110 -            try {
   1.111 -                testSeed = Integer.parseInt(seedVal);
   1.112 -            } catch(NumberFormatException nfe) {
   1.113 -                Random srand = new Random();
   1.114 -                testSeed = srand.nextInt();
   1.115 -            }
   1.116 -        } else {
   1.117 -            Random srand = new Random();
   1.118 -            testSeed = srand.nextInt();
   1.119 -        }
   1.120 -
   1.121 -        // TestCaseNum system property
   1.122 -        String testNumStr = System.getProperty("TestCaseNum");
   1.123 -        if(testNumStr != null && !testNumStr.isEmpty()) {
   1.124 -            try {
   1.125 -                testCaseNum = Integer.parseInt(testNumStr);
   1.126 -                if (testCaseNum < 0 || testCaseNum > maxTestNum) {
   1.127 -                    throw new NumberFormatException();
   1.128 -                }
   1.129 -            } catch(NumberFormatException nfe) {
   1.130 -                System.out.println("Invalid TestCaseNumber property value " +
   1.131 -                        testNumStr + ". Possible value in range: 0 to " +
   1.132 -                        maxTestNum + ". Defaulting to last test case.");
   1.133 -                testCaseNum = maxTestNum;
   1.134 -            }
   1.135 -
   1.136 -            if ( numberOfTests != -1) {
   1.137 -                System.out.println("TestMode or NumberOfTests cannot be set along with TestCaseNum. Ignoring TestCaseNumber.");
   1.138 -                testCaseNum = -1;
   1.139 -            }
   1.140 -        }
   1.141 -
   1.142 -        if (numberOfTests == -1 && testCaseNum == -1) {
   1.143 -            numberOfTests = DEFAULT_TEST_COUNT;
   1.144 -            System.out.println("Setting TestMode to default, will run " + numberOfTests + "tests.");
   1.145 -        }
   1.146 -
   1.147 -        /*
   1.148 -         *  By this point in code, we will have:
   1.149 -         *  - testSeed: as per TestSeed or a Random one
   1.150 -         *  - numberOfTests to run or -1 to denote not set
   1.151 -         *  - testCaseNum to run or -1 to denote not set
   1.152 -         */
   1.153 -
   1.154 -        /*
   1.155 -         * If numberOfTests = maxTestNum, all tests are to be run,
   1.156 -         * so no randNum will be required
   1.157 -         */
   1.158 -        if (numberOfTests != -1 && numberOfTests < maxTestNum) {
   1.159 -            System.out.println("Seed = " + testSeed);
   1.160 -            randNum = new Random(testSeed);
   1.161 -            uniqueTestSet = new HashSet<>();
   1.162 -        }
   1.163 -
   1.164 -        testCompletedCount = 0;
   1.165 -        // to be used to keep sequential count when running all tests
   1.166 -        curTestNum = 0;
   1.167 -    }
   1.168 -
   1.169 -    /*
   1.170 -     * returns next test case number to run
   1.171 -     * returns -1 when there are no more tests to run
   1.172 -     */
   1.173 -    public int getNextTestCase() {
   1.174 -        if (testCaseNum != -1) {
   1.175 -            int nextTC = testCaseNum;
   1.176 -            testCaseNum = -1;
   1.177 -            return nextTC;
   1.178 -        }
   1.179 -        if (++testCompletedCount <= numberOfTests) {
   1.180 -            if (numberOfTests == maxTestNum) {
   1.181 -                //all the tests need to be run, so just return
   1.182 -                //next test case sequentially
   1.183 -                return curTestNum++;
   1.184 -            } else {
   1.185 -                int nextTC = -1;
   1.186 -                // Ensuring unique test are run
   1.187 -                while(!uniqueTestSet.add(nextTC = randNum.nextInt(maxTestNum))) {
   1.188 -                }
   1.189 -                return nextTC;
   1.190 -            }
   1.191 -        }
   1.192 -        return -1;
   1.193 -    }
   1.194 -}

mercurial