Exemplo n.º 1
0
        public void runConformance(String fileName, int options)
        {
            String line = null;

            String[]
            fields                 = new String[5];
            StringBuffer buf       = new StringBuffer();
            int          passCount = 0;
            int          failCount = 0;
            UnicodeSet   other     = new UnicodeSet(0, 0x10ffff);
            int          c         = 0;
            TextReader   input     = null;

            try
            {
                input = TestUtil.GetDataReader(fileName);
                for (int count = 0; ; ++count)
                {
                    line = input.ReadLine();
                    if (line == null)
                    {
                        //read the extra test cases
                        if (count > moreCases.Length)
                        {
                            count = 0;
                        }
                        else if (count == moreCases.Length)
                        {
                            // all done
                            break;
                        }
                        line = moreCases[count++];
                    }
                    if (line.Length == 0)
                    {
                        continue;
                    }

                    // Expect 5 columns of this format:
                    // 1E0C;1E0C;0044 0323;1E0C;0044 0323; # <comments>

                    // Skip comments
                    if (line[0] == '#' || line[0] == '@')
                    {
                        continue;
                    }

                    // Parse out the fields
                    hexsplit(line, ';', fields, buf);

                    // Remove a single code point from the "other" UnicodeSet
                    if (fields[0].Length == UTF16.MoveCodePointOffset(fields[0], 0, 1))
                    {
                        c = UTF16.CharAt(fields[0], 0);
                        if (0xac20 <= c && c <= 0xd73f)
                        {
                            // not an exhaustive test run: skip most Hangul syllables
                            if (c == 0xac20)
                            {
                                other.Remove(0xac20, 0xd73f);
                            }
                            continue;
                        }
                        other.Remove(c);
                    }
                    if (checkConformance(fields, line, options))
                    {
                        ++passCount;
                    }
                    else
                    {
                        ++failCount;
                    }
                    if ((count % 1000) == 999)
                    {
                        Logln("Line " + (count + 1));
                    }
                }
            }
            catch (IOException ex)
            {
                ex.PrintStackTrace();
                throw new ArgumentException("Couldn't read file "
                                            + ex.GetType().Name + " " + ex.ToString()
                                            + " line = " + line
                                            );
            }
            finally
            {
                if (input != null)
                {
                    try
                    {
                        input.Dispose();
                    }
                    catch (IOException ignored)
                    {
                    }
                }
            }

            if (failCount != 0)
            {
                Errln("Total: " + failCount + " lines failed, " +
                      passCount + " lines passed");
            }
            else
            {
                Logln("Total: " + passCount + " lines passed");
            }
        }