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 / PcapFileOpenFailTest.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.Assert.fail;
17import static org.junit.Assume.assumeTrue;
18
19import java.io.IOException;
20
71f2817f
AM
21import org.eclipse.tracecompass.internal.pcap.core.trace.BadPcapFileException;
22import org.eclipse.tracecompass.internal.pcap.core.trace.PcapFile;
23import org.eclipse.tracecompass.pcap.core.tests.shared.PcapTestTrace;
a1d21447
VP
24import org.junit.Test;
25
26/**
27 * JUnit Class that tests the opening of non-valid pcap files.
28 *
29 * @author Vincent Perot
30 */
31public class PcapFileOpenFailTest {
32
33 /**
34 * Test that tries to open a pcap with a bad magic number
35 *
36 * @throws IOException
37 * Thrown when an IO error occurs. Fails the test.
38 */
39 @Test
40 public void FileOpenBadPcapTest() throws IOException {
41 PcapTestTrace trace = PcapTestTrace.BAD_PCAPFILE;
42 assumeTrue(trace.exists());
43
333a2acb 44 try (PcapFile file = new PcapFile(trace.getPath());) {
a1d21447
VP
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());
48 }
49 }
50
51 /**
52 * Test that tries to open a non-pcap binary file
53 *
54 * @throws IOException
55 * Thrown when an IO error occurs. Fails the test.
56 */
57 @Test
58 public void FileOpenBinaryFile() throws IOException {
59 PcapTestTrace trace = PcapTestTrace.KERNEL_TRACE;
60 assumeTrue(trace.exists());
61
333a2acb 62 try (PcapFile file = new PcapFile(trace.getPath());) {
a1d21447
VP
63 fail("The file was accepted even though it is not a pcap file!");
64 } catch (BadPcapFileException e) {
333a2acb 65 assertEquals("c11ffcc1 is not a known magic number.", e.getMessage());
a1d21447
VP
66 }
67 }
68
69 /**
70 * Test that tries to open a directory
71 *
72 * @throws IOException
73 * Thrown when an IO error occurs. Fails the test.
74 */
75 @Test
76 public void FileOpenDirectory() throws IOException {
77 PcapTestTrace trace = PcapTestTrace.KERNEL_DIRECTORY;
78 assumeTrue(trace.exists());
79
333a2acb 80 try (PcapFile file = new PcapFile(trace.getPath());) {
a1d21447
VP
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());
84 }
85 }
86}
This page took 0.044181 seconds and 5 git commands to generate.