Commit | Line | Data |
---|---|---|
a1d21447 VP |
1 | /******************************************************************************* |
2 | * Copyright (c) 2014 Ericsson | |
3 | * | |
4 | * All rights reserved. This program and the accompanying materials are | |
5 | * made available under the terms of the Eclipse Public License v1.0 which | |
6 | * accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * Vincent Perot - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.linuxtools.pcap.core.tests.file; | |
14 | ||
15 | import static org.junit.Assert.assertEquals; | |
16 | import static org.junit.Assume.assumeTrue; | |
17 | ||
18 | import java.io.IOException; | |
19 | import java.nio.ByteOrder; | |
20 | ||
21 | import org.eclipse.linuxtools.pcap.core.tests.shared.PcapTestTrace; | |
22 | import org.eclipse.linuxtools.pcap.core.trace.BadPcapFileException; | |
23 | import org.eclipse.linuxtools.pcap.core.trace.PcapFile; | |
24 | import org.junit.Test; | |
25 | ||
26 | /** | |
27 | * JUnit Class that tests the opening of valid pcap files. | |
28 | * | |
29 | * @author Vincent Perot | |
30 | */ | |
31 | public class PcapFileOpenTest { | |
32 | ||
33 | /** | |
34 | * Test that verify that an empty pcap file is properly opened and that the | |
35 | * file properties are correct. | |
36 | * | |
37 | * @throws BadPcapFileException | |
38 | * Thrown when the file is erroneous. Fails the test. | |
39 | * @throws IOException | |
40 | * Thrown when an IO error occurs. Fails the test. | |
41 | */ | |
42 | @Test | |
43 | public void FileOpenEmptyTest() throws IOException, BadPcapFileException { | |
44 | ||
45 | PcapTestTrace trace = PcapTestTrace.EMPTY_PCAP; | |
46 | assumeTrue(trace.exists()); | |
47 | ||
48 | String path = trace.getPath(); | |
49 | try (PcapFile file = new PcapFile(path);) { | |
50 | assertEquals(PcapTestTrace.EMPTY_PCAP.getPath(), file.getPath()); | |
51 | assertEquals(2, file.getMajorVersion()); | |
52 | assertEquals(4, file.getMinorVersion()); | |
53 | assertEquals(1, file.getDataLinkType()); | |
54 | assertEquals(65535, file.getSnapLength()); | |
55 | assertEquals(0, file.getTimeAccuracy()); | |
56 | assertEquals(0, file.getTimeZoneCorrection()); | |
57 | assertEquals(ByteOrder.LITTLE_ENDIAN, file.getByteOrder()); | |
58 | ||
59 | assertEquals(0, file.getTotalNbPackets()); | |
60 | ||
61 | } | |
62 | } | |
63 | ||
64 | /** | |
65 | * Test that verify that an non-empty pcap file is properly opened and that | |
66 | * the file properties are correct. | |
67 | * | |
68 | * @throws BadPcapFileException | |
69 | * Thrown when the file is erroneous. Fails the test. | |
70 | * @throws IOException | |
71 | * Thrown when an IO error occurs. Fails the test. | |
72 | */ | |
73 | ||
74 | @Test | |
75 | public void FileOpenTest() throws IOException, BadPcapFileException { | |
76 | ||
77 | PcapTestTrace trace = PcapTestTrace.MOSTLY_TCP; | |
78 | assumeTrue(trace.exists()); | |
79 | ||
80 | String path = trace.getPath(); | |
81 | try (PcapFile file = new PcapFile(path);) { | |
82 | assertEquals(PcapTestTrace.MOSTLY_TCP.getPath(), file.getPath()); | |
83 | assertEquals(2, file.getMajorVersion()); | |
84 | assertEquals(4, file.getMinorVersion()); | |
85 | assertEquals(1, file.getDataLinkType()); | |
86 | assertEquals(65535, file.getSnapLength()); | |
87 | assertEquals(0, file.getTimeAccuracy()); | |
88 | assertEquals(0, file.getTimeZoneCorrection()); | |
89 | assertEquals(ByteOrder.LITTLE_ENDIAN, file.getByteOrder()); | |
90 | ||
91 | assertEquals(43, file.getTotalNbPackets()); | |
92 | ||
93 | } | |
94 | } | |
95 | ||
96 | } |