You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by sy...@apache.org on 2014/04/07 22:15:12 UTC
[2/2] git commit: Starting work to fix the tests suite + Java compat
work
Starting work to fix the tests suite + Java compat work
Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/a1bda0ab
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/a1bda0ab
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/a1bda0ab
Branch: refs/heads/branch_4x
Commit: a1bda0ab894ad557ab5d49cd29dfef6837a83c97
Parents: 346bffd
Author: synhershko <it...@code972.com>
Authored: Mon Apr 7 23:14:42 2014 +0300
Committer: synhershko <it...@code972.com>
Committed: Mon Apr 7 23:14:42 2014 +0300
----------------------------------------------------------------------
lib/repositories.config | 1 +
test/core/Analysis/TestCharFilter.cs | 61 ++-
test/core/Analysis/TestToken.cs | 483 ++++++++++---------
.../Tokenattributes/TestSimpleAttributeImpls.cs | 44 +-
.../Tokenattributes/TestTermAttributeImpl.cs | 4 -
test/core/Document/TestDateTools.cs | 1 -
test/core/Lucene.Net.Test.csproj | 9 +-
test/core/packages.config | 4 +
test/test-framework/Attributes.cs | 64 +++
.../JavaCompatibility/LuceneTestCase.cs | 88 ++++
.../JavaCompatibility/LuceneTypesHelpers.cs | 9 +
.../JavaCompatibility/SystemTypesHelpers.cs | 34 ++
.../Lucene.Net.TestFramework.csproj | 8 +-
test/test-framework/LuceneTestCase.cs | 423 ++++++++++++++++
test/test-framework/Util/Attributes.cs | 64 ---
test/test-framework/Util/LuceneTestCase.cs | 481 ------------------
test/test-framework/Util/_TestUtil.cs | 20 +
17 files changed, 966 insertions(+), 832 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a1bda0ab/lib/repositories.config
----------------------------------------------------------------------
diff --git a/lib/repositories.config b/lib/repositories.config
index 7ef44ec..5741bef 100644
--- a/lib/repositories.config
+++ b/lib/repositories.config
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<repositories>
+ <repository path="..\test\core\packages.config" />
<repository path="..\test\test-framework\packages.config" />
</repositories>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a1bda0ab/test/core/Analysis/TestCharFilter.cs
----------------------------------------------------------------------
diff --git a/test/core/Analysis/TestCharFilter.cs b/test/core/Analysis/TestCharFilter.cs
index cc5717a..212bcb0 100644
--- a/test/core/Analysis/TestCharFilter.cs
+++ b/test/core/Analysis/TestCharFilter.cs
@@ -15,51 +15,48 @@
* limitations under the License.
*/
-using System;
-
+using System.IO;
using NUnit.Framework;
-using LuceneTestCase = Lucene.Net.Util.LuceneTestCase;
-
namespace Lucene.Net.Analysis
{
[TestFixture]
public class TestCharFilter:LuceneTestCase
{
-
+
[Test]
- public virtual void TestCharFilter1()
- {
- CharStream cs = new CharFilter1(CharReader.Get(new System.IO.StringReader("")));
- Assert.AreEqual(1, cs.CorrectOffset(0), "corrected offset is invalid");
- }
-
+ public void testCharFilter1()
+ {
+ CharFilter cs = new CharFilter1(new StringReader(""));
+ assertEquals("corrected offset is invalid", 1, cs.CorrectOffset(0));
+ }
+
[Test]
- public virtual void TestCharFilter2()
- {
- CharStream cs = new CharFilter2(CharReader.Get(new System.IO.StringReader("")));
- Assert.AreEqual(2, cs.CorrectOffset(0), "corrected offset is invalid");
- }
-
+ public void testCharFilter2()
+ {
+ CharFilter cs = new CharFilter2(new StringReader(""));
+ assertEquals("corrected offset is invalid", 2, cs.CorrectOffset(0));
+ }
+
[Test]
- public virtual void TestCharFilter12()
- {
- CharStream cs = new CharFilter2(new CharFilter1(CharReader.Get(new System.IO.StringReader(""))));
- Assert.AreEqual(3, cs.CorrectOffset(0), "corrected offset is invalid");
- }
-
+ public void testCharFilter12()
+ {
+ CharFilter cs = new CharFilter2(new CharFilter1(new StringReader("")));
+ assertEquals("corrected offset is invalid", 3, cs.CorrectOffset(0));
+ }
+
[Test]
- public virtual void TestCharFilter11()
- {
- CharStream cs = new CharFilter1(new CharFilter1(CharReader.Get(new System.IO.StringReader(""))));
- Assert.AreEqual(2, cs.CorrectOffset(0), "corrected offset is invalid");
- }
-
- internal class CharFilter1:CharFilter
+ public void testCharFilter11()
+ {
+ CharFilter cs = new CharFilter1(new CharFilter1(new StringReader("")));
+ assertEquals("corrected offset is invalid", 2, cs.CorrectOffset(0));
+ }
+
+ internal class CharFilter1 : CharFilter
{
- protected internal CharFilter1(CharStream in_Renamed):base(in_Renamed)
+ protected internal CharFilter1(TextReader cs):base(cs)
{
}
@@ -72,7 +69,7 @@ namespace Lucene.Net.Analysis
internal class CharFilter2:CharFilter
{
- protected internal CharFilter2(CharStream in_Renamed):base(in_Renamed)
+ protected internal CharFilter2(TextReader cs):base(cs)
{
}
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a1bda0ab/test/core/Analysis/TestToken.cs
----------------------------------------------------------------------
diff --git a/test/core/Analysis/TestToken.cs b/test/core/Analysis/TestToken.cs
index 11441ef..5bbf23c 100644
--- a/test/core/Analysis/TestToken.cs
+++ b/test/core/Analysis/TestToken.cs
@@ -16,234 +16,212 @@
*/
using System;
-using System.IO;
-using Lucene.Net.Analysis.Tokenattributes;
+using System.Text;
using Lucene.Net.Util;
using NUnit.Framework;
using Attribute = Lucene.Net.Util.Attribute;
-using Payload = Lucene.Net.Index.Payload;
-using TestSimpleAttributeImpls = Lucene.Net.Analysis.Tokenattributes.TestSimpleAttributeImpls;
-using LuceneTestCase = Lucene.Net.Util.LuceneTestCase;
namespace Lucene.Net.Analysis
-{
-
+{
[TestFixture]
public class TestToken:LuceneTestCase
{
- public TestToken()
+ [Test]
+ public void testCtor()
{
+ Token t = new Token();
+ char[] content = "hello".toCharArray();
+ t.CopyBuffer(content, 0, content.Length);
+ assertNotSame(t.Buffer, content);
+ assertEquals(0, t.StartOffset);
+ assertEquals(0, t.EndOffset);
+ assertEquals("hello", t.ToString());
+ assertEquals("word", t.Type);
+ assertEquals(0, t.Flags);
+
+ t = new Token(6, 22);
+ t.CopyBuffer(content, 0, content.Length);
+ assertEquals("hello", t.ToString());
+ assertEquals("hello", t.ToString());
+ assertEquals(6, t.StartOffset);
+ assertEquals(22, t.EndOffset);
+ assertEquals("word", t.Type);
+ assertEquals(0, t.Flags);
+
+ t = new Token(6, 22, 7);
+ t.CopyBuffer(content, 0, content.Length);
+ assertEquals("hello", t.ToString());
+ assertEquals("hello", t.ToString());
+ assertEquals(6, t.StartOffset);
+ assertEquals(22, t.EndOffset);
+ assertEquals("word", t.Type);
+ assertEquals(7, t.Flags);
+
+ t = new Token(6, 22, "junk");
+ t.CopyBuffer(content, 0, content.Length);
+ assertEquals("hello", t.ToString());
+ assertEquals("hello", t.ToString());
+ assertEquals(6, t.StartOffset);
+ assertEquals(22, t.EndOffset);
+ assertEquals("junk", t.Type);
+ assertEquals(0, t.Flags);
}
- public TestToken(System.String name):base(name)
- {
- }
-
- [Test]
- public virtual void TestCtor()
- {
- Token t = new Token();
- char[] content = "hello".ToCharArray();
- t.SetTermBuffer(content, 0, content.Length);
- char[] buf = t.TermBuffer();
- Assert.AreNotEqual(t.TermBuffer(), content);
- Assert.AreEqual("hello", t.Term);
- Assert.AreEqual("word", t.Type);
- Assert.AreEqual(0, t.Flags);
-
- t = new Token(6, 22);
- t.SetTermBuffer(content, 0, content.Length);
- Assert.AreEqual("hello", t.Term);
- Assert.AreEqual("(hello,6,22)", t.ToString());
- Assert.AreEqual("word", t.Type);
- Assert.AreEqual(0, t.Flags);
-
- t = new Token(6, 22, 7);
- t.SetTermBuffer(content, 0, content.Length);
- Assert.AreEqual("hello", t.Term);
- Assert.AreEqual("(hello,6,22)", t.ToString());
- Assert.AreEqual(7, t.Flags);
-
- t = new Token(6, 22, "junk");
- t.SetTermBuffer(content, 0, content.Length);
- Assert.AreEqual("hello", t.Term);
- Assert.AreEqual("(hello,6,22,type=junk)", t.ToString());
- Assert.AreEqual(0, t.Flags);
- }
-
[Test]
- public virtual void TestResize()
- {
- Token t = new Token();
- char[] content = "hello".ToCharArray();
- t.SetTermBuffer(content, 0, content.Length);
- for (int i = 0; i < 2000; i++)
- {
- t.ResizeTermBuffer(i);
- Assert.IsTrue(i <= t.TermBuffer().Length);
- Assert.AreEqual("hello", t.Term);
- }
- }
+ public void testResize()
+ {
+ Token t = new Token();
+ char[] content = "hello".toCharArray();
+ t.CopyBuffer(content, 0, content.Length);
+ for (int i = 0; i < 2000; i++)
+ {
+ t.ResizeBuffer(i);
+ assertTrue(i <= t.Buffer.Length);
+ assertEquals("hello", t.ToString());
+ }
+ }
[Test]
- public virtual void TestGrow()
- {
- Token t = new Token();
- System.Text.StringBuilder buf = new System.Text.StringBuilder("ab");
- for (int i = 0; i < 20; i++)
- {
- char[] content = buf.ToString().ToCharArray();
- t.SetTermBuffer(content, 0, content.Length);
- Assert.AreEqual(buf.Length, t.TermLength());
- Assert.AreEqual(buf.ToString(), t.Term);
- buf.Append(buf.ToString());
- }
- Assert.AreEqual(1048576, t.TermLength());
- Assert.AreEqual(1179654, t.TermBuffer().Length);
-
- // now as a string, first variant
- t = new Token();
- buf = new System.Text.StringBuilder("ab");
- for (int i = 0; i < 20; i++)
- {
- System.String content = buf.ToString();
- t.SetTermBuffer(content, 0, content.Length);
- Assert.AreEqual(content.Length, t.TermLength());
- Assert.AreEqual(content, t.Term);
- buf.Append(content);
- }
- Assert.AreEqual(1048576, t.TermLength());
- Assert.AreEqual(1179654, t.TermBuffer().Length);
-
- // now as a string, second variant
- t = new Token();
- buf = new System.Text.StringBuilder("ab");
- for (int i = 0; i < 20; i++)
- {
- System.String content = buf.ToString();
- t.SetTermBuffer(content);
- Assert.AreEqual(content.Length, t.TermLength());
- Assert.AreEqual(content, t.Term);
- buf.Append(content);
- }
- Assert.AreEqual(1048576, t.TermLength());
- Assert.AreEqual(1179654, t.TermBuffer().Length);
-
- // Test for slow growth to a long term
- t = new Token();
- buf = new System.Text.StringBuilder("a");
- for (int i = 0; i < 20000; i++)
- {
- System.String content = buf.ToString();
- t.SetTermBuffer(content);
- Assert.AreEqual(content.Length, t.TermLength());
- Assert.AreEqual(content, t.Term);
- buf.Append("a");
- }
- Assert.AreEqual(20000, t.TermLength());
- Assert.AreEqual(20167, t.TermBuffer().Length);
-
- // Test for slow growth to a long term
- t = new Token();
- buf = new System.Text.StringBuilder("a");
- for (int i = 0; i < 20000; i++)
- {
- System.String content = buf.ToString();
- t.SetTermBuffer(content);
- Assert.AreEqual(content.Length, t.TermLength());
- Assert.AreEqual(content, t.Term);
- buf.Append("a");
- }
- Assert.AreEqual(20000, t.TermLength());
- Assert.AreEqual(20167, t.TermBuffer().Length);
- }
-
+ public void testGrow()
+ {
+ Token t = new Token();
+ StringBuilder buf = new StringBuilder("ab");
+ for (int i = 0; i < 20; i++)
+ {
+ char[] content = buf.toString().toCharArray();
+ t.CopyBuffer(content, 0, content.Length);
+ assertEquals(buf.Length, t.Length);
+ assertEquals(buf.toString(), t.toString());
+ buf.Append(buf.toString());
+ }
+ assertEquals(1048576, t.Length);
+
+ // now as a string, second variant
+ t = new Token();
+ buf = new StringBuilder("ab");
+ for (int i = 0; i < 20; i++)
+ {
+ t.SetEmpty().Append(buf);
+ String content = buf.toString();
+ assertEquals(content.Length, t.Length);
+ assertEquals(content, t.toString());
+ buf.append(content);
+ }
+ assertEquals(1048576, t.Length);
+
+ // Test for slow growth to a long term
+ t = new Token();
+ buf = new StringBuilder("a");
+ for (int i = 0; i < 20000; i++)
+ {
+ t.SetEmpty().Append(buf);
+ String content = buf.toString();
+ assertEquals(content.Length, t.Length);
+ assertEquals(content, t.toString());
+ buf.append("a");
+ }
+ assertEquals(20000, t.Length);
+
+ // Test for slow growth to a long term
+ t = new Token();
+ buf = new StringBuilder("a");
+ for (int i = 0; i < 20000; i++)
+ {
+ t.SetEmpty().Append(buf);
+ String content = buf.toString();
+ assertEquals(content.Length, t.Length);
+ assertEquals(content, t.toString());
+ buf.append("a");
+ }
+ assertEquals(20000, t.Length);
+ }
+
[Test]
- public virtual void TestToString()
- {
- char[] b = new char[]{'a', 'l', 'o', 'h', 'a'};
- Token t = new Token("", 0, 5);
- t.SetTermBuffer(b, 0, 5);
- Assert.AreEqual("(aloha,0,5)", t.ToString());
-
- t.SetTermBuffer("hi there");
- Assert.AreEqual("(hi there,0,5)", t.ToString());
- }
-
+ public void testToString()
+ {
+ char[] b = {'a', 'l', 'o', 'h', 'a'};
+ Token t = new Token("", 0, 5);
+ t.CopyBuffer(b, 0, 5);
+ assertEquals("aloha", t.toString());
+
+ t.SetEmpty().Append("hi there");
+ assertEquals("hi there", t.toString());
+ }
+
[Test]
- public virtual void TestTermBufferEquals()
- {
- Token t1a = new Token();
- char[] content1a = "hello".ToCharArray();
- t1a.SetTermBuffer(content1a, 0, 5);
- Token t1b = new Token();
- char[] content1b = "hello".ToCharArray();
- t1b.SetTermBuffer(content1b, 0, 5);
- Token t2 = new Token();
- char[] content2 = "hello2".ToCharArray();
- t2.SetTermBuffer(content2, 0, 6);
- Assert.IsTrue(t1a.Equals(t1b));
- Assert.IsFalse(t1a.Equals(t2));
- Assert.IsFalse(t2.Equals(t1b));
- }
-
+ public void testTermBufferEquals()
+ {
+ Token t1a = new Token();
+ char[] content1a = "hello".toCharArray();
+ t1a.CopyBuffer(content1a, 0, 5);
+ Token t1b = new Token();
+ char[] content1b = "hello".toCharArray();
+ t1b.CopyBuffer(content1b, 0, 5);
+ Token t2 = new Token();
+ char[] content2 = "hello2".toCharArray();
+ t2.CopyBuffer(content2, 0, 6);
+ assertTrue(t1a.equals(t1b));
+ assertFalse(t1a.equals(t2));
+ assertFalse(t2.equals(t1b));
+ }
+
[Test]
- public virtual void TestMixedStringArray()
- {
- Token t = new Token("hello", 0, 5);
- Assert.AreEqual(t.TermLength(), 5);
- Assert.AreEqual(t.Term, "hello");
- t.SetTermBuffer("hello2");
- Assert.AreEqual(t.TermLength(), 6);
- Assert.AreEqual(t.Term, "hello2");
- t.SetTermBuffer("hello3".ToCharArray(), 0, 6);
- Assert.AreEqual(t.Term, "hello3");
-
- char[] buffer = t.TermBuffer();
- buffer[1] = 'o';
- Assert.AreEqual(t.Term, "hollo3");
- }
-
+ public void testMixedStringArray()
+ {
+ Token t = new Token("hello", 0, 5);
+ assertEquals(t.Length, 5);
+ assertEquals(t.toString(), "hello");
+ t.SetEmpty().Append("hello2");
+ assertEquals(t.Length, 6);
+ assertEquals(t.toString(), "hello2");
+ t.CopyBuffer("hello3".toCharArray(), 0, 6);
+ assertEquals(t.toString(), "hello3");
+
+ char[] buffer = t.Buffer;
+ buffer[1] = 'o';
+ assertEquals(t.toString(), "hollo3");
+ }
+
[Test]
- public virtual void TestClone()
- {
- Token t = new Token(0, 5);
- char[] content = "hello".ToCharArray();
- t.SetTermBuffer(content, 0, 5);
- char[] buf = t.TermBuffer();
- Token copy = (Token) TestSimpleAttributeImpls.AssertCloneIsEqual(t);
- Assert.AreEqual(t.Term, copy.Term);
- Assert.AreNotSame(buf, copy.TermBuffer());
-
- Payload pl = new Payload(new byte[]{1, 2, 3, 4});
- t.Payload = pl;
- copy = (Token) TestSimpleAttributeImpls.AssertCloneIsEqual(t);
- Assert.AreEqual(pl, copy.Payload);
- Assert.AreNotSame(pl, copy.Payload);
- }
-
+ public void testClone()
+ {
+ Token t = new Token(0, 5);
+ char[] content = "hello".toCharArray();
+ t.CopyBuffer(content, 0, 5);
+ char[] buf = t.Buffer;
+ Token copy = assertCloneIsEqual(t);
+ assertEquals(t.toString(), copy.toString());
+ assertNotSame(buf, copy.Buffer);
+
+ BytesRef pl = new BytesRef(new sbyte[] {1, 2, 3, 4});
+ t.Payload = pl;
+ copy = assertCloneIsEqual(t);
+ assertEquals(pl, copy.Payload);
+ assertNotSame(pl, copy.Payload);
+ }
+
[Test]
- public virtual void TestCopyTo()
- {
- Token t = new Token();
- Token copy = (Token) TestSimpleAttributeImpls.AssertCopyIsEqual(t);
- Assert.AreEqual("", t.Term);
- Assert.AreEqual("", copy.Term);
-
- t = new Token(0, 5);
- char[] content = "hello".ToCharArray();
- t.SetTermBuffer(content, 0, 5);
- char[] buf = t.TermBuffer();
- copy = (Token) TestSimpleAttributeImpls.AssertCopyIsEqual(t);
- Assert.AreEqual(t.Term, copy.Term);
- Assert.AreNotSame(buf, copy.TermBuffer());
-
- Payload pl = new Payload(new byte[]{1, 2, 3, 4});
- t.Payload = pl;
- copy = (Token) TestSimpleAttributeImpls.AssertCopyIsEqual(t);
- Assert.AreEqual(pl, copy.Payload);
- Assert.AreNotSame(pl, copy.Payload);
- }
+ public void testCopyTo()
+ {
+ Token t = new Token();
+ Token copy = assertCopyIsEqual(t);
+ assertEquals("", t.toString());
+ assertEquals("", copy.toString());
+
+ t = new Token(0, 5);
+ char[] content = "hello".toCharArray();
+ t.CopyBuffer(content, 0, 5);
+ char[] buf = t.Buffer;
+ copy = assertCopyIsEqual(t);
+ assertEquals(t.toString(), copy.toString());
+ assertNotSame(buf, copy.Buffer);
+
+ BytesRef pl = new BytesRef(new sbyte[] {1, 2, 3, 4});
+ t.Payload = pl;
+ copy = assertCopyIsEqual(t);
+ assertEquals(pl, copy.Payload);
+ assertNotSame(pl, copy.Payload);
+ }
public interface ISenselessAttribute : IAttribute {}
@@ -266,20 +244,85 @@ namespace Lucene.Net.Analysis
}
}
- [Test]
- public void TestTokenAttributeFactory()
+// [Test]
+// public void testTokenAttributeFactory() {
+// //TODO MockTokenizer
+// //TokenStream ts = new MockTokenizer(Token.TOKEN_ATTRIBUTE_FACTORY, new StringReader("foo bar"), MockTokenizer.WHITESPACE, false, MockTokenizer.DEFAULT_MAX_TOKEN_LENGTH);
+//
+// TokenStream ts = new WhitespaceTokenizer(Analysis.Token.TOKEN_ATTRIBUTE_FACTORY, new StringReader("foo, bar"));
+//
+// assertTrue("SenselessAttribute is not implemented by SenselessAttributeImpl",
+// ts.addAttribute(SenselessAttribute.class) instanceof SenselessAttributeImpl);
+//
+// assertTrue("CharTermAttribute is not implemented by Token",
+// ts.addAttribute(CharTermAttribute.class) instanceof Token);
+// assertTrue("OffsetAttribute is not implemented by Token",
+// ts.addAttribute(OffsetAttribute.class) instanceof Token);
+// assertTrue("FlagsAttribute is not implemented by Token",
+// ts.addAttribute(FlagsAttribute.class) instanceof Token);
+// assertTrue("PayloadAttribute is not implemented by Token",
+// ts.addAttribute(PayloadAttribute.class) instanceof Token);
+// assertTrue("PositionIncrementAttribute is not implemented by Token",
+// ts.addAttribute(PositionIncrementAttribute.class) instanceof Token);
+// assertTrue("TypeAttribute is not implemented by Token",
+// ts.addAttribute(TypeAttribute.class) instanceof Token);
+// }
+//
+// [Test]
+// public void TestTokenAttributeFactory()
+// {
+// TokenStream ts = new WhitespaceTokenizer(Token.TOKEN_ATTRIBUTE_FACTORY, new StringReader("foo, bar"));
+//
+// Assert.IsTrue(ts.AddAttribute<ISenselessAttribute>() is SenselessAttribute,
+// "TypeAttribute is not implemented by SenselessAttributeImpl");
+//
+// Assert.IsTrue(ts.AddAttribute<ITermAttribute>() is Token, "TermAttribute is not implemented by Token");
+// Assert.IsTrue(ts.AddAttribute<IOffsetAttribute>() is Token, "OffsetAttribute is not implemented by Token");
+// Assert.IsTrue(ts.AddAttribute<IFlagsAttribute>() is Token, "FlagsAttribute is not implemented by Token");
+// Assert.IsTrue(ts.AddAttribute<IPayloadAttribute>() is Token, "PayloadAttribute is not implemented by Token");
+// Assert.IsTrue(ts.AddAttribute<IPositionIncrementAttribute>() is Token, "PositionIncrementAttribute is not implemented by Token");
+// Assert.IsTrue(ts.AddAttribute<ITypeAttribute>() is Token, "TypeAttribute is not implemented by Token");
+// }
+// [Test]
+// public void testAttributeReflection() {
+// Token t = new Token("foobar", 6, 22, 8);
+// _TestUtil.assertAttributeReflection(t,
+// new HashMap<String,Object>() {{
+// put(CharTermAttribute.class.getName() + "#term", "foobar");
+// put(TermToBytesRefAttribute.class.getName() + "#bytes", new BytesRef("foobar"));
+// put(OffsetAttribute.class.getName() + "#startOffset", 6);
+// put(OffsetAttribute.class.getName() + "#endOffset", 22);
+// put(PositionIncrementAttribute.class.getName() + "#positionIncrement", 1);
+// put(PayloadAttribute.class.getName() + "#payload", null);
+// put(TypeAttribute.class.getName() + "#type", TypeAttribute.DEFAULT_TYPE);
+// put(FlagsAttribute.class.getName() + "#flags", 8);
+// }});
+// }
+
+ public static Token assertCloneIsEqual(Token att)
{
- TokenStream ts = new WhitespaceTokenizer(Token.TOKEN_ATTRIBUTE_FACTORY, new StringReader("foo, bar"));
+ Token clone = (Token) att.Clone();
+ Assert.AreEqual(att, clone, "Clone must be equal");
+ Assert.AreEqual(att.GetHashCode(), clone.GetHashCode(), "Clone's hashcode must be equal");
+ return clone;
+ }
- Assert.IsTrue(ts.AddAttribute<ISenselessAttribute>() is SenselessAttribute,
- "TypeAttribute is not implemented by SenselessAttributeImpl");
+ public static Token assertCopyIsEqual(Token att)
+ {
+ var copy = (Token) System.Activator.CreateInstance(att.GetType());
+ att.CopyTo(copy);
+ Assert.AreEqual(att, copy, "Copied instance must be equal");
+ Assert.AreEqual(att.GetHashCode(), copy.GetHashCode(), "Copied instance's hashcode must be equal");
+ return copy;
+ }
- Assert.IsTrue(ts.AddAttribute<ITermAttribute>() is Token, "TermAttribute is not implemented by Token");
- Assert.IsTrue(ts.AddAttribute<IOffsetAttribute>() is Token, "OffsetAttribute is not implemented by Token");
- Assert.IsTrue(ts.AddAttribute<IFlagsAttribute>() is Token, "FlagsAttribute is not implemented by Token");
- Assert.IsTrue(ts.AddAttribute<IPayloadAttribute>() is Token, "PayloadAttribute is not implemented by Token");
- Assert.IsTrue(ts.AddAttribute<IPositionIncrementAttribute>() is Token, "PositionIncrementAttribute is not implemented by Token");
- Assert.IsTrue(ts.AddAttribute<ITypeAttribute>() is Token, "TypeAttribute is not implemented by Token");
+ public TestToken()
+ {
+ }
+
+ public TestToken(System.String name)
+ : base(name)
+ {
}
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a1bda0ab/test/core/Analysis/Tokenattributes/TestSimpleAttributeImpls.cs
----------------------------------------------------------------------
diff --git a/test/core/Analysis/Tokenattributes/TestSimpleAttributeImpls.cs b/test/core/Analysis/Tokenattributes/TestSimpleAttributeImpls.cs
index 0da4c8b..99334b0 100644
--- a/test/core/Analysis/Tokenattributes/TestSimpleAttributeImpls.cs
+++ b/test/core/Analysis/Tokenattributes/TestSimpleAttributeImpls.cs
@@ -15,12 +15,8 @@
* limitations under the License.
*/
-using System;
-
using NUnit.Framework;
using Attribute = Lucene.Net.Util.Attribute;
-using Payload = Lucene.Net.Index.Payload;
-using LuceneTestCase = Lucene.Net.Util.LuceneTestCase;
namespace Lucene.Net.Analysis.Tokenattributes
{
@@ -90,26 +86,26 @@ namespace Lucene.Net.Analysis.Tokenattributes
Assert.AreEqual(TypeAttribute.DEFAULT_TYPE, att.Type);
}
- [Test]
- public virtual void TestPayloadAttribute()
- {
- PayloadAttribute att = new PayloadAttribute();
- Assert.IsNull(att.Payload);
-
- Payload pl = new Payload(new byte[]{1, 2, 3, 4});
- att.Payload = pl;
-
- PayloadAttribute att2 = (PayloadAttribute) AssertCloneIsEqual(att);
- Assert.AreEqual(pl, att2.Payload);
- Assert.AreNotSame(pl, att2.Payload);
-
- att2 = (PayloadAttribute) AssertCopyIsEqual(att);
- Assert.AreEqual(pl, att2.Payload);
- Assert.AreNotSame(pl, att2.Payload);
-
- att.Clear();
- Assert.IsNull(att.Payload);
- }
+// [Test]
+// public virtual void TestPayloadAttribute()
+// {
+// PayloadAttribute att = new PayloadAttribute();
+// Assert.IsNull(att.Payload);
+//
+// Payload pl = new Payload(new byte[]{1, 2, 3, 4});
+// att.Payload = pl;
+//
+// PayloadAttribute att2 = (PayloadAttribute) AssertCloneIsEqual(att);
+// Assert.AreEqual(pl, att2.Payload);
+// Assert.AreNotSame(pl, att2.Payload);
+//
+// att2 = (PayloadAttribute) AssertCopyIsEqual(att);
+// Assert.AreEqual(pl, att2.Payload);
+// Assert.AreNotSame(pl, att2.Payload);
+//
+// att.Clear();
+// Assert.IsNull(att.Payload);
+// }
[Test]
public virtual void TestOffsetAttribute()
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a1bda0ab/test/core/Analysis/Tokenattributes/TestTermAttributeImpl.cs
----------------------------------------------------------------------
diff --git a/test/core/Analysis/Tokenattributes/TestTermAttributeImpl.cs b/test/core/Analysis/Tokenattributes/TestTermAttributeImpl.cs
index e4de1d0..29666cf 100644
--- a/test/core/Analysis/Tokenattributes/TestTermAttributeImpl.cs
+++ b/test/core/Analysis/Tokenattributes/TestTermAttributeImpl.cs
@@ -15,12 +15,8 @@
* limitations under the License.
*/
-using System;
-
using NUnit.Framework;
-using LuceneTestCase = Lucene.Net.Util.LuceneTestCase;
-
namespace Lucene.Net.Analysis.Tokenattributes
{
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a1bda0ab/test/core/Document/TestDateTools.cs
----------------------------------------------------------------------
diff --git a/test/core/Document/TestDateTools.cs b/test/core/Document/TestDateTools.cs
index bbfc773..0a93507 100644
--- a/test/core/Document/TestDateTools.cs
+++ b/test/core/Document/TestDateTools.cs
@@ -20,7 +20,6 @@ using System;
using NUnit.Framework;
using LocalizedTestCase = Lucene.Net.Util.LocalizedTestCase;
-using LuceneTestCase = Lucene.Net.Util.LuceneTestCase;
namespace Lucene.Net.Documents
{
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a1bda0ab/test/core/Lucene.Net.Test.csproj
----------------------------------------------------------------------
diff --git a/test/core/Lucene.Net.Test.csproj b/test/core/Lucene.Net.Test.csproj
index fd665ad..79abb1e 100644
--- a/test/core/Lucene.Net.Test.csproj
+++ b/test/core/Lucene.Net.Test.csproj
@@ -175,9 +175,8 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\ICSharpCode\SharpZipLib\0.85\ICSharpCode.SharpZipLib.dll</HintPath>
</Reference>
- <Reference Include="nunit.framework, Version=2.5.9.10348, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\..\lib\NUnit.org\NUnit\2.5.9\bin\net-2.0\framework\nunit.framework.dll</HintPath>
+ <Reference Include="nunit.framework">
+ <HintPath>..\..\lib\NUnit.2.6.3\lib\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="nunit.mocks, Version=2.5.9.10348, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
@@ -200,6 +199,8 @@
</Reference>
</ItemGroup>
<ItemGroup>
+ <Compile Include="Analysis\TestToken.cs" />
+ <Compile Include="Analysis\Tokenattributes\TestSimpleAttributeImpls.cs" />
<Compile Include="AssemblyInfo.cs">
<SubType>Code</SubType>
</Compile>
@@ -222,6 +223,7 @@
<None Include="Index\index.29.cfs.zip" />
<None Include="Index\index.29.nocfs.zip" />
<None Include="Lucene.Net.snk" />
+ <None Include="packages.config" />
<None Include="README.md" />
</ItemGroup>
<ItemGroup>
@@ -265,7 +267,6 @@
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
- <Folder Include="Analysis\Tokenattributes\" />
<Folder Include="QueryParser\" />
<Folder Include="Randomization\" />
<Folder Include="Search\Function\" />
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a1bda0ab/test/core/packages.config
----------------------------------------------------------------------
diff --git a/test/core/packages.config b/test/core/packages.config
new file mode 100644
index 0000000..967502d
--- /dev/null
+++ b/test/core/packages.config
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+ <package id="NUnit" version="2.6.3" targetFramework="net40" />
+</packages>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a1bda0ab/test/test-framework/Attributes.cs
----------------------------------------------------------------------
diff --git a/test/test-framework/Attributes.cs b/test/test-framework/Attributes.cs
new file mode 100644
index 0000000..5991ab4
--- /dev/null
+++ b/test/test-framework/Attributes.cs
@@ -0,0 +1,64 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Lucene.Net.Util
+{
+
+ public class LuceneCategoryAttribute : NUnit.Framework.CategoryAttribute
+ {
+ public LuceneCategoryAttribute(string name)
+ : base(name.Replace(":", " ").Replace(".", " "))
+ {
+
+ }
+ }
+
+ public class NightlyAttribute : LuceneCategoryAttribute
+ {
+ public const string KEY = "tests:nightly";
+
+ public NightlyAttribute()
+ : base(KEY)
+ {
+
+ }
+ }
+
+ public class AwaitsFixAttribute : LuceneCategoryAttribute
+ {
+ public const string KEY = "tests:awaitsfix";
+
+ public AwaitsFixAttribute()
+ : base(KEY)
+ {
+
+ }
+ }
+
+
+ public class WeeklyAttribute : LuceneCategoryAttribute
+ {
+ public const string KEY = "tests:weekly";
+
+ public WeeklyAttribute()
+ : base(KEY)
+ {
+
+ }
+ }
+
+ public class SlowAttribute : LuceneCategoryAttribute
+ {
+ public const string KEY = "tests:slow";
+
+ public static bool Ignore { get; set; }
+
+ public SlowAttribute(bool enabled)
+ : base(KEY)
+ {
+
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a1bda0ab/test/test-framework/JavaCompatibility/LuceneTestCase.cs
----------------------------------------------------------------------
diff --git a/test/test-framework/JavaCompatibility/LuceneTestCase.cs b/test/test-framework/JavaCompatibility/LuceneTestCase.cs
new file mode 100644
index 0000000..7361b7e
--- /dev/null
+++ b/test/test-framework/JavaCompatibility/LuceneTestCase.cs
@@ -0,0 +1,88 @@
+using NUnit.Framework;
+
+namespace Lucene.Net
+{
+ public abstract partial class LuceneTestCase
+ {
+ public static void assertTrue(bool condition)
+ {
+ Assert.IsTrue(condition);
+ }
+
+ public static void assertTrue(string message, bool condition)
+ {
+ Assert.IsTrue(condition, message);
+ }
+
+ public static void assertFalse(bool condition)
+ {
+ Assert.IsFalse(condition);
+ }
+
+ public static void assertFalse(string message, bool condition)
+ {
+ Assert.IsFalse(condition, message);
+ }
+
+ public static void assertEquals(object expected, object actual)
+ {
+ Assert.AreEqual(expected, actual);
+ }
+
+ public static void assertEquals(string message, object expected, object actual)
+ {
+ Assert.AreEqual(expected, actual, message);
+ }
+
+ public static void assertEquals(long expected, long actual)
+ {
+ Assert.AreEqual(expected, actual);
+ }
+
+ public static void assertEquals(string message, long expected, long actual)
+ {
+ Assert.AreEqual(expected, actual, message);
+ }
+
+ public static void assertNotSame(object unexpected, object actual)
+ {
+ Assert.AreNotSame(unexpected, actual);
+ }
+
+ public static void assertNotSame(string message, object unexpected, object actual)
+ {
+ Assert.AreNotSame(unexpected, actual, message);
+ }
+
+
+ protected static void assertEquals(double d1, double d2, double delta)
+ {
+ Assert.AreEqual(d1, d2, delta);
+ }
+
+ protected static void assertEquals(string msg, double d1, double d2, double delta)
+ {
+ Assert.AreEqual(d1, d2, delta, msg);
+ }
+
+ protected static void assertNotNull(object o)
+ {
+ Assert.NotNull(o);
+ }
+
+ protected static void assertNotNull(string msg, object o)
+ {
+ Assert.NotNull(o, msg);
+ }
+
+ protected static void assertNull(object o)
+ {
+ Assert.Null(o);
+ }
+
+ protected static void assertNull(string msg, object o)
+ {
+ Assert.Null(o, msg);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a1bda0ab/test/test-framework/JavaCompatibility/LuceneTypesHelpers.cs
----------------------------------------------------------------------
diff --git a/test/test-framework/JavaCompatibility/LuceneTypesHelpers.cs b/test/test-framework/JavaCompatibility/LuceneTypesHelpers.cs
new file mode 100644
index 0000000..838b432
--- /dev/null
+++ b/test/test-framework/JavaCompatibility/LuceneTypesHelpers.cs
@@ -0,0 +1,9 @@
+using Lucene.Net.Analysis;
+
+namespace Lucene.Net
+{
+ public static class LuceneTypesHelpers
+ {
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a1bda0ab/test/test-framework/JavaCompatibility/SystemTypesHelpers.cs
----------------------------------------------------------------------
diff --git a/test/test-framework/JavaCompatibility/SystemTypesHelpers.cs b/test/test-framework/JavaCompatibility/SystemTypesHelpers.cs
new file mode 100644
index 0000000..f8f7e4b
--- /dev/null
+++ b/test/test-framework/JavaCompatibility/SystemTypesHelpers.cs
@@ -0,0 +1,34 @@
+using System.Text;
+
+namespace Lucene.Net
+{
+ public static class SystemTypesHelpers
+ {
+ public static char[] toCharArray(this string str)
+ {
+ return str.ToCharArray();
+ }
+
+ public static string toString(this object obj)
+ {
+ return obj.ToString();
+ }
+
+ public static bool equals(this object obj1, object obj2)
+ {
+ return obj1.Equals(obj2);
+ }
+
+ public static StringBuilder append(this StringBuilder sb, long value)
+ {
+ sb.Append(value);
+ return sb;
+ }
+
+ public static StringBuilder append(this StringBuilder sb, string value)
+ {
+ sb.Append(value);
+ return sb;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a1bda0ab/test/test-framework/Lucene.Net.TestFramework.csproj
----------------------------------------------------------------------
diff --git a/test/test-framework/Lucene.Net.TestFramework.csproj b/test/test-framework/Lucene.Net.TestFramework.csproj
index 823f1f7..109c4a9 100644
--- a/test/test-framework/Lucene.Net.TestFramework.csproj
+++ b/test/test-framework/Lucene.Net.TestFramework.csproj
@@ -54,6 +54,9 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
+ <Compile Include="JavaCompatibility\LuceneTestCase.cs" />
+ <Compile Include="JavaCompatibility\LuceneTypesHelpers.cs" />
+ <Compile Include="JavaCompatibility\SystemTypesHelpers.cs" />
<Compile Include="Randomized\Attributes\SeedDecoratorAttribute.cs" />
<Compile Include="Randomized\IllegalStateException.cs" />
<Compile Include="Randomized\InternalAssumptionViolatedException.cs">
@@ -68,9 +71,10 @@
<Compile Include="Randomized\ThreadGroup.cs" />
<Compile Include="Support\RandomizedTest.cs" />
<Compile Include="Support\SystemProperties.cs" />
- <Compile Include="Util\Attributes.cs" />
- <Compile Include="Util\LuceneTestCase.cs" />
+ <Compile Include="Attributes.cs" />
+ <Compile Include="LuceneTestCase.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="Util\_TestUtil.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\core\Lucene.Net.csproj">
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a1bda0ab/test/test-framework/LuceneTestCase.cs
----------------------------------------------------------------------
diff --git a/test/test-framework/LuceneTestCase.cs b/test/test-framework/LuceneTestCase.cs
new file mode 100644
index 0000000..9d14d52
--- /dev/null
+++ b/test/test-framework/LuceneTestCase.cs
@@ -0,0 +1,423 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using Lucene.Net.Util;
+using NUnit.Framework;
+
+using ConcurrentMergeScheduler = Lucene.Net.Index.ConcurrentMergeScheduler;
+using Insanity = Lucene.Net.Util.FieldCacheSanityChecker.Insanity;
+using FieldCache = Lucene.Net.Search.FieldCache;
+using Lucene.Net.TestFramework.Support;
+using System.Collections.Generic;
+using Lucene.Net.Search;
+
+using Lucene.Net.TestFramework;
+
+namespace Lucene.Net
+{
+
+ /// <summary> Base class for all Lucene unit tests.
+ /// <p/>
+ /// Currently the
+ /// only added functionality over JUnit's TestCase is
+ /// asserting that no unhandled exceptions occurred in
+ /// threads launched by ConcurrentMergeScheduler and asserting sane
+ /// FieldCache usage athe moment of tearDown.
+ /// <p/>
+ /// If you
+ /// override either <c>setUp()</c> or
+ /// <c>tearDown()</c> in your unit test, make sure you
+ /// call <c>super.setUp()</c> and
+ /// <c>super.tearDown()</c>
+ /// <p/>
+ /// </summary>
+ /// <seealso cref="assertSaneFieldCaches">
+ /// </seealso>
+ [Serializable]
+ [TestFixture]
+ public abstract partial class LuceneTestCase : Assert
+ {
+ // --------------------------------------------------------------------
+ // Test groups, system properties and other annotations modifying tests
+ // --------------------------------------------------------------------
+
+ public const string SYSPROP_NIGHTLY = "tests.nightly";
+ public const string SYSPROP_WEEKLY = "tests.weekly";
+ public const string SYSPROP_AWAITSFIX = "tests.awaitsfix";
+ public const string SYSPROP_SLOW = "tests.slow";
+ public const string SYSPROP_BADAPPLES = "tests.badapples";
+
+ /** @see #ignoreAfterMaxFailures*/
+ private const string SYSPROP_MAXFAILURES = "tests.maxfailures";
+
+ /** @see #ignoreAfterMaxFailures*/
+ private const string SYSPROP_FAILFAST = "tests.failfast";
+
+
+
+
+ public static readonly Util.Version TEST_VERSION_CURRENT = Util.Version.LUCENE_43;
+
+ public static readonly bool VERBOSE = RandomizedTest.SystemPropertyAsBoolean("tests.verbose", false);
+
+ public static readonly bool INFOSTREAM = RandomizedTest.SystemPropertyAsBoolean("tests.infostream", VERBOSE);
+
+ public static readonly int RANDOM_MULTIPLIER = RandomizedTest.SystemPropertyAsInt("tests.multiplier", 1);
+
+ public static readonly string DEFAULT_LINE_DOCS_FILE = "europarl.lines.txt.gz";
+
+ public static readonly string JENKINS_LARGE_LINE_DOCS_FILE = "enwiki.random.lines.txt";
+
+ public static readonly string TEST_CODEC = SystemProperties.GetProperty("tests.codec", "random");
+
+ public static readonly string TEST_DOCVALUESFORMAT = SystemProperties.GetProperty("tests.docvaluesformat", "random");
+
+ public static readonly string TEST_DIRECTORY = SystemProperties.GetProperty("tests.directory", "random");
+
+ public static readonly string TEST_LINE_DOCS_FILE = SystemProperties.GetProperty("tests.linedocsfile", DEFAULT_LINE_DOCS_FILE);
+
+ public static readonly bool TEST_NIGHTLY = RandomizedTest.SystemPropertyAsBoolean(NightlyAttribute.KEY, false);
+
+ public static readonly bool TEST_WEEKLY = RandomizedTest.SystemPropertyAsBoolean(WeeklyAttribute.KEY, false);
+
+ public static readonly bool TEST_AWAITSFIX = RandomizedTest.SystemPropertyAsBoolean(AwaitsFixAttribute.KEY, false);
+
+ public static readonly bool TEST_SLOW = RandomizedTest.SystemPropertyAsBoolean(SlowAttribute.KEY, false);
+
+ //public static readonly MockDirectoryWrapper.Throttling TEST_THROTTLING = TEST_NIGHTLY ? MockDirectoryWrapper.Throttling.SOMETIMES : MockDirectoryWrapper.Throttling.NEVER;
+
+ public static readonly System.IO.DirectoryInfo TEMP_DIR;
+
+ static LuceneTestCase()
+ {
+ String s = SystemProperties.GetProperty("tempDir", System.IO.Path.GetTempPath());
+ if (s == null)
+ throw new SystemException("To run tests, you need to define system property 'tempDir' or 'java.io.tmpdir'.");
+
+ TEMP_DIR = new System.IO.DirectoryInfo(s);
+ if (!TEMP_DIR.Exists) TEMP_DIR.Create();
+
+ CORE_DIRECTORIES = new List<string>(FS_DIRECTORIES);
+ CORE_DIRECTORIES.Add("RAMDirectory");
+
+
+ }
+
+ private static readonly string[] IGNORED_INVARIANT_PROPERTIES = {
+ "user.timezone", "java.rmi.server.randomIDs"
+ };
+
+ private static readonly IList<String> FS_DIRECTORIES = new[] {
+ "SimpleFSDirectory",
+ "NIOFSDirectory",
+ "MMapDirectory"
+ };
+
+ private static readonly IList<String> CORE_DIRECTORIES;
+
+ // .NET Port: this Java code moved to static ctor above
+ //static {
+ // CORE_DIRECTORIES = new ArrayList<String>(FS_DIRECTORIES);
+ // CORE_DIRECTORIES.add("RAMDirectory");
+ //};
+
+ protected static readonly ISet<String> doesntSupportOffsets = new HashSet<String>(new[] {
+ "Lucene3x",
+ "MockFixedIntBlock",
+ "MockVariableIntBlock",
+ "MockSep",
+ "MockRandom"
+ });
+
+ public void Test()
+ {
+
+ }
+
+ public static bool PREFLEX_IMPERSONATION_IS_ACTIVE;
+
+ //private static readonly TestRuleStoreClassName classNameRule;
+
+ //internal static readonly TestRuleSetupAndRestoreClassEnv classEnvRule;
+
+ //public static readonly TestRuleMarkFailure suiteFailureMarker =
+ // new TestRuleMarkFailure();
+
+ //internal static readonly TestRuleIgnoreAfterMaxFailures ignoreAfterMaxFailures;
+
+ private const long STATIC_LEAK_THRESHOLD = 10 * 1024 * 1024;
+
+ //private static readonly ISet<String> STATIC_LEAK_IGNORED_TYPES =
+ // new HashSet<String>(new[] {
+ // "org.slf4j.Logger",
+ // "org.apache.solr.SolrLogFormatter",
+ // typeof(EnumSet).FullName});
+
+ // public static TestRule classRules = RuleChain
+ //.outerRule(new TestRuleIgnoreTestSuites())
+ //.around(ignoreAfterMaxFailures)
+ //.around(suiteFailureMarker)
+ //.around(new TestRuleAssertionsRequired())
+ //.around(new StaticFieldsInvariantRule(STATIC_LEAK_THRESHOLD, true) {
+ // @Override
+ // protected boolean accept(java.lang.reflect.Field field) {
+ // // Don't count known classes that consume memory once.
+ // if (STATIC_LEAK_IGNORED_TYPES.contains(field.getType().getName())) {
+ // return false;
+ // }
+ // // Don't count references from ourselves, we're top-level.
+ // if (field.getDeclaringClass() == LuceneTestCase.class) {
+ // return false;
+ // }
+ // return super.accept(field);
+ // }
+ //})
+ //.around(new NoClassHooksShadowingRule())
+ //.around(new NoInstanceHooksOverridesRule() {
+ // @Override
+ // protected boolean verify(Method key) {
+ // String name = key.getName();
+ // return !(name.equals("setUp") || name.equals("tearDown"));
+ // }
+ //})
+ //.around(new SystemPropertiesInvariantRule(IGNORED_INVARIANT_PROPERTIES))
+ //.around(classNameRule = new TestRuleStoreClassName())
+ //.around(classEnvRule = new TestRuleSetupAndRestoreClassEnv());
+
+ //static {
+ // int maxFailures = systemPropertyAsInt(SYSPROP_MAXFAILURES, Integer.MAX_VALUE);
+ // boolean failFast = systemPropertyAsBoolean(SYSPROP_FAILFAST, false);
+
+ // if (failFast) {
+ // if (maxFailures == Integer.MAX_VALUE) {
+ // maxFailures = 1;
+ // } else {
+ // Logger.getLogger(LuceneTestCase.class.getSimpleName()).warning(
+ // "Property '" + SYSPROP_MAXFAILURES + "'=" + maxFailures + ", 'failfast' is" +
+ // " ignored.");
+ // }
+ // }
+
+ // ignoreAfterMaxFailures = new TestRuleIgnoreAfterMaxFailures(maxFailures);
+ //}
+
+ //bool allowDocsOutOfOrder = true;
+
+ public LuceneTestCase()
+ : base()
+ {
+ }
+
+
+
+ public LuceneTestCase(System.String name)
+ {
+ }
+
+ [SetUp]
+ public virtual void SetUp()
+ {
+ //ConcurrentMergeScheduler.SetTestMode();
+ //parentChainCallRule.setupCalled = true;
+ }
+
+ /// <summary> Forcible purges all cache entries from the FieldCache.
+ /// <p/>
+ /// This method will be called by tearDown to clean up FieldCache.DEFAULT.
+ /// If a (poorly written) test has some expectation that the FieldCache
+ /// will persist across test methods (ie: a static IndexReader) this
+ /// method can be overridden to do nothing.
+ /// <p/>
+ /// </summary>
+ /// <seealso cref="FieldCache.PurgeAllCaches()">
+ /// </seealso>
+ protected internal virtual void PurgeFieldCache(IFieldCache fc)
+ {
+ fc.PurgeAllCaches();
+ }
+
+ protected internal virtual string GetTestLabel()
+ {
+ return NUnit.Framework.TestContext.CurrentContext.Test.FullName;
+ }
+
+ [TearDown]
+ public virtual void TearDown()
+ {
+ try
+ {
+ // this isn't as useful as calling directly from the scope where the
+ // index readers are used, because they could be gc'ed just before
+ // tearDown is called.
+ // But it's better then nothing.
+ AssertSaneFieldCaches(GetTestLabel());
+
+ //if (ConcurrentMergeScheduler.AnyUnhandledExceptions())
+ //{
+ // // Clear the failure so that we don't just keep
+ // // failing subsequent test cases
+ // ConcurrentMergeScheduler.ClearUnhandledExceptions();
+ // Assert.Fail("ConcurrentMergeScheduler hit unhandled exceptions");
+ //}
+ }
+ finally
+ {
+ PurgeFieldCache(Lucene.Net.Search.FieldCache.DEFAULT);
+ }
+
+ //base.TearDown(); // {{Aroush-2.9}}
+ this.seed = null;
+
+ //parentChainCallRule.teardownCalled = true;
+ }
+
+
+
+ /// <summary> Asserts that FieldCacheSanityChecker does not detect any
+ /// problems with FieldCache.DEFAULT.
+ /// <p/>
+ /// If any problems are found, they are logged to System.err
+ /// (allong with the msg) when the Assertion is thrown.
+ /// <p/>
+ /// This method is called by tearDown after every test method,
+ /// however IndexReaders scoped inside test methods may be garbage
+ /// collected prior to this method being called, causing errors to
+ /// be overlooked. Tests are encouraged to keep their IndexReaders
+ /// scoped at the class level, or to explicitly call this method
+ /// directly in the same scope as the IndexReader.
+ /// <p/>
+ /// </summary>
+ /// <seealso cref="FieldCacheSanityChecker">
+ /// </seealso>
+ protected internal virtual void AssertSaneFieldCaches(string msg)
+ {
+ FieldCache.CacheEntry[] entries = Lucene.Net.Search.FieldCache.DEFAULT.GetCacheEntries();
+ Insanity[] insanity = null;
+ try
+ {
+ try
+ {
+ insanity = FieldCacheSanityChecker.CheckSanity(entries);
+ }
+ catch (System.SystemException e)
+ {
+ System.IO.StreamWriter temp_writer;
+ temp_writer = new System.IO.StreamWriter(System.Console.OpenStandardError(), System.Console.Error.Encoding);
+ temp_writer.AutoFlush = true;
+ DumpArray(msg + ": FieldCache", entries, temp_writer);
+ throw e;
+ }
+
+ Assert.AreEqual(0, insanity.Length, msg + ": Insane FieldCache usage(s) found");
+ insanity = null;
+ }
+ finally
+ {
+
+ // report this in the event of any exception/failure
+ // if no failure, then insanity will be null anyway
+ if (null != insanity)
+ {
+ System.IO.StreamWriter temp_writer2;
+ temp_writer2 = new System.IO.StreamWriter(System.Console.OpenStandardError(), System.Console.Error.Encoding);
+ temp_writer2.AutoFlush = true;
+ DumpArray(msg + ": Insane FieldCache usage(s)", insanity, temp_writer2);
+ }
+ }
+ }
+
+ /// <summary> Convinience method for logging an iterator.</summary>
+ /// <param name="label">String logged before/after the items in the iterator
+ /// </param>
+ /// <param name="iter">Each next() is toString()ed and logged on it's own line. If iter is null this is logged differnetly then an empty iterator.
+ /// </param>
+ /// <param name="stream">Stream to log messages to.
+ /// </param>
+ public static void DumpIterator(System.String label, System.Collections.IEnumerator iter, System.IO.StreamWriter stream)
+ {
+ stream.WriteLine("*** BEGIN " + label + " ***");
+ if (null == iter)
+ {
+ stream.WriteLine(" ... NULL ...");
+ }
+ else
+ {
+ while (iter.MoveNext())
+ {
+ stream.WriteLine(iter.Current.ToString());
+ }
+ }
+ stream.WriteLine("*** END " + label + " ***");
+ }
+
+ /// <summary> Convinience method for logging an array. Wraps the array in an iterator and delegates</summary>
+ /// <seealso cref="dumpIterator(String,Iterator,PrintStream)">
+ /// </seealso>
+ public static void DumpArray(System.String label, System.Object[] objs, System.IO.StreamWriter stream)
+ {
+ System.Collections.IEnumerator iter = (null == objs) ? null : new System.Collections.ArrayList(objs).GetEnumerator();
+ DumpIterator(label, iter, stream);
+ }
+
+ /// <summary> Returns a {@link Random} instance for generating random numbers during the test.
+ /// The random seed is logged during test execution and printed to System.out on any failure
+ /// for reproducing the test using {@link #NewRandom(long)} with the recorded seed
+ /// .
+ /// </summary>
+ public virtual Random NewRandom()
+ {
+ if (this.seed != null)
+ {
+ throw new SystemException("please call LuceneTestCase.newRandom only once per test");
+ }
+ return NewRandom(seedRnd.Next(Int32.MinValue, Int32.MaxValue));
+ }
+
+ /// <summary> Returns a {@link Random} instance for generating random numbers during the test.
+ /// If an error occurs in the test that is not reproducible, you can use this method to
+ /// initialize the number generator with the seed that was printed out during the failing test.
+ /// </summary>
+ public virtual Random NewRandom(int seed)
+ {
+ if (this.seed != null)
+ {
+ throw new System.SystemException("please call LuceneTestCase.newRandom only once per test");
+ }
+ this.seed = seed;
+ return new System.Random(seed);
+ }
+
+ // recorded seed
+ [NonSerialized]
+ protected internal int? seed = null;
+ //protected internal bool seed_init = false;
+
+ // static members
+ [NonSerialized]
+ private static readonly System.Random seedRnd = new System.Random();
+
+
+ protected static void Ok(bool condition, string message = null)
+ {
+ if (!string.IsNullOrWhiteSpace(message))
+ Assert.True(condition, message);
+ else
+ Assert.True(condition);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a1bda0ab/test/test-framework/Util/Attributes.cs
----------------------------------------------------------------------
diff --git a/test/test-framework/Util/Attributes.cs b/test/test-framework/Util/Attributes.cs
deleted file mode 100644
index 5991ab4..0000000
--- a/test/test-framework/Util/Attributes.cs
+++ /dev/null
@@ -1,64 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-namespace Lucene.Net.Util
-{
-
- public class LuceneCategoryAttribute : NUnit.Framework.CategoryAttribute
- {
- public LuceneCategoryAttribute(string name)
- : base(name.Replace(":", " ").Replace(".", " "))
- {
-
- }
- }
-
- public class NightlyAttribute : LuceneCategoryAttribute
- {
- public const string KEY = "tests:nightly";
-
- public NightlyAttribute()
- : base(KEY)
- {
-
- }
- }
-
- public class AwaitsFixAttribute : LuceneCategoryAttribute
- {
- public const string KEY = "tests:awaitsfix";
-
- public AwaitsFixAttribute()
- : base(KEY)
- {
-
- }
- }
-
-
- public class WeeklyAttribute : LuceneCategoryAttribute
- {
- public const string KEY = "tests:weekly";
-
- public WeeklyAttribute()
- : base(KEY)
- {
-
- }
- }
-
- public class SlowAttribute : LuceneCategoryAttribute
- {
- public const string KEY = "tests:slow";
-
- public static bool Ignore { get; set; }
-
- public SlowAttribute(bool enabled)
- : base(KEY)
- {
-
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a1bda0ab/test/test-framework/Util/LuceneTestCase.cs
----------------------------------------------------------------------
diff --git a/test/test-framework/Util/LuceneTestCase.cs b/test/test-framework/Util/LuceneTestCase.cs
deleted file mode 100644
index e937e85..0000000
--- a/test/test-framework/Util/LuceneTestCase.cs
+++ /dev/null
@@ -1,481 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-using System;
-
-using NUnit.Framework;
-
-using ConcurrentMergeScheduler = Lucene.Net.Index.ConcurrentMergeScheduler;
-using Insanity = Lucene.Net.Util.FieldCacheSanityChecker.Insanity;
-using FieldCache = Lucene.Net.Search.FieldCache;
-using Lucene.Net.TestFramework.Support;
-using System.Collections.Generic;
-using Lucene.Net.Search;
-
-using Lucene.Net.TestFramework;
-
-namespace Lucene.Net.Util
-{
-
- /// <summary> Base class for all Lucene unit tests.
- /// <p/>
- /// Currently the
- /// only added functionality over JUnit's TestCase is
- /// asserting that no unhandled exceptions occurred in
- /// threads launched by ConcurrentMergeScheduler and asserting sane
- /// FieldCache usage athe moment of tearDown.
- /// <p/>
- /// If you
- /// override either <c>setUp()</c> or
- /// <c>tearDown()</c> in your unit test, make sure you
- /// call <c>super.setUp()</c> and
- /// <c>super.tearDown()</c>
- /// <p/>
- /// </summary>
- /// <seealso cref="assertSaneFieldCaches">
- /// </seealso>
- [Serializable]
- [TestFixture]
- public abstract class LuceneTestCase : Assert
- {
- // --------------------------------------------------------------------
- // Test groups, system properties and other annotations modifying tests
- // --------------------------------------------------------------------
-
- public const string SYSPROP_NIGHTLY = "tests.nightly";
- public const string SYSPROP_WEEKLY = "tests.weekly";
- public const string SYSPROP_AWAITSFIX = "tests.awaitsfix";
- public const string SYSPROP_SLOW = "tests.slow";
- public const string SYSPROP_BADAPPLES = "tests.badapples";
-
- /** @see #ignoreAfterMaxFailures*/
- private const string SYSPROP_MAXFAILURES = "tests.maxfailures";
-
- /** @see #ignoreAfterMaxFailures*/
- private const string SYSPROP_FAILFAST = "tests.failfast";
-
-
-
-
- public static readonly Util.Version TEST_VERSION_CURRENT = Util.Version.LUCENE_43;
-
- public static readonly bool VERBOSE = RandomizedTest.SystemPropertyAsBoolean("tests.verbose", false);
-
- public static readonly bool INFOSTREAM = RandomizedTest.SystemPropertyAsBoolean("tests.infostream", VERBOSE);
-
- public static readonly int RANDOM_MULTIPLIER = RandomizedTest.SystemPropertyAsInt("tests.multiplier", 1);
-
- public static readonly string DEFAULT_LINE_DOCS_FILE = "europarl.lines.txt.gz";
-
- public static readonly string JENKINS_LARGE_LINE_DOCS_FILE = "enwiki.random.lines.txt";
-
- public static readonly string TEST_CODEC = SystemProperties.GetProperty("tests.codec", "random");
-
- public static readonly string TEST_DOCVALUESFORMAT = SystemProperties.GetProperty("tests.docvaluesformat", "random");
-
- public static readonly string TEST_DIRECTORY = SystemProperties.GetProperty("tests.directory", "random");
-
- public static readonly string TEST_LINE_DOCS_FILE = SystemProperties.GetProperty("tests.linedocsfile", DEFAULT_LINE_DOCS_FILE);
-
- public static readonly bool TEST_NIGHTLY = RandomizedTest.SystemPropertyAsBoolean(NightlyAttribute.KEY, false);
-
- public static readonly bool TEST_WEEKLY = RandomizedTest.SystemPropertyAsBoolean(WeeklyAttribute.KEY, false);
-
- public static readonly bool TEST_AWAITSFIX = RandomizedTest.SystemPropertyAsBoolean(AwaitsFixAttribute.KEY, false);
-
- public static readonly bool TEST_SLOW = RandomizedTest.SystemPropertyAsBoolean(SlowAttribute.KEY, false);
-
- //public static readonly MockDirectoryWrapper.Throttling TEST_THROTTLING = TEST_NIGHTLY ? MockDirectoryWrapper.Throttling.SOMETIMES : MockDirectoryWrapper.Throttling.NEVER;
-
- public static readonly System.IO.DirectoryInfo TEMP_DIR;
-
- static LuceneTestCase()
- {
- String s = SystemProperties.GetProperty("tempDir", System.IO.Path.GetTempPath());
- if (s == null)
- throw new SystemException("To run tests, you need to define system property 'tempDir' or 'java.io.tmpdir'.");
-
- TEMP_DIR = new System.IO.DirectoryInfo(s);
- if (!TEMP_DIR.Exists) TEMP_DIR.Create();
-
- CORE_DIRECTORIES = new List<string>(FS_DIRECTORIES);
- CORE_DIRECTORIES.Add("RAMDirectory");
-
-
- }
-
- private static readonly string[] IGNORED_INVARIANT_PROPERTIES = {
- "user.timezone", "java.rmi.server.randomIDs"
- };
-
- private static readonly IList<String> FS_DIRECTORIES = new[] {
- "SimpleFSDirectory",
- "NIOFSDirectory",
- "MMapDirectory"
- };
-
- private static readonly IList<String> CORE_DIRECTORIES;
-
- // .NET Port: this Java code moved to static ctor above
- //static {
- // CORE_DIRECTORIES = new ArrayList<String>(FS_DIRECTORIES);
- // CORE_DIRECTORIES.add("RAMDirectory");
- //};
-
- protected static readonly ISet<String> doesntSupportOffsets = new HashSet<String>(new[] {
- "Lucene3x",
- "MockFixedIntBlock",
- "MockVariableIntBlock",
- "MockSep",
- "MockRandom"
- });
-
- public void Test()
- {
-
- }
-
- public static bool PREFLEX_IMPERSONATION_IS_ACTIVE;
-
- //private static readonly TestRuleStoreClassName classNameRule;
-
- //internal static readonly TestRuleSetupAndRestoreClassEnv classEnvRule;
-
- //public static readonly TestRuleMarkFailure suiteFailureMarker =
- // new TestRuleMarkFailure();
-
- //internal static readonly TestRuleIgnoreAfterMaxFailures ignoreAfterMaxFailures;
-
- private const long STATIC_LEAK_THRESHOLD = 10 * 1024 * 1024;
-
- //private static readonly ISet<String> STATIC_LEAK_IGNORED_TYPES =
- // new HashSet<String>(new[] {
- // "org.slf4j.Logger",
- // "org.apache.solr.SolrLogFormatter",
- // typeof(EnumSet).FullName});
-
- // public static TestRule classRules = RuleChain
- //.outerRule(new TestRuleIgnoreTestSuites())
- //.around(ignoreAfterMaxFailures)
- //.around(suiteFailureMarker)
- //.around(new TestRuleAssertionsRequired())
- //.around(new StaticFieldsInvariantRule(STATIC_LEAK_THRESHOLD, true) {
- // @Override
- // protected boolean accept(java.lang.reflect.Field field) {
- // // Don't count known classes that consume memory once.
- // if (STATIC_LEAK_IGNORED_TYPES.contains(field.getType().getName())) {
- // return false;
- // }
- // // Don't count references from ourselves, we're top-level.
- // if (field.getDeclaringClass() == LuceneTestCase.class) {
- // return false;
- // }
- // return super.accept(field);
- // }
- //})
- //.around(new NoClassHooksShadowingRule())
- //.around(new NoInstanceHooksOverridesRule() {
- // @Override
- // protected boolean verify(Method key) {
- // String name = key.getName();
- // return !(name.equals("setUp") || name.equals("tearDown"));
- // }
- //})
- //.around(new SystemPropertiesInvariantRule(IGNORED_INVARIANT_PROPERTIES))
- //.around(classNameRule = new TestRuleStoreClassName())
- //.around(classEnvRule = new TestRuleSetupAndRestoreClassEnv());
-
- //static {
- // int maxFailures = systemPropertyAsInt(SYSPROP_MAXFAILURES, Integer.MAX_VALUE);
- // boolean failFast = systemPropertyAsBoolean(SYSPROP_FAILFAST, false);
-
- // if (failFast) {
- // if (maxFailures == Integer.MAX_VALUE) {
- // maxFailures = 1;
- // } else {
- // Logger.getLogger(LuceneTestCase.class.getSimpleName()).warning(
- // "Property '" + SYSPROP_MAXFAILURES + "'=" + maxFailures + ", 'failfast' is" +
- // " ignored.");
- // }
- // }
-
- // ignoreAfterMaxFailures = new TestRuleIgnoreAfterMaxFailures(maxFailures);
- //}
-
- //bool allowDocsOutOfOrder = true;
-
- public LuceneTestCase()
- : base()
- {
- }
-
-
-
- public LuceneTestCase(System.String name)
- {
- }
-
- [SetUp]
- public virtual void SetUp()
- {
- //ConcurrentMergeScheduler.SetTestMode();
- //parentChainCallRule.setupCalled = true;
- }
-
- /// <summary> Forcible purges all cache entries from the FieldCache.
- /// <p/>
- /// This method will be called by tearDown to clean up FieldCache.DEFAULT.
- /// If a (poorly written) test has some expectation that the FieldCache
- /// will persist across test methods (ie: a static IndexReader) this
- /// method can be overridden to do nothing.
- /// <p/>
- /// </summary>
- /// <seealso cref="FieldCache.PurgeAllCaches()">
- /// </seealso>
- protected internal virtual void PurgeFieldCache(IFieldCache fc)
- {
- fc.PurgeAllCaches();
- }
-
- protected internal virtual string GetTestLabel()
- {
- return NUnit.Framework.TestContext.CurrentContext.Test.FullName;
- }
-
- [TearDown]
- public virtual void TearDown()
- {
- try
- {
- // this isn't as useful as calling directly from the scope where the
- // index readers are used, because they could be gc'ed just before
- // tearDown is called.
- // But it's better then nothing.
- AssertSaneFieldCaches(GetTestLabel());
-
- //if (ConcurrentMergeScheduler.AnyUnhandledExceptions())
- //{
- // // Clear the failure so that we don't just keep
- // // failing subsequent test cases
- // ConcurrentMergeScheduler.ClearUnhandledExceptions();
- // Assert.Fail("ConcurrentMergeScheduler hit unhandled exceptions");
- //}
- }
- finally
- {
- PurgeFieldCache(Lucene.Net.Search.FieldCache.DEFAULT);
- }
-
- //base.TearDown(); // {{Aroush-2.9}}
- this.seed = null;
-
- //parentChainCallRule.teardownCalled = true;
- }
-
-
-
- /// <summary> Asserts that FieldCacheSanityChecker does not detect any
- /// problems with FieldCache.DEFAULT.
- /// <p/>
- /// If any problems are found, they are logged to System.err
- /// (allong with the msg) when the Assertion is thrown.
- /// <p/>
- /// This method is called by tearDown after every test method,
- /// however IndexReaders scoped inside test methods may be garbage
- /// collected prior to this method being called, causing errors to
- /// be overlooked. Tests are encouraged to keep their IndexReaders
- /// scoped at the class level, or to explicitly call this method
- /// directly in the same scope as the IndexReader.
- /// <p/>
- /// </summary>
- /// <seealso cref="FieldCacheSanityChecker">
- /// </seealso>
- protected internal virtual void AssertSaneFieldCaches(string msg)
- {
- FieldCache.CacheEntry[] entries = Lucene.Net.Search.FieldCache.DEFAULT.GetCacheEntries();
- Insanity[] insanity = null;
- try
- {
- try
- {
- insanity = FieldCacheSanityChecker.CheckSanity(entries);
- }
- catch (System.SystemException e)
- {
- System.IO.StreamWriter temp_writer;
- temp_writer = new System.IO.StreamWriter(System.Console.OpenStandardError(), System.Console.Error.Encoding);
- temp_writer.AutoFlush = true;
- DumpArray(msg + ": FieldCache", entries, temp_writer);
- throw e;
- }
-
- Assert.AreEqual(0, insanity.Length, msg + ": Insane FieldCache usage(s) found");
- insanity = null;
- }
- finally
- {
-
- // report this in the event of any exception/failure
- // if no failure, then insanity will be null anyway
- if (null != insanity)
- {
- System.IO.StreamWriter temp_writer2;
- temp_writer2 = new System.IO.StreamWriter(System.Console.OpenStandardError(), System.Console.Error.Encoding);
- temp_writer2.AutoFlush = true;
- DumpArray(msg + ": Insane FieldCache usage(s)", insanity, temp_writer2);
- }
- }
- }
-
- /// <summary> Convinience method for logging an iterator.</summary>
- /// <param name="label">String logged before/after the items in the iterator
- /// </param>
- /// <param name="iter">Each next() is toString()ed and logged on it's own line. If iter is null this is logged differnetly then an empty iterator.
- /// </param>
- /// <param name="stream">Stream to log messages to.
- /// </param>
- public static void DumpIterator(System.String label, System.Collections.IEnumerator iter, System.IO.StreamWriter stream)
- {
- stream.WriteLine("*** BEGIN " + label + " ***");
- if (null == iter)
- {
- stream.WriteLine(" ... NULL ...");
- }
- else
- {
- while (iter.MoveNext())
- {
- stream.WriteLine(iter.Current.ToString());
- }
- }
- stream.WriteLine("*** END " + label + " ***");
- }
-
- /// <summary> Convinience method for logging an array. Wraps the array in an iterator and delegates</summary>
- /// <seealso cref="dumpIterator(String,Iterator,PrintStream)">
- /// </seealso>
- public static void DumpArray(System.String label, System.Object[] objs, System.IO.StreamWriter stream)
- {
- System.Collections.IEnumerator iter = (null == objs) ? null : new System.Collections.ArrayList(objs).GetEnumerator();
- DumpIterator(label, iter, stream);
- }
-
- /// <summary> Returns a {@link Random} instance for generating random numbers during the test.
- /// The random seed is logged during test execution and printed to System.out on any failure
- /// for reproducing the test using {@link #NewRandom(long)} with the recorded seed
- /// .
- /// </summary>
- public virtual Random NewRandom()
- {
- if (this.seed != null)
- {
- throw new SystemException("please call LuceneTestCase.newRandom only once per test");
- }
- return NewRandom(seedRnd.Next(Int32.MinValue, Int32.MaxValue));
- }
-
- /// <summary> Returns a {@link Random} instance for generating random numbers during the test.
- /// If an error occurs in the test that is not reproducible, you can use this method to
- /// initialize the number generator with the seed that was printed out during the failing test.
- /// </summary>
- public virtual Random NewRandom(int seed)
- {
- if (this.seed != null)
- {
- throw new System.SystemException("please call LuceneTestCase.newRandom only once per test");
- }
- this.seed = seed;
- return new System.Random(seed);
- }
-
- // recorded seed
- [NonSerialized]
- protected internal int? seed = null;
- //protected internal bool seed_init = false;
-
- // static members
- [NonSerialized]
- private static readonly System.Random seedRnd = new System.Random();
-
-
-
-
- protected static void Ok(bool condition, string message = null)
- {
- if (!string.IsNullOrWhiteSpace(message))
- Assert.True(condition, message);
- else
- Assert.True(condition);
- }
-
- #region Java porting shortcuts
-
-
-
- protected static void assertEquals(string msg, object obj1, object obj2)
- {
- Assert.AreEqual(obj1, obj2, msg);
- }
-
- protected static void assertEquals(object obj1, object obj2)
- {
- Assert.AreEqual(obj1, obj2);
- }
-
-
- protected static void assertEquals(double d1, double d2, double delta)
- {
- Assert.AreEqual(d1, d2, delta);
- }
-
- protected static void assertEquals(string msg, double d1, double d2, double delta)
- {
- Assert.AreEqual(d1, d2, delta, msg);
- }
-
- protected static void assertTrue(bool cnd)
- {
- Assert.IsTrue(cnd);
- }
-
- protected static void assertTrue(string msg, bool cnd)
- {
- Assert.IsTrue(cnd, msg);
- }
-
- protected static void assertNotNull(object o)
- {
- Assert.NotNull(o);
- }
-
- protected static void assertNotNull(string msg, object o)
- {
- Assert.NotNull(o, msg);
- }
-
- protected static void assertNull(object o)
- {
- Assert.Null(o);
- }
-
- protected static void assertNull(string msg, object o)
- {
- Assert.Null(o, msg);
- }
- #endregion
- }
-}
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a1bda0ab/test/test-framework/Util/_TestUtil.cs
----------------------------------------------------------------------
diff --git a/test/test-framework/Util/_TestUtil.cs b/test/test-framework/Util/_TestUtil.cs
new file mode 100644
index 0000000..dd10f5f
--- /dev/null
+++ b/test/test-framework/Util/_TestUtil.cs
@@ -0,0 +1,20 @@
+using System;
+using Lucene.Net.Support;
+using NUnit.Framework;
+
+namespace Lucene.Net.Util
+{
+ public class _TestUtil
+ {
+// public static void assertAttributeReflection<T>(AttributeImpl att, HashMap<String,T> reflectedValues) {
+// var map = new HashMap<String,Object>();
+// att.reflectWith(new AttributeReflector() {
+// @Override
+// public void reflect(Class<? extends Attribute> attClass, String key, Object value) {
+// map.put(attClass.getName() + '#' + key, value);
+// }
+// });
+// Assert.AreEqual(reflectedValues, map, "Reflection does not produce same map");
+// }
+ }
+}