|
| 1 | +/* |
| 2 | + * Copyright 2026 Damon Lu and open-source contributors |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.damon233.performtrackermod.utils.platform.windows; |
| 18 | + |
| 19 | +import org.junit.jupiter.api.Test; |
| 20 | +import org.junit.jupiter.params.ParameterizedTest; |
| 21 | +import org.junit.jupiter.params.provider.CsvSource; |
| 22 | + |
| 23 | +import static org.junit.jupiter.api.Assertions.*; |
| 24 | + |
| 25 | +class WindowsVersionTypeTest { |
| 26 | + |
| 27 | + @ParameterizedTest |
| 28 | + @CsvSource({ |
| 29 | + "5, 1, 0, WINDOWS_XP", |
| 30 | + "5, 2, 0, WINDOWS_SERVER_2003", |
| 31 | + "6, 0, 0, WINDOWS_VISTA", |
| 32 | + "6, 1, 0, WINDOWS_7", |
| 33 | + "6, 2, 0, WINDOWS_8", |
| 34 | + "6, 3, 0, WINDOWS_8_1" |
| 35 | + }) |
| 36 | + void fromNtVersion_preWindows10_returnsCorrectType(int major, int minor, int build, WindowsVersionType expected) { |
| 37 | + assertEquals(expected, WindowsVersionType.fromNtVersion(major, minor, build)); |
| 38 | + } |
| 39 | + |
| 40 | + @ParameterizedTest |
| 41 | + @CsvSource({ |
| 42 | + "10, 0, 0, WINDOWS_10", |
| 43 | + "10, 0, 10240, WINDOWS_10", |
| 44 | + "10, 0, 14393, WINDOWS_10", |
| 45 | + "10, 0, 19045, WINDOWS_10", |
| 46 | + "10, 0, 21996, WINDOWS_11", |
| 47 | + "10, 0, 22631, WINDOWS_11", |
| 48 | + "10, 0, 26100, WINDOWS_11" |
| 49 | + }) |
| 50 | + void fromNtVersion_windows10And11_detectsCorrectly(int major, int minor, int build, WindowsVersionType expected) { |
| 51 | + assertEquals(expected, WindowsVersionType.fromNtVersion(major, minor, build)); |
| 52 | + } |
| 53 | + |
| 54 | + @Test |
| 55 | + void fromNtVersion_unknownVersion_returnsUnknown() { |
| 56 | + assertEquals(WindowsVersionType.UNKNOWN, WindowsVersionType.fromNtVersion(4, 0, 0)); |
| 57 | + assertEquals(WindowsVersionType.UNKNOWN, WindowsVersionType.fromNtVersion(0, 0, 0)); |
| 58 | + } |
| 59 | + |
| 60 | + @Test |
| 61 | + void isWindows11_onlyWindows11_returnsTrue() { |
| 62 | + assertTrue(WindowsVersionType.WINDOWS_11.isWindows11()); |
| 63 | + } |
| 64 | + |
| 65 | + @ParameterizedTest |
| 66 | + @CsvSource({ |
| 67 | + "WINDOWS_XP", |
| 68 | + "WINDOWS_SERVER_2003", |
| 69 | + "WINDOWS_VISTA", |
| 70 | + "WINDOWS_7", |
| 71 | + "WINDOWS_8", |
| 72 | + "WINDOWS_8_1", |
| 73 | + "WINDOWS_10", |
| 74 | + "UNKNOWN" |
| 75 | + }) |
| 76 | + void isWindows11_otherTypes_returnsFalse(WindowsVersionType type) { |
| 77 | + assertFalse(type.isWindows11()); |
| 78 | + } |
| 79 | + |
| 80 | + @ParameterizedTest |
| 81 | + @CsvSource({ |
| 82 | + "WINDOWS_XP, Windows XP", |
| 83 | + "WINDOWS_SERVER_2003, Windows Server 2003", |
| 84 | + "WINDOWS_VISTA, Windows Vista", |
| 85 | + "WINDOWS_7, Windows 7", |
| 86 | + "WINDOWS_8, Windows 8", |
| 87 | + "WINDOWS_8_1, Windows 8.1", |
| 88 | + "WINDOWS_10, Windows 10", |
| 89 | + "WINDOWS_11, Windows 11", |
| 90 | + "UNKNOWN, Unknown" |
| 91 | + }) |
| 92 | + void getProductName_returnsCorrectName(WindowsVersionType type, String expectedName) { |
| 93 | + assertEquals(expectedName, type.getProductName()); |
| 94 | + } |
| 95 | +} |
0 commit comments