예제 #1
0
 public override void SetStringValue(string value)
 {
     key          = collator.GetRawCollationKey(value, key);
     bytes.Bytes  = key.Bytes;
     bytes.Offset = 0;
     bytes.Length = key.Length;
 }
예제 #2
0
        private void conformanceTest(RuleBasedCollator coll)
        {
            if (@in == null || coll == null)
            {
                return;
            }
            int skipFlags = 0;

            if (coll.IsAlternateHandlingShifted)
            {
                skipFlags |= IS_SHIFTED;
            }
            if (coll == rbUCA)
            {
                skipFlags |= FROM_RULES;
            }

            Logln("-prop:ucaconfnosortkeys=1 turns off getSortKey() in UCAConformanceTest");
            bool withSortKeys = GetProperty("ucaconfnosortkeys") == null;

            int lineNo = 0;

            String          line = null, oldLine = null, buffer = null, oldB = null;
            RawCollationKey sk1 = new RawCollationKey(), sk2 = new RawCollationKey();
            RawCollationKey oldSk = null, newSk = sk1;

            try
            {
                while ((line = @in.ReadLine()) != null)
                {
                    lineNo++;
                    if (line.Length == 0 || line[0] == '#')
                    {
                        continue;
                    }
                    buffer = parseString(line);

                    if (skipLineBecauseOfBug(buffer, skipFlags))
                    {
                        Logln("Skipping line " + lineNo + " because of a known bug");
                        continue;
                    }

                    if (withSortKeys)
                    {
                        coll.GetRawCollationKey(buffer, newSk);
                    }
                    if (oldSk != null)
                    {
                        bool ok      = true;
                        int  skres   = withSortKeys ? oldSk.CompareTo(newSk) : 0;
                        int  cmpres  = coll.Compare(oldB, buffer);
                        int  cmpres2 = coll.Compare(buffer, oldB);

                        if (cmpres != -cmpres2)
                        {
                            Errln(String.Format(
                                      "Compare result not symmetrical on line {0}: "
                                      + "previous vs. current ({1}) / current vs. previous ({2})",
                                      lineNo, cmpres, cmpres2));
                            ok = false;
                        }

                        // TODO: Compare with normalization turned off if the input passes the FCD test.

                        if (withSortKeys && cmpres != normalizeResult(skres))
                        {
                            Errln("Difference between coll.compare (" + cmpres + ") and sortkey compare (" + skres
                                  + ") on line " + lineNo);
                            ok = false;
                        }

                        int res = cmpres;
                        if (res == 0 && !isAtLeastUCA62)
                        {
                            // Up to UCA 6.1, the collation test files use a custom tie-breaker,
                            // comparing the raw input strings.
                            res = comparer.Compare(oldB, buffer);
                            // Starting with UCA 6.2, the collation test files use the standard UCA tie-breaker,
                            // comparing the NFD versions of the input strings,
                            // which we do via setting strength=identical.
                        }
                        if (res > 0)
                        {
                            Errln("Line " + lineNo + " is not greater or equal than previous line");
                            ok = false;
                        }

                        if (!ok)
                        {
                            Errln("  Previous data line " + oldLine);
                            Errln("  Current data line  " + line);
                            if (withSortKeys)
                            {
                                Errln("  Previous key: " + CollationTest.Prettify(oldSk));
                                Errln("  Current key:  " + CollationTest.Prettify(newSk));
                            }
                        }
                    }

                    oldSk   = newSk;
                    oldB    = buffer;
                    oldLine = line;
                    if (oldSk == sk1)
                    {
                        newSk = sk2;
                    }
                    else
                    {
                        newSk = sk1;
                    }
                }
            }
            catch (Exception e)
            {
                Errln("Unexpected exception " + e);
            }
            finally
            {
                try
                {
                    @in.Dispose();
                }
                catch (IOException ignored)
                {
                }
                @in = null;
            }
        }