lttng: Move plugins to the Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.pcap.core.tests / shared / org / eclipse / linuxtools / pcap / core / tests / shared / PcapTestTrace.java
CommitLineData
a1d21447
VP
1/*******************************************************************************
2 * Copyright (c) 2014 Ericsson
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Vincent Perot - Initial API and implementation
10 *******************************************************************************/
11
12package org.eclipse.linuxtools.pcap.core.tests.shared;
13
a1d21447 14import java.io.IOException;
333a2acb
AM
15import java.nio.file.FileSystems;
16import java.nio.file.Files;
17import java.nio.file.Path;
a1d21447
VP
18
19import org.eclipse.jdt.annotation.NonNull;
93d1d135
AM
20import org.eclipse.linuxtools.internal.pcap.core.trace.BadPcapFileException;
21import org.eclipse.linuxtools.internal.pcap.core.trace.PcapFile;
a1d21447
VP
22
23/**
24 * Here is the list of the available test traces for the Pcap parser.
25 *
26 * @author Vincent Perot
27 */
28public enum PcapTestTrace {
29
30 /** A bad pcap file. */
333a2acb 31 BAD_PCAPFILE("..", "org.eclipse.linuxtools.pcap.core.tests", "rsc", "BadPcapFile.pcap"),
a1d21447
VP
32
33 /** A Valid Pcap that is empty. */
333a2acb 34 EMPTY_PCAP("..", "org.eclipse.linuxtools.pcap.core.tests", "rsc", "EmptyPcap.pcap"),
a1d21447
VP
35
36 /** A Pcap that mostly contains TCP packets. */
333a2acb 37 MOSTLY_TCP("..", "org.eclipse.linuxtools.pcap.core.tests", "rsc", "mostlyTCP.pcap"),
a1d21447
VP
38
39 /** A Pcap that mostly contains UDP packets. */
333a2acb 40 MOSTLY_UDP("..", "org.eclipse.linuxtools.pcap.core.tests", "rsc", "mostlyUDP.pcap"),
a1d21447
VP
41
42 /** A big-endian trace that contains two packets. */
333a2acb 43 SHORT_BIG_ENDIAN("..", "org.eclipse.linuxtools.pcap.core.tests", "rsc", "Short_BigEndian.pcap"),
a1d21447
VP
44
45 /** A little-endian trace that contains two packets. */
333a2acb 46 SHORT_LITTLE_ENDIAN("..", "org.eclipse.linuxtools.pcap.core.tests", "rsc", "Short_LittleEndian.pcap"),
a1d21447 47
82983c92 48 /** A large trace for benchmarking. */
333a2acb 49 BENCHMARK_TRACE("..", "org.eclipse.linuxtools.pcap.core.tests", "rsc", "benchmarkTrace.pcap"),
82983c92 50
a1d21447 51 /** A Kernel trace directory. */
333a2acb 52 KERNEL_DIRECTORY("..", "org.eclipse.linuxtools.pcap.core.tests", "rsc", "kernel"),
a1d21447
VP
53
54 /** A Kernel trace file. */
333a2acb 55 KERNEL_TRACE("..", "org.eclipse.linuxtools.pcap.core.tests", "rsc", "kernel", "channel0_0");
a1d21447 56
333a2acb 57 private final @NonNull Path fPath;
a1d21447 58
333a2acb
AM
59 private PcapTestTrace(@NonNull String first, String... more) {
60 @SuppressWarnings("null")
61 @NonNull Path path = FileSystems.getDefault().getPath(first, more);
a1d21447
VP
62 fPath = path;
63 }
64
65 /** @return The path to the test trace */
333a2acb 66 public @NonNull Path getPath() {
a1d21447
VP
67 return fPath;
68 }
69
70 /**
71 * Get a Pcap Trace instance of a test trace. Make sure to call
72 * {@link #exists()} before calling this!
73 *
74 * @return The PcapFile object
75 * @throws IOException
76 * Thrown when some IO error occurs.
77 * @throws BadPcapFileException
78 * Thrown when the file is not a valid Pcap File.
79 */
80 public PcapFile getTrace() throws BadPcapFileException, IOException {
81 return new PcapFile(fPath);
82 }
83
84 /**
85 * Check if this test trace actually exists on disk.
86 *
87 * @return If the trace exists
88 */
89 public boolean exists() {
333a2acb 90 if (Files.notExists(fPath)) {
a1d21447
VP
91 return false;
92 }
93 return true;
94 }
95
96}
This page took 0.033269 seconds and 5 git commands to generate.