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