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
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
71f2817f 13package org.eclipse.tracecompass.pcap.core.tests.file;
a1d21447
VP
14
15import static org.junit.Assert.assertEquals;
16import static org.junit.Assume.assumeTrue;
17
18import java.io.IOException;
19import java.nio.ByteOrder;
333a2acb 20import java.nio.file.Path;
a1d21447 21
71f2817f
AM
22import org.eclipse.tracecompass.internal.pcap.core.packet.BadPacketException;
23import org.eclipse.tracecompass.internal.pcap.core.trace.BadPcapFileException;
24import org.eclipse.tracecompass.internal.pcap.core.trace.PcapFile;
25import org.eclipse.tracecompass.pcap.core.tests.shared.PcapTestTrace;
a1d21447
VP
26import 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 */
34public 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());
333a2acb 51 Path path1 = trace.getPath();
a1d21447
VP
52
53 trace = PcapTestTrace.SHORT_LITTLE_ENDIAN;
54 assumeTrue(trace.exists());
333a2acb 55 Path path2 = PcapTestTrace.SHORT_BIG_ENDIAN.getPath();
a1d21447
VP
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.047307 seconds and 5 git commands to generate.