Exemplo n.º 1
0
        [TestMethod] public void testSetRelevantDescPatternsSetsAllDescriptionsForRegularLengthNumbers()
        {
            String xmlInput =
                "<territory countryCode=\"33\">" +
                "  <fixedLine><nationalNumberPattern>\\d{1}</nationalNumberPattern></fixedLine>" +
                "  <mobile><nationalNumberPattern>\\d{2}</nationalNumberPattern></mobile>" +
                "  <pager><nationalNumberPattern>\\d{3}</nationalNumberPattern></pager>" +
                "  <tollFree><nationalNumberPattern>\\d{4}</nationalNumberPattern></tollFree>" +
                "  <premiumRate><nationalNumberPattern>\\d{5}</nationalNumberPattern></premiumRate>" +
                "  <sharedCost><nationalNumberPattern>\\d{6}</nationalNumberPattern></sharedCost>" +
                "  <personalNumber><nationalNumberPattern>\\d{7}</nationalNumberPattern></personalNumber>" +
                "  <voip><nationalNumberPattern>\\d{8}</nationalNumberPattern></voip>" +
                "  <uan><nationalNumberPattern>\\d{9}</nationalNumberPattern></uan>" +
                "</territory>";
            XmlElement territoryElement = parseXmlString(xmlInput);

            PhoneMetadata.Builder metadata = PhoneMetadata.newBuilder();
            BuildMetadataFromXml.setRelevantDescPatterns(metadata, territoryElement, false /* liteBuild */,
                                                         false /* isShortNumberMetadata */);
            Assert.AreEqual("\\d{1}", metadata.getFixedLine().getNationalNumberPattern());
            Assert.AreEqual("\\d{2}", metadata.getMobile().getNationalNumberPattern());
            Assert.AreEqual("\\d{3}", metadata.getPager().getNationalNumberPattern());
            Assert.AreEqual("\\d{4}", metadata.getTollFree().getNationalNumberPattern());
            Assert.AreEqual("\\d{5}", metadata.getPremiumRate().getNationalNumberPattern());
            Assert.AreEqual("\\d{6}", metadata.getSharedCost().getNationalNumberPattern());
            Assert.AreEqual("\\d{7}", metadata.getPersonalNumber().getNationalNumberPattern());
            Assert.AreEqual("\\d{8}", metadata.getVoip().getNationalNumberPattern());
            Assert.AreEqual("\\d{9}", metadata.getUan().getNationalNumberPattern());
        }
Exemplo n.º 2
0
        // @VisibleForTesting
        internal static void setRelevantDescPatterns(PhoneMetadata.Builder metadata, XmlElement element,
                                                     bool liteBuild, bool isShortNumberMetadata)
        {
            PhoneNumberDesc.Builder generalDesc = PhoneNumberDesc.newBuilder();
            generalDesc = processPhoneNumberDescElement(generalDesc, element, GENERAL_DESC, liteBuild);
            metadata.setGeneralDesc(generalDesc);

            if (!isShortNumberMetadata)
            {
                // Set fields used only by regular length phone numbers.
                metadata.setFixedLine(
                    processPhoneNumberDescElement(generalDesc, element, FIXED_LINE, liteBuild));
                metadata.setMobile(
                    processPhoneNumberDescElement(generalDesc, element, MOBILE, liteBuild));
                metadata.setSharedCost(
                    processPhoneNumberDescElement(generalDesc, element, SHARED_COST, liteBuild));
                metadata.setVoip(
                    processPhoneNumberDescElement(generalDesc, element, VOIP, liteBuild));
                metadata.setPersonalNumber(
                    processPhoneNumberDescElement(generalDesc, element, PERSONAL_NUMBER, liteBuild));
                metadata.setPager(
                    processPhoneNumberDescElement(generalDesc, element, PAGER, liteBuild));
                metadata.setUan(
                    processPhoneNumberDescElement(generalDesc, element, UAN, liteBuild));
                metadata.setVoicemail(
                    processPhoneNumberDescElement(generalDesc, element, VOICEMAIL, liteBuild));
                metadata.setNoInternationalDialling(
                    processPhoneNumberDescElement(generalDesc, element, NO_INTERNATIONAL_DIALLING,
                                                  liteBuild));
                metadata.setSameMobileAndFixedLinePattern(
                    metadata.getMobile().getNationalNumberPattern().Equals(
                        metadata.getFixedLine().getNationalNumberPattern()));
            }
            else
            {
                // Set fields used only by short numbers.
                metadata.setStandardRate(
                    processPhoneNumberDescElement(generalDesc, element, STANDARD_RATE, liteBuild));
                metadata.setShortCode(
                    processPhoneNumberDescElement(generalDesc, element, SHORT_CODE, liteBuild));
                metadata.setCarrierSpecific(
                    processPhoneNumberDescElement(generalDesc, element, CARRIER_SPECIFIC, liteBuild));
                metadata.setEmergency(
                    processPhoneNumberDescElement(generalDesc, element, EMERGENCY, liteBuild));
            }

            // Set fields used by both regular length and short numbers.
            metadata.setTollFree(
                processPhoneNumberDescElement(generalDesc, element, TOLL_FREE, liteBuild));
            metadata.setPremiumRate(
                processPhoneNumberDescElement(generalDesc, element, PREMIUM_RATE, liteBuild));
        }