2 * Copyright (c) 2013 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.openflowplugin.openflow.md.core.sal.convertor.match;
10 import java.lang.reflect.Constructor;
11 import org.junit.Assert;
12 import org.junit.Test;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Ipv6ExthdrFlags;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
17 public class MatchConvertorUtilTest {
19 private static Logger LOG = LoggerFactory
20 .getLogger(MatchConvertorUtilTest.class);
23 * Test method for {@link MatchConvertorUtil#ipv6ExthdrFlagsToInt(Ipv6ExthdrFlags)}.
26 public void testIpv6ExthdrFlagsToInt() throws Exception {
27 Ipv6ExthdrFlags flags;
28 Constructor<Ipv6ExthdrFlags> ctor = Ipv6ExthdrFlags.class.getConstructor(
29 Boolean.class, Boolean.class, Boolean.class, Boolean.class,
30 Boolean.class, Boolean.class, Boolean.class, Boolean.class, Boolean.class);
32 int[] expectedFlagCumulants = new int[] { 4, 8, 2, 16, 64, 1, 32, 128, 256 };
34 for (int i = 0; i < 9; i++) {
35 flags = ctor.newInstance(createIpv6ExthdrFlagsCtorParams(i));
36 int intResult = MatchConvertorUtil.ipv6ExthdrFlagsToInt(flags);
37 LOG.debug("{}:Ipv6ExthdrFlags[{}] as int = {}", i, flags, intResult);
38 Assert.assertEquals(expectedFlagCumulants[i], intResult);
41 flags = new Ipv6ExthdrFlags(
42 false, false, false, false, false, false, false, false, false);
43 Assert.assertEquals(0, MatchConvertorUtil.ipv6ExthdrFlagsToInt(flags).intValue());
45 flags = new Ipv6ExthdrFlags(
46 true, true, true, true, true, true, true, true, true);
47 Assert.assertEquals(511, MatchConvertorUtil.ipv6ExthdrFlagsToInt(flags).intValue());
50 private static Object[] createIpv6ExthdrFlagsCtorParams(final int trueIndex) {
51 Boolean[] flags = new Boolean[]{false, false, false, false, false, false, false, false, false};
52 flags[trueIndex] = true;