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;
12 import org.junit.Assert;
13 import org.junit.Test;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Ipv6ExthdrFlags;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
21 public class MatchConvertorUtilTest {
23 private static Logger LOG = LoggerFactory
24 .getLogger(MatchConvertorUtilTest.class);
27 * Test method for {@link org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchConvertorUtil#ipv6ExthdrFlagsToInt(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Ipv6ExthdrFlags)}.
31 public void testIpv6ExthdrFlagsToInt() throws Exception {
32 Ipv6ExthdrFlags pField;
33 Constructor<Ipv6ExthdrFlags> ctor = Ipv6ExthdrFlags.class.getConstructor(
34 Boolean.class, Boolean.class, Boolean.class, Boolean.class,
35 Boolean.class, Boolean.class, Boolean.class, Boolean.class, Boolean.class);
37 int[] expectedFlagCumulants = new int[] {
38 4, 8, 2, 16, 64, 1, 32, 128, 256
41 for (int i = 0; i < 9; i++) {
42 pField = ctor.newInstance(createIpv6ExthdrFlagsCtorParams(i));
43 int intResult = MatchConvertorUtil.ipv6ExthdrFlagsToInt(pField);
44 LOG.debug("{}:Ipv6ExthdrFlags[{}] as int = {}", i, pField, intResult);
45 Assert.assertEquals(expectedFlagCumulants[i], intResult);
48 pField = new Ipv6ExthdrFlags(
49 false, false, false, false, false, false, false, false, false);
50 Assert.assertEquals(0, MatchConvertorUtil.ipv6ExthdrFlagsToInt(pField).intValue());
52 pField = new Ipv6ExthdrFlags(
53 true, true, true, true, true, true, true, true, true);
54 Assert.assertEquals(511, MatchConvertorUtil.ipv6ExthdrFlagsToInt(pField).intValue());
60 private static Object[] createIpv6ExthdrFlagsCtorParams(int trueIndex) {
61 Boolean[] flags = new Boolean[]{false, false, false, false, false, false, false, false, false};
62 flags[trueIndex] = true;