pcap: Add unit tests to pcap.core
[deliverable/tracecompass.git] / org.eclipse.linuxtools.pcap.core.tests / src / org / eclipse / linuxtools / pcap / core / tests / protocol / ProtocolTest.java
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
13 package org.eclipse.linuxtools.pcap.core.tests.protocol;
14
15 import static org.junit.Assert.assertEquals;
16 import static org.junit.Assert.fail;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21 import org.eclipse.linuxtools.pcap.core.protocol.Protocol;
22 import org.eclipse.linuxtools.pcap.core.protocol.ProtocolValues;
23 import org.junit.Test;
24
25 /**
26 * JUnit Class that tests whether protocol operation are happening without
27 * error.
28 *
29 * @author Vincent Perot
30 */
31 public class ProtocolTest {
32
33 /**
34 * Test that verify if the protocol attributes are as expected.
35 */
36 @Test
37 public void TestProtocolAttributes() {
38 assertEquals(Protocol.PCAP.getName(), "Packet Capture");
39 assertEquals(Protocol.PCAP.getShortName(), "pcap");
40 assertEquals(Protocol.PCAP.getLayer(), ProtocolValues.LAYER_0);
41 }
42
43 /**
44 * Test that verify if the protocol getter methods are working properly.
45 */
46 @Test
47 public void TestgetProtocols() {
48 List<Protocol> list = new ArrayList<>();
49 List<Protocol> manualListLayer = new ArrayList<>();
50 for (int i = ProtocolValues.LAYER_0; i <= ProtocolValues.LAYER_7; i++) {
51 List<Protocol> listLayer = Protocol.getProtocolsOnLayer(i);
52 list.addAll(listLayer);
53
54 manualListLayer.clear();
55 switch (i) {
56 case ProtocolValues.LAYER_0:
57 manualListLayer.add(Protocol.PCAP);
58 break;
59 case ProtocolValues.LAYER_1:
60 break;
61 case ProtocolValues.LAYER_2:
62 manualListLayer.add(Protocol.ETHERNET_II);
63 break;
64 case ProtocolValues.LAYER_3:
65 manualListLayer.add(Protocol.IPV4);
66 break;
67 case ProtocolValues.LAYER_4:
68 manualListLayer.add(Protocol.TCP);
69 manualListLayer.add(Protocol.UDP);
70 break;
71 case ProtocolValues.LAYER_5:
72 break;
73 case ProtocolValues.LAYER_6:
74 break;
75 case ProtocolValues.LAYER_7:
76 manualListLayer.add(Protocol.UNKNOWN);
77 break;
78 default:
79 fail("Illegal layer value!");
80 }
81 assertEquals(manualListLayer, listLayer);
82 }
83 assertEquals(Protocol.getAllProtocols(), list);
84
85 }
86
87 }
This page took 0.031758 seconds and 5 git commands to generate.