예제 #1
0
        public void TestPrepare()
        {
            StringPrep sp = StringPrep.GetInstance(0);

            try
            {
                if (!(sp.Prepare("dummy", 0)).Equals("dummy"))
                {
                    Errln("StringPrep.prepare(String,int) was suppose to return " + "'dummy'");
                }
            }
            catch (Exception e)
            {
                Errln("StringPrep.prepare(String,int) was not suppose to return " + "an exception.");
            }
        }
예제 #2
0
        public void TestGetInstance()
        {
            // Tests when "if (profile < 0 || profile > MAX_PROFILE)" is true
            int[] neg_num_cases = { -100, -50, -10, -5, -2, -1 };
            for (int i = 0; i < neg_num_cases.Length; i++)
            {
                try
                {
                    StringPrep.GetInstance((StringPrepProfile)neg_num_cases[i]);
                    Errln("StringPrep.GetInstance(int) expected an exception for " +
                          "an invalid parameter of " + neg_num_cases[i]);
                }
                catch (Exception e)
                {
                }
            }

            StringPrepProfile[] max_profile_cases = { StringPrepProfile.Rfc4518LdapCaseInsensitive + 1, StringPrepProfile.Rfc4518LdapCaseInsensitive + 2, StringPrepProfile.Rfc4518LdapCaseInsensitive + 5, StringPrepProfile.Rfc4518LdapCaseInsensitive + 10 };
            for (int i = 0; i < max_profile_cases.Length; i++)
            {
                try
                {
                    StringPrep.GetInstance(max_profile_cases[i]);
                    Errln("StringPrep.GetInstance(int) expected an exception for " +
                          "an invalid parameter of " + max_profile_cases[i]);
                }
                catch (Exception e)
                {
                }
            }

            // Tests when "if (instance == null)", "if (stream != null)", "if (instance != null)", and "if (ref != null)" is true
            int[] cases = { 0, 1, (int)StringPrepProfile.Rfc4518LdapCaseInsensitive };
            for (int i = 0; i < cases.Length; i++)
            {
                try
                {
                    StringPrep.GetInstance((StringPrepProfile)cases[i]);
                }
                catch (Exception e)
                {
                    Errln("StringPrep.GetInstance(int) did not expected an exception for " +
                          "an valid parameter of " + cases[i]);
                }
            }
        }
예제 #3
0
        public void TestProfiles()
        {
            String     profileName = null;
            StringPrep sprep       = null;
            String     result      = null;
            String     src         = null;
            String     expected    = null;

            for (int i = 0; i < testCases.Length; i++)
            {
                for (int j = 0; j < testCases[i].Length; j++)
                {
                    if (j == 0)
                    {
                        profileName = testCases[i][j];

                        sprep = StringPrep.GetInstance(GetOptionFromProfileName(profileName));
                    }
                    else
                    {
                        src      = testCases[i][j];
                        expected = testCases[i][++j];
                        try
                        {
                            result = sprep.Prepare(src, StringPrepOptions.AllowUnassigned);
                            if (src.StartsWith("FAIL", StringComparison.Ordinal))
                            {
                                Errln("Failed: Expected error for Test[" + i + "] Profile: " + profileName);
                            }
                            else if (!result.Equals(expected))
                            {
                                Errln("Failed: Test[" + i + "] Result string does not match expected string for StringPrep test for profile: " + profileName);
                            }
                        }
                        catch (StringPrepParseException ex)
                        {
                            if (!src.StartsWith("FAIL", StringComparison.Ordinal))
                            {
                                Errln("Failed: Test[" + i + "] StringPrep profile " + profileName + " got error: " + ex);
                            }
                        }
                    }
                }
            }
        }
예제 #4
0
        //---------------------------------------------------------------------
        // Static method
        //---------------------------------------------------------------------
        public static IACEConverter Create(string pSchema)
        {
            IACEConverter converter = null;

            try
            {
                // valid?
                if (null != pSchema)
                {
                    pSchema = pSchema.ToUpper();
                }

                // create converter
                switch (pSchema)
                {
                case SCHEMA_RACE:
                    converter = new ACEConverter(StringPrep.GetInstance(), new RaceConverter());
                    break;

                case SCHEMA_PUNYCODE:
                    converter = new ACEConverter(StringPrep.GetInstance(), new PunyConverter());
                    break;

                default:
                    converter = null;
                    break;
                }
            }
            catch (Exception)
            {
                converter = null;
            }

            // Done
            return(converter);
        }