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
.pcap
.core
.tests
.shared
.PcapTestTrace
;
22 import org
.eclipse
.linuxtools
.pcap
.core
.trace
.BadPcapFileException
;
23 import org
.eclipse
.linuxtools
.pcap
.core
.trace
.PcapFile
;
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 String path
= trace
.getPath();
45 try (PcapFile file
= new PcapFile(path
);) {
46 fail("The pcap was accepted even though the magic number is invalid!");
47 } catch (BadPcapFileException e
) {
48 assertEquals("c3d4a1b2 is not a known magic number.", e
.getMessage());
53 * Test that tries to open a non-pcap binary file
56 * Thrown when an IO error occurs. Fails the test.
59 public void FileOpenBinaryFile() throws IOException
{
60 PcapTestTrace trace
= PcapTestTrace
.KERNEL_TRACE
;
61 assumeTrue(trace
.exists());
63 String path
= trace
.getPath();
64 try (PcapFile file
= new PcapFile(path
);) {
65 fail("The file was accepted even though it is not a pcap file!");
66 } catch (BadPcapFileException e
) {
67 assertEquals("Bad Pcap File.", e
.getMessage());
72 * Test that tries to open a directory
75 * Thrown when an IO error occurs. Fails the test.
78 public void FileOpenDirectory() throws IOException
{
79 PcapTestTrace trace
= PcapTestTrace
.KERNEL_DIRECTORY
;
80 assumeTrue(trace
.exists());
82 String path
= trace
.getPath();
83 try (PcapFile file
= new PcapFile(path
);) {
84 fail("The file was accepted even though it is not a pcap file!");
85 } catch (BadPcapFileException e
) {
86 assertEquals("Bad Pcap File.", e
.getMessage());
This page took 0.032967 seconds and 5 git commands to generate.