Jonathan Hart | 2a65575 | 2015-04-07 16:46:33 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package org.onlab.packet; |
| 18 | |
| 19 | import org.junit.Before; |
| 20 | import org.junit.Test; |
| 21 | |
| 22 | import java.nio.ByteBuffer; |
| 23 | |
| 24 | import static org.junit.Assert.assertEquals; |
| 25 | |
| 26 | /** |
| 27 | * Unit tests for LLC class. |
| 28 | */ |
| 29 | public class LLCTest { |
| 30 | |
| 31 | private Deserializer<LLC> deserializer; |
| 32 | |
| 33 | private byte dsap = 10; |
| 34 | private byte ssap = 20; |
| 35 | private byte ctrl = 30; |
| 36 | |
| 37 | private byte[] bytes; |
| 38 | |
| 39 | @Before |
| 40 | public void setUp() throws Exception { |
| 41 | deserializer = LLC.deserializer(); |
| 42 | |
| 43 | ByteBuffer bb = ByteBuffer.allocate(LLC.LLC_HEADER_LENGTH); |
| 44 | |
| 45 | bb.put(dsap); |
| 46 | bb.put(ssap); |
| 47 | bb.put(ctrl); |
| 48 | |
| 49 | bytes = bb.array(); |
| 50 | } |
| 51 | |
| 52 | @Test |
| 53 | public void testDeserializeBadInput() throws Exception { |
| 54 | PacketTestUtils.testDeserializeBadInput(deserializer); |
| 55 | } |
| 56 | |
| 57 | @Test |
| 58 | public void testDeserializeTruncated() throws Exception { |
| 59 | PacketTestUtils.testDeserializeTruncated(deserializer, bytes); |
| 60 | } |
| 61 | |
| 62 | @Test |
| 63 | public void testDeserialize() throws Exception { |
| 64 | LLC llc = deserializer.deserialize(bytes, 0, bytes.length); |
| 65 | |
| 66 | assertEquals(dsap, llc.getDsap()); |
| 67 | assertEquals(ssap, llc.getSsap()); |
| 68 | assertEquals(ctrl, llc.getCtrl()); |
| 69 | } |
| 70 | } |