public _testFoldedValue(Int32TrieBuilder builder) { m_builder_ = builder; }
private void _testTrieRanges(SetRange[] setRanges, int countSetRanges, CheckRange[] checkRanges, int countCheckRanges, bool latin1Linear) { Int32TrieBuilder newTrie = new Int32TrieBuilder(null, 2000, checkRanges[0].Value, checkRanges[0].Value, latin1Linear); // set values from setRanges[] bool ok = true; for (int i = 0; i < countSetRanges; ++i) { int start = setRanges[i].start; int limit = setRanges[i].limit; int value = setRanges[i].value; bool 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+" + (start).ToHexString() + "]==0x" + (newTrie.GetValue(start).ToHexString()) + " instead of 0x" + (value).ToHexString()); } ++start; } } Int32Trie 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+" + (start).ToHexString() + "]==0x" + ( trie.GetLatin1LinearValue((char)start).ToHexString()) + " instead of 0x" + (value).ToHexString()); } ++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+" + (start).ToHexString() + " == 0x" + (value2).ToHexString() + " instead of 0x" + (value).ToHexString()); } if (!UTF16.IsLeadSurrogate((char)start)) { value2 = trie.GetLeadValue((char)start); if (value != value2) { Errln("serialized trie.getLeadValue(U+" + (start).ToHexString() + " == 0x" + (value2).ToHexString() + " instead of 0x" + (value).ToHexString()); } } } { int value2 = trie.GetCodePointValue(start); if (value != value2) { Errln("serialized trie.getCodePointValue(U+" + (start).ToHexString() + ")==0x" + (value2).ToHexString() + " instead of 0x" + (value).ToHexString()); } ++start; } } } // enumerate and verify all ranges int enumRanges = 1; TrieEnumerator iter = new _testEnumValue(trie); while (iter.MoveNext()) { RangeValueEnumeratorElement result = iter.Current; 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+" + (result.Start).ToHexString() + "..U+" + (result.Limit).ToHexString() + "].0x" + (result.Value ^ 0x5555).ToHexString() + " instead of [U+" + (checkRanges[enumRanges - 1].Limit).ToHexString() + "..U+" + (checkRanges[enumRanges].Limit).ToHexString() + "].0x" + (checkRanges[enumRanges].Value).ToHexString()); } 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+" + (start).ToHexString() + "]=0x" + ( trie.GetLatin1LinearValue((char)start).ToHexString()) + " instead of 0x" + ( trie.GetLeadValue((char)start)).ToHexString()); } } } _testTrieIteration(trie, checkRanges, countCheckRanges); } }