Skip to content

Commit

Permalink
8257856: Make ClassFileVersionsTest.java robust to JDK version updates
Browse files Browse the repository at this point in the history
Reviewed-by: mbaesken
Backport-of: 79aa7b15dbc54de891838ae2d4ca63838028c157
  • Loading branch information
RealCLanger committed May 10, 2023
1 parent 6a28ccb commit 7b2d5fc
Showing 1 changed file with 51 additions and 26 deletions.
77 changes: 51 additions & 26 deletions test/jdk/java/lang/module/ClassFileVersionsTest.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -43,40 +43,65 @@
import static org.testng.Assert.*;

public class ClassFileVersionsTest {
private static final int FEATURE;
static {
FEATURE = Runtime.version().feature();
assert FEATURE >= 10;
}

// major, minor, modifiers for requires java.base
@DataProvider(name = "supported")
public Object[][] supported() {
return new Object[][]{
{ 53, 0, Set.of() }, // JDK 9
{ 53, 0, Set.of(STATIC) },
{ 53, 0, Set.of(TRANSITIVE) },
{ 53, 0, Set.of(STATIC, TRANSITIVE) },

{ 54, 0, Set.of() }, // JDK 10

{ 55, 0, Set.of()}, // JDK 11
};
/*
* There are four test cases for JDK 9 and then one test case
* for each subsequent JDK version from JDK 10 to the current
* feature release for a total of (4 + (FEATURE - 9) ) =>
* (feature - 5) rows.
*/
Object[][] result = new Object[(FEATURE - 5)][];

// Class file version of JDK 9 is 53.0
result[0] = new Object[]{ 53, 0, Set.of()};
result[1] = new Object[]{ 53, 0, Set.of(STATIC) };
result[2] = new Object[]{ 53, 0, Set.of(TRANSITIVE) };
result[3] = new Object[]{ 53, 0, Set.of(STATIC, TRANSITIVE) };

// Major class file version of JDK N is 44 + n. Create rows
// for JDK 10 through FEATURE.
for (int i = 4; i < (FEATURE - 5) ; i++) {
result[i] = new Object[]{i + 50, 0, Set.of()};
}

return result;
}

// major, minor, modifiers for requires java.base
@DataProvider(name = "unsupported")
public Object[][] unsupported() {
return new Object[][]{
{ 50, 0, Set.of()}, // JDK 6
{ 51, 0, Set.of()}, // JDK 7
{ 52, 0, Set.of()}, // JDK 8

{ 54, 0, Set.of(STATIC) }, // JDK 10
{ 54, 0, Set.of(TRANSITIVE) },
{ 54, 0, Set.of(STATIC, TRANSITIVE) },

{ 55, 0, Set.of(STATIC) }, // JDK 11
{ 55, 0, Set.of(TRANSITIVE) },
{ 55, 0, Set.of(STATIC, TRANSITIVE) },

{ 56, 0, Set.of()}, // JDK 12
};
/*
* There are three test cases for releases prior to JDK 9,
* three test cases for each JDK version from JDK 10 to the
* current feature release, plus one addition test case for
* the next release for a total of (3 + (FEATURE - 9) * 3 + 1)
* rows.
*/
int unsupportedCount = 3 + (FEATURE - 9)*3 + 1;
Object[][] result = new Object[unsupportedCount][];

result[0] = new Object[]{50, 0, Set.of()}; // JDK 6
result[1] = new Object[]{51, 0, Set.of()}; // JDK 7
result[2] = new Object[]{52, 0, Set.of()}; // JDK 8

for (int i = 10; i <= FEATURE ; i++) {
int base = 3 + (i-10)*3;
// Major class file version of JDK N is 44+n
result[base] = new Object[]{i + 44, 0, Set.of(STATIC)};
result[base + 1] = new Object[]{i + 44, 0, Set.of(TRANSITIVE)};
result[base + 2] = new Object[]{i + 44, 0, Set.of(STATIC, TRANSITIVE)};
}

result[unsupportedCount - 1] = new Object[]{FEATURE+1+44, 0, Set.of()};
return result;
}

@Test(dataProvider = "supported")
Expand Down

1 comment on commit 7b2d5fc

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.