コード例 #1
0
    public bool Test(CultureInfo culture, string str1, string str2, int expected, CompareOptions options, string id)
    {
        CompareInfo ci = culture.CompareInfo;

        if (!id.Contains("s") || !Utilities.IsVistaOrLater)         //Due Windows 7 bug 130925
        {
            expected = GlobLocHelper.OSLastIndexOf(culture, str1, str2, options);
        }
        bool result = true;

        if (str1 == null || str2 == null || (str1.Length < 100 && str2.Length < 100))
        {
            TestFramework.BeginScenario(id + ": Comparing " + ((str1 == null) ? "null" : str1) + " / " + ((str2 == null) ? "null" : str2) + "; options: " + options + "; culture: " + ci.Name);
        }
        else
        {
            TestFramework.BeginScenario(id + ": Comparing LongStr (" + str1.Length + ") / LongStr(" + str2.Length + "); options: " + options + "; culture: " + ci.Name);
        }
        try
        {
            int i = ci.LastIndexOf(str1, str2, options);
            if (i != expected)
            {
                result = false;
                TestFramework.LogError("001z", "Error in " + id + ", unexpected comparison result. Actual: " + i + ", Expected: " + expected);
            }
        }
        catch (Exception exc)
        {
            result = false;
            TestFramework.LogError("003z", "Unexpected exception in " + id + ", excpetion: " + exc.ToString());
        }
        return(result);
    }