Populate codec/ directory
[yangtools.git] / codec / yang-data-codec-binfmt / src / test / java / org / opendaylight / yangtools / yang / data / codec / binfmt / BytesSerializationTest.java
1 /*
2  * Copyright (c) 2019 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.data.codec.binfmt;
9
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;
17
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);
23
24     @Parameters(name = "{0}")
25     public static Iterable<Object[]> data() {
26         return Arrays.asList(
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 });
31     }
32
33     @Parameter(1)
34     public int emptySize;
35     @Parameter(2)
36     public int oneSize;
37     @Parameter(3)
38     public int size128;
39     @Parameter(4)
40     public int size384;
41     @Parameter(5)
42     public int size65920;
43
44     @Test
45     public void testEmptyBytes() {
46         assertEquals(new byte[0], emptySize);
47     }
48
49     @Test
50     public void testOne() {
51         assertEquals(randomBytes(1), oneSize);
52     }
53
54     @Test
55     public void test128() {
56         assertEquals(BINARY_128, size128);
57     }
58
59     @Test
60     public void test384() {
61         assertEquals(BINARY_384, size384);
62     }
63
64     @Test
65     public void test65920() {
66         assertEquals(BINARY_65920, size65920);
67     }
68
69     private static byte[] randomBytes(final int size) {
70         final byte[] ret = new byte[size];
71         ThreadLocalRandom.current().nextBytes(ret);
72         return ret;
73     }
74 }