2 * Copyright (c) 2016 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.yangtools.yang.data.impl.codec;
10 import static org.junit.jupiter.api.Assertions.assertEquals;
11 import static org.opendaylight.yangtools.yang.data.impl.codec.TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx;
12 import static org.opendaylight.yangtools.yang.data.impl.codec.TypeDefinitionAwareCodecTestHelper.getCodec;
14 import org.junit.jupiter.api.Test;
15 import org.opendaylight.yangtools.yang.data.api.codec.Int64Codec;
16 import org.opendaylight.yangtools.yang.model.ri.type.BaseTypes;
19 * Unit tests for Int64CodecString.
21 * @author Thomas Pantelis
23 class Int64CodecStringTest {
24 @SuppressWarnings("unchecked")
26 void testSerialize() {
27 final var codec = getCodec(BaseTypes.int64Type(), Int64Codec.class);
28 assertEquals("12345", codec.serialize(Long.valueOf(12345)), "serialize");
31 @SuppressWarnings("unchecked")
33 void testDeserialize() {
34 final var hexa = "0X75EDC78edCBA";
35 final var negHexa = "-0X75EDC78edCBA";
36 final var octal = "+03536670743556272";
37 final var negOctal = "-03536670743556272";
38 final var integer = "+129664115727546";
39 final var negInteger = "-129664115727546";
41 final var codec = getCodec(BaseTypes.int64Type(), Int64Codec.class);
43 assertEquals(codec.deserialize(hexa), Long.valueOf("075EDC78edCBA", 16), "deserialize");
44 assertEquals(codec.deserialize(negHexa), Long.valueOf("-075EDC78edCBA", 16), "deserialize");
45 assertEquals(codec.deserialize(octal), Long.valueOf(octal, 8), "deserialize");
46 assertEquals(codec.deserialize(negOctal), Long.valueOf(negOctal, 8), "deserialize");
47 assertEquals(codec.deserialize(integer), Long.valueOf(integer, 10), "deserialize");
48 assertEquals(codec.deserialize(negInteger), Long.valueOf(negInteger, 10), "deserialize");
50 deserializeWithExpectedIllegalArgEx(codec, "1234o");
51 deserializeWithExpectedIllegalArgEx(codec, "");