Migrate concepts to Jupiter API
[yangtools.git] / common / concepts / src / test / java / org / opendaylight / yangtools / concepts / WritableObjectsTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. 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.concepts;
9
10 import static org.junit.jupiter.api.Assertions.assertEquals;
11
12 import com.google.common.io.ByteArrayDataOutput;
13 import com.google.common.io.ByteStreams;
14 import java.io.IOException;
15 import org.junit.jupiter.api.Test;
16
17 public class WritableObjectsTest {
18
19     private static void assertRecovery(final long expected) throws IOException {
20         final ByteArrayDataOutput out = ByteStreams.newDataOutput();
21         WritableObjects.writeLong(out, expected);
22         final long actual = WritableObjects.readLong(ByteStreams.newDataInput(out.toByteArray()));
23         assertEquals(Long.toUnsignedString(expected, 16), Long.toUnsignedString(actual, 16));
24     }
25
26     @Test
27     public void testReadWriteLong() throws IOException {
28         assertRecovery(0L);
29         assertRecovery(1L);
30         assertRecovery(255L);
31         assertRecovery(256L);
32
33         assertRecovery(Long.MAX_VALUE);
34         assertRecovery(Long.MIN_VALUE);
35
36         assertRecovery(0xF000000000000000L);
37         assertRecovery(0x0F00000000000000L);
38         assertRecovery(0x00F0000000000000L);
39         assertRecovery(0x000F000000000000L);
40         assertRecovery(0x0000F00000000000L);
41         assertRecovery(0x00000F0000000000L);
42         assertRecovery(0x000000F000000000L);
43         assertRecovery(0x0000000F00000000L);
44         assertRecovery(0x00000000F0000000L);
45         assertRecovery(0x000000000F000000L);
46         assertRecovery(0x0000000000F00000L);
47         assertRecovery(0x00000000000F0000L);
48         assertRecovery(0x000000000000F000L);
49         assertRecovery(0x0000000000000F00L);
50         assertRecovery(0x00000000000000F0L);
51
52         assertRecovery(0xF0F0F0F0F0F0F0F0L);
53         assertRecovery(0x0FF0F0F0F0F0F0F0L);
54         assertRecovery(0x00F0F0F0F0F0F0F0L);
55         assertRecovery(0x000FF0F0F0F0F0F0L);
56         assertRecovery(0x0000F0F0F0F0F0F0L);
57         assertRecovery(0x00000F00F0F0F0F0L);
58         assertRecovery(0x000000F0F0F0F0F0L);
59         assertRecovery(0x0000000FF0F0F0F0L);
60         assertRecovery(0x00000000F0F0F0F0L);
61         assertRecovery(0x000000000FF0F0F0L);
62         assertRecovery(0x0000000000F0F0F0L);
63         assertRecovery(0x00000000000FF0F0L);
64         assertRecovery(0x000000000000F0F0L);
65         assertRecovery(0x0000000000000FF0L);
66         assertRecovery(0x00000000000000F0L);
67
68         assertRecovery(0x8000000000000000L);
69         assertRecovery(0x0800000000000000L);
70         assertRecovery(0x0080000000000000L);
71         assertRecovery(0x0008000000000000L);
72         assertRecovery(0x0000800000000000L);
73         assertRecovery(0x0000080000000000L);
74         assertRecovery(0x0000008000000000L);
75         assertRecovery(0x0000000800000000L);
76         assertRecovery(0x0000000080000000L);
77         assertRecovery(0x0000000008000000L);
78         assertRecovery(0x0000000000800000L);
79         assertRecovery(0x0000000000080000L);
80         assertRecovery(0x0000000000008000L);
81         assertRecovery(0x0000000000000800L);
82         assertRecovery(0x0000000000000080L);
83         assertRecovery(0x0000000000000008L);
84     }
85 }