示例#1
0
  public void TestDummyIntTrie() {
    IntTrie trie;
    final int initialValue = 0x01234567, leadUnitValue = 0x89abcdef;
    int value;
    int c;
    trie = new IntTrie(initialValue, leadUnitValue, new DummyGetFoldingOffset());

    /* test that all code points have initialValue */
    for (c = 0; c <= 0x10ffff; ++c) {
      value = trie.getCodePointValue(c);
      if (value != initialValue) {
        errln(
            "IntTrie/dummy.getCodePointValue(c)(U+"
                + hex(c)
                + ")=0x"
                + hex(value)
                + " instead of 0x"
                + hex(initialValue));
      }
    }

    /* test that the lead surrogate code units have leadUnitValue */
    for (c = 0xd800; c <= 0xdbff; ++c) {
      value = trie.getLeadValue((char) c);
      if (value != leadUnitValue) {
        errln(
            "IntTrie/dummy.getLeadValue(c)(U+"
                + hex(c)
                + ")=0x"
                + hex(value)
                + " instead of 0x"
                + hex(leadUnitValue));
      }
    }
  }
示例#2
0
 private void _testTrieIteration(IntTrie trie, CheckRange checkRanges[], int countCheckRanges) {
   // write a string
   int countValues = 0;
   StringBuffer s = new StringBuffer();
   int values[] = new int[30];
   for (int i = 0; i < countCheckRanges; ++i) {
     int c = checkRanges[i].limit;
     if (c != 0) {
       --c;
       UTF16.append(s, c);
       values[countValues++] = checkRanges[i].value;
     }
   }
   int limit = s.length();
   // try forward
   int p = 0;
   int i = 0;
   while (p < limit) {
     int c = UTF16.charAt(s, p);
     p += UTF16.getCharCount(c);
     int value = trie.getCodePointValue(c);
     if (value != values[i]) {
       errln(
           "wrong value from UTRIE_NEXT(U+"
               + Integer.toHexString(c)
               + "): 0x"
               + Integer.toHexString(value)
               + " instead of 0x"
               + Integer.toHexString(values[i]));
     }
     // unlike the c version lead is 0 if c is non-supplementary
     char lead = UTF16.getLeadSurrogate(c);
     char trail = UTF16.getTrailSurrogate(c);
     if (lead == 0
         ? trail != s.charAt(p - 1)
         : !UTF16.isLeadSurrogate(lead)
             || !UTF16.isTrailSurrogate(trail)
             || lead != s.charAt(p - 2)
             || trail != s.charAt(p - 1)) {
       errln("wrong (lead, trail) from UTRIE_NEXT(U+" + Integer.toHexString(c));
       continue;
     }
     if (lead != 0) {
       value = trie.getLeadValue(lead);
       value = trie.getTrailValue(value, trail);
       if (value != trie.getSurrogateValue(lead, trail) && value != values[i]) {
         errln(
             "wrong value from getting supplementary "
                 + "values (U+"
                 + Integer.toHexString(c)
                 + "): 0x"
                 + Integer.toHexString(value)
                 + " instead of 0x"
                 + Integer.toHexString(values[i]));
       }
     }
     ++i;
   }
 }
示例#3
0
  private void _testTrieRanges(
      SetRange setRanges[],
      int countSetRanges,
      CheckRange checkRanges[],
      int countCheckRanges,
      boolean latin1Linear) {
    IntTrieBuilder newTrie =
        new IntTrieBuilder(null, 2000, checkRanges[0].value, checkRanges[0].value, latin1Linear);

    // set values from setRanges[]
    boolean ok = true;
    for (int i = 0; i < countSetRanges; ++i) {
      int start = setRanges[i].start;
      int limit = setRanges[i].limit;
      int value = setRanges[i].value;
      boolean overwrite = setRanges[i].overwrite;
      if ((limit - start) == 1 && overwrite) {
        ok &= newTrie.setValue(start, value);
      } else {
        ok &= newTrie.setRange(start, limit, value, overwrite);
      }
    }
    if (!ok) {
      errln("setting values into a trie failed");
      return;
    }

    // verify that all these values are in the new Trie
    int start = 0;
    for (int i = 0; i < countCheckRanges; ++i) {
      int limit = checkRanges[i].limit;
      int value = checkRanges[i].value;

      while (start < limit) {
        if (value != newTrie.getValue(start)) {
          errln(
              "newTrie [U+"
                  + Integer.toHexString(start)
                  + "]==0x"
                  + Integer.toHexString(newTrie.getValue(start))
                  + " instead of 0x"
                  + Integer.toHexString(value));
        }
        ++start;
      }
    }

    IntTrie trie = newTrie.serialize(new _testFoldedValue(newTrie), new _testFoldingOffset());

    // test linear Latin-1 range from utrie_getData()
    if (latin1Linear) {
      start = 0;
      for (int i = 0; i < countCheckRanges && start <= 0xff; ++i) {
        int limit = checkRanges[i].limit;
        int value = checkRanges[i].value;

        while (start < limit && start <= 0xff) {
          if (value != trie.getLatin1LinearValue((char) start)) {
            errln(
                "IntTrie.getLatin1LinearValue[U+"
                    + Integer.toHexString(start)
                    + "]==0x"
                    + Integer.toHexString(trie.getLatin1LinearValue((char) start))
                    + " instead of 0x"
                    + Integer.toHexString(value));
          }
          ++start;
        }
      }
    }

    if (latin1Linear != trie.isLatin1Linear()) {
      errln("trie serialization did not preserve " + "Latin-1-linearity");
    }

    // verify that all these values are in the serialized Trie
    start = 0;
    for (int i = 0; i < countCheckRanges; ++i) {
      int limit = checkRanges[i].limit;
      int value = checkRanges[i].value;

      if (start == 0xd800) {
        // skip surrogates
        start = limit;
        continue;
      }

      while (start < limit) {
        if (start <= 0xffff) {
          int value2 = trie.getBMPValue((char) start);
          if (value != value2) {
            errln(
                "serialized trie.getBMPValue(U+"
                    + Integer.toHexString(start)
                    + " == 0x"
                    + Integer.toHexString(value2)
                    + " instead of 0x"
                    + Integer.toHexString(value));
          }
          if (!UTF16.isLeadSurrogate((char) start)) {
            value2 = trie.getLeadValue((char) start);
            if (value != value2) {
              errln(
                  "serialized trie.getLeadValue(U+"
                      + Integer.toHexString(start)
                      + " == 0x"
                      + Integer.toHexString(value2)
                      + " instead of 0x"
                      + Integer.toHexString(value));
            }
          }
        }
        int value2 = trie.getCodePointValue(start);
        if (value != value2) {
          errln(
              "serialized trie.getCodePointValue(U+"
                  + Integer.toHexString(start)
                  + ")==0x"
                  + Integer.toHexString(value2)
                  + " instead of 0x"
                  + Integer.toHexString(value));
        }
        ++start;
      }
    }

    // enumerate and verify all ranges

    int enumRanges = 1;
    TrieIterator iter = new _testEnumValue(trie);
    RangeValueIterator.Element result = new RangeValueIterator.Element();
    while (iter.next(result)) {
      if (result.start != checkRanges[enumRanges - 1].limit
          || result.limit != checkRanges[enumRanges].limit
          || (result.value ^ 0x5555) != checkRanges[enumRanges].value) {
        errln(
            "utrie_enum() delivers wrong range [U+"
                + Integer.toHexString(result.start)
                + "..U+"
                + Integer.toHexString(result.limit)
                + "].0x"
                + Integer.toHexString(result.value ^ 0x5555)
                + " instead of [U+"
                + Integer.toHexString(checkRanges[enumRanges - 1].limit)
                + "..U+"
                + Integer.toHexString(checkRanges[enumRanges].limit)
                + "].0x"
                + Integer.toHexString(checkRanges[enumRanges].value));
      }
      enumRanges++;
    }

    // test linear Latin-1 range
    if (trie.isLatin1Linear()) {
      for (start = 0; start < 0x100; ++start) {
        if (trie.getLatin1LinearValue((char) start) != trie.getLeadValue((char) start)) {
          errln(
              "trie.getLatin1LinearValue[U+"
                  + Integer.toHexString(start)
                  + "]=0x"
                  + Integer.toHexString(trie.getLatin1LinearValue((char) start))
                  + " instead of 0x"
                  + Integer.toHexString(trie.getLeadValue((char) start)));
        }
      }
    }

    _testTrieIteration(trie, checkRanges, countCheckRanges);
  }