pcap: Add unit tests to pcap.core
[deliverable/tracecompass.git] / org.eclipse.linuxtools.pcap.core.tests / src / org / eclipse / linuxtools / pcap / core / tests / file / PcapFileEndiannessTest.java
CommitLineData
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
13package org.eclipse.linuxtools.pcap.core.tests.file;
14
15import static org.junit.Assert.assertEquals;
16import static org.junit.Assume.assumeTrue;
17
18import java.io.IOException;
19import java.nio.ByteOrder;
20
21import org.eclipse.linuxtools.pcap.core.packet.BadPacketException;
22import org.eclipse.linuxtools.pcap.core.tests.shared.PcapTestTrace;
23import org.eclipse.linuxtools.pcap.core.trace.BadPcapFileException;
24import org.eclipse.linuxtools.pcap.core.trace.PcapFile;
25import org.junit.Test;
26
27/**
28 * JUnit Class that tests whether the Pcap parser can read both big endian and
29 * little endian files.
30 *
31 * @author Vincent Perot
32 */
33public class PcapFileEndiannessTest {
34
35 /**
36 * Test that verify that two files with different endianness contain the
37 * same packets.
38 *
39 * @throws BadPcapFileException
40 * Thrown when the file is erroneous. Fails the test.
41 * @throws IOException
42 * Thrown when an IO error occurs. Fails the test.
43 * @throws BadPacketException
44 * Thrown when a packet is erroneous. Fails the test.
45 */
46 @Test
47 public void EndiannessTest() throws IOException, BadPcapFileException, BadPacketException {
48 PcapTestTrace trace = PcapTestTrace.SHORT_LITTLE_ENDIAN;
49 assumeTrue(trace.exists());
50 String path1 = trace.getPath();
51
52 trace = PcapTestTrace.SHORT_LITTLE_ENDIAN;
53 assumeTrue(trace.exists());
54 String path2 = PcapTestTrace.SHORT_BIG_ENDIAN.getPath();
55
56 try (PcapFile littleEndian = new PcapFile(path1);
57 PcapFile bigEndian = new PcapFile(path2);) {
58 assertEquals(ByteOrder.BIG_ENDIAN, bigEndian.getByteOrder());
59 assertEquals(ByteOrder.LITTLE_ENDIAN, littleEndian.getByteOrder());
60 while (littleEndian.hasNextPacket() && bigEndian.hasNextPacket()) {
61 assertEquals(littleEndian.parseNextPacket(), bigEndian.parseNextPacket());
62 }
63 }
64 }
65}
This page took 0.027133 seconds and 5 git commands to generate.