You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@lucene.apache.org by rm...@apache.org on 2010/02/23 21:48:05 UTC
svn commit: r915514 - in
/lucene/java/branches/flex_1458_3_0_back_compat_tests/src:
java/org/apache/lucene/util/ test/org/apache/lucene/index/
Author: rmuir
Date: Tue Feb 23 20:48:05 2010
New Revision: 915514
URL: http://svn.apache.org/viewvc?rev=915514&view=rev
Log:
LUCENE-2111: new backwards tests for UTF8Result -> BytesRef
Modified:
lucene/java/branches/flex_1458_3_0_back_compat_tests/src/java/org/apache/lucene/util/BytesRef.java
lucene/java/branches/flex_1458_3_0_back_compat_tests/src/java/org/apache/lucene/util/UnicodeUtil.java
lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestIndexWriter.java
lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestPayloads.java
Modified: lucene/java/branches/flex_1458_3_0_back_compat_tests/src/java/org/apache/lucene/util/BytesRef.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458_3_0_back_compat_tests/src/java/org/apache/lucene/util/BytesRef.java?rev=915514&r1=915513&r2=915514&view=diff
==============================================================================
--- lucene/java/branches/flex_1458_3_0_back_compat_tests/src/java/org/apache/lucene/util/BytesRef.java (original)
+++ lucene/java/branches/flex_1458_3_0_back_compat_tests/src/java/org/apache/lucene/util/BytesRef.java Tue Feb 23 20:48:05 2010
@@ -2,6 +2,8 @@
// stub for tests only
public class BytesRef {
+ public BytesRef(int capacity) {}
+ public BytesRef() {}
public byte[] bytes;
public int offset;
public int length;
Modified: lucene/java/branches/flex_1458_3_0_back_compat_tests/src/java/org/apache/lucene/util/UnicodeUtil.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458_3_0_back_compat_tests/src/java/org/apache/lucene/util/UnicodeUtil.java?rev=915514&r1=915513&r2=915514&view=diff
==============================================================================
--- lucene/java/branches/flex_1458_3_0_back_compat_tests/src/java/org/apache/lucene/util/UnicodeUtil.java (original)
+++ lucene/java/branches/flex_1458_3_0_back_compat_tests/src/java/org/apache/lucene/util/UnicodeUtil.java Tue Feb 23 20:48:05 2010
@@ -106,6 +106,10 @@
}
}
+ // stubs for tests only
+ public static void UTF16toUTF8(char[] source, int offset, int length, BytesRef result) {}
+ public static void UTF16toUTF8(CharSequence s, int offset, int length, BytesRef result) {}
+
/** Encode characters from a char[] source, starting at
* offset and stopping when the character 0xffff is seen.
* Returns the number of bytes written to bytesOut. */
@@ -223,7 +227,7 @@
/** Encode characters from this String, starting at offset
* for length characters. Returns the number of bytes
* written to bytesOut. */
- public static void UTF16toUTF8(final String s, final int offset, final int length, UTF8Result result) {
+ public static void UTF16toUTF8(final CharSequence s, final int offset, final int length, UTF8Result result) {
final int end = offset + length;
byte[] out = result.result;
Modified: lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestIndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestIndexWriter.java?rev=915514&r1=915513&r2=915514&view=diff
==============================================================================
--- lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestIndexWriter.java (original)
+++ lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestIndexWriter.java Tue Feb 23 20:48:05 2010
@@ -64,6 +64,7 @@
import org.apache.lucene.store.NoLockFactory;
import org.apache.lucene.store.RAMDirectory;
import org.apache.lucene.store.SingleInstanceLockFactory;
+import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.UnicodeUtil;
import org.apache.lucene.util._TestUtil;
import org.apache.lucene.util.Version;
@@ -3309,7 +3310,7 @@
// LUCENE-510
public void testAllUnicodeChars() throws Throwable {
- UnicodeUtil.UTF8Result utf8 = new UnicodeUtil.UTF8Result();
+ BytesRef utf8 = new BytesRef(10);
UnicodeUtil.UTF16Result utf16 = new UnicodeUtil.UTF16Result();
char[] chars = new char[2];
for(int ch=0;ch<0x0010FFFF;ch++) {
@@ -3329,16 +3330,16 @@
UnicodeUtil.UTF16toUTF8(chars, 0, len, utf8);
String s1 = new String(chars, 0, len);
- String s2 = new String(utf8.result, 0, utf8.length, "UTF-8");
+ String s2 = new String(utf8.bytes, 0, utf8.length, "UTF-8");
assertEquals("codepoint " + ch, s1, s2);
- UnicodeUtil.UTF8toUTF16(utf8.result, 0, utf8.length, utf16);
+ UnicodeUtil.UTF8toUTF16(utf8.bytes, 0, utf8.length, utf16);
assertEquals("codepoint " + ch, s1, new String(utf16.result, 0, utf16.length));
byte[] b = s1.getBytes("UTF-8");
assertEquals(utf8.length, b.length);
for(int j=0;j<utf8.length;j++)
- assertEquals(utf8.result[j], b[j]);
+ assertEquals(utf8.bytes[j], b[j]);
}
}
@@ -3403,7 +3404,7 @@
char[] buffer = new char[20];
char[] expected = new char[20];
- UnicodeUtil.UTF8Result utf8 = new UnicodeUtil.UTF8Result();
+ BytesRef utf8 = new BytesRef(20);
UnicodeUtil.UTF16Result utf16 = new UnicodeUtil.UTF16Result();
for(int iter=0;iter<100000;iter++) {
@@ -3414,10 +3415,10 @@
byte[] b = new String(buffer, 0, 20).getBytes("UTF-8");
assertEquals(b.length, utf8.length);
for(int i=0;i<b.length;i++)
- assertEquals(b[i], utf8.result[i]);
+ assertEquals(b[i], utf8.bytes[i]);
}
- UnicodeUtil.UTF8toUTF16(utf8.result, 0, utf8.length, utf16);
+ UnicodeUtil.UTF8toUTF16(utf8.bytes, 0, utf8.length, utf16);
assertEquals(utf16.length, 20);
for(int i=0;i<20;i++)
assertEquals(expected[i], utf16.result[i]);
@@ -3430,7 +3431,7 @@
char[] buffer = new char[20];
char[] expected = new char[20];
- UnicodeUtil.UTF8Result utf8 = new UnicodeUtil.UTF8Result();
+ BytesRef utf8 = new BytesRef(20);
UnicodeUtil.UTF16Result utf16 = new UnicodeUtil.UTF16Result();
UnicodeUtil.UTF16Result utf16a = new UnicodeUtil.UTF16Result();
@@ -3453,7 +3454,7 @@
byte[] b = new String(buffer, 0, 20).getBytes("UTF-8");
assertEquals(b.length, utf8.length);
for(int i=0;i<b.length;i++)
- assertEquals(b[i], utf8.result[i]);
+ assertEquals(b[i], utf8.bytes[i]);
}
int bytePrefix = 20;
@@ -3461,18 +3462,18 @@
bytePrefix = 0;
else
for(int i=0;i<20;i++)
- if (last[i] != utf8.result[i]) {
+ if (last[i] != utf8.bytes[i]) {
bytePrefix = i;
break;
}
- System.arraycopy(utf8.result, 0, last, 0, utf8.length);
+ System.arraycopy(utf8.bytes, 0, last, 0, utf8.length);
- UnicodeUtil.UTF8toUTF16(utf8.result, bytePrefix, utf8.length-bytePrefix, utf16);
+ UnicodeUtil.UTF8toUTF16(utf8.bytes, bytePrefix, utf8.length-bytePrefix, utf16);
assertEquals(20, utf16.length);
for(int i=0;i<20;i++)
assertEquals(expected[i], utf16.result[i]);
- UnicodeUtil.UTF8toUTF16(utf8.result, 0, utf8.length, utf16a);
+ UnicodeUtil.UTF8toUTF16(utf8.bytes, 0, utf8.length, utf16a);
assertEquals(20, utf16a.length);
for(int i=0;i<20;i++)
assertEquals(expected[i], utf16a.result[i]);
Modified: lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestPayloads.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestPayloads.java?rev=915514&r1=915513&r2=915514&view=diff
==============================================================================
--- lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestPayloads.java (original)
+++ lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestPayloads.java Tue Feb 23 20:48:05 2010
@@ -39,6 +39,7 @@
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.store.RAMDirectory;
+import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.UnicodeUtil;
import org.apache.lucene.util._TestUtil;
@@ -561,13 +562,13 @@
}
}
- private UnicodeUtil.UTF8Result utf8Result = new UnicodeUtil.UTF8Result();
+ private BytesRef utf8Result = new BytesRef(10);
synchronized String bytesToString(byte[] bytes) {
String s = new String(bytes);
UnicodeUtil.UTF16toUTF8(s, 0, s.length(), utf8Result);
try {
- return new String(utf8Result.result, 0, utf8Result.length, "UTF-8");
+ return new String(utf8Result.bytes, 0, utf8Result.length, "UTF-8");
} catch (UnsupportedEncodingException uee) {
return null;
}