nicklesh adlakha | 90bfa6a | 2016-04-28 20:38:33 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
nicklesh adlakha | 90bfa6a | 2016-04-28 20:38:33 +0530 | [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 | package org.onosproject.isis.io.util; |
| 17 | |
| 18 | import org.junit.After; |
| 19 | import org.junit.Before; |
| 20 | import org.junit.Test; |
| 21 | |
| 22 | import static org.hamcrest.CoreMatchers.is; |
| 23 | import static org.junit.Assert.assertThat; |
| 24 | |
| 25 | /** |
| 26 | * Unit test class for ChecksumCalculator. |
| 27 | */ |
| 28 | public class ChecksumCalculatorTest { |
| 29 | |
| 30 | private final byte[] l1Lsp = { |
| 31 | -125, 27, 1, 0, 18, 1, 0, 0, 0, 86, 4, -81, 34, 34, 34, |
| 32 | 34, 34, 34, 0, 0, 0, 0, 0, 9, 99, 11, 1, 1, 4, 3, 73, |
| 33 | 0, 10, -127, 1, -52, -119, 2, 82, 50, -124, 4, -64, -88, 10, 1, -128, |
| 34 | 24, 10, -128, -128, -128, 10, 0, 10, 0, -1, -1, -1, -4, 10, -128, -128, |
| 35 | -128, -64, -88, 10, 0, -1, -1, -1, 0, 2, 12, 0, 10, -128, -128, -128, |
| 36 | 51, 51, 51, 51, 51, 51, 2 |
| 37 | }; |
| 38 | private ChecksumCalculator calculator; |
| 39 | private byte[] result; |
| 40 | private boolean result1; |
| 41 | |
| 42 | @Before |
| 43 | public void setUp() throws Exception { |
| 44 | calculator = new ChecksumCalculator(); |
| 45 | } |
| 46 | |
| 47 | @After |
| 48 | public void tearDown() throws Exception { |
| 49 | calculator = null; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Tests validateLspCheckSum() method. |
| 54 | */ |
| 55 | @Test |
| 56 | public void testValidateLspCheckSum() throws Exception { |
| 57 | result1 = calculator.validateLspCheckSum(l1Lsp, IsisConstants.CHECKSUMPOSITION, |
| 58 | IsisConstants.CHECKSUMPOSITION + 1); |
| 59 | |
| 60 | assertThat(result1, is(true)); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Tests calculateLspChecksum() method. |
| 65 | */ |
| 66 | @Test |
| 67 | public void testCalculateLspChecksum() throws Exception { |
| 68 | result = calculator.calculateLspChecksum(l1Lsp, IsisConstants.CHECKSUMPOSITION, |
| 69 | IsisConstants.CHECKSUMPOSITION + 1); |
| 70 | assertThat(result[0], |
| 71 | is(l1Lsp[IsisConstants.CHECKSUMPOSITION])); |
| 72 | assertThat(result[1], |
| 73 | is(l1Lsp[IsisConstants.CHECKSUMPOSITION + 1])); |
| 74 | } |
| 75 | } |