Move ipv4/ipv6 ByteBuf utilities to Ipv{4,6}Util
[bgpcep.git] / util / src / test / java / org / opendaylight / protocol / util / ByteBufWriteUtilTest.java
1 /*
2  * Copyright (c) 2014 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.protocol.util;
9
10 import static org.junit.Assert.assertArrayEquals;
11 import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeFloat32;
12
13 import io.netty.buffer.ByteBuf;
14 import io.netty.buffer.Unpooled;
15 import org.junit.Test;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32;
17
18 public class ByteBufWriteUtilTest {
19     private static final byte[] FOUR_BYTE_ZEROS = { 0, 0, 0, 0 };
20
21     @Test
22     public void testWriteFloat32() {
23         final byte[] result = { 0, 0, 0, 5 };
24         final ByteBuf output = Unpooled.buffer(Float.BYTES);
25         writeFloat32(new Float32(result), output);
26         assertArrayEquals(result, output.array());
27
28         output.clear();
29         writeFloat32(null, output);
30         assertArrayEquals(FOUR_BYTE_ZEROS, output.array());
31     }
32 }