Index: lucene/src/test/org/apache/lucene/util/LuceneTestCaseJ4.java =================================================================== --- lucene/src/test/org/apache/lucene/util/LuceneTestCaseJ4.java (revision 979227) +++ lucene/src/test/org/apache/lucene/util/LuceneTestCaseJ4.java (working copy) @@ -324,6 +324,9 @@ throw new IllegalStateException("please call LuceneTestCaseJ4.newRandom only once per test"); } this.seed = Long.valueOf(seedRnd.nextLong()); + if (VERBOSE) { + System.out.println("NOTE: random seed of testcase '" + getName() + "' is: " + this.seed); + } return new Random(seed); } Index: lucene/src/test/org/apache/lucene/util/LuceneTestCase.java =================================================================== --- lucene/src/test/org/apache/lucene/util/LuceneTestCase.java (revision 979227) +++ lucene/src/test/org/apache/lucene/util/LuceneTestCase.java (working copy) @@ -248,6 +248,9 @@ throw new IllegalStateException("please call LuceneTestCase.newRandom only once per test"); } this.seed = Long.valueOf(seedRnd.nextLong()); + if (VERBOSE) { + System.out.println("NOTE: random seed of testcase '" + getName() + "' is: " + this.seed); + } return new Random(seed); } Index: lucene/src/test/org/apache/lucene/util/automaton/TestUTF32ToUTF8.java =================================================================== --- lucene/src/test/org/apache/lucene/util/automaton/TestUTF32ToUTF8.java (revision 979227) +++ lucene/src/test/org/apache/lucene/util/automaton/TestUTF32ToUTF8.java (working copy) @@ -46,15 +46,44 @@ private void testOne(Random r, ByteRunAutomaton a, int startCode, int endCode, int iters) { // Verify correct ints are accepted + final int nonSurrogateCount; + final boolean ovSurStart; + if (endCode < UnicodeUtil.UNI_SUR_HIGH_START || + startCode > UnicodeUtil.UNI_SUR_LOW_END) { + // no overlap w/ surrogates + nonSurrogateCount = endCode - startCode + 1; + ovSurStart = false; + } else if (isSurrogate(startCode)) { + // start of range overlaps surrogates + nonSurrogateCount = endCode - startCode + 1 - (UnicodeUtil.UNI_SUR_LOW_END - startCode + 1); + ovSurStart = false; + } else if (isSurrogate(endCode)) { + // end of range overlaps surrogates + ovSurStart = true; + nonSurrogateCount = endCode - startCode + 1 - (endCode - UnicodeUtil.UNI_SUR_HIGH_START + 1); + } else { + // range completely subsumes surrogates + ovSurStart = true; + nonSurrogateCount = endCode - startCode + 1 - (UnicodeUtil.UNI_SUR_LOW_END - UnicodeUtil.UNI_SUR_HIGH_START + 1); + } + + assert nonSurrogateCount > 0; + for(int iter=0;iter= UnicodeUtil.UNI_SUR_HIGH_START && code <= UnicodeUtil.UNI_SUR_HIGH_END) | - (code >= UnicodeUtil.UNI_SUR_LOW_START && code <= UnicodeUtil.UNI_SUR_LOW_END)) { - iter--; - continue; + int code = startCode + r.nextInt(nonSurrogateCount); + if (isSurrogate(code)) { + if (ovSurStart) { + code = UnicodeUtil.UNI_SUR_LOW_END + 1 + (code - UnicodeUtil.UNI_SUR_HIGH_START); + } else { + code = UnicodeUtil.UNI_SUR_LOW_END + 1 + (code - startCode); + } } + + assert code >= startCode && code <= endCode: "code=" + code + " start=" + startCode + " end=" + endCode; + assert !isSurrogate(code); + assertTrue("DFA for range " + startCode + "-" + endCode + " failed to match code=" + code, matches(a, code)); } @@ -97,6 +126,10 @@ } } + private static boolean isSurrogate(int code) { + return code >= UnicodeUtil.UNI_SUR_HIGH_START && code <= UnicodeUtil.UNI_SUR_LOW_END; + } + public void testRandomRanges() throws Exception { final Random r = random; int ITERS = 10*_TestUtil.getRandomMultiplier(); @@ -113,6 +146,11 @@ startCode = x2; endCode = x1; } + + if (isSurrogate(startCode) && isSurrogate(endCode)) { + iter--; + continue; + } final Automaton a = new Automaton(); final State end = new State();