1
2
3
4
5 package oshi.util;
6
7 import static org.hamcrest.MatcherAssert.assertThat;
8 import static org.hamcrest.Matchers.arrayWithSize;
9 import static org.hamcrest.Matchers.is;
10
11 import org.junit.jupiter.api.Test;
12
13
14
15
16 class EdidUtilTest {
17
18 private static final String EDID_HEADER = "00FFFFFFFFFFFF00";
19 private static final String EDID_MANUFID = "0610";
20 private static final String EDID_PRODCODE = "2792";
21 private static final String EDID_SERIAL = "250C2C16";
22 private static final String EDID_WKYR = "2C16";
23 private static final String EDID_VERSION = "0104";
24 private static final String EDID_VIDEO = "B53C2278226FB1A7554C9E250C5054000000";
25 private static final String EDID_TIMING = "01010101010101010101010101010101";
26 private static final String EDID_DESC1 = "565E00A0A0A029503020350055502100001A";
27 private static final String EDID_DESC2 = "1A1D008051D01C204080350055502100001C";
28 private static final String EDID_DESC3 = "000000FF004330324A4D325046463247430A";
29 private static final String EDID_DESC4 = "000000FC005468756E646572626F6C740A20";
30 private static final String EDID_DESC5 = "000000FA004330324A4D325046463247430A";
31 private static final String EDID_DESC6 = "000000FB005468756E646572626F6C740A20";
32 private static final String EDID_DESC7 = "000000FD004330324A4D325046463247430A";
33 private static final String EDID_DESC8 = "000000FE005468756E646572626F6C740A20";
34 private static final String EDID_EXTS = "01";
35 private static final String EDID_CHKSUM = "C7";
36 private static final String EDID_STR = EDID_HEADER + EDID_MANUFID + EDID_PRODCODE + EDID_SERIAL + EDID_WKYR
37 + EDID_VERSION + EDID_VIDEO + EDID_TIMING + EDID_DESC1 + EDID_DESC2 + EDID_DESC3 + EDID_DESC4 + EDID_EXTS
38 + EDID_CHKSUM;
39 private static final String EDID_STR2 = EDID_HEADER + EDID_MANUFID + EDID_PRODCODE + EDID_SERIAL + EDID_WKYR
40 + EDID_VERSION + EDID_VIDEO + EDID_TIMING + EDID_DESC5 + EDID_DESC6 + EDID_DESC7 + EDID_DESC8 + EDID_EXTS
41 + EDID_CHKSUM;
42 private static final byte[] EDID = ParseUtil.hexStringToByteArray(EDID_STR);
43
44 @Test
45 void testGetEdidAttrs() {
46 assertThat("manufacturerId", EdidUtil.getManufacturerID(EDID), is("A"));
47 assertThat("productId", EdidUtil.getProductID(EDID), is("9227"));
48 assertThat("serialNo", EdidUtil.getSerialNo(EDID), is("162C0C25"));
49 assertThat("week", EdidUtil.getWeek(EDID), is((byte) 44));
50 assertThat("year", EdidUtil.getYear(EDID), is(2012));
51 assertThat("version", EdidUtil.getVersion(EDID), is("1.4"));
52 assertThat("digital", EdidUtil.isDigital(EDID), is(true));
53 assertThat("hcm", EdidUtil.getHcm(EDID), is(60));
54 assertThat("vcm", EdidUtil.getVcm(EDID), is(34));
55 }
56
57 @Test
58 void testGetDescriptors() {
59 byte[][] descs = EdidUtil.getDescriptors(EDID);
60 for (int i = 0; i < 4; i++) {
61 int type = EdidUtil.getDescriptorType(descs[i]);
62 String timing = EdidUtil.getTimingDescriptor(descs[i]);
63 String range = EdidUtil.getDescriptorRangeLimits(descs[i]);
64 switch (i) {
65 case 0:
66 assertThat("desc 0 type", type, is(0x565E00A0));
67 assertThat("desc 0 timing", timing, is("Clock 241MHz, Active Pixels 2560x1440 "));
68 assertThat("desc 0 range", range,
69 is("Field Rate -96-41 Hz vertical, 80-48 Hz horizontal, Max clock: 320 MHz"));
70 break;
71 case 1:
72 assertThat("desc 1 type", type, is(0x1A1D0080));
73 assertThat("desc 1 timing", timing, is("Clock 74MHz, Active Pixels 1280x720 "));
74 assertThat("desc 1 range", range,
75 is("Field Rate -48-28 Hz vertical, 32-64 Hz horizontal, Max clock: -1280 MHz"));
76 break;
77 case 2:
78 assertThat("desc 2 type", type, is(0xFF));
79 assertThat("desc 2 descriptorText", EdidUtil.getDescriptorText(descs[i]), is("C02JM2PFF2GC"));
80 assertThat("desc 2 descriptorHex", ParseUtil.byteArrayToHexString(descs[i]), is(EDID_DESC3));
81 break;
82 case 3:
83 assertThat("desc 3 type", type, is(0xFC));
84 assertThat("desc 3 descriptorText", EdidUtil.getDescriptorText(descs[i]), is("Thunderbolt"));
85 break;
86 default:
87 }
88 }
89 }
90
91 @Test
92 void testToString() {
93 assertThat("edid toString", EdidUtil.toString(EDID).split("\\n"), is(arrayWithSize(6)));
94 assertThat("edid2 toString", EdidUtil.toString(ParseUtil.hexStringToByteArray(EDID_STR2)).split("\\n"),
95 is(arrayWithSize(6)));
96 }
97 }