Path: blob/master/test/jdk/java/lang/System/VerifyRawIndexesTest.java
41149 views
/*1* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import jdk.internal.util.SystemProps.Raw;2425import org.testng.Assert;26import org.testng.annotations.Test;2728import java.lang.reflect.Field;29import java.lang.reflect.Modifier;303132/*33* @test34* @summary Test to verify that the SystemProps.Raw _xxx_NDX indices are unique and without gaps.35* @modules java.base/jdk.internal.util:+open36* @run testng VerifyRawIndexesTest37*/3839@Test40public class VerifyRawIndexesTest {4142/**43* Check that the Raw._*_NDX indexes are sequential and followed by44* the FIXED_LENGTH value.45* It verifies there there are no gaps or duplication in the declarations.46*/47@Test48void verifyIndexes() {49Field[] fields = Raw.class.getDeclaredFields();50int expectedModifiers = Modifier.PRIVATE | Modifier.STATIC | Modifier.FINAL;5152int next = 0; // indexes start at zero53int fixedLength = -1;54for (Field f : fields) {55try {56int mods = f.getModifiers();57String name = f.getName();58if (((mods & expectedModifiers) == expectedModifiers) &&59(name.endsWith("_NDX") || name.equals("FIXED_LENGTH"))) {60f.setAccessible(true);61int ndx = f.getInt(null);62System.out.printf("%s: %s%n", name, ndx);63Assert.assertEquals(ndx, next, "index value wrong");64if (name.equals("FIXED_LENGTH")) {65fixedLength = next; // remember for final check66}67next++;68} else {69System.out.printf("Ignoring field: " + f);70}71} catch (IllegalAccessException iae) {72Assert.fail("unexpected exception", iae);73}74}75Assert.assertEquals(next - 1, fixedLength,76"FIXED_LENGTH should be 1 greater than max of _NDX indexes");77}78}798081