pcap: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / pcap / org.eclipse.tracecompass.pcap.core.tests / src / org / eclipse / tracecompass / pcap / core / tests / file / PcapFileOpenTest.java
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.tracecompass.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.tracecompass.internal.pcap.core.trace.BadPcapFileException;
22 import org.eclipse.tracecompass.internal.pcap.core.trace.PcapFile;
23 import org.eclipse.tracecompass.pcap.core.tests.shared.PcapTestTrace;
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 try (PcapFile file = new PcapFile(trace.getPath());) {
49 assertEquals(PcapTestTrace.EMPTY_PCAP.getPath(), file.getPath());
50 assertEquals(2, file.getMajorVersion());
51 assertEquals(4, file.getMinorVersion());
52 assertEquals(1, file.getDataLinkType());
53 assertEquals(65535, file.getSnapLength());
54 assertEquals(0, file.getTimeAccuracy());
55 assertEquals(0, file.getTimeZoneCorrection());
56 assertEquals(ByteOrder.LITTLE_ENDIAN, file.getByteOrder());
57
58 assertEquals(0, file.getTotalNbPackets());
59
60 }
61 }
62
63 /**
64 * Test that verify that an non-empty pcap file is properly opened and that
65 * the file properties are correct.
66 *
67 * @throws BadPcapFileException
68 * Thrown when the file is erroneous. Fails the test.
69 * @throws IOException
70 * Thrown when an IO error occurs. Fails the test.
71 */
72
73 @Test
74 public void FileOpenTest() throws IOException, BadPcapFileException {
75
76 PcapTestTrace trace = PcapTestTrace.MOSTLY_TCP;
77 assumeTrue(trace.exists());
78
79 try (PcapFile file = new PcapFile(trace.getPath());) {
80 assertEquals(PcapTestTrace.MOSTLY_TCP.getPath(), file.getPath());
81 assertEquals(2, file.getMajorVersion());
82 assertEquals(4, file.getMinorVersion());
83 assertEquals(1, file.getDataLinkType());
84 assertEquals(65535, file.getSnapLength());
85 assertEquals(0, file.getTimeAccuracy());
86 assertEquals(0, file.getTimeZoneCorrection());
87 assertEquals(ByteOrder.LITTLE_ENDIAN, file.getByteOrder());
88
89 assertEquals(43, file.getTotalNbPackets());
90
91 }
92 }
93
94 }
This page took 0.034687 seconds and 5 git commands to generate.