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
.Assert
.fail
;
17 import static org
.junit
.Assume
.assumeTrue
;
19 import java
.io
.IOException
;
21 import org
.eclipse
.linuxtools
.internal
.pcap
.core
.trace
.BadPcapFileException
;
22 import org
.eclipse
.linuxtools
.internal
.pcap
.core
.trace
.PcapFile
;
23 import org
.eclipse
.linuxtools
.pcap
.core
.tests
.shared
.PcapTestTrace
;
24 import org
.junit
.Test
;
27 * JUnit Class that tests the opening of non-valid pcap files.
29 * @author Vincent Perot
31 public class PcapFileOpenFailTest
{
34 * Test that tries to open a pcap with a bad magic number
37 * Thrown when an IO error occurs. Fails the test.
40 public void FileOpenBadPcapTest() throws IOException
{
41 PcapTestTrace trace
= PcapTestTrace
.BAD_PCAPFILE
;
42 assumeTrue(trace
.exists());
44 try (PcapFile file
= new PcapFile(trace
.getPath());) {
45 fail("The pcap was accepted even though the magic number is invalid!");
46 } catch (BadPcapFileException e
) {
47 assertEquals("c3d4a1b2 is not a known magic number.", e
.getMessage());
52 * Test that tries to open a non-pcap binary file
55 * Thrown when an IO error occurs. Fails the test.
58 public void FileOpenBinaryFile() throws IOException
{
59 PcapTestTrace trace
= PcapTestTrace
.KERNEL_TRACE
;
60 assumeTrue(trace
.exists());
62 try (PcapFile file
= new PcapFile(trace
.getPath());) {
63 fail("The file was accepted even though it is not a pcap file!");
64 } catch (BadPcapFileException e
) {
65 assertEquals("c11ffcc1 is not a known magic number.", e
.getMessage());
70 * Test that tries to open a directory
73 * Thrown when an IO error occurs. Fails the test.
76 public void FileOpenDirectory() throws IOException
{
77 PcapTestTrace trace
= PcapTestTrace
.KERNEL_DIRECTORY
;
78 assumeTrue(trace
.exists());
80 try (PcapFile file
= new PcapFile(trace
.getPath());) {
81 fail("The file was accepted even though it is not a pcap file!");
82 } catch (BadPcapFileException e
) {
83 assertEquals("Bad Pcap File.", e
.getMessage());
This page took 0.052948 seconds and 5 git commands to generate.