author | herrick |
Fri, 01 Nov 2019 10:25:15 -0400 | |
branch | JDK-8200758-branch |
changeset 58890 | 6539ad1d90aa |
parent 58696 | 61c44899b4eb |
permissions | -rw-r--r-- |
58696 | 1 |
/* |
2 |
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
package jdk.jpackage.internal; |
|
24 |
||
58890
6539ad1d90aa
8233333 : Incorrect comparison of number version strings in ToolValidator
herrick
parents:
58696
diff
changeset
|
25 |
import java.util.ArrayList; |
58696 | 26 |
import java.util.List; |
58890
6539ad1d90aa
8233333 : Incorrect comparison of number version strings in ToolValidator
herrick
parents:
58696
diff
changeset
|
27 |
import java.util.function.Function; |
58696 | 28 |
import org.junit.Test; |
29 |
import org.junit.runner.RunWith; |
|
30 |
import org.junit.runners.Parameterized; |
|
31 |
import org.junit.runners.Parameterized.Parameters; |
|
32 |
import static org.junit.Assert.*; |
|
33 |
||
34 |
@RunWith(Parameterized.class) |
|
35 |
public class CompareDottedVersionTest { |
|
36 |
||
58890
6539ad1d90aa
8233333 : Incorrect comparison of number version strings in ToolValidator
herrick
parents:
58696
diff
changeset
|
37 |
public CompareDottedVersionTest(boolean greedy, String version1, |
6539ad1d90aa
8233333 : Incorrect comparison of number version strings in ToolValidator
herrick
parents:
58696
diff
changeset
|
38 |
String version2, int result) { |
58696 | 39 |
this.version1 = version1; |
40 |
this.version2 = version2; |
|
41 |
this.expectedResult = result; |
|
58890
6539ad1d90aa
8233333 : Incorrect comparison of number version strings in ToolValidator
herrick
parents:
58696
diff
changeset
|
42 |
|
6539ad1d90aa
8233333 : Incorrect comparison of number version strings in ToolValidator
herrick
parents:
58696
diff
changeset
|
43 |
if (greedy) { |
6539ad1d90aa
8233333 : Incorrect comparison of number version strings in ToolValidator
herrick
parents:
58696
diff
changeset
|
44 |
createTestee = DottedVersion::greedy; |
6539ad1d90aa
8233333 : Incorrect comparison of number version strings in ToolValidator
herrick
parents:
58696
diff
changeset
|
45 |
} else { |
6539ad1d90aa
8233333 : Incorrect comparison of number version strings in ToolValidator
herrick
parents:
58696
diff
changeset
|
46 |
createTestee = DottedVersion::lazy; |
6539ad1d90aa
8233333 : Incorrect comparison of number version strings in ToolValidator
herrick
parents:
58696
diff
changeset
|
47 |
} |
58696 | 48 |
} |
49 |
||
50 |
@Parameters |
|
51 |
public static List<Object[]> data() { |
|
58890
6539ad1d90aa
8233333 : Incorrect comparison of number version strings in ToolValidator
herrick
parents:
58696
diff
changeset
|
52 |
List<Object[]> data = new ArrayList<>(); |
6539ad1d90aa
8233333 : Incorrect comparison of number version strings in ToolValidator
herrick
parents:
58696
diff
changeset
|
53 |
for (var greedy : List.of(true, false)) { |
6539ad1d90aa
8233333 : Incorrect comparison of number version strings in ToolValidator
herrick
parents:
58696
diff
changeset
|
54 |
data.addAll(List.of(new Object[][] { |
6539ad1d90aa
8233333 : Incorrect comparison of number version strings in ToolValidator
herrick
parents:
58696
diff
changeset
|
55 |
{ greedy, "00.0.0", "0", 0 }, |
6539ad1d90aa
8233333 : Incorrect comparison of number version strings in ToolValidator
herrick
parents:
58696
diff
changeset
|
56 |
{ greedy, "0.035", "0.0035", 0 }, |
6539ad1d90aa
8233333 : Incorrect comparison of number version strings in ToolValidator
herrick
parents:
58696
diff
changeset
|
57 |
{ greedy, "1", "1", 0 }, |
6539ad1d90aa
8233333 : Incorrect comparison of number version strings in ToolValidator
herrick
parents:
58696
diff
changeset
|
58 |
{ greedy, "2", "2.0", 0 }, |
6539ad1d90aa
8233333 : Incorrect comparison of number version strings in ToolValidator
herrick
parents:
58696
diff
changeset
|
59 |
{ greedy, "2.00", "2.0", 0 }, |
6539ad1d90aa
8233333 : Incorrect comparison of number version strings in ToolValidator
herrick
parents:
58696
diff
changeset
|
60 |
{ greedy, "1.2.3.4", "1.2.3.4.5", -1 }, |
6539ad1d90aa
8233333 : Incorrect comparison of number version strings in ToolValidator
herrick
parents:
58696
diff
changeset
|
61 |
{ greedy, "34", "33", 1 }, |
6539ad1d90aa
8233333 : Incorrect comparison of number version strings in ToolValidator
herrick
parents:
58696
diff
changeset
|
62 |
{ greedy, "34.0.78", "34.1.78", -1 } |
6539ad1d90aa
8233333 : Incorrect comparison of number version strings in ToolValidator
herrick
parents:
58696
diff
changeset
|
63 |
})); |
6539ad1d90aa
8233333 : Incorrect comparison of number version strings in ToolValidator
herrick
parents:
58696
diff
changeset
|
64 |
} |
6539ad1d90aa
8233333 : Incorrect comparison of number version strings in ToolValidator
herrick
parents:
58696
diff
changeset
|
65 |
|
6539ad1d90aa
8233333 : Incorrect comparison of number version strings in ToolValidator
herrick
parents:
58696
diff
changeset
|
66 |
data.addAll(List.of(new Object[][] { |
6539ad1d90aa
8233333 : Incorrect comparison of number version strings in ToolValidator
herrick
parents:
58696
diff
changeset
|
67 |
{ false, "", "1", -1 }, |
6539ad1d90aa
8233333 : Incorrect comparison of number version strings in ToolValidator
herrick
parents:
58696
diff
changeset
|
68 |
{ false, "1.2.4-R4", "1.2.4-R5", 0 }, |
6539ad1d90aa
8233333 : Incorrect comparison of number version strings in ToolValidator
herrick
parents:
58696
diff
changeset
|
69 |
{ false, "1.2.4.-R4", "1.2.4.R5", 0 }, |
6539ad1d90aa
8233333 : Incorrect comparison of number version strings in ToolValidator
herrick
parents:
58696
diff
changeset
|
70 |
{ false, "7+1", "7+4", 0 }, |
6539ad1d90aa
8233333 : Incorrect comparison of number version strings in ToolValidator
herrick
parents:
58696
diff
changeset
|
71 |
{ false, "2+14", "2-14", 0 }, |
6539ad1d90aa
8233333 : Incorrect comparison of number version strings in ToolValidator
herrick
parents:
58696
diff
changeset
|
72 |
{ false, "23.4.RC4", "23.3.RC10", 1 }, |
6539ad1d90aa
8233333 : Incorrect comparison of number version strings in ToolValidator
herrick
parents:
58696
diff
changeset
|
73 |
{ false, "77.0", "77.99999999999999999999999999999999999999999999999", 0 }, |
6539ad1d90aa
8233333 : Incorrect comparison of number version strings in ToolValidator
herrick
parents:
58696
diff
changeset
|
74 |
})); |
6539ad1d90aa
8233333 : Incorrect comparison of number version strings in ToolValidator
herrick
parents:
58696
diff
changeset
|
75 |
|
6539ad1d90aa
8233333 : Incorrect comparison of number version strings in ToolValidator
herrick
parents:
58696
diff
changeset
|
76 |
return data; |
58696 | 77 |
} |
78 |
||
79 |
@Test |
|
80 |
public void testIt() { |
|
81 |
int actualResult = compare(version1, version2); |
|
82 |
assertEquals(expectedResult, actualResult); |
|
83 |
||
84 |
int actualNegateResult = compare(version2, version1); |
|
85 |
assertEquals(actualResult, -1 * actualNegateResult); |
|
86 |
} |
|
87 |
||
58890
6539ad1d90aa
8233333 : Incorrect comparison of number version strings in ToolValidator
herrick
parents:
58696
diff
changeset
|
88 |
private int compare(String x, String y) { |
6539ad1d90aa
8233333 : Incorrect comparison of number version strings in ToolValidator
herrick
parents:
58696
diff
changeset
|
89 |
int result = createTestee.apply(x).compareTo(y); |
58696 | 90 |
|
91 |
if (result < 0) { |
|
92 |
return -1; |
|
93 |
} |
|
94 |
||
95 |
if (result > 0) { |
|
96 |
return 1; |
|
97 |
} |
|
98 |
||
99 |
return 0; |
|
100 |
} |
|
101 |
||
102 |
private final String version1; |
|
103 |
private final String version2; |
|
104 |
private final int expectedResult; |
|
58890
6539ad1d90aa
8233333 : Incorrect comparison of number version strings in ToolValidator
herrick
parents:
58696
diff
changeset
|
105 |
private final Function<String, DottedVersion> createTestee; |
58696 | 106 |
} |