Update MRI upstreams for Phosphorus
[openflowplugin.git] / openflowplugin / src / test / java / org / opendaylight / openflowplugin / openflow / md / core / sal / convertor / match / MatchConvertorUtilTest.java
1 /*
2  * Copyright (c) 2013 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.openflowplugin.openflow.md.core.sal.convertor.match;
9
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;
16
17 public class MatchConvertorUtilTest {
18     private static final Logger LOG = LoggerFactory.getLogger(MatchConvertorUtilTest.class);
19
20     /**
21      * Test method for {@link MatchConvertorUtil#ipv6ExthdrFlagsToInt(Ipv6ExthdrFlags)}.
22      */
23     @Test
24     public void testIpv6ExthdrFlagsToInt() throws Exception {
25         Ipv6ExthdrFlags flags;
26         Constructor<Ipv6ExthdrFlags> ctor = Ipv6ExthdrFlags.class.getConstructor(
27                 Boolean.class, Boolean.class, Boolean.class, Boolean.class,
28                 Boolean.class, Boolean.class, Boolean.class, Boolean.class, Boolean.class);
29
30         int[] expectedFlagCumulants = new int[] { 4, 8, 2, 16, 64, 1, 32, 128, 256 };
31
32         for (int i = 0; i < 9; i++) {
33             flags = ctor.newInstance(createIpv6ExthdrFlagsCtorParams(i));
34             int intResult = MatchConvertorUtil.ipv6ExthdrFlagsToInt(flags);
35             LOG.debug("{}:Ipv6ExthdrFlags[{}] as int = {}", i, flags, intResult);
36             Assert.assertEquals(expectedFlagCumulants[i], intResult);
37         }
38
39         flags = new Ipv6ExthdrFlags(
40                 false, false, false, false, false, false, false, false, false);
41         Assert.assertEquals(0, MatchConvertorUtil.ipv6ExthdrFlagsToInt(flags));
42
43         flags = new Ipv6ExthdrFlags(
44                 true, true, true, true, true, true, true, true, true);
45         Assert.assertEquals(511, MatchConvertorUtil.ipv6ExthdrFlagsToInt(flags));
46     }
47
48     private static Object[] createIpv6ExthdrFlagsCtorParams(final int trueIndex) {
49         Boolean[] flags = new Boolean[]{false, false, false, false, false, false, false, false, false};
50         flags[trueIndex] = true;
51         return flags;
52     }
53 }