Commit | Line | Data |
---|---|---|
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 | ||
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 | ||
c88feda9 AM |
21 | import org.eclipse.linuxtools.internal.pcap.core.protocol.PcapProtocol; |
22 | import org.eclipse.linuxtools.internal.pcap.core.protocol.PcapProtocolValues; | |
a1d21447 VP |
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() { | |
c88feda9 AM |
38 | assertEquals(PcapProtocol.PCAP.getName(), "Packet Capture"); |
39 | assertEquals(PcapProtocol.PCAP.getShortName(), "pcap"); | |
40 | assertEquals(PcapProtocol.PCAP.getLayer(), PcapProtocolValues.LAYER_0); | |
a1d21447 VP |
41 | } |
42 | ||
43 | /** | |
44 | * Test that verify if the protocol getter methods are working properly. | |
45 | */ | |
46 | @Test | |
47 | public void TestgetProtocols() { | |
c88feda9 AM |
48 | List<PcapProtocol> list = new ArrayList<>(); |
49 | List<PcapProtocol> manualListLayer = new ArrayList<>(); | |
50 | for (int i = PcapProtocolValues.LAYER_0; i <= PcapProtocolValues.LAYER_7; i++) { | |
51 | List<PcapProtocol> listLayer = PcapProtocol.getProtocolsOnLayer(i); | |
a1d21447 VP |
52 | list.addAll(listLayer); |
53 | ||
54 | manualListLayer.clear(); | |
55 | switch (i) { | |
c88feda9 AM |
56 | case PcapProtocolValues.LAYER_0: |
57 | manualListLayer.add(PcapProtocol.PCAP); | |
a1d21447 | 58 | break; |
c88feda9 | 59 | case PcapProtocolValues.LAYER_1: |
a1d21447 | 60 | break; |
c88feda9 AM |
61 | case PcapProtocolValues.LAYER_2: |
62 | manualListLayer.add(PcapProtocol.ETHERNET_II); | |
a1d21447 | 63 | break; |
c88feda9 AM |
64 | case PcapProtocolValues.LAYER_3: |
65 | manualListLayer.add(PcapProtocol.IPV4); | |
a1d21447 | 66 | break; |
c88feda9 AM |
67 | case PcapProtocolValues.LAYER_4: |
68 | manualListLayer.add(PcapProtocol.TCP); | |
69 | manualListLayer.add(PcapProtocol.UDP); | |
a1d21447 | 70 | break; |
c88feda9 | 71 | case PcapProtocolValues.LAYER_5: |
a1d21447 | 72 | break; |
c88feda9 | 73 | case PcapProtocolValues.LAYER_6: |
a1d21447 | 74 | break; |
c88feda9 AM |
75 | case PcapProtocolValues.LAYER_7: |
76 | manualListLayer.add(PcapProtocol.UNKNOWN); | |
a1d21447 VP |
77 | break; |
78 | default: | |
79 | fail("Illegal layer value!"); | |
80 | } | |
81 | assertEquals(manualListLayer, listLayer); | |
82 | } | |
c88feda9 | 83 | assertEquals(PcapProtocol.getAllProtocols(), list); |
a1d21447 VP |
84 | |
85 | } | |
86 | ||
87 | } |