+ assertEquals(2, (int) value2.getValue());
+ assertEquals("The IPv6 protocol as defined in RFC 2460.",
+ value2.getDescription());
+ }
+
+ @Test
+ public void testIpAddress() {
+ Module tested = findModule(testedModules, "ietf-inet-types");
+ Set<TypeDefinition<?>> typedefs = tested.getTypeDefinitions();
+ TypeDefinition<?> type = findTypedef(typedefs, "ip-address");
+ UnionType baseType = (UnionType) type.getBaseType();
+ List<TypeDefinition<?>> unionTypes = baseType.getTypes();
+
+ ExtendedType ipv4 = (ExtendedType)unionTypes.get(0);
+ StringType ipv4Base = (StringType) ipv4.getBaseType();
+ String expectedPattern = "(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.){3}"
+ + "([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])"
+ + "(%[\\p{N}\\p{L}]+)?";
+ assertEquals(expectedPattern, ipv4Base.getPatterns().get(0)
+ .getRegularExpression());
+
+ ExtendedType ipv6 = (ExtendedType)unionTypes.get(1);
+ StringType ipv6Base = (StringType) ipv6.getBaseType();
+ List<PatternConstraint> ipv6Patterns = ipv6Base.getPatterns();
+ expectedPattern = "((:|[0-9a-fA-F]{0,4}):)([0-9a-fA-F]{0,4}:){0,5}"
+ + "((([0-9a-fA-F]{0,4}:)?(:|[0-9a-fA-F]{0,4}))|"
+ + "(((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\\.){3}"
+ + "(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])))"
+ + "(%[\\p{N}\\p{L}]+)?";
+ assertEquals(expectedPattern, ipv6Patterns.get(0)
+ .getRegularExpression());
+
+ expectedPattern = "(([^:]+:){6}(([^:]+:[^:]+)|(.*\\..*)))|"
+ + "((([^:]+:)*[^:]+)?::(([^:]+:)*[^:]+)?)" + "(%.+)?";
+ assertEquals(expectedPattern, ipv6Patterns.get(1)
+ .getRegularExpression());
+ }
+
+ @Test
+ public void testDomainName() {
+ Module tested = findModule(testedModules, "ietf-inet-types");
+ Set<TypeDefinition<?>> typedefs = tested.getTypeDefinitions();
+ TypeDefinition<?> type = findTypedef(typedefs, "domain-name");
+ StringType baseType = (StringType) type.getBaseType();
+ List<PatternConstraint> patterns = baseType.getPatterns();
+ assertEquals(1, patterns.size());
+ String expectedPattern = "((([a-zA-Z0-9_]([a-zA-Z0-9\\-_]){0,61})?[a-zA-Z0-9]\\.)*"
+ + "([a-zA-Z0-9_]([a-zA-Z0-9\\-_]){0,61})?[a-zA-Z0-9]\\.?)"
+ + "|\\.";
+ assertEquals(expectedPattern, patterns.get(0).getRegularExpression());
+
+ List<LengthConstraint> lengths = baseType.getLengthStatements();
+ assertEquals(1, lengths.size());
+ LengthConstraint length = baseType.getLengthStatements().get(0);
+ assertEquals(1L, length.getMin());
+ assertEquals(253L, length.getMax());
+ }
+
+ @Test
+ public void testInstanceIdentifier1() {
+ Module tested = findModule(testedModules, "custom-types-test");
+ LeafSchemaNode leaf = (LeafSchemaNode) tested
+ .getDataChildByName("inst-id-leaf1");
+ InstanceIdentifier leafType = (InstanceIdentifier) leaf.getType();
+ assertFalse(leafType.requireInstance());
+ }
+
+ @Test
+ public void testInstanceIdentifier2() {
+ Module tested = findModule(testedModules, "custom-types-test");
+ LeafSchemaNode leaf = (LeafSchemaNode) tested
+ .getDataChildByName("inst-id-leaf2");
+ InstanceIdentifier leafType = (InstanceIdentifier) leaf.getType();
+ assertTrue(leafType.requireInstance());
+ }
+
+ @Test
+ public void testIdentity() {
+ Module tested = findModule(testedModules, "custom-types-test");
+ Set<IdentitySchemaNode> identities = tested.getIdentities();
+ IdentitySchemaNode testedIdentity = null;
+ for (IdentitySchemaNode id : identities) {
+ if (id.getQName().getLocalName().equals("crypto-alg")) {
+ testedIdentity = id;
+ IdentitySchemaNode baseIdentity = id.getBaseIdentity();
+ assertEquals("crypto-base", baseIdentity.getQName()
+ .getLocalName());
+ assertNull(baseIdentity.getBaseIdentity());
+ }
+ }
+ assertNotNull(testedIdentity);
+ }
+
+ @Test
+ public void testBitsType1() {
+ Module tested = findModule(testedModules, "custom-types-test");
+ LeafSchemaNode leaf = (LeafSchemaNode) tested
+ .getDataChildByName("mybits");
+ BitsType leafType = (BitsType) leaf.getType();
+ List<Bit> bits = leafType.getBits();
+ assertEquals(3, bits.size());
+
+ Bit bit1 = bits.get(0);
+ assertEquals("disable-nagle", bit1.getName());
+ assertEquals(0L, (long) bit1.getPosition());
+
+ Bit bit2 = bits.get(1);
+ assertEquals("auto-sense-speed", bit2.getName());
+ assertEquals(1L, (long) bit2.getPosition());
+
+ Bit bit3 = bits.get(2);
+ assertEquals("10-Mb-only", bit3.getName());
+ assertEquals(2L, (long) bit3.getPosition());
+ }
+
+ @Test
+ public void testBitsType2() {
+ Module tested = findModule(testedModules, "custom-types-test");
+ Set<TypeDefinition<?>> typedefs = tested.getTypeDefinitions();
+ TypeDefinition<?> testedType = findTypedef(typedefs,
+ "access-operations-type");
+
+ BitsType bitsType = (BitsType) testedType.getBaseType();
+ List<Bit> bits = bitsType.getBits();
+ assertEquals(5, bits.size());
+
+ Bit bit0 = bits.get(0);
+ assertEquals(0L, (long) bit0.getPosition());
+
+ Bit bit1 = bits.get(1);
+ assertEquals(500L, (long) bit1.getPosition());
+
+ Bit bit2 = bits.get(2);
+ assertEquals(501L, (long) bit2.getPosition());
+
+ Bit bit3 = bits.get(3);
+ assertEquals(365L, (long) bit3.getPosition());
+
+ Bit bit4 = bits.get(4);
+ assertEquals(502L, (long) bit4.getPosition());