2 * Copyright (c) 2014 Cisco Systems, Inc. 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.protocol.util;
10 import static org.junit.Assert.assertArrayEquals;
11 import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeFloat32;
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;
18 public class ByteBufWriteUtilTest {
19 private static final byte[] FOUR_BYTE_ZEROS = { 0, 0, 0, 0 };
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());
29 writeFloat32(null, output);
30 assertArrayEquals(FOUR_BYTE_ZEROS, output.array());