1 /*******************************************************************************
2 * Copyright (c) 2014 Ericsson
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
10 * Vincent Perot - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.pcap
.core
.tests
.file
;
15 import static org
.junit
.Assert
.assertEquals
;
16 import static org
.junit
.Assume
.assumeTrue
;
18 import java
.io
.IOException
;
19 import java
.nio
.ByteOrder
;
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
;
27 * JUnit Class that tests the opening of valid pcap files.
29 * @author Vincent Perot
31 public class PcapFileOpenTest
{
34 * Test that verify that an empty pcap file is properly opened and that the
35 * file properties are correct.
37 * @throws BadPcapFileException
38 * Thrown when the file is erroneous. Fails the test.
40 * Thrown when an IO error occurs. Fails the test.
43 public void FileOpenEmptyTest() throws IOException
, BadPcapFileException
{
45 PcapTestTrace trace
= PcapTestTrace
.EMPTY_PCAP
;
46 assumeTrue(trace
.exists());
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());
58 assertEquals(0, file
.getTotalNbPackets());
64 * Test that verify that an non-empty pcap file is properly opened and that
65 * the file properties are correct.
67 * @throws BadPcapFileException
68 * Thrown when the file is erroneous. Fails the test.
70 * Thrown when an IO error occurs. Fails the test.
74 public void FileOpenTest() throws IOException
, BadPcapFileException
{
76 PcapTestTrace trace
= PcapTestTrace
.MOSTLY_TCP
;
77 assumeTrue(trace
.exists());
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());
89 assertEquals(43, file
.getTotalNbPackets());
This page took 0.033674 seconds and 6 git commands to generate.