2 * Copyright (c) 2019 PANTHEON.tech, s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.data.codec.binfmt;
10 import java.util.Arrays;
11 import java.util.concurrent.ThreadLocalRandom;
12 import org.junit.Test;
13 import org.junit.runner.RunWith;
14 import org.junit.runners.Parameterized;
15 import org.junit.runners.Parameterized.Parameter;
16 import org.junit.runners.Parameterized.Parameters;
18 @RunWith(Parameterized.class)
19 public class BytesSerializationTest extends AbstractSerializationTest {
20 private static final byte[] BINARY_128 = randomBytes(128);
21 private static final byte[] BINARY_384 = randomBytes(384);
22 private static final byte[] BINARY_65920 = randomBytes(65920);
24 @Parameters(name = "{0}")
25 public static Iterable<Object[]> data() {
27 new Object[] { NormalizedNodeStreamVersion.LITHIUM, 100, 101, 228, 484, 66020 },
28 new Object[] { NormalizedNodeStreamVersion.NEON_SR2, 102, 103, 230, 486, 66022 },
29 new Object[] { NormalizedNodeStreamVersion.SODIUM_SR1, 96, 97, 225, 482, 66020 },
30 new Object[] { NormalizedNodeStreamVersion.MAGNESIUM, 96, 97, 225, 482, 66020 });
45 public void testEmptyBytes() {
46 assertEquals(new byte[0], emptySize);
50 public void testOne() {
51 assertEquals(randomBytes(1), oneSize);
55 public void test128() {
56 assertEquals(BINARY_128, size128);
60 public void test384() {
61 assertEquals(BINARY_384, size384);
65 public void test65920() {
66 assertEquals(BINARY_65920, size65920);
69 private static byte[] randomBytes(final int size) {
70 final byte[] ret = new byte[size];
71 ThreadLocalRandom.current().nextBytes(ret);