Commit | Line | Data |
---|---|---|
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 | ||
13 | package org.eclipse.linuxtools.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; | |
333a2acb | 20 | import java.nio.file.Path; |
a1d21447 | 21 | |
93d1d135 AM |
22 | import org.eclipse.linuxtools.internal.pcap.core.packet.BadPacketException; |
23 | import org.eclipse.linuxtools.internal.pcap.core.trace.BadPcapFileException; | |
24 | import org.eclipse.linuxtools.internal.pcap.core.trace.PcapFile; | |
a1d21447 | 25 | import org.eclipse.linuxtools.pcap.core.tests.shared.PcapTestTrace; |
a1d21447 VP |
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()); | |
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 | } |