Jonathan Hart | 2a65575 | 2015-04-07 16:46:33 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Jonathan Hart | 2a65575 | 2015-04-07 16:46:33 -0700 | [diff] [blame] | 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 | |
Jian Li | 5fc1429 | 2015-12-04 11:30:46 -0800 | [diff] [blame] | 19 | import org.apache.commons.lang3.StringUtils; |
Jonathan Hart | 2a65575 | 2015-04-07 16:46:33 -0700 | [diff] [blame] | 20 | import org.junit.Before; |
| 21 | import org.junit.Test; |
| 22 | |
| 23 | import java.nio.ByteBuffer; |
| 24 | |
| 25 | import static org.junit.Assert.assertEquals; |
Jian Li | 5fc1429 | 2015-12-04 11:30:46 -0800 | [diff] [blame] | 26 | import static org.junit.Assert.assertTrue; |
Jonathan Hart | 2a65575 | 2015-04-07 16:46:33 -0700 | [diff] [blame] | 27 | |
| 28 | /** |
| 29 | * Unit tests for LLC class. |
| 30 | */ |
| 31 | public class LLCTest { |
| 32 | |
| 33 | private Deserializer<LLC> deserializer; |
| 34 | |
| 35 | private byte dsap = 10; |
| 36 | private byte ssap = 20; |
| 37 | private byte ctrl = 30; |
| 38 | |
| 39 | private byte[] bytes; |
| 40 | |
| 41 | @Before |
| 42 | public void setUp() throws Exception { |
| 43 | deserializer = LLC.deserializer(); |
| 44 | |
| 45 | ByteBuffer bb = ByteBuffer.allocate(LLC.LLC_HEADER_LENGTH); |
| 46 | |
| 47 | bb.put(dsap); |
| 48 | bb.put(ssap); |
| 49 | bb.put(ctrl); |
| 50 | |
| 51 | bytes = bb.array(); |
| 52 | } |
| 53 | |
| 54 | @Test |
| 55 | public void testDeserializeBadInput() throws Exception { |
| 56 | PacketTestUtils.testDeserializeBadInput(deserializer); |
| 57 | } |
| 58 | |
| 59 | @Test |
| 60 | public void testDeserializeTruncated() throws Exception { |
| 61 | PacketTestUtils.testDeserializeTruncated(deserializer, bytes); |
| 62 | } |
| 63 | |
Jian Li | 5fc1429 | 2015-12-04 11:30:46 -0800 | [diff] [blame] | 64 | /** |
| 65 | * Tests deserialize and getters. |
| 66 | */ |
Jonathan Hart | 2a65575 | 2015-04-07 16:46:33 -0700 | [diff] [blame] | 67 | @Test |
| 68 | public void testDeserialize() throws Exception { |
| 69 | LLC llc = deserializer.deserialize(bytes, 0, bytes.length); |
| 70 | |
| 71 | assertEquals(dsap, llc.getDsap()); |
| 72 | assertEquals(ssap, llc.getSsap()); |
| 73 | assertEquals(ctrl, llc.getCtrl()); |
| 74 | } |
Jian Li | 5fc1429 | 2015-12-04 11:30:46 -0800 | [diff] [blame] | 75 | |
| 76 | /** |
| 77 | * Tests toString. |
| 78 | */ |
| 79 | @Test |
| 80 | public void testToStringLLC() throws Exception { |
| 81 | LLC llc = deserializer.deserialize(bytes, 0, bytes.length); |
| 82 | String str = llc.toString(); |
| 83 | |
| 84 | assertTrue(StringUtils.contains(str, "dsap=" + dsap)); |
| 85 | assertTrue(StringUtils.contains(str, "ssap=" + ssap)); |
| 86 | assertTrue(StringUtils.contains(str, "ctrl=" + ctrl)); |
| 87 | } |
Jonathan Hart | 2a65575 | 2015-04-07 16:46:33 -0700 | [diff] [blame] | 88 | } |