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
;
20 import java
.nio
.file
.Path
;
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
;
25 import org
.eclipse
.linuxtools
.pcap
.core
.tests
.shared
.PcapTestTrace
;
26 import org
.junit
.Test
;
29 * JUnit Class that tests whether the Pcap parser can read both big endian and
30 * little endian files.
32 * @author Vincent Perot
34 public class PcapFileEndiannessTest
{
37 * Test that verify that two files with different endianness contain the
40 * @throws BadPcapFileException
41 * Thrown when the file is erroneous. Fails the test.
43 * Thrown when an IO error occurs. Fails the test.
44 * @throws BadPacketException
45 * Thrown when a packet is erroneous. Fails the 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();
53 trace
= PcapTestTrace
.SHORT_LITTLE_ENDIAN
;
54 assumeTrue(trace
.exists());
55 Path path2
= PcapTestTrace
.SHORT_BIG_ENDIAN
.getPath();
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());
This page took 0.031007 seconds and 5 git commands to generate.