|
33 | 33 | import processing.app.TestHelper;
|
34 | 34 |
|
35 | 35 | import static org.junit.Assert.assertEquals;
|
| 36 | +import static processing.app.macosx.SystemProfilerParser.extractVIDAndPID; |
| 37 | + |
| 38 | +import java.io.IOException; |
| 39 | +import java.io.InputStream; |
36 | 40 |
|
37 | 41 | public class SystemProfilerParserTest {
|
38 | 42 |
|
39 | 43 | @Test
|
40 | 44 | public void shouldCorrectlyParse() throws Exception {
|
41 |
| - String output = TestHelper.inputStreamToString(SystemProfilerParserTest.class.getResourceAsStream("system_profiler_output.txt")); |
42 |
| - |
43 |
| - assertEquals("0X2341_0X0044", new SystemProfilerParser().extractVIDAndPID(output, "/dev/cu.usbmodemfa121")); |
44 |
| - assertEquals("0X2341_0X0044", new SystemProfilerParser().extractVIDAndPID(output, "/dev/tty.usbmodemfa121")); |
45 |
| - |
46 |
| - output = TestHelper.inputStreamToString(SystemProfilerParserTest.class.getResourceAsStream("system_profiler_output2.txt")); |
47 |
| - |
48 |
| - assertEquals("0X2341_0X8036", new SystemProfilerParser().extractVIDAndPID(output, "/dev/cu.usbmodemfd131")); |
49 |
| - assertEquals("0X2341_0X8036", new SystemProfilerParser().extractVIDAndPID(output, "/dev/tty.usbmodemfd131")); |
50 |
| - |
51 |
| - output = TestHelper.inputStreamToString(SystemProfilerParserTest.class.getResourceAsStream("system_profiler_output3.txt")); |
52 |
| - |
53 |
| - assertEquals("0X2341_0X8041", new SystemProfilerParser().extractVIDAndPID(output, "/dev/cu.usbmodemfd121")); |
54 |
| - assertEquals("0X2341_0X8041", new SystemProfilerParser().extractVIDAndPID(output, "/dev/tty.usbmodemfd121")); |
55 |
| - |
56 |
| - output = TestHelper.inputStreamToString(SystemProfilerParserTest.class.getResourceAsStream("system_profiler_output4.txt")); |
57 |
| - |
58 |
| - assertEquals("0X2341_0X0041", new SystemProfilerParser().extractVIDAndPID(output, "/dev/cu.usbmodem411")); |
59 |
| - assertEquals("0X2341_0X0041", new SystemProfilerParser().extractVIDAndPID(output, "/dev/tty.usbmodem411")); |
60 |
| - |
61 |
| - output = TestHelper.inputStreamToString(SystemProfilerParserTest.class.getResourceAsStream("system_profiler_output5.txt")); |
62 |
| - |
63 |
| - assertEquals("0X2341_0X8041", new SystemProfilerParser().extractVIDAndPID(output, "/dev/cu.usbmodem621")); |
64 |
| - assertEquals("0X2341_0X8041", new SystemProfilerParser().extractVIDAndPID(output, "/dev/tty.usbmodem621")); |
65 |
| - |
66 |
| - output = TestHelper.inputStreamToString(SystemProfilerParserTest.class.getResourceAsStream("system_profiler_output6.txt")); |
67 |
| - |
68 |
| - assertEquals("0X2341_0X8041", new SystemProfilerParser().extractVIDAndPID(output, "/dev/cu.usbmodem1421")); |
69 |
| - assertEquals("0X2341_0X8041", new SystemProfilerParser().extractVIDAndPID(output, "/dev/tty.usbmodem1421")); |
70 |
| - |
71 |
| - output = TestHelper.inputStreamToString(SystemProfilerParserTest.class.getResourceAsStream("system_profiler_output7.txt")); |
72 |
| - |
73 |
| - assertEquals("0X2341_0X8036", new SystemProfilerParser().extractVIDAndPID(output, "/dev/cu.usbmodem24131")); |
74 |
| - assertEquals("0X2341_0X8036", new SystemProfilerParser().extractVIDAndPID(output, "/dev/tty.usbmodem24131")); |
75 |
| - assertEquals("0X0403_0X6015", new SystemProfilerParser().extractVIDAndPID(output, "/dev/cu.usbserial-DN0031EV")); |
76 |
| - assertEquals("0X0403_0X6015", new SystemProfilerParser().extractVIDAndPID(output, "/dev/tty.usbserial-DN0031EV")); |
77 |
| - |
78 |
| - output = TestHelper.inputStreamToString(SystemProfilerParserTest.class.getResourceAsStream("system_profiler_output8.txt")); |
| 45 | + String output = getFileContent("system_profiler_output.txt"); |
| 46 | + assertEquals("0X2341_0X0044", extractVIDAndPID(output, "/dev/cu.usbmodemfa121")); |
| 47 | + assertEquals("0X2341_0X0044", extractVIDAndPID(output, "/dev/tty.usbmodemfa121")); |
| 48 | + |
| 49 | + output = getFileContent("system_profiler_output2.txt"); |
| 50 | + assertEquals("0X2341_0X8036", extractVIDAndPID(output, "/dev/cu.usbmodemfd131")); |
| 51 | + assertEquals("0X2341_0X8036", extractVIDAndPID(output, "/dev/tty.usbmodemfd131")); |
| 52 | + |
| 53 | + output = getFileContent("system_profiler_output3.txt"); |
| 54 | + assertEquals("0X2341_0X8041", extractVIDAndPID(output, "/dev/cu.usbmodemfd121")); |
| 55 | + assertEquals("0X2341_0X8041", extractVIDAndPID(output, "/dev/tty.usbmodemfd121")); |
| 56 | + |
| 57 | + output = getFileContent("system_profiler_output4.txt"); |
| 58 | + assertEquals("0X2341_0X0041", extractVIDAndPID(output, "/dev/cu.usbmodem411")); |
| 59 | + assertEquals("0X2341_0X0041", extractVIDAndPID(output, "/dev/tty.usbmodem411")); |
| 60 | + |
| 61 | + output = getFileContent("system_profiler_output5.txt"); |
| 62 | + assertEquals("0X2341_0X8041", extractVIDAndPID(output, "/dev/cu.usbmodem621")); |
| 63 | + assertEquals("0X2341_0X8041", extractVIDAndPID(output, "/dev/tty.usbmodem621")); |
| 64 | + |
| 65 | + output = getFileContent("system_profiler_output6.txt"); |
| 66 | + assertEquals("0X2341_0X8041", extractVIDAndPID(output, "/dev/cu.usbmodem1421")); |
| 67 | + assertEquals("0X2341_0X8041", extractVIDAndPID(output, "/dev/tty.usbmodem1421")); |
| 68 | + |
| 69 | + output = getFileContent("system_profiler_output7.txt"); |
| 70 | + assertEquals("0X2341_0X8036", extractVIDAndPID(output, "/dev/cu.usbmodem24131")); |
| 71 | + assertEquals("0X2341_0X8036", extractVIDAndPID(output, "/dev/tty.usbmodem24131")); |
| 72 | + assertEquals("0X0403_0X6015", extractVIDAndPID(output, "/dev/cu.usbserial-DN0031EV")); |
| 73 | + assertEquals("0X0403_0X6015", extractVIDAndPID(output, "/dev/tty.usbserial-DN0031EV")); |
| 74 | + |
| 75 | + output = getFileContent("system_profiler_output8.txt"); |
| 76 | + assertEquals("0X03EB_0X2157", extractVIDAndPID(output, "/dev/tty.usbmodemfd132")); |
| 77 | + |
| 78 | + // OSX El Capitan |
| 79 | + output = getFileContent("system_profiler_output9.txt"); |
| 80 | + assertEquals("0X2341_0X8036", extractVIDAndPID(output, "/dev/tty.usbmodemFA121")); |
| 81 | + } |
79 | 82 |
|
80 |
| - assertEquals("0X03EB_0X2157", new SystemProfilerParser().extractVIDAndPID(output, "/dev/tty.usbmodemfd132")); |
| 83 | + private String getFileContent(String filename) throws IOException { |
| 84 | + InputStream resource = SystemProfilerParserTest.class.getResourceAsStream(filename); |
| 85 | + return TestHelper.inputStreamToString(resource); |
81 | 86 | }
|
82 | 87 | }
|
0 commit comments