You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by mi...@apache.org on 2010/10/14 10:48:40 UTC
[lucy-commits] svn commit: r1022422 [25/43] - in /incubator/lucy/trunk/import: ./
charmonizer/ charmonizer/src/ charmonizer/src/Charmonizer/
charmonizer/src/Charmonizer/Core/ charmonizer/src/Charmonizer/Probe/
charmonizer/src/Charmonizer/Test/ clownfish/ clownfish/li...
Added: incubator/lucy/trunk/import/core/KinoSearch/Test/Analysis/TestStemmer.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/core/KinoSearch/Test/Analysis/TestStemmer.c?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/core/KinoSearch/Test/Analysis/TestStemmer.c (added)
+++ incubator/lucy/trunk/import/core/KinoSearch/Test/Analysis/TestStemmer.c Thu Oct 14 08:48:04 2010
@@ -0,0 +1,53 @@
+#define C_KINO_TESTSTEMMER
+#include "KinoSearch/Util/ToolSet.h"
+
+#include "KinoSearch/Test.h"
+#include "KinoSearch/Test/Analysis/TestStemmer.h"
+#include "KinoSearch/Analysis/Stemmer.h"
+
+static void
+test_Dump_Load_and_Equals(TestBatch *batch)
+{
+ CharBuf *EN = (CharBuf*)ZCB_WRAP_STR("en", 2);
+ CharBuf *ES = (CharBuf*)ZCB_WRAP_STR("es", 2);
+ Stemmer *stemmer = Stemmer_new(EN);
+ Stemmer *other = Stemmer_new(ES);
+ Obj *dump = (Obj*)Stemmer_Dump(stemmer);
+ Obj *other_dump = (Obj*)Stemmer_Dump(other);
+ Stemmer *clone = (Stemmer*)Stemmer_Load(other, dump);
+ Stemmer *other_clone = (Stemmer*)Stemmer_Load(other, other_dump);
+
+ TEST_FALSE(batch, Stemmer_Equals(stemmer,
+ (Obj*)other), "Equals() false with different language");
+ TEST_TRUE(batch, Stemmer_Equals(stemmer,
+ (Obj*)clone), "Dump => Load round trip");
+ TEST_TRUE(batch, Stemmer_Equals(other,
+ (Obj*)other_clone), "Dump => Load round trip");
+
+ DECREF(stemmer);
+ DECREF(dump);
+ DECREF(clone);
+ DECREF(other);
+ DECREF(other_dump);
+ DECREF(other_clone);
+}
+
+void
+TestStemmer_run_tests()
+{
+ TestBatch *batch = TestBatch_new(3);
+
+ TestBatch_Plan(batch);
+
+ test_Dump_Load_and_Equals(batch);
+
+ DECREF(batch);
+}
+
+
+/* Copyright 2005-2010 Marvin Humphrey
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * under the same terms as Perl itself.
+ */
+
Propchange: incubator/lucy/trunk/import/core/KinoSearch/Test/Analysis/TestStemmer.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/lucy/trunk/import/core/KinoSearch/Test/Analysis/TestStemmer.cfh
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/core/KinoSearch/Test/Analysis/TestStemmer.cfh?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/core/KinoSearch/Test/Analysis/TestStemmer.cfh (added)
+++ incubator/lucy/trunk/import/core/KinoSearch/Test/Analysis/TestStemmer.cfh Thu Oct 14 08:48:04 2010
@@ -0,0 +1,13 @@
+parcel KinoSearch cnick Kino;
+
+inert class KinoSearch::Test::Analysis::TestStemmer {
+ inert void
+ run_tests();
+}
+
+/* Copyright 2005-2010 Marvin Humphrey
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * under the same terms as Perl itself.
+ */
+
Added: incubator/lucy/trunk/import/core/KinoSearch/Test/Analysis/TestStopalizer.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/core/KinoSearch/Test/Analysis/TestStopalizer.c?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/core/KinoSearch/Test/Analysis/TestStopalizer.c (added)
+++ incubator/lucy/trunk/import/core/KinoSearch/Test/Analysis/TestStopalizer.c Thu Oct 14 08:48:04 2010
@@ -0,0 +1,72 @@
+#define C_KINO_TESTSTOPALIZER
+#include "KinoSearch/Util/ToolSet.h"
+#include <stdarg.h>
+
+#include "KinoSearch/Test.h"
+#include "KinoSearch/Test/Analysis/TestStopalizer.h"
+#include "KinoSearch/Analysis/Stopalizer.h"
+
+static Stopalizer*
+S_make_stopalizer(void *unused, ...)
+{
+ va_list args;
+ Stopalizer *self = (Stopalizer*)VTable_Make_Obj(STOPALIZER);
+ Hash *stoplist = Hash_new(0);
+ char *stopword;
+
+ va_start(args, unused);
+ while (NULL != (stopword = va_arg(args, char*))) {
+ Hash_Store_Str(stoplist, stopword, strlen(stopword), INCREF(&EMPTY));
+ }
+ va_end(args);
+
+ self = Stopalizer_init(self, NULL, stoplist);
+ DECREF(stoplist);
+ return self;
+}
+
+static void
+test_Dump_Load_and_Equals(TestBatch *batch)
+{
+ Stopalizer *stopalizer
+ = S_make_stopalizer(NULL, "foo", "bar", "baz", NULL);
+ Stopalizer *other = S_make_stopalizer(NULL, "foo", "bar", NULL);
+ Obj *dump = Stopalizer_Dump(stopalizer);
+ Obj *other_dump = Stopalizer_Dump(other);
+ Stopalizer *clone = (Stopalizer*)Stopalizer_Load(other, dump);
+ Stopalizer *other_clone = (Stopalizer*)Stopalizer_Load(other, other_dump);
+
+ TEST_FALSE(batch, Stopalizer_Equals(stopalizer,
+ (Obj*)other), "Equals() false with different stoplist");
+ TEST_TRUE(batch, Stopalizer_Equals(stopalizer,
+ (Obj*)clone), "Dump => Load round trip");
+ TEST_TRUE(batch, Stopalizer_Equals(other,
+ (Obj*)other_clone), "Dump => Load round trip");
+
+ DECREF(stopalizer);
+ DECREF(dump);
+ DECREF(clone);
+ DECREF(other);
+ DECREF(other_dump);
+ DECREF(other_clone);
+}
+
+void
+TestStopalizer_run_tests()
+{
+ TestBatch *batch = TestBatch_new(3);
+
+ TestBatch_Plan(batch);
+
+ test_Dump_Load_and_Equals(batch);
+
+ DECREF(batch);
+}
+
+
+/* Copyright 2005-2010 Marvin Humphrey
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * under the same terms as Perl itself.
+ */
+
Propchange: incubator/lucy/trunk/import/core/KinoSearch/Test/Analysis/TestStopalizer.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/lucy/trunk/import/core/KinoSearch/Test/Analysis/TestStopalizer.cfh
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/core/KinoSearch/Test/Analysis/TestStopalizer.cfh?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/core/KinoSearch/Test/Analysis/TestStopalizer.cfh (added)
+++ incubator/lucy/trunk/import/core/KinoSearch/Test/Analysis/TestStopalizer.cfh Thu Oct 14 08:48:04 2010
@@ -0,0 +1,13 @@
+parcel KinoSearch cnick Kino;
+
+inert class KinoSearch::Test::Analysis::TestStopalizer {
+ inert void
+ run_tests();
+}
+
+/* Copyright 2005-2010 Marvin Humphrey
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * under the same terms as Perl itself.
+ */
+
Added: incubator/lucy/trunk/import/core/KinoSearch/Test/Analysis/TestTokenizer.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/core/KinoSearch/Test/Analysis/TestTokenizer.c?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/core/KinoSearch/Test/Analysis/TestTokenizer.c (added)
+++ incubator/lucy/trunk/import/core/KinoSearch/Test/Analysis/TestTokenizer.c Thu Oct 14 08:48:04 2010
@@ -0,0 +1,58 @@
+#define C_KINO_TESTTOKENIZER
+#include "KinoSearch/Util/ToolSet.h"
+
+#include "KinoSearch/Test.h"
+#include "KinoSearch/Test/Analysis/TestTokenizer.h"
+#include "KinoSearch/Analysis/Tokenizer.h"
+
+
+static void
+test_Dump_Load_and_Equals(TestBatch *batch)
+{
+ ZombieCharBuf *word_char_pattern = ZCB_WRAP_STR("\\w+", 3);
+ ZombieCharBuf *whitespace_pattern = ZCB_WRAP_STR("\\S+", 3);
+ Tokenizer *word_char_tokenizer =
+ Tokenizer_new((CharBuf*)word_char_pattern);
+ Tokenizer *whitespace_tokenizer =
+ Tokenizer_new((CharBuf*)whitespace_pattern);
+ Obj *word_char_dump = Tokenizer_Dump(word_char_tokenizer);
+ Obj *whitespace_dump = Tokenizer_Dump(whitespace_tokenizer);
+ Tokenizer *word_char_clone
+ = Tokenizer_Load(whitespace_tokenizer, word_char_dump);
+ Tokenizer *whitespace_clone
+ = Tokenizer_Load(whitespace_tokenizer, whitespace_dump);
+
+ TEST_FALSE(batch, Tokenizer_Equals(word_char_tokenizer,
+ (Obj*)whitespace_tokenizer), "Equals() false with different pattern");
+ TEST_TRUE(batch, Tokenizer_Equals(word_char_tokenizer,
+ (Obj*)word_char_clone), "Dump => Load round trip");
+ TEST_TRUE(batch, Tokenizer_Equals(whitespace_tokenizer,
+ (Obj*)whitespace_clone), "Dump => Load round trip");
+
+ DECREF(word_char_tokenizer);
+ DECREF(word_char_dump);
+ DECREF(word_char_clone);
+ DECREF(whitespace_tokenizer);
+ DECREF(whitespace_dump);
+ DECREF(whitespace_clone);
+}
+
+void
+TestTokenizer_run_tests()
+{
+ TestBatch *batch = TestBatch_new(3);
+
+ TestBatch_Plan(batch);
+
+ test_Dump_Load_and_Equals(batch);
+
+ DECREF(batch);
+}
+
+
+/* Copyright 2005-2010 Marvin Humphrey
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * under the same terms as Perl itself.
+ */
+
Propchange: incubator/lucy/trunk/import/core/KinoSearch/Test/Analysis/TestTokenizer.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/lucy/trunk/import/core/KinoSearch/Test/Analysis/TestTokenizer.cfh
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/core/KinoSearch/Test/Analysis/TestTokenizer.cfh?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/core/KinoSearch/Test/Analysis/TestTokenizer.cfh (added)
+++ incubator/lucy/trunk/import/core/KinoSearch/Test/Analysis/TestTokenizer.cfh Thu Oct 14 08:48:04 2010
@@ -0,0 +1,13 @@
+parcel KinoSearch cnick Kino;
+
+inert class KinoSearch::Test::Analysis::TestTokenizer {
+ inert void
+ run_tests();
+}
+
+/* Copyright 2005-2010 Marvin Humphrey
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * under the same terms as Perl itself.
+ */
+
Added: incubator/lucy/trunk/import/core/KinoSearch/Test/Index/TestDocWriter.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/core/KinoSearch/Test/Index/TestDocWriter.c?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/core/KinoSearch/Test/Index/TestDocWriter.c (added)
+++ incubator/lucy/trunk/import/core/KinoSearch/Test/Index/TestDocWriter.c Thu Oct 14 08:48:04 2010
@@ -0,0 +1,22 @@
+#define C_KINO_TESTDOCWRITER
+#include "KinoSearch/Util/ToolSet.h"
+
+#include "KinoSearch/Test.h"
+#include "KinoSearch/Test/Index/TestDocWriter.h"
+#include "KinoSearch/Index/DocWriter.h"
+
+void
+TestDocWriter_run_tests()
+{
+ TestBatch *batch = TestBatch_new(1);
+ TestBatch_Plan(batch);
+ PASS(batch, "placeholder");
+ DECREF(batch);
+}
+
+/* Copyright 2005-2010 Marvin Humphrey
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * under the same terms as Perl itself.
+ */
+
Propchange: incubator/lucy/trunk/import/core/KinoSearch/Test/Index/TestDocWriter.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/lucy/trunk/import/core/KinoSearch/Test/Index/TestDocWriter.cfh
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/core/KinoSearch/Test/Index/TestDocWriter.cfh?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/core/KinoSearch/Test/Index/TestDocWriter.cfh (added)
+++ incubator/lucy/trunk/import/core/KinoSearch/Test/Index/TestDocWriter.cfh Thu Oct 14 08:48:04 2010
@@ -0,0 +1,13 @@
+parcel KinoSearch cnick Kino;
+
+inert class KinoSearch::Test::Index::TestDocWriter {
+ inert void
+ run_tests();
+}
+
+/* Copyright 2005-2010 Marvin Humphrey
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * under the same terms as Perl itself.
+ */
+
Added: incubator/lucy/trunk/import/core/KinoSearch/Test/Index/TestHighlightWriter.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/core/KinoSearch/Test/Index/TestHighlightWriter.c?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/core/KinoSearch/Test/Index/TestHighlightWriter.c (added)
+++ incubator/lucy/trunk/import/core/KinoSearch/Test/Index/TestHighlightWriter.c Thu Oct 14 08:48:04 2010
@@ -0,0 +1,22 @@
+#define C_KINO_TESTHIGHLIGHTWRITER
+#include "KinoSearch/Util/ToolSet.h"
+
+#include "KinoSearch/Test.h"
+#include "KinoSearch/Test/Index/TestHighlightWriter.h"
+#include "KinoSearch/Index/HighlightWriter.h"
+
+void
+TestHLWriter_run_tests()
+{
+ TestBatch *batch = TestBatch_new(1);
+ TestBatch_Plan(batch);
+ PASS(batch, "Placeholder");
+ DECREF(batch);
+}
+
+/* Copyright 2005-2010 Marvin Humphrey
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * under the same terms as Perl itself.
+ */
+
Propchange: incubator/lucy/trunk/import/core/KinoSearch/Test/Index/TestHighlightWriter.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/lucy/trunk/import/core/KinoSearch/Test/Index/TestHighlightWriter.cfh
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/core/KinoSearch/Test/Index/TestHighlightWriter.cfh?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/core/KinoSearch/Test/Index/TestHighlightWriter.cfh (added)
+++ incubator/lucy/trunk/import/core/KinoSearch/Test/Index/TestHighlightWriter.cfh Thu Oct 14 08:48:04 2010
@@ -0,0 +1,15 @@
+parcel KinoSearch cnick Kino;
+
+inert class KinoSearch::Test::Index::TestHighlightWriter
+ cnick TestHLWriter {
+
+ inert void
+ run_tests();
+}
+
+/* Copyright 2005-2010 Marvin Humphrey
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * under the same terms as Perl itself.
+ */
+
Added: incubator/lucy/trunk/import/core/KinoSearch/Test/Index/TestPostingListWriter.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/core/KinoSearch/Test/Index/TestPostingListWriter.c?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/core/KinoSearch/Test/Index/TestPostingListWriter.c (added)
+++ incubator/lucy/trunk/import/core/KinoSearch/Test/Index/TestPostingListWriter.c Thu Oct 14 08:48:04 2010
@@ -0,0 +1,21 @@
+#define C_KINO_TESTPOSTINGLISTWRITER
+#include "KinoSearch/Util/ToolSet.h"
+
+#include "KinoSearch/Test.h"
+#include "KinoSearch/Test/Index/TestPostingListWriter.h"
+
+void
+TestPListWriter_run_tests()
+{
+ TestBatch *batch = TestBatch_new(1);
+ TestBatch_Plan(batch);
+ PASS(batch, "Placeholder");
+ DECREF(batch);
+}
+
+/* Copyright 2005-2010 Marvin Humphrey
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * under the same terms as Perl itself.
+ */
+
Propchange: incubator/lucy/trunk/import/core/KinoSearch/Test/Index/TestPostingListWriter.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/lucy/trunk/import/core/KinoSearch/Test/Index/TestPostingListWriter.cfh
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/core/KinoSearch/Test/Index/TestPostingListWriter.cfh?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/core/KinoSearch/Test/Index/TestPostingListWriter.cfh (added)
+++ incubator/lucy/trunk/import/core/KinoSearch/Test/Index/TestPostingListWriter.cfh Thu Oct 14 08:48:04 2010
@@ -0,0 +1,15 @@
+parcel KinoSearch cnick Kino;
+
+inert class KinoSearch::Test::Index::TestPostingListWriter
+ cnick TestPListWriter {
+
+ inert void
+ run_tests();
+}
+
+/* Copyright 2005-2010 Marvin Humphrey
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * under the same terms as Perl itself.
+ */
+
Added: incubator/lucy/trunk/import/core/KinoSearch/Test/Index/TestSegWriter.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/core/KinoSearch/Test/Index/TestSegWriter.c?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/core/KinoSearch/Test/Index/TestSegWriter.c (added)
+++ incubator/lucy/trunk/import/core/KinoSearch/Test/Index/TestSegWriter.c Thu Oct 14 08:48:04 2010
@@ -0,0 +1,22 @@
+#define C_KINO_TESTSEGWRITER
+#include "KinoSearch/Util/ToolSet.h"
+
+#include "KinoSearch/Test.h"
+#include "KinoSearch/Test/Index/TestSegWriter.h"
+#include "KinoSearch/Index/SegWriter.h"
+
+void
+TestSegWriter_run_tests()
+{
+ TestBatch *batch = TestBatch_new(1);
+ TestBatch_Plan(batch);
+ PASS(batch, "placeholder");
+ DECREF(batch);
+}
+
+/* Copyright 2005-2010 Marvin Humphrey
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * under the same terms as Perl itself.
+ */
+
Propchange: incubator/lucy/trunk/import/core/KinoSearch/Test/Index/TestSegWriter.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/lucy/trunk/import/core/KinoSearch/Test/Index/TestSegWriter.cfh
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/core/KinoSearch/Test/Index/TestSegWriter.cfh?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/core/KinoSearch/Test/Index/TestSegWriter.cfh (added)
+++ incubator/lucy/trunk/import/core/KinoSearch/Test/Index/TestSegWriter.cfh Thu Oct 14 08:48:04 2010
@@ -0,0 +1,14 @@
+parcel KinoSearch cnick Kino;
+
+inert class KinoSearch::Test::Index::TestSegWriter {
+
+ inert void
+ run_tests();
+}
+
+/* Copyright 2005-2010 Marvin Humphrey
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * under the same terms as Perl itself.
+ */
+
Added: incubator/lucy/trunk/import/core/KinoSearch/Test/Index/TestSegment.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/core/KinoSearch/Test/Index/TestSegment.c?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/core/KinoSearch/Test/Index/TestSegment.c (added)
+++ incubator/lucy/trunk/import/core/KinoSearch/Test/Index/TestSegment.c Thu Oct 14 08:48:04 2010
@@ -0,0 +1,158 @@
+#define C_KINO_TESTSEG
+#include "KinoSearch/Util/ToolSet.h"
+
+#include "KinoSearch/Test.h"
+#include "KinoSearch/Test/Index/TestSegment.h"
+#include "KinoSearch/Index/Segment.h"
+#include "KinoSearch/Store/RAMFolder.h"
+
+static void
+test_fields(TestBatch *batch)
+{
+ Segment *segment = Seg_new(1);
+ ZombieCharBuf *foo = ZCB_WRAP_STR("foo",3 );
+ ZombieCharBuf *bar = ZCB_WRAP_STR("bar", 3);
+ ZombieCharBuf *baz = ZCB_WRAP_STR("baz", 3);
+ int32_t field_num;
+
+ field_num = Seg_Add_Field(segment, (CharBuf*)foo);
+ TEST_TRUE(batch, field_num == 1,
+ "Add_Field returns field number, and field numbers start at 1");
+ field_num = Seg_Add_Field(segment, (CharBuf*)bar);
+ TEST_TRUE(batch, field_num == 2, "add a second field");
+ field_num = Seg_Add_Field(segment, (CharBuf*)foo);
+ TEST_TRUE(batch, field_num == 1,
+ "Add_Field returns existing field number if field is already known");
+
+ TEST_TRUE(batch, ZCB_Equals(bar, (Obj*)Seg_Field_Name(segment, 2)),
+ "Field_Name");
+ TEST_TRUE(batch, Seg_Field_Name(segment, 3) == NULL,
+ "Field_Name returns NULL for unknown field number");
+ TEST_TRUE(batch, Seg_Field_Num(segment, (CharBuf*)bar) == 2,
+ "Field_Num");
+ TEST_TRUE(batch, Seg_Field_Num(segment, (CharBuf*)baz) == 0,
+ "Field_Num returns 0 for unknown field name");
+
+ DECREF(segment);
+}
+
+static void
+test_metadata_storage(TestBatch *batch)
+{
+ Segment *segment = Seg_new(1);
+ CharBuf *got;
+
+ Seg_Store_Metadata_Str(segment, "foo", 3, (Obj*)CB_newf("bar"));
+ got = (CharBuf*)Seg_Fetch_Metadata_Str(segment, "foo", 3);
+ TEST_TRUE(batch,
+ got
+ && CB_Is_A(got, CHARBUF)
+ && CB_Equals_Str(got, "bar", 3),
+ "metadata round trip");
+ DECREF(segment);
+}
+
+static void
+test_seg_name_and_num(TestBatch *batch)
+{
+ Segment *segment_z = Seg_new(35);
+ CharBuf *seg_z_name = Seg_num_to_name(35);
+ TEST_TRUE(batch, Seg_Get_Number(segment_z) == I64_C(35), "Get_Number");
+ TEST_TRUE(batch, CB_Equals_Str(Seg_Get_Name(segment_z), "seg_z", 5),
+ "Get_Name");
+ TEST_TRUE(batch, CB_Equals_Str(seg_z_name, "seg_z", 5),
+ "num_to_name");
+ DECREF(seg_z_name);
+ DECREF(segment_z);
+}
+
+static void
+test_count(TestBatch *batch)
+{
+ Segment *segment = Seg_new(100);
+
+ TEST_TRUE(batch, Seg_Get_Count(segment) == 0, "count starts off at 0");
+ Seg_Set_Count(segment, 120);
+ TEST_TRUE(batch, Seg_Get_Count(segment) == 120, "Set_Count");
+ TEST_TRUE(batch, Seg_Increment_Count(segment, 10) == 130,
+ "Increment_Count");
+
+ DECREF(segment);
+}
+
+static void
+test_Compare_To(TestBatch *batch)
+{
+ Segment *segment_1 = Seg_new(1);
+ Segment *segment_2 = Seg_new(2);
+ Segment *also_segment_2 = Seg_new(2);
+
+ TEST_TRUE(batch, Seg_Compare_To(segment_1, (Obj*)segment_2) < 0,
+ "Compare_To 1 < 2");
+ TEST_TRUE(batch, Seg_Compare_To(segment_2, (Obj*)segment_1) > 0,
+ "Compare_To 1 < 2");
+ TEST_TRUE(batch, Seg_Compare_To(segment_1, (Obj*)segment_1) == 0,
+ "Compare_To identity");
+ TEST_TRUE(batch, Seg_Compare_To(segment_2, (Obj*)also_segment_2) == 0,
+ "Compare_To 2 == 2");
+
+ DECREF(segment_1);
+ DECREF(segment_2);
+ DECREF(also_segment_2);
+}
+
+static void
+test_Write_File_and_Read_File(TestBatch *batch)
+{
+ RAMFolder *folder = RAMFolder_new(NULL);
+ Segment *segment = Seg_new(100);
+ Segment *got = Seg_new(100);
+ CharBuf *meta;
+ CharBuf *flotsam = (CharBuf*)ZCB_WRAP_STR("flotsam", 7);
+ CharBuf *jetsam = (CharBuf*)ZCB_WRAP_STR("jetsam", 6);
+
+ Seg_Set_Count(segment, 111);
+ Seg_Store_Metadata_Str(segment, "foo", 3, (Obj*)CB_newf("bar"));
+ Seg_Add_Field(segment, flotsam);
+ Seg_Add_Field(segment, jetsam);
+
+ RAMFolder_MkDir(folder, Seg_Get_Name(segment));
+ Seg_Write_File(segment, (Folder*)folder);
+ Seg_Read_File(got, (Folder*)folder);
+
+ TEST_TRUE(batch, Seg_Get_Count(got) == Seg_Get_Count(segment),
+ "Round-trip count through file");
+ TEST_TRUE(batch,
+ Seg_Field_Num(got, jetsam) == Seg_Field_Num(segment, jetsam),
+ "Round trip field names through file");
+ meta = (CharBuf*)Seg_Fetch_Metadata_Str(got, "foo", 3);
+ TEST_TRUE(batch, meta && CB_Is_A(meta, CHARBUF)
+ && CB_Equals_Str(meta, "bar", 3), "Round trip metadata through file");
+
+ DECREF(got);
+ DECREF(segment);
+ DECREF(folder);
+}
+
+void
+TestSeg_run_tests()
+{
+ TestBatch *batch = TestBatch_new(21);
+
+ TestBatch_Plan(batch);
+ test_fields(batch);
+ test_metadata_storage(batch);
+ test_seg_name_and_num(batch);
+ test_count(batch);
+ test_Compare_To(batch);
+ test_Write_File_and_Read_File(batch);
+
+ DECREF(batch);
+}
+
+/* Copyright 2005-2010 Marvin Humphrey
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * under the same terms as Perl itself.
+ */
+
Propchange: incubator/lucy/trunk/import/core/KinoSearch/Test/Index/TestSegment.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/lucy/trunk/import/core/KinoSearch/Test/Index/TestSegment.cfh
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/core/KinoSearch/Test/Index/TestSegment.cfh?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/core/KinoSearch/Test/Index/TestSegment.cfh (added)
+++ incubator/lucy/trunk/import/core/KinoSearch/Test/Index/TestSegment.cfh Thu Oct 14 08:48:04 2010
@@ -0,0 +1,13 @@
+parcel KinoSearch cnick Kino;
+
+inert class KinoSearch::Test::Index::TestSegment cnick TestSeg {
+ inert void
+ run_tests();
+}
+
+/* Copyright 2005-2010 Marvin Humphrey
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * under the same terms as Perl itself.
+ */
+
Added: incubator/lucy/trunk/import/core/KinoSearch/Test/Index/TestSnapshot.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/core/KinoSearch/Test/Index/TestSnapshot.c?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/core/KinoSearch/Test/Index/TestSnapshot.c (added)
+++ incubator/lucy/trunk/import/core/KinoSearch/Test/Index/TestSnapshot.c Thu Oct 14 08:48:04 2010
@@ -0,0 +1,100 @@
+#include "KinoSearch/Util/ToolSet.h"
+
+#include "KinoSearch/Test.h"
+#include "KinoSearch/Test/Index/TestSnapshot.h"
+#include "KinoSearch/Index/Snapshot.h"
+#include "KinoSearch/Store/RAMFolder.h"
+
+static void
+test_Add_and_Delete(TestBatch *batch)
+{
+ Snapshot *snapshot = Snapshot_new();
+ CharBuf *foo = (CharBuf*)ZCB_WRAP_STR("foo", 3);
+ CharBuf *bar = (CharBuf*)ZCB_WRAP_STR("bar", 3);
+
+ Snapshot_Add_Entry(snapshot, foo);
+ Snapshot_Add_Entry(snapshot, foo); // redundant
+ VArray *entries = Snapshot_List(snapshot);
+ TEST_INT_EQ(batch, Snapshot_Num_Entries(snapshot), 1,
+ "One entry added");
+ TEST_TRUE(batch, CB_Equals(foo, VA_Fetch(entries, 0)), "correct entry");
+ DECREF(entries);
+
+ Snapshot_Add_Entry(snapshot, bar);
+ TEST_INT_EQ(batch, Snapshot_Num_Entries(snapshot), 2,
+ "second entry added");
+ Snapshot_Delete_Entry(snapshot, foo);
+ TEST_INT_EQ(batch, Snapshot_Num_Entries(snapshot), 1, "Delete_Entry");
+
+ DECREF(snapshot);
+}
+
+static void
+test_path_handling(TestBatch *batch)
+{
+ Snapshot *snapshot = Snapshot_new();
+ Folder *folder = (Folder*)RAMFolder_new(NULL);
+ CharBuf *snap = (CharBuf*)ZCB_WRAP_STR("snap", 4);
+ CharBuf *crackle = (CharBuf*)ZCB_WRAP_STR("crackle", 7);
+
+ Snapshot_Write_File(snapshot, folder, snap);
+ TEST_TRUE(batch, CB_Equals(snap, (Obj*)Snapshot_Get_Path(snapshot)),
+ "Write_File() sets path as a side effect");
+
+ Folder_Rename(folder, snap, crackle);
+ Snapshot_Read_File(snapshot, folder, crackle);
+ TEST_TRUE(batch, CB_Equals(crackle, (Obj*)Snapshot_Get_Path(snapshot)),
+ "Read_File() sets path as a side effect");
+
+ Snapshot_Set_Path(snapshot, snap);
+ TEST_TRUE(batch, CB_Equals(snap, (Obj*)Snapshot_Get_Path(snapshot)),
+ "Set_Path()");
+
+ DECREF(folder);
+ DECREF(snapshot);
+}
+
+static void
+test_Read_File_and_Write_File(TestBatch *batch)
+{
+ Snapshot *snapshot = Snapshot_new();
+ Folder *folder = (Folder*)RAMFolder_new(NULL);
+ CharBuf *snap = (CharBuf*)ZCB_WRAP_STR("snap", 4);
+ CharBuf *foo = (CharBuf*)ZCB_WRAP_STR("foo", 3);
+
+ Snapshot_Add_Entry(snapshot, foo);
+ Snapshot_Write_File(snapshot, folder, snap);
+
+ Snapshot *dupe = Snapshot_new();
+ Snapshot *read_retval = Snapshot_Read_File(dupe, folder, snap);
+ TEST_TRUE(batch, dupe == read_retval, "Read_File() returns the object");
+
+ VArray *orig_list = Snapshot_List(snapshot);
+ VArray *dupe_list = Snapshot_List(dupe);
+ TEST_TRUE(batch, VA_Equals(orig_list, (Obj*)dupe_list),
+ "Round trip through Write_File() and Read_File()");
+
+ DECREF(orig_list);
+ DECREF(dupe_list);
+ DECREF(dupe);
+ DECREF(snapshot);
+ DECREF(folder);
+}
+
+void
+TestSnapshot_run_tests()
+{
+ TestBatch *batch = TestBatch_new(9);
+ TestBatch_Plan(batch);
+ test_Add_and_Delete(batch);
+ test_path_handling(batch);
+ test_Read_File_and_Write_File(batch);
+ DECREF(batch);
+}
+
+/* Copyright 2005-2010 Marvin Humphrey
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * under the same terms as Perl itself.
+ */
+
Propchange: incubator/lucy/trunk/import/core/KinoSearch/Test/Index/TestSnapshot.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/lucy/trunk/import/core/KinoSearch/Test/Index/TestSnapshot.cfh
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/core/KinoSearch/Test/Index/TestSnapshot.cfh?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/core/KinoSearch/Test/Index/TestSnapshot.cfh (added)
+++ incubator/lucy/trunk/import/core/KinoSearch/Test/Index/TestSnapshot.cfh Thu Oct 14 08:48:04 2010
@@ -0,0 +1,13 @@
+parcel KinoSearch cnick Kino;
+
+inert class KinoSearch::Test::Index::TestSnapshot {
+ inert void
+ run_tests();
+}
+
+/* Copyright 2005-2010 Marvin Humphrey
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * under the same terms as Perl itself.
+ */
+
Added: incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestBitVector.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestBitVector.c?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestBitVector.c (added)
+++ incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestBitVector.c Thu Oct 14 08:48:04 2010
@@ -0,0 +1,468 @@
+#define C_KINO_TESTBITVECTOR
+#include "KinoSearch/Util/ToolSet.h"
+
+#include "KinoSearch/Test.h"
+#include "KinoSearch/Test/TestUtils.h"
+#include "KinoSearch/Test/Object/TestBitVector.h"
+
+static void
+test_Set_and_Get(TestBatch *batch)
+{
+ unsigned i, max;
+ const uint32_t three = 3;
+ const uint32_t seventeen = 17;
+ BitVector *bit_vec = BitVec_new(8);
+
+ BitVec_Set(bit_vec, three);
+ TEST_TRUE(batch, BitVec_Get_Capacity(bit_vec) < seventeen,
+ "set below cap");
+ BitVec_Set(bit_vec, seventeen);
+ TEST_TRUE(batch, BitVec_Get_Capacity(bit_vec) > seventeen,
+ "set above cap causes BitVector to grow");
+
+ for (i = 0, max = BitVec_Get_Capacity(bit_vec); i < max; i++) {
+ if (i == three || i == seventeen) {
+ TEST_TRUE(batch, BitVec_Get(bit_vec, i), "set/get %d", i);
+ }
+ else {
+ TEST_FALSE(batch, BitVec_Get(bit_vec, i), "get %d", i);
+ }
+ }
+ TEST_FALSE(batch, BitVec_Get(bit_vec, i), "out of range get");
+
+ DECREF(bit_vec);
+}
+
+static void
+test_Flip(TestBatch *batch)
+{
+ BitVector *bit_vec = BitVec_new(0);
+ int i;
+
+ for (i = 0; i <= 20; i++) { BitVec_Flip(bit_vec, i); }
+ for (i = 0; i <= 20; i++) {
+ TEST_TRUE(batch, BitVec_Get(bit_vec, i), "flip on %d", i);
+ }
+ TEST_FALSE(batch, BitVec_Get(bit_vec, i), "no flip %d", i);
+ for (i = 0; i <= 20; i++) { BitVec_Flip(bit_vec, i); }
+ for (i = 0; i <= 20; i++) {
+ TEST_FALSE(batch, BitVec_Get(bit_vec, i), "flip off %d", i);
+ }
+ TEST_FALSE(batch, BitVec_Get(bit_vec, i), "still no flip %d", i);
+
+ DECREF(bit_vec);
+}
+
+static void
+test_Flip_Block_ascending(TestBatch *batch)
+{
+ BitVector *bit_vec = BitVec_new(0);
+ int i;
+
+ for (i = 0; i <= 20; i++) {
+ BitVec_Flip_Block(bit_vec, i, 21 - i);
+ }
+
+ for (i = 0; i <= 20; i++) {
+ if (i % 2 == 0) {
+ TEST_TRUE(batch, BitVec_Get(bit_vec, i),
+ "Flip_Block ascending %d", i);
+ }
+ else {
+ TEST_FALSE(batch, BitVec_Get(bit_vec, i),
+ "Flip_Block ascending %d", i);
+ }
+ }
+
+ DECREF(bit_vec);
+}
+
+static void
+test_Flip_Block_descending(TestBatch *batch)
+{
+ BitVector *bit_vec = BitVec_new(0);
+ int i;
+
+ for (i = 19; i >= 0; i--) {
+ BitVec_Flip_Block(bit_vec, 1, i);
+ }
+
+ for (i = 0; i <= 20; i++) {
+ if (i % 2) {
+ TEST_TRUE(batch, BitVec_Get(bit_vec, i),
+ "Flip_Block descending %d", i);
+ }
+ else {
+ TEST_FALSE(batch, BitVec_Get(bit_vec, i),
+ "Flip_Block descending %d", i);
+ }
+ }
+
+ DECREF(bit_vec);
+}
+
+static void
+test_Flip_Block_bulk(TestBatch *batch)
+{
+ int32_t offset;
+
+ for (offset = 0; offset <= 17; offset++) {
+ int32_t len;
+ for (len = 0; len <= 17; len++) {
+ int i;
+ int upper = offset + len - 1;
+ BitVector *bit_vec = BitVec_new(0);
+
+ BitVec_Flip_Block(bit_vec, offset, len);
+ for (i = 0; i <= 17; i++) {
+ if (i >= offset && i <= upper) {
+ if (!BitVec_Get(bit_vec, i)) { break; }
+ }
+ else {
+ if (BitVec_Get(bit_vec, i)) { break; }
+ }
+ }
+ TEST_INT_EQ(batch, i, 18, "Flip_Block(%d, %d)", offset, len);
+
+ DECREF(bit_vec);
+ }
+ }
+}
+
+static void
+test_Mimic(TestBatch *batch)
+{
+ int foo;
+
+ for (foo = 0; foo <= 17; foo++) {
+ int bar;
+ for (bar = 0; bar <= 17; bar++) {
+ int i;
+ BitVector *foo_vec = BitVec_new(0);
+ BitVector *bar_vec = BitVec_new(0);
+
+ BitVec_Set(foo_vec, foo);
+ BitVec_Set(bar_vec, bar);
+ BitVec_Mimic(foo_vec, (Obj*)bar_vec);
+
+ for (i = 0; i <= 17; i++) {
+ if (BitVec_Get(foo_vec, i) && i != bar) { break; }
+ }
+ TEST_INT_EQ(batch, i, 18, "Mimic(%d, %d)", foo, bar);
+
+ DECREF(foo_vec);
+ DECREF(bar_vec);
+ }
+ }
+}
+
+static BitVector*
+S_create_set(int set_num)
+{
+ int i;
+ int nums_1[] = { 1, 2, 3, 10, 20, 30, 0 };
+ int nums_2[] = { 2, 3, 4, 5, 6, 7, 8, 9, 10,
+ 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 0 };
+ int *nums = set_num == 1 ? nums_1 : nums_2;
+ BitVector *bit_vec = BitVec_new(31);
+ for (i = 0; nums[i] != 0; i++) {
+ BitVec_Set(bit_vec, nums[i]);
+ }
+ return bit_vec;
+}
+
+#define OP_OR 1
+#define OP_XOR 2
+#define OP_AND 3
+#define OP_AND_NOT 4
+static int
+S_verify_logical_op(BitVector *bit_vec, BitVector *set_1, BitVector *set_2,
+ int op)
+{
+ int i;
+
+ for (i = 0; i < 50; i++) {
+ bool_t wanted;
+
+ switch(op) {
+ case OP_OR:
+ wanted = BitVec_Get(set_1, i) || BitVec_Get(set_2, i);
+ break;
+ case OP_XOR:
+ wanted = (!BitVec_Get(set_1, i)) != (!BitVec_Get(set_2, i));
+ break;
+ case OP_AND:
+ wanted = BitVec_Get(set_1, i) && BitVec_Get(set_2, i);
+ break;
+ case OP_AND_NOT:
+ wanted = BitVec_Get(set_1, i) && (!BitVec_Get(set_2, i));
+ break;
+ default:
+ wanted = false;
+ THROW(ERR, "unknown op: %d", op);
+ }
+
+ if (BitVec_Get(bit_vec, i) != wanted) { break; }
+ }
+
+ return i;
+}
+
+static void
+test_Or(TestBatch *batch)
+{
+ BitVector *smaller = S_create_set(1);
+ BitVector *larger = S_create_set(2);
+ BitVector *set_1 = S_create_set(1);
+ BitVector *set_2 = S_create_set(2);
+
+ BitVec_Or(smaller, set_2);
+ TEST_INT_EQ(batch, S_verify_logical_op(smaller, set_1, set_2, OP_OR),
+ 50, "OR with self smaller than other");
+ BitVec_Or(larger, set_1);
+ TEST_INT_EQ(batch, S_verify_logical_op(larger, set_1, set_2, OP_OR),
+ 50, "OR with other smaller than self");
+
+ DECREF(smaller);
+ DECREF(larger);
+ DECREF(set_1);
+ DECREF(set_2);
+}
+
+static void
+test_Xor(TestBatch *batch)
+{
+ BitVector *smaller = S_create_set(1);
+ BitVector *larger = S_create_set(2);
+ BitVector *set_1 = S_create_set(1);
+ BitVector *set_2 = S_create_set(2);
+
+ BitVec_Xor(smaller, set_2);
+ TEST_INT_EQ(batch, S_verify_logical_op(smaller, set_1, set_2, OP_XOR),
+ 50, "XOR with self smaller than other");
+ BitVec_Xor(larger, set_1);
+ TEST_INT_EQ(batch, S_verify_logical_op(larger, set_1, set_2, OP_XOR),
+ 50, "XOR with other smaller than self");
+
+ DECREF(smaller);
+ DECREF(larger);
+ DECREF(set_1);
+ DECREF(set_2);
+}
+
+static void
+test_And(TestBatch *batch)
+{
+ BitVector *smaller = S_create_set(1);
+ BitVector *larger = S_create_set(2);
+ BitVector *set_1 = S_create_set(1);
+ BitVector *set_2 = S_create_set(2);
+
+ BitVec_And(smaller, set_2);
+ TEST_INT_EQ(batch, S_verify_logical_op(smaller, set_1, set_2, OP_AND),
+ 50, "AND with self smaller than other");
+ BitVec_And(larger, set_1);
+ TEST_INT_EQ(batch, S_verify_logical_op(larger, set_1, set_2, OP_AND),
+ 50, "AND with other smaller than self");
+
+ DECREF(smaller);
+ DECREF(larger);
+ DECREF(set_1);
+ DECREF(set_2);
+}
+
+static void
+test_And_Not(TestBatch *batch)
+{
+ BitVector *smaller = S_create_set(1);
+ BitVector *larger = S_create_set(2);
+ BitVector *set_1 = S_create_set(1);
+ BitVector *set_2 = S_create_set(2);
+
+ BitVec_And_Not(smaller, set_2);
+ TEST_INT_EQ(batch,
+ S_verify_logical_op(smaller, set_1, set_2, OP_AND_NOT),
+ 50, "AND_NOT with self smaller than other");
+ BitVec_And_Not(larger, set_1);
+ TEST_INT_EQ(batch,
+ S_verify_logical_op(larger, set_2, set_1, OP_AND_NOT),
+ 50, "AND_NOT with other smaller than self");
+
+ DECREF(smaller);
+ DECREF(larger);
+ DECREF(set_1);
+ DECREF(set_2);
+}
+
+static void
+test_Count(TestBatch *batch)
+{
+ int i;
+ int shuffled[64];
+ BitVector *bit_vec = BitVec_new(64);
+
+ for (i = 0; i < 64; i++) { shuffled[i] = i; }
+ for (i = 0; i < 64; i++) {
+ int shuffle_pos = rand() % 64;
+ int temp = shuffled[shuffle_pos];
+ shuffled[shuffle_pos] = shuffled[i];
+ shuffled[i] = temp;
+ }
+ for (i = 0; i < 64; i++) {
+ BitVec_Set(bit_vec, shuffled[i]);
+ if (BitVec_Count(bit_vec) != (uint32_t)(i + 1)) { break; }
+ }
+ TEST_INT_EQ(batch, i, 64, "Count() returns the right number of bits");
+
+ DECREF(bit_vec);
+}
+
+static void
+test_Next_Hit(TestBatch *batch)
+{
+ int i;
+
+ for (i = 24; i <= 33; i++) {
+ int probe;
+ BitVector *bit_vec = BitVec_new(64);
+ BitVec_Set(bit_vec, i);
+ TEST_INT_EQ(batch, BitVec_Next_Hit(bit_vec, 0), i,
+ "Next_Hit for 0 is %d", i);
+ TEST_INT_EQ(batch, BitVec_Next_Hit(bit_vec, 0), i,
+ "Next_Hit for 1 is %d", i);
+ for (probe = 15; probe <= i; probe++) {
+ TEST_INT_EQ(batch, BitVec_Next_Hit(bit_vec, probe), i,
+ "Next_Hit for %d is %d", probe, i);
+ }
+ for (probe = i + 1; probe <= i + 9; probe++) {
+ TEST_INT_EQ(batch, BitVec_Next_Hit(bit_vec, probe), -1,
+ "no Next_Hit for %d when max is %d", probe, i );
+ }
+ DECREF(bit_vec);
+ }
+}
+
+static void
+test_Clear_All(TestBatch *batch)
+{
+ BitVector *bit_vec = BitVec_new(64);
+ BitVec_Flip_Block(bit_vec, 0, 63);
+ BitVec_Clear_All(bit_vec);
+ TEST_INT_EQ(batch, BitVec_Next_Hit(bit_vec, 0), -1, "Clear_All");
+ DECREF(bit_vec);
+}
+
+static void
+test_Clone(TestBatch *batch)
+{
+ int i;
+ BitVector *self = BitVec_new(30);
+ BitVector *evil_twin;
+
+ BitVec_Set(self, 2);
+ BitVec_Set(self, 3);
+ BitVec_Set(self, 10);
+ BitVec_Set(self, 20);
+
+ evil_twin = BitVec_Clone(self);
+ for (i = 0; i < 50; i++) {
+ if (BitVec_Get(self, i) != BitVec_Get(evil_twin, i)) { break; }
+ }
+ TEST_INT_EQ(batch, i, 50, "Clone");
+ TEST_INT_EQ(batch, BitVec_Count(evil_twin), 4, "clone Count");
+
+ DECREF(self);
+ DECREF(evil_twin);
+}
+
+static int
+S_compare_u64s(void *context, const void *va, const void *vb)
+{
+ uint64_t a = *(uint64_t*)va;
+ uint64_t b = *(uint64_t*)vb;
+ UNUSED_VAR(context);
+ return a == b ? 0 : a < b ? -1 : 1;
+}
+
+static void
+test_To_Array(TestBatch *batch)
+{
+ uint64_t *source_ints = TestUtils_random_u64s(NULL, 20, 0, 200);
+ BitVector *bit_vec = BitVec_new(0);
+ I32Array *array;
+ long num_unique = 0;
+ long i;
+
+ // Unique the random ints.
+ Sort_quicksort(source_ints, 20, sizeof(uint64_t),
+ S_compare_u64s, NULL);
+ for (i = 0; i < 19; i++) {
+ if (source_ints[i] != source_ints[i + 1]) {
+ source_ints[num_unique] = source_ints[i];
+ num_unique++;
+ }
+ }
+
+ // Set bits.
+ for (i = 0; i < num_unique; i++) {
+ BitVec_Set(bit_vec, (uint32_t)source_ints[i]);
+ }
+
+ // Create the array and compare it to the source.
+ array = BitVec_To_Array(bit_vec);
+ for (i = 0; i < num_unique; i++) {
+ if (I32Arr_Get(array, i) != (int32_t)source_ints[i]) { break; }
+ }
+ TEST_INT_EQ(batch, i, num_unique, "To_Array (%ld == %ld)", i,
+ num_unique);
+
+ DECREF(array);
+ DECREF(bit_vec);
+ FREEMEM(source_ints);
+}
+
+
+// Valgrind only - detect off-by-one error.
+static void
+test_off_by_one_error()
+{
+ int cap;
+ for (cap = 5; cap <= 24; cap++) {
+ BitVector *bit_vec = BitVec_new(cap);
+ BitVec_Set(bit_vec, cap - 2);
+ DECREF(bit_vec);
+ }
+}
+
+void
+TestBitVector_run_tests()
+{
+ TestBatch *batch = TestBatch_new(1029);
+
+ TestBatch_Plan(batch);
+ test_Set_and_Get(batch);
+ test_Flip(batch);
+ test_Flip_Block_ascending(batch);
+ test_Flip_Block_descending(batch);
+ test_Flip_Block_bulk(batch);
+ test_Mimic(batch);
+ test_Or(batch);
+ test_Xor(batch);
+ test_And(batch);
+ test_And_Not(batch);
+ test_Count(batch);
+ test_Next_Hit(batch);
+ test_Clear_All(batch);
+ test_Clone(batch);
+ test_To_Array(batch);
+ test_off_by_one_error();
+
+ DECREF(batch);
+}
+
+/* Copyright 2005-2010 Marvin Humphrey
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * under the same terms as Perl itself.
+ */
+
Propchange: incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestBitVector.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestBitVector.cfh
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestBitVector.cfh?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestBitVector.cfh (added)
+++ incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestBitVector.cfh Thu Oct 14 08:48:04 2010
@@ -0,0 +1,13 @@
+parcel KinoSearch cnick Kino;
+
+inert class KinoSearch::Test::Object::TestBitVector {
+ inert void
+ run_tests();
+}
+
+/* Copyright 2005-2010 Marvin Humphrey
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * under the same terms as Perl itself.
+ */
+
Added: incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestByteBuf.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestByteBuf.c?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestByteBuf.c (added)
+++ incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestByteBuf.c Thu Oct 14 08:48:04 2010
@@ -0,0 +1,157 @@
+#define C_KINO_TESTBYTEBUF
+#include "KinoSearch/Util/ToolSet.h"
+
+#include "KinoSearch/Test.h"
+#include "KinoSearch/Test/TestUtils.h"
+#include "KinoSearch/Test/Object/TestByteBuf.h"
+
+static void
+test_Equals(TestBatch *batch)
+{
+ ByteBuf *wanted = BB_new_bytes("foo", 4); // Include terminating NULL.
+ ByteBuf *got = BB_new_bytes("foo", 4);
+
+ TEST_TRUE(batch, BB_Equals(wanted, (Obj*)got), "Equals");
+ TEST_INT_EQ(batch, BB_Hash_Sum(got), BB_Hash_Sum(wanted), "Hash_Sum");
+
+ TEST_TRUE(batch, BB_Equals_Bytes(got, "foo", 4), "Equals_Bytes");
+ TEST_FALSE(batch, BB_Equals_Bytes(got, "foo", 3),
+ "Equals_Bytes spoiled by different size");
+ TEST_FALSE(batch, BB_Equals_Bytes(got, "bar", 4),
+ "Equals_Bytes spoiled by different content");
+
+ BB_Set_Size(got, 3);
+ TEST_FALSE(batch, BB_Equals(wanted, (Obj*)got),
+ "Different size spoils Equals");
+ TEST_FALSE(batch, BB_Hash_Sum(got) == BB_Hash_Sum(wanted),
+ "Different size spoils Hash_Sum (probably -- at least this one)");
+
+ BB_Mimic_Bytes(got, "bar", 4);
+ TEST_INT_EQ(batch, BB_Get_Size(wanted), BB_Get_Size(got),
+ "same length");
+ TEST_FALSE(batch, BB_Equals(wanted, (Obj*)got),
+ "Different content spoils Equals");
+
+ DECREF(got);
+ DECREF(wanted);
+}
+
+static void
+test_Grow(TestBatch *batch)
+{
+ ByteBuf *bb = BB_new(1);
+ TEST_INT_EQ(batch, BB_Get_Capacity(bb), 8,
+ "Allocate in 8-byte increments");
+ BB_Grow(bb, 9);
+ TEST_INT_EQ(batch, BB_Get_Capacity(bb), 16,
+ "Grow in 8-byte increments");
+ DECREF(bb);
+}
+
+static void
+test_Clone(TestBatch *batch)
+{
+ ByteBuf *bb = BB_new_bytes("foo", 3);
+ ByteBuf *evil_twin = BB_Clone(bb);
+ TEST_TRUE(batch, BB_Equals(bb, (Obj*)evil_twin), "Clone");
+ DECREF(bb);
+ DECREF(evil_twin);
+}
+
+static void
+test_compare(TestBatch *batch)
+{
+ ByteBuf *a = BB_new_bytes("foo\0a", 5);
+ ByteBuf *b = BB_new_bytes("foo\0b", 5);
+
+ BB_Set_Size(a, 4);
+ BB_Set_Size(b, 4);
+ TEST_INT_EQ(batch, BB_compare(&a, &b), 0,
+ "BB_compare returns 0 for equal ByteBufs");
+
+ BB_Set_Size(a, 3);
+ TEST_TRUE(batch, BB_compare(&a, &b) < 0, "shorter ByteBuf sorts first");
+
+ BB_Set_Size(a, 5);
+ BB_Set_Size(b, 5);
+ TEST_TRUE(batch, BB_compare(&a, &b) < 0,
+ "NULL doesn't interfere with BB_compare");
+
+ DECREF(a);
+ DECREF(b);
+}
+
+static void
+test_Mimic(TestBatch *batch)
+{
+ ByteBuf *a = BB_new_bytes("foo", 3);
+ ByteBuf *b = BB_new(0);
+
+ BB_Mimic(b, (Obj*)a);
+ TEST_TRUE(batch, BB_Equals(a, (Obj*)b), "Mimic");
+
+ BB_Mimic_Bytes(a, "bar", 4);
+ TEST_TRUE(batch, strcmp(BB_Get_Buf(a), "bar") == 0,
+ "Mimic_Bytes content");
+ TEST_INT_EQ(batch, BB_Get_Size(a), 4, "Mimic_Bytes size");
+
+ BB_Mimic(b, (Obj*)a);
+ TEST_TRUE(batch, BB_Equals(a, (Obj*)b), "Mimic");
+
+ DECREF(a);
+ DECREF(b);
+}
+
+static void
+test_Cat(TestBatch *batch)
+{
+ ByteBuf *wanted = BB_new_bytes("foobar", 6);
+ ByteBuf *got = BB_new_bytes("foo", 3);
+ ByteBuf *scratch = BB_new_bytes("bar", 3);
+
+ BB_Cat(got, scratch);
+ TEST_TRUE(batch, BB_Equals(wanted, (Obj*)got), "Cat");
+
+ BB_Mimic_Bytes(wanted,"foobarbaz", 9);
+ BB_Cat_Bytes(got, "baz", 3);
+ TEST_TRUE(batch, BB_Equals(wanted, (Obj*)got), "Cat_Bytes");
+
+ DECREF(scratch);
+ DECREF(got);
+ DECREF(wanted);
+}
+
+static void
+test_serialization(TestBatch *batch)
+{
+ ByteBuf *wanted = BB_new_bytes("foobar", 6);
+ ByteBuf *got = (ByteBuf*)TestUtils_freeze_thaw((Obj*)wanted);
+ TEST_TRUE(batch, got && BB_Equals(wanted, (Obj*)got),
+ "Serialization round trip");
+ DECREF(wanted);
+ DECREF(got);
+}
+
+void
+TestBB_run_tests()
+{
+ TestBatch *batch = TestBatch_new(22);
+ TestBatch_Plan(batch);
+
+ test_Equals(batch);
+ test_Grow(batch);
+ test_Clone(batch);
+ test_compare(batch);
+ test_Mimic(batch);
+ test_Cat(batch);
+ test_serialization(batch);
+
+ DECREF(batch);
+}
+
+/* Copyright 2005-2010 Marvin Humphrey
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * under the same terms as Perl itself.
+ */
+
Propchange: incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestByteBuf.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestByteBuf.cfh
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestByteBuf.cfh?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestByteBuf.cfh (added)
+++ incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestByteBuf.cfh Thu Oct 14 08:48:04 2010
@@ -0,0 +1,16 @@
+parcel KinoSearch cnick Kino;
+parcel KinoSearch cnick Kino;
+
+class KinoSearch::Test::Object::TestByteBuf cnick TestBB
+ inherits KinoSearch::Object::Obj {
+
+ inert void
+ run_tests();
+}
+
+/* Copyright 2005-2010 Marvin Humphrey
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * under the same terms as Perl itself.
+ */
+
Added: incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestCharBuf.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestCharBuf.c?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestCharBuf.c (added)
+++ incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestCharBuf.c Thu Oct 14 08:48:04 2010
@@ -0,0 +1,416 @@
+#define C_KINO_TESTCHARBUF
+#include "KinoSearch/Util/ToolSet.h"
+#include <stdarg.h>
+#include <string.h>
+#include <stdio.h>
+
+#include "KinoSearch/Test.h"
+#include "KinoSearch/Test/TestUtils.h"
+#include "KinoSearch/Test/Object/TestCharBuf.h"
+
+static char smiley[] = { (char)0xE2, (char)0x98, (char)0xBA, 0 };
+static uint32_t smiley_len = 3;
+
+static CharBuf*
+S_get_cb(char *string)
+{
+ return CB_new_from_utf8(string, strlen(string));
+}
+
+static void
+test_Cat(TestBatch *batch)
+{
+ CharBuf *wanted = CB_newf("a%s", smiley);
+ CharBuf *got = S_get_cb("");
+
+ CB_Cat(got, wanted);
+ TEST_TRUE(batch, CB_Equals(wanted, (Obj*)got), "Cat");
+ DECREF(got);
+
+ got = S_get_cb("a");
+ CB_Cat_Char(got, 0x263A);
+ TEST_TRUE(batch, CB_Equals(wanted, (Obj*)got), "Cat_Char");
+ DECREF(got);
+
+ got = S_get_cb("a");
+ CB_Cat_Str(got, smiley, smiley_len);
+ TEST_TRUE(batch, CB_Equals(wanted, (Obj*)got), "Cat_Str");
+ DECREF(got);
+
+ got = S_get_cb("a");
+ CB_Cat_Trusted_Str(got, smiley, smiley_len);
+ TEST_TRUE(batch, CB_Equals(wanted, (Obj*)got), "Cat_Trusted_Str");
+ DECREF(got);
+
+ DECREF(wanted);
+}
+
+static void
+test_Mimic_and_Clone(TestBatch *batch)
+{
+ CharBuf *wanted = S_get_cb("foo");
+ CharBuf *got = S_get_cb("bar");
+
+ CB_Mimic(got, (Obj*)wanted);
+ TEST_TRUE(batch, CB_Equals(wanted, (Obj*)got), "Mimic");
+ DECREF(got);
+
+ got = S_get_cb("bar");
+ CB_Mimic_Str(got, "foo", 3);
+ TEST_TRUE(batch, CB_Equals(wanted, (Obj*)got), "Mimic_Str");
+ DECREF(got);
+
+ got = CB_Clone(wanted);
+ TEST_TRUE(batch, CB_Equals(wanted, (Obj*)got), "Clone");
+ DECREF(got);
+
+ DECREF(wanted);
+}
+
+static void
+test_Code_Point_At_and_From(TestBatch *batch)
+{
+ uint32_t code_points[] = { 'a', 0x263A, 0x263A, 'b', 0x263A, 'c' };
+ uint32_t num_code_points = sizeof(code_points) / sizeof(uint32_t);
+ CharBuf *string = CB_newf("a%s%sb%sc", smiley, smiley, smiley);
+ uint32_t i;
+
+ for (i = 0; i < num_code_points; i++) {
+ uint32_t from = num_code_points - i - 1;
+ TEST_INT_EQ(batch, CB_Code_Point_At(string, i), code_points[i],
+ "Code_Point_At %ld", (long)i);
+ TEST_INT_EQ(batch, CB_Code_Point_At(string, from),
+ code_points[from], "Code_Point_From %ld", (long)from);
+ }
+
+ DECREF(string);
+}
+
+static void
+test_SubString(TestBatch *batch)
+{
+ CharBuf *string = CB_newf("a%s%sb%sc", smiley, smiley, smiley);
+ CharBuf *wanted = CB_newf("%sb%s", smiley, smiley);
+ CharBuf *got = CB_SubString(string, 2, 3);
+ TEST_TRUE(batch, CB_Equals(wanted, (Obj*)got), "SubString");
+ DECREF(wanted);
+ DECREF(got);
+ DECREF(string);
+}
+
+static void
+test_Nip_and_Chop(TestBatch *batch)
+{
+ CharBuf *wanted;
+ CharBuf *got;
+
+ wanted = CB_newf("%sb%sc", smiley, smiley);
+ got = CB_newf("a%s%sb%sc", smiley, smiley, smiley);
+ CB_Nip(got, 2);
+ TEST_TRUE(batch, CB_Equals(wanted, (Obj*)got), "Nip");
+ DECREF(wanted);
+ DECREF(got);
+
+ wanted = CB_newf("a%s%s", smiley, smiley);
+ got = CB_newf("a%s%sb%sc", smiley, smiley, smiley);
+ CB_Chop(got, 3);
+ TEST_TRUE(batch, CB_Equals(wanted, (Obj*)got), "Chop");
+ DECREF(wanted);
+ DECREF(got);
+}
+
+
+static void
+test_Truncate(TestBatch *batch)
+{
+ CharBuf *wanted = CB_newf("a%s", smiley, smiley);
+ CharBuf *got = CB_newf("a%s%sb%sc", smiley, smiley, smiley);
+ CB_Truncate(got, 2);
+ TEST_TRUE(batch, CB_Equals(wanted, (Obj*)got), "Truncate");
+ DECREF(wanted);
+ DECREF(got);
+}
+
+static void
+test_Trim(TestBatch *batch)
+{
+ uint32_t spaces[] = {
+ ' ', '\t', '\r', '\n', 0x000B, 0x000C, 0x000D, 0x0085,
+ 0x00A0, 0x1680, 0x180E, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004,
+ 0x2005, 0x2006, 0x2007, 0x2008, 0x2009, 0x200A, 0x2028, 0x2029,
+ 0x202F, 0x205F, 0x3000
+ };
+ uint32_t num_spaces = sizeof(spaces) / sizeof(uint32_t);
+ uint32_t i;
+ CharBuf *got = CB_new(0);
+
+ // Surround a smiley with lots of whitespace.
+ for (i = 0; i < num_spaces; i++) { CB_Cat_Char(got, spaces[i]); }
+ CB_Cat_Char(got, 0x263A);
+ for (i = 0; i < num_spaces; i++) { CB_Cat_Char(got, spaces[i]); }
+
+ TEST_TRUE(batch, CB_Trim_Top(got), "Trim_Top returns true on success");
+ TEST_FALSE(batch, CB_Trim_Top(got),
+ "Trim_Top returns false on failure");
+ TEST_TRUE(batch, CB_Trim_Tail(got), "Trim_Tail returns true on success");
+ TEST_FALSE(batch, CB_Trim_Tail(got),
+ "Trim_Tail returns false on failure");
+ TEST_TRUE(batch, CB_Equals_Str(got, smiley, smiley_len),
+ "Trim_Top and Trim_Tail worked");
+
+ // Build the spacey smiley again.
+ CB_Truncate(got, 0);
+ for (i = 0; i < num_spaces; i++) { CB_Cat_Char(got, spaces[i]); }
+ CB_Cat_Char(got, 0x263A);
+ for (i = 0; i < num_spaces; i++) { CB_Cat_Char(got, spaces[i]); }
+
+ TEST_TRUE(batch, CB_Trim(got), "Trim returns true on success");
+ TEST_FALSE(batch, CB_Trim(got), "Trim returns false on failure");
+ TEST_TRUE(batch, CB_Equals_Str(got, smiley, smiley_len),
+ "Trim worked");
+
+ DECREF(got);
+}
+
+static void
+test_To_F64(TestBatch *batch)
+{
+ CharBuf *charbuf = S_get_cb("1.5");
+ double difference = 1.5 - CB_To_F64(charbuf);
+ if (difference < 0) { difference = 0 - difference; }
+ TEST_TRUE(batch, difference < 0.001, "To_F64");
+
+ CB_setf(charbuf, "-1.5");
+ difference = 1.5 + CB_To_F64(charbuf);
+ if (difference < 0) { difference = 0 - difference; }
+ TEST_TRUE(batch, difference < 0.001, "To_F64 negative");
+
+ DECREF(charbuf);
+}
+
+static void
+test_To_I64(TestBatch *batch)
+{
+ CharBuf *charbuf = S_get_cb("10");
+ TEST_TRUE(batch, CB_To_I64(charbuf) == 10, "To_I64");
+ CB_setf(charbuf, "-10");
+ TEST_TRUE(batch, CB_To_I64(charbuf) == -10, "To_I64 negative");
+ DECREF(charbuf);
+}
+
+
+static void
+test_vcatf_s(TestBatch *batch)
+{
+ CharBuf *wanted = S_get_cb("foo bar bizzle baz");
+ CharBuf *got = S_get_cb("foo ");
+ CB_catf(got, "bar %s baz", "bizzle");
+ TEST_TRUE(batch, CB_Equals(wanted, (Obj*)got), "%%s");
+ DECREF(wanted);
+ DECREF(got);
+}
+
+static void
+test_vcatf_null_string(TestBatch *batch)
+{
+ CharBuf *wanted = S_get_cb("foo bar [NULL] baz");
+ CharBuf *got = S_get_cb("foo ");
+ CB_catf(got, "bar %s baz", NULL);
+ TEST_TRUE(batch, CB_Equals(wanted, (Obj*)got), "%%s NULL");
+ DECREF(wanted);
+ DECREF(got);
+}
+
+static void
+test_vcatf_cb(TestBatch *batch)
+{
+ CharBuf *wanted = S_get_cb("foo bar ZEKE baz");
+ CharBuf *catworthy = S_get_cb("ZEKE");
+ CharBuf *got = S_get_cb("foo ");
+ CB_catf(got, "bar %o baz", catworthy);
+ TEST_TRUE(batch, CB_Equals(wanted, (Obj*)got), "%%o CharBuf");
+ DECREF(catworthy);
+ DECREF(wanted);
+ DECREF(got);
+}
+
+static void
+test_vcatf_obj(TestBatch *batch)
+{
+ CharBuf *wanted = S_get_cb("ooga 20 booga");
+ Integer32 *i32 = Int32_new(20);
+ CharBuf *got = S_get_cb("ooga");
+ CB_catf(got, " %o booga", i32);
+ TEST_TRUE(batch, CB_Equals(wanted, (Obj*)got), "%%o Obj");
+ DECREF(i32);
+ DECREF(wanted);
+ DECREF(got);
+}
+
+static void
+test_vcatf_null_obj(TestBatch *batch)
+{
+ CharBuf *wanted = S_get_cb("foo bar [NULL] baz");
+ CharBuf *got = S_get_cb("foo ");
+ CB_catf(got, "bar %o baz", NULL);
+ TEST_TRUE(batch, CB_Equals(wanted, (Obj*)got), "%%o NULL");
+ DECREF(wanted);
+ DECREF(got);
+}
+
+static void
+test_vcatf_i8(TestBatch *batch)
+{
+ CharBuf *wanted = S_get_cb("foo bar -3 baz");
+ int8_t num = -3;
+ CharBuf *got = S_get_cb("foo ");
+ CB_catf(got, "bar %i8 baz", num);
+ TEST_TRUE(batch, CB_Equals(wanted, (Obj*)got), "%%i8");
+ DECREF(wanted);
+ DECREF(got);
+}
+
+static void
+test_vcatf_i32(TestBatch *batch)
+{
+ CharBuf *wanted = S_get_cb("foo bar -100000 baz");
+ int32_t num = -100000;
+ CharBuf *got = S_get_cb("foo ");
+ CB_catf(got, "bar %i32 baz", num);
+ TEST_TRUE(batch, CB_Equals(wanted, (Obj*)got), "%%i32");
+ DECREF(wanted);
+ DECREF(got);
+}
+
+static void
+test_vcatf_i64(TestBatch *batch)
+{
+ CharBuf *wanted = S_get_cb("foo bar -5000000000 baz");
+ int64_t num = I64_C(-5000000000);
+ CharBuf *got = S_get_cb("foo ");
+ CB_catf(got, "bar %i64 baz", num);
+ TEST_TRUE(batch, CB_Equals(wanted, (Obj*)got), "%%i64");
+ DECREF(wanted);
+ DECREF(got);
+}
+
+static void
+test_vcatf_u8(TestBatch *batch)
+{
+ CharBuf *wanted = S_get_cb("foo bar 3 baz");
+ uint8_t num = 3;
+ CharBuf *got = S_get_cb("foo ");
+ CB_catf(got, "bar %u8 baz", num);
+ TEST_TRUE(batch, CB_Equals(wanted, (Obj*)got), "%%u8");
+ DECREF(wanted);
+ DECREF(got);
+}
+
+static void
+test_vcatf_u32(TestBatch *batch)
+{
+ CharBuf *wanted = S_get_cb("foo bar 100000 baz");
+ uint32_t num = 100000;
+ CharBuf *got = S_get_cb("foo ");
+ CB_catf(got, "bar %u32 baz", num);
+ TEST_TRUE(batch, CB_Equals(wanted, (Obj*)got), "%%u32");
+ DECREF(wanted);
+ DECREF(got);
+}
+
+static void
+test_vcatf_u64(TestBatch *batch)
+{
+ CharBuf *wanted = S_get_cb("foo bar 5000000000 baz");
+ uint64_t num = U64_C(5000000000);
+ CharBuf *got = S_get_cb("foo ");
+ CB_catf(got, "bar %u64 baz", num);
+ TEST_TRUE(batch, CB_Equals(wanted, (Obj*)got), "%%u64");
+ DECREF(wanted);
+ DECREF(got);
+}
+
+static void
+test_vcatf_f64(TestBatch *batch)
+{
+ CharBuf *wanted;
+ char buf[64];
+ float num = 1.3f;
+ CharBuf *got = S_get_cb("foo ");
+ sprintf(buf, "foo bar %g baz", num);
+ wanted = CB_new_from_trusted_utf8(buf, strlen(buf));
+ CB_catf(got, "bar %f64 baz", num);
+ TEST_TRUE(batch, CB_Equals(wanted, (Obj*)got), "%%f64");
+ DECREF(wanted);
+ DECREF(got);
+}
+
+static void
+test_vcatf_x32(TestBatch *batch)
+{
+ CharBuf *wanted;
+ char buf[64];
+ unsigned long num = I32_MAX;
+ CharBuf *got = S_get_cb("foo ");
+#if (SIZEOF_LONG == 4)
+ sprintf(buf, "foo bar %.8lx baz", num);
+#elif (SIZEOF_INT == 4)
+ sprintf(buf, "foo bar %.8x baz", (unsigned)num);
+#endif
+ wanted = CB_new_from_trusted_utf8(buf, strlen(buf));
+ CB_catf(got, "bar %x32 baz", (uint32_t)num);
+ TEST_TRUE(batch, CB_Equals(wanted, (Obj*)got), "%%x32");
+ DECREF(wanted);
+ DECREF(got);
+}
+
+static void
+test_serialization(TestBatch *batch)
+{
+ CharBuf *wanted = S_get_cb("foo");
+ CharBuf *got = (CharBuf*)TestUtils_freeze_thaw((Obj*)wanted);
+ TEST_TRUE(batch, got && CB_Equals(wanted, (Obj*)got),
+ "Round trip through FREEZE/THAW");
+ DECREF(got);
+ DECREF(wanted);
+}
+
+void
+TestCB_run_tests()
+{
+ TestBatch *batch = TestBatch_new(49);
+ TestBatch_Plan(batch);
+
+ test_vcatf_s(batch);
+ test_vcatf_null_string(batch);
+ test_vcatf_cb(batch);
+ test_vcatf_obj(batch);
+ test_vcatf_null_obj(batch);
+ test_vcatf_i8(batch);
+ test_vcatf_i32(batch);
+ test_vcatf_i64(batch);
+ test_vcatf_u8(batch);
+ test_vcatf_u32(batch);
+ test_vcatf_u64(batch);
+ test_vcatf_f64(batch);
+ test_vcatf_x32(batch);
+ test_Cat(batch);
+ test_Mimic_and_Clone(batch);
+ test_Code_Point_At_and_From(batch);
+ test_SubString(batch);
+ test_Nip_and_Chop(batch);
+ test_Truncate(batch);
+ test_Trim(batch);
+ test_To_F64(batch);
+ test_To_I64(batch);
+ test_serialization(batch);
+
+ DECREF(batch);
+}
+
+/* Copyright 2005-2010 Marvin Humphrey
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * under the same terms as Perl itself.
+ */
+
Propchange: incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestCharBuf.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestCharBuf.cfh
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestCharBuf.cfh?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestCharBuf.cfh (added)
+++ incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestCharBuf.cfh Thu Oct 14 08:48:04 2010
@@ -0,0 +1,16 @@
+parcel KinoSearch cnick Kino;
+parcel KinoSearch cnick Kino;
+
+class KinoSearch::Test::Object::TestCharBuf cnick TestCB
+ inherits KinoSearch::Object::Obj {
+
+ inert void
+ run_tests();
+}
+
+/* Copyright 2005-2010 Marvin Humphrey
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * under the same terms as Perl itself.
+ */
+
Added: incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestHash.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestHash.c?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestHash.c (added)
+++ incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestHash.c Thu Oct 14 08:48:04 2010
@@ -0,0 +1,305 @@
+#include "KinoSearch/Util/ToolSet.h"
+#include <stdlib.h>
+#include <time.h>
+
+#include "KinoSearch/Test.h"
+#include "KinoSearch/Test/TestUtils.h"
+#include "KinoSearch/Test/Object/TestHash.h"
+#include "KinoSearch/Object/Hash.h"
+
+static CharBuf*
+S_random_string()
+{
+ uint32_t len = rand() % 1200;
+ CharBuf *string = CB_new(len * 3);
+
+ while (len--) {
+ uint8_t bytes = (rand() % 3) + 1;
+ uint32_t code_point = 0;
+ switch (bytes & 0x3) {
+ case 1:
+ code_point = rand() % 0x80;
+ break;
+ case 2:
+ code_point = (rand() % (0x0800 - 0x0080)) + 0x0080;
+ break;
+ case 3:
+ code_point = (rand() % (0x10000 - 0x0800)) + 0x0800;
+ break;
+ }
+ CB_Cat_Char(string, code_point);
+ }
+
+ return string;
+}
+
+static void
+test_Equals(TestBatch *batch)
+{
+ Hash *hash = Hash_new(0);
+ Hash *other = Hash_new(0);
+ ZombieCharBuf *stuff = ZCB_WRAP_STR("stuff", 5);
+
+ TEST_TRUE(batch, Hash_Equals(hash, (Obj*)other),
+ "Empty hashes are equal");
+
+ Hash_Store_Str(hash, "foo", 3, INCREF(&EMPTY));
+ TEST_FALSE(batch, Hash_Equals(hash, (Obj*)other),
+ "Add one pair and Equals returns false");
+
+ Hash_Store_Str(other, "foo", 3, INCREF(&EMPTY));
+ TEST_TRUE(batch, Hash_Equals(hash, (Obj*)other),
+ "Add a matching pair and Equals returns true");
+
+ Hash_Store_Str(other, "foo", 3, INCREF(stuff));
+ TEST_FALSE(batch, Hash_Equals(hash, (Obj*)other),
+ "Non-matching value spoils Equals");
+
+ DECREF(hash);
+ DECREF(other);
+}
+
+static void
+test_Store_and_Fetch(TestBatch *batch)
+{
+ Hash *hash = Hash_new(100);
+ Hash *dupe = Hash_new(100);
+ const uint32_t starting_cap = Hash_Get_Capacity(hash);
+ VArray *expected = VA_new(100);
+ VArray *got = VA_new(100);
+ ZombieCharBuf *twenty = ZCB_WRAP_STR("20", 2);
+ ZombieCharBuf *forty = ZCB_WRAP_STR("40", 2);
+ ZombieCharBuf *foo = ZCB_WRAP_STR("foo", 3);
+ int32_t i;
+
+ for (i = 0; i < 100; i++) {
+ CharBuf *cb = CB_newf("%i32", i);
+ Hash_Store(hash, (Obj*)cb, (Obj*)cb);
+ Hash_Store(dupe, (Obj*)cb, INCREF(cb));
+ VA_Push(expected, INCREF(cb));
+ }
+ TEST_TRUE(batch, Hash_Equals(hash, (Obj*)dupe), "Equals");
+
+ TEST_INT_EQ(batch, Hash_Get_Capacity(hash), starting_cap,
+ "Initial capacity sufficient (no rebuilds)");
+
+ for (i = 0; i < 100; i++) {
+ Obj *key = VA_Fetch(expected, i);
+ Obj *elem = Hash_Fetch(hash, key);
+ VA_Push(got, (Obj*)INCREF(elem));
+ }
+
+ TEST_TRUE(batch, VA_Equals(got, (Obj*)expected),
+ "basic Store and Fetch");
+ TEST_INT_EQ(batch, Hash_Get_Size(hash), 100,
+ "size incremented properly by Hash_Store");
+
+ TEST_TRUE(batch, Hash_Fetch(hash, (Obj*)foo) == NULL,
+ "Fetch against non-existent key returns NULL");
+
+ Hash_Store(hash, (Obj*)forty, INCREF(foo));
+ TEST_TRUE(batch, ZCB_Equals(foo, Hash_Fetch(hash, (Obj*)forty)),
+ "Hash_Store replaces existing value");
+ TEST_FALSE(batch, Hash_Equals(hash, (Obj*)dupe),
+ "replacement value spoils equals");
+ TEST_INT_EQ(batch, Hash_Get_Size(hash), 100,
+ "size unaffected after value replaced");
+
+ TEST_TRUE(batch, Hash_Delete(hash, (Obj*)forty) == (Obj*)foo,
+ "Delete returns value");
+ DECREF(foo);
+ TEST_INT_EQ(batch, Hash_Get_Size(hash), 99,
+ "size decremented by successful Delete");
+ TEST_TRUE(batch, Hash_Delete(hash, (Obj*)forty) == NULL,
+ "Delete returns NULL when key not found");
+ TEST_INT_EQ(batch, Hash_Get_Size(hash), 99,
+ "size not decremented by unsuccessful Delete");
+ DECREF(Hash_Delete(dupe, (Obj*)forty));
+ TEST_TRUE(batch, VA_Equals(got, (Obj*)expected), "Equals after Delete");
+
+ Hash_Clear(hash);
+ TEST_TRUE(batch, Hash_Fetch(hash, (Obj*)twenty) == NULL, "Clear");
+ TEST_TRUE(batch, Hash_Get_Size(hash) == 0, "size is 0 after Clear");
+
+ DECREF(hash);
+ DECREF(dupe);
+ DECREF(got);
+ DECREF(expected);
+}
+
+static void
+test_Keys_Values_Iter(TestBatch *batch)
+{
+ uint32_t i;
+ Hash *hash = Hash_new(0); // trigger multiple rebuilds.
+ VArray *expected = VA_new(100);
+ VArray *keys;
+ VArray *values;
+
+ for (i = 0; i < 500; i++) {
+ CharBuf *cb = CB_newf("%u32", i);
+ Hash_Store(hash, (Obj*)cb, (Obj*)cb);
+ VA_Push(expected, INCREF(cb));
+ }
+
+ VA_Sort(expected, NULL, NULL);
+
+ keys = Hash_Keys(hash);
+ values = Hash_Values(hash);
+ VA_Sort(keys, NULL, NULL);
+ VA_Sort(values, NULL, NULL);
+ TEST_TRUE(batch, VA_Equals(keys, (Obj*)expected), "Keys");
+ TEST_TRUE(batch, VA_Equals(values, (Obj*)expected), "Values");
+ VA_Clear(keys);
+ VA_Clear(values);
+
+ {
+ Obj *key;
+ Obj *value;
+ Hash_Iterate(hash);
+ while (Hash_Next(hash, &key, &value)) {
+ VA_Push(keys, INCREF(key));
+ VA_Push(values, INCREF(value));
+ }
+ }
+
+ VA_Sort(keys, NULL, NULL);
+ VA_Sort(values, NULL, NULL);
+ TEST_TRUE(batch, VA_Equals(keys, (Obj*)expected), "Keys from Iter");
+ TEST_TRUE(batch, VA_Equals(values, (Obj*)expected), "Values from Iter");
+
+ {
+ ZombieCharBuf *forty = ZCB_WRAP_STR("40", 2);
+ ZombieCharBuf *nope = ZCB_WRAP_STR("nope", 4);
+ Obj *key = Hash_Find_Key(hash, (Obj*)forty, ZCB_Hash_Sum(forty));
+ TEST_TRUE(batch, Obj_Equals(key, (Obj*)forty), "Find_Key");
+ key = Hash_Find_Key(hash, (Obj*)nope, ZCB_Hash_Sum(nope)),
+ TEST_TRUE(batch, key == NULL,
+ "Find_Key returns NULL for non-existent key");
+ }
+
+ DECREF(hash);
+ DECREF(expected);
+ DECREF(keys);
+ DECREF(values);
+}
+
+static void
+test_Dump_and_Load(TestBatch *batch)
+{
+ Hash *hash = Hash_new(0);
+ Obj *dump;
+ Hash *loaded;
+
+ Hash_Store_Str(hash, "foo", 3,
+ (Obj*)CB_new_from_trusted_utf8("foo", 3));
+ dump = (Obj*)Hash_Dump(hash);
+ loaded = (Hash*)Obj_Load(dump, dump);
+ TEST_TRUE(batch, Hash_Equals(hash, (Obj*)loaded),
+ "Dump => Load round trip");
+ DECREF(dump);
+ DECREF(loaded);
+
+ /* TODO: Fix Hash_Load().
+
+ Hash_Store_Str(hash, "_class", 6,
+ (Obj*)CB_new_from_trusted_utf8("not_a_class", 11));
+ dump = (Obj*)Hash_Dump(hash);
+ loaded = (Hash*)Obj_Load(dump, dump);
+
+ TEST_TRUE(batch, Hash_Equals(hash, (Obj*)loaded),
+ "Load still works with _class if it's not a real class");
+ DECREF(dump);
+ DECREF(loaded);
+
+ */
+
+ DECREF(hash);
+}
+
+static void
+test_serialization(TestBatch *batch)
+{
+ Hash *wanted = Hash_new(0);
+ Hash *got;
+ uint32_t i;
+
+ for (i = 0; i < 10; i++) {
+ CharBuf *cb = S_random_string();
+ Integer32 *num = Int32_new(i);
+ Hash_Store(wanted, (Obj*)cb, (Obj*)num);
+ Hash_Store(wanted, (Obj*)num, (Obj*)cb);
+ }
+
+ got = (Hash*)TestUtils_freeze_thaw((Obj*)wanted);
+ TEST_TRUE(batch, got && Hash_Equals(wanted, (Obj*)got),
+ "Round trip through serialization.");
+
+ DECREF(got);
+ DECREF(wanted);
+}
+
+static void
+test_stress(TestBatch *batch)
+{
+ uint32_t i;
+ Hash *hash = Hash_new(0); // trigger multiple rebuilds.
+ VArray *expected = VA_new(1000);
+ VArray *keys;
+ VArray *values;
+
+ for (i = 0; i < 1000; i++) {
+ CharBuf *cb = S_random_string();
+ while (Hash_Fetch(hash, (Obj*)cb)) {
+ DECREF(cb);
+ cb = S_random_string();
+ }
+ Hash_Store(hash, (Obj*)cb, (Obj*)cb);
+ VA_Push(expected, INCREF(cb));
+ }
+
+ VA_Sort(expected, NULL, NULL);
+
+ // Overwrite for good measure.
+ for (i = 0; i < 1000; i++) {
+ CharBuf *cb = (CharBuf*)VA_Fetch(expected, i);
+ Hash_Store(hash, (Obj*)cb, INCREF(cb));
+ }
+
+ keys = Hash_Keys(hash);
+ values = Hash_Values(hash);
+ VA_Sort(keys, NULL, NULL);
+ VA_Sort(values, NULL, NULL);
+ TEST_TRUE(batch, VA_Equals(keys, (Obj*)expected), "stress Keys");
+ TEST_TRUE(batch, VA_Equals(values, (Obj*)expected), "stress Values");
+
+ DECREF(keys);
+ DECREF(values);
+ DECREF(expected);
+ DECREF(hash);
+}
+
+void
+TestHash_run_tests()
+{
+ TestBatch *batch = TestBatch_new(29);
+
+ srand((unsigned int)time((time_t*)NULL));
+
+ TestBatch_Plan(batch);
+ test_Equals(batch);
+ test_Store_and_Fetch(batch);
+ test_Keys_Values_Iter(batch);
+ test_Dump_and_Load(batch);
+ test_serialization(batch);
+ test_stress(batch);
+
+ DECREF(batch);
+}
+
+/* Copyright 2005-2010 Marvin Humphrey
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * under the same terms as Perl itself.
+ */
+
Propchange: incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestHash.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestHash.cfh
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestHash.cfh?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestHash.cfh (added)
+++ incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestHash.cfh Thu Oct 14 08:48:04 2010
@@ -0,0 +1,13 @@
+parcel KinoSearch cnick Kino;
+
+inert class KinoSearch::Test::Object::TestHash {
+ inert void
+ run_tests();
+}
+
+/* Copyright 2005-2010 Marvin Humphrey
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * under the same terms as Perl itself.
+ */
+
Added: incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestI32Array.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestI32Array.c?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestI32Array.c (added)
+++ incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestI32Array.c Thu Oct 14 08:48:04 2010
@@ -0,0 +1,61 @@
+#define C_KINO_TESTI32ARRAY
+#include "KinoSearch/Util/ToolSet.h"
+
+#include "KinoSearch/Test.h"
+#include "KinoSearch/Test/Object/TestI32Array.h"
+
+static int32_t source_ints[] = { -1, 0, I32_MIN, I32_MAX, 1 };
+static size_t num_ints = sizeof(source_ints) / sizeof(int32_t);
+
+static void
+test_all(TestBatch *batch)
+{
+ I32Array *i32_array = I32Arr_new(source_ints, num_ints);
+ int32_t *ints_copy = (int32_t*)malloc(num_ints * sizeof(int32_t));
+ I32Array *stolen = I32Arr_new_steal(ints_copy, num_ints);
+ size_t num_matched;
+
+ memcpy(ints_copy, source_ints, num_ints * sizeof(int32_t));
+
+ TEST_TRUE(batch, I32Arr_Get_Size(i32_array) == num_ints,
+ "Get_Size");
+ TEST_TRUE(batch, I32Arr_Get_Size(stolen) == num_ints,
+ "Get_Size for stolen");
+
+ for (num_matched = 0; num_matched < num_ints; num_matched++) {
+ if (source_ints[num_matched] != I32Arr_Get(i32_array, num_matched)) {
+ break;
+ }
+ }
+ TEST_INT_EQ(batch, num_matched, num_ints,
+ "Matched all source ints with Get()");
+
+ for (num_matched = 0; num_matched < num_ints; num_matched++) {
+ if (source_ints[num_matched] != I32Arr_Get(stolen, num_matched)) {
+ break;
+ }
+ }
+ TEST_INT_EQ(batch, num_matched, num_ints,
+ "Matched all source ints in stolen I32Array with Get()");
+
+ DECREF(i32_array);
+ DECREF(stolen);
+}
+
+void
+TestI32Arr_run_tests()
+{
+ TestBatch *batch = TestBatch_new(4);
+
+ TestBatch_Plan(batch);
+ test_all(batch);
+
+ DECREF(batch);
+}
+
+/* Copyright 2005-2010 Marvin Humphrey
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * under the same terms as Perl itself.
+ */
+
Propchange: incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestI32Array.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestI32Array.cfh
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestI32Array.cfh?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestI32Array.cfh (added)
+++ incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestI32Array.cfh Thu Oct 14 08:48:04 2010
@@ -0,0 +1,13 @@
+parcel KinoSearch cnick Kino;
+
+inert class KinoSearch::Test::Object::TestI32Array cnick TestI32Arr {
+ inert void
+ run_tests();
+}
+
+/* Copyright 2005-2010 Marvin Humphrey
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * under the same terms as Perl itself.
+ */
+
Added: incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestLockFreeRegistry.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestLockFreeRegistry.c?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestLockFreeRegistry.c (added)
+++ incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestLockFreeRegistry.c Thu Oct 14 08:48:04 2010
@@ -0,0 +1,71 @@
+#include <string.h>
+
+#include "KinoSearch/Util/ToolSet.h"
+
+#include "KinoSearch/Test.h"
+#include "KinoSearch/Test/TestUtils.h"
+#include "KinoSearch/Test/Object/TestLockFreeRegistry.h"
+#include "KinoSearch/Object/LockFreeRegistry.h"
+
+StupidHashCharBuf*
+StupidHashCharBuf_new(char *text)
+{
+ return (StupidHashCharBuf*)CB_new_from_utf8(text, strlen(text));
+}
+
+int32_t
+StupidHashCharBuf_hash_sum(StupidHashCharBuf *self)
+{
+ UNUSED_VAR(self);
+ return 1;
+}
+
+static void
+test_all(TestBatch *batch)
+{
+ LockFreeRegistry *registry = LFReg_new(10);
+ StupidHashCharBuf *foo = StupidHashCharBuf_new("foo");
+ StupidHashCharBuf *bar = StupidHashCharBuf_new("bar");
+ StupidHashCharBuf *baz = StupidHashCharBuf_new("baz");
+ StupidHashCharBuf *foo_dupe = StupidHashCharBuf_new("foo");
+
+ TEST_TRUE(batch, LFReg_Register(registry, (Obj*)foo, (Obj*)foo),
+ "Register() returns true on success");
+ TEST_FALSE(batch,
+ LFReg_Register(registry, (Obj*)foo_dupe, (Obj*)foo_dupe),
+ "Can't Register() keys that test equal");
+
+ TEST_TRUE(batch, LFReg_Register(registry, (Obj*)bar, (Obj*)bar),
+ "Register() key with the same Hash_Sum but that isn't Equal");
+
+ TEST_TRUE(batch, LFReg_Fetch(registry, (Obj*)foo_dupe) == (Obj*)foo,
+ "Fetch()");
+ TEST_TRUE(batch, LFReg_Fetch(registry, (Obj*)bar) == (Obj*)bar,
+ "Fetch() again");
+ TEST_TRUE(batch, LFReg_Fetch(registry, (Obj*)baz) == NULL,
+ "Fetch() non-existent key returns NULL");
+
+ DECREF(foo_dupe);
+ DECREF(baz);
+ DECREF(bar);
+ DECREF(foo);
+ DECREF(registry);
+}
+
+void
+TestLFReg_run_tests()
+{
+ TestBatch *batch = TestBatch_new(6);
+
+ TestBatch_Plan(batch);
+ test_all(batch);
+
+ DECREF(batch);
+}
+
+/* Copyright 2005-2010 Marvin Humphrey
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * under the same terms as Perl itself.
+ */
+
Propchange: incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestLockFreeRegistry.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestLockFreeRegistry.cfh
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestLockFreeRegistry.cfh?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestLockFreeRegistry.cfh (added)
+++ incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestLockFreeRegistry.cfh Thu Oct 14 08:48:04 2010
@@ -0,0 +1,24 @@
+parcel KinoSearch cnick Kino;
+
+inert class KinoSearch::Test::Object::TestLockFreeRegistry cnick TestLFReg {
+ inert void
+ run_tests();
+}
+
+/** Private test-only class for stressing LockFreeRegistry.
+ */
+class KinoSearch::Test::Object::StupidHashCharBuf inherits KinoSearch::Object::CharBuf {
+ inert incremented StupidHashCharBuf*
+ new(char *text);
+
+ /** Always returns 1, guaranteeing collisions. */
+ public int32_t
+ Hash_Sum(StupidHashCharBuf *self);
+}
+
+/* Copyright 2005-2010 Marvin Humphrey
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * under the same terms as Perl itself.
+ */
+
Added: incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestNum.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestNum.c?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestNum.c (added)
+++ incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestNum.c Thu Oct 14 08:48:04 2010
@@ -0,0 +1,266 @@
+#define C_KINO_TESTNUM
+#include "KinoSearch/Util/ToolSet.h"
+
+#include "KinoSearch/Test.h"
+#include "KinoSearch/Test/TestUtils.h"
+#include "KinoSearch/Test/Object/TestNum.h"
+
+static void
+test_To_String(TestBatch *batch)
+{
+ Float32 *f32 = Float32_new(1.33f);
+ Float64 *f64 = Float64_new(1.33);
+ Integer32 *i32 = Int32_new(I32_MAX);
+ Integer64 *i64 = Int64_new(I64_MAX);
+ CharBuf *f32_string = Float32_To_String(f32);
+ CharBuf *f64_string = Float64_To_String(f64);
+ CharBuf *i32_string = Int32_To_String(i32);
+ CharBuf *i64_string = Int64_To_String(i64);
+
+ TEST_TRUE(batch, CB_Starts_With_Str(f32_string, "1.3", 3),
+ "Float32_To_String");
+ TEST_TRUE(batch, CB_Starts_With_Str(f64_string, "1.3", 3),
+ "Float64_To_String");
+ TEST_TRUE(batch, CB_Equals_Str(i32_string, "2147483647", 10),
+ "Int32_To_String");
+ TEST_TRUE(batch, CB_Equals_Str(i64_string, "9223372036854775807", 19),
+ "Int64_To_String");
+
+ DECREF(i64_string);
+ DECREF(i32_string);
+ DECREF(f64_string);
+ DECREF(f32_string);
+ DECREF(i64);
+ DECREF(i32);
+ DECREF(f64);
+ DECREF(f32);
+}
+
+static void
+test_accessors(TestBatch *batch)
+{
+ Float32 *f32 = Float32_new(1.0);
+ Float64 *f64 = Float64_new(1.0);
+ Integer32 *i32 = Int32_new(1);
+ Integer64 *i64 = Int64_new(1);
+ float wanted32 = 1.33f;
+ double wanted64 = 1.33;
+ float got32;
+ double got64;
+
+ Float32_Set_Value(f32, 1.33f);
+ TEST_FLOAT_EQ(batch, Float32_Get_Value(f32), 1.33f,
+ "F32 Set_Value Get_Value");
+
+ Float64_Set_Value(f64, 1.33);
+ got64 = Float64_Get_Value(f64);
+ TEST_TRUE(batch, *(int64_t*)&got64 == *(int64_t*)&wanted64,
+ "F64 Set_Value Get_Value");
+
+ TEST_TRUE(batch, Float32_To_I64(f32) == 1, "Float32_To_I64");
+ TEST_TRUE(batch, Float64_To_I64(f64) == 1, "Float64_To_I64");
+
+ got32 = Float32_To_F64(f32);
+ TEST_TRUE(batch, *(int32_t*)&got32 == *(int32_t*)&wanted32,
+ "Float32_To_F64");
+
+ got64 = Float64_To_F64(f64);
+ TEST_TRUE(batch, *(int64_t*)&got64 == *(int64_t*)&wanted64,
+ "Float64_To_F64");
+
+ Int32_Set_Value(i32, I32_MIN);
+ TEST_INT_EQ(batch, Int32_Get_Value(i32), I32_MIN,
+ "I32 Set_Value Get_Value");
+
+ Int64_Set_Value(i64, I64_MIN);
+ TEST_TRUE(batch, Int64_Get_Value(i64) == I64_MIN,
+ "I64 Set_Value Get_Value");
+
+ Int32_Set_Value(i32, -1);
+ Int64_Set_Value(i64, -1);
+ TEST_TRUE(batch, Int32_To_F64(i32) == -1, "Int32_To_F64");
+ TEST_TRUE(batch, Int64_To_F64(i64) == -1, "Int64_To_F64");
+
+ DECREF(i64);
+ DECREF(i32);
+ DECREF(f64);
+ DECREF(f32);
+}
+
+static void
+test_Equals_and_Compare_To(TestBatch *batch)
+{
+ Float32 *f32 = Float32_new(1.0);
+ Float64 *f64 = Float64_new(1.0);
+ Integer32 *i32 = Int32_new(I32_MAX);
+ Integer64 *i64 = Int64_new(I64_MAX);
+
+ TEST_TRUE(batch, Float32_Compare_To(f32, (Obj*)f64) == 0,
+ "F32_Compare_To equal");
+ TEST_TRUE(batch, Float32_Equals(f32, (Obj*)f64),
+ "F32_Equals equal");
+
+ Float64_Set_Value(f64, 2.0);
+ TEST_TRUE(batch, Float32_Compare_To(f32, (Obj*)f64) < 0,
+ "F32_Compare_To less than");
+ TEST_FALSE(batch, Float32_Equals(f32, (Obj*)f64),
+ "F32_Equals less than");
+
+ Float64_Set_Value(f64, 0.0);
+ TEST_TRUE(batch, Float32_Compare_To(f32, (Obj*)f64) > 0,
+ "F32_Compare_To greater than");
+ TEST_FALSE(batch, Float32_Equals(f32, (Obj*)f64),
+ "F32_Equals greater than");
+
+ Float64_Set_Value(f64, 1.0);
+ Float32_Set_Value(f32, 1.0);
+ TEST_TRUE(batch, Float64_Compare_To(f64, (Obj*)f32) == 0,
+ "F64_Compare_To equal");
+ TEST_TRUE(batch, Float64_Equals(f64, (Obj*)f32),
+ "F64_Equals equal");
+
+ Float32_Set_Value(f32, 2.0);
+ TEST_TRUE(batch, Float64_Compare_To(f64, (Obj*)f32) < 0,
+ "F64_Compare_To less than");
+ TEST_FALSE(batch, Float64_Equals(f64, (Obj*)f32),
+ "F64_Equals less than");
+
+ Float32_Set_Value(f32, 0.0);
+ TEST_TRUE(batch, Float64_Compare_To(f64, (Obj*)f32) > 0,
+ "F64_Compare_To greater than");
+ TEST_FALSE(batch, Float64_Equals(f64, (Obj*)f32),
+ "F64_Equals greater than");
+
+ Float64_Set_Value(f64, I64_MAX * 2.0);
+ TEST_TRUE(batch, Float64_Compare_To(f64, (Obj*)i64) > 0,
+ "Float64 comparison to Integer64");
+ TEST_TRUE(batch, Int64_Compare_To(i64, (Obj*)f64) < 0,
+ "Integer64 comparison to Float64");
+
+ Float32_Set_Value(f32, I32_MAX * 2.0f);
+ TEST_TRUE(batch, Float32_Compare_To(f32, (Obj*)i32) > 0,
+ "Float32 comparison to Integer32");
+ TEST_TRUE(batch, Int32_Compare_To(i32, (Obj*)f32) < 0,
+ "Integer32 comparison to Float32");
+
+ DECREF(i64);
+ DECREF(i32);
+ DECREF(f64);
+ DECREF(f32);
+}
+
+static void
+test_Clone(TestBatch *batch)
+{
+ Float32 *f32 = Float32_new(1.33f);
+ Float64 *f64 = Float64_new(1.33);
+ Integer32 *i32 = Int32_new(I32_MAX);
+ Integer64 *i64 = Int64_new(I64_MAX);
+ Float32 *f32_dupe = Float32_Clone(f32);
+ Float64 *f64_dupe = Float64_Clone(f64);
+ Integer32 *i32_dupe = Int32_Clone(i32);
+ Integer64 *i64_dupe = Int64_Clone(i64);
+ TEST_TRUE(batch, Float32_Equals(f32, (Obj*)f32_dupe),
+ "Float32 Clone");
+ TEST_TRUE(batch, Float64_Equals(f64, (Obj*)f64_dupe),
+ "Float64 Clone");
+ TEST_TRUE(batch, Int32_Equals(i32, (Obj*)i32_dupe),
+ "Integer32 Clone");
+ TEST_TRUE(batch, Int64_Equals(i64, (Obj*)i64_dupe),
+ "Integer64 Clone");
+ DECREF(i64_dupe);
+ DECREF(i32_dupe);
+ DECREF(f64_dupe);
+ DECREF(f32_dupe);
+ DECREF(i64);
+ DECREF(i32);
+ DECREF(f64);
+ DECREF(f32);
+}
+
+static void
+test_Mimic(TestBatch *batch)
+{
+ Float32 *f32 = Float32_new(1.33f);
+ Float64 *f64 = Float64_new(1.33);
+ Integer32 *i32 = Int32_new(I32_MAX);
+ Integer64 *i64 = Int64_new(I64_MAX);
+ Float32 *f32_dupe = Float32_new(0.0f);
+ Float64 *f64_dupe = Float64_new(0.0);
+ Integer32 *i32_dupe = Int32_new(0);
+ Integer64 *i64_dupe = Int64_new(0);
+ Float32_Mimic(f32_dupe, (Obj*)f32);
+ Float64_Mimic(f64_dupe, (Obj*)f64);
+ Int32_Mimic(i32_dupe, (Obj*)i32);
+ Int64_Mimic(i64_dupe, (Obj*)i64);
+ TEST_TRUE(batch, Float32_Equals(f32, (Obj*)f32_dupe),
+ "Float32 Mimic");
+ TEST_TRUE(batch, Float64_Equals(f64, (Obj*)f64_dupe),
+ "Float64 Mimic");
+ TEST_TRUE(batch, Int32_Equals(i32, (Obj*)i32_dupe),
+ "Integer32 Mimic");
+ TEST_TRUE(batch, Int64_Equals(i64, (Obj*)i64_dupe),
+ "Integer64 Mimic");
+ DECREF(i64_dupe);
+ DECREF(i32_dupe);
+ DECREF(f64_dupe);
+ DECREF(f32_dupe);
+ DECREF(i64);
+ DECREF(i32);
+ DECREF(f64);
+ DECREF(f32);
+}
+
+static void
+test_serialization(TestBatch *batch)
+{
+ Float32 *f32 = Float32_new(1.33f);
+ Float64 *f64 = Float64_new(1.33);
+ Integer32 *i32 = Int32_new(-1);
+ Integer64 *i64 = Int64_new(-1);
+ Float32 *f32_thaw = (Float32*)TestUtils_freeze_thaw((Obj*)f32);
+ Float64 *f64_thaw = (Float64*)TestUtils_freeze_thaw((Obj*)f64);
+ Integer32 *i32_thaw = (Integer32*)TestUtils_freeze_thaw((Obj*)i32);
+ Integer64 *i64_thaw = (Integer64*)TestUtils_freeze_thaw((Obj*)i64);
+
+ TEST_TRUE(batch, Float32_Equals(f32, (Obj*)f32_thaw),
+ "Float32 freeze/thaw");
+ TEST_TRUE(batch, Float64_Equals(f64, (Obj*)f64_thaw),
+ "Float64 freeze/thaw");
+ TEST_TRUE(batch, Int32_Equals(i32, (Obj*)i32_thaw),
+ "Integer32 freeze/thaw");
+ TEST_TRUE(batch, Int64_Equals(i64, (Obj*)i64_thaw),
+ "Integer64 freeze/thaw");
+
+ DECREF(i64_thaw);
+ DECREF(i32_thaw);
+ DECREF(f64_thaw);
+ DECREF(f32_thaw);
+ DECREF(i64);
+ DECREF(i32);
+ DECREF(f64);
+ DECREF(f32);
+}
+
+void
+TestNum_run_tests()
+{
+ TestBatch *batch = TestBatch_new(42);
+ TestBatch_Plan(batch);
+
+ test_To_String(batch);
+ test_accessors(batch);
+ test_Equals_and_Compare_To(batch);
+ test_Clone(batch);
+ test_Mimic(batch);
+ test_serialization(batch);
+
+ DECREF(batch);
+}
+
+/* Copyright 2005-2010 Marvin Humphrey
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * under the same terms as Perl itself.
+ */
+
Propchange: incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestNum.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestNum.cfh
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestNum.cfh?rev=1022422&view=auto
==============================================================================
--- incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestNum.cfh (added)
+++ incubator/lucy/trunk/import/core/KinoSearch/Test/Object/TestNum.cfh Thu Oct 14 08:48:04 2010
@@ -0,0 +1,13 @@
+parcel KinoSearch cnick Kino;
+
+inert class KinoSearch::Test::Object::TestNum {
+ inert void
+ run_tests();
+}
+
+/* Copyright 2005-2010 Marvin Humphrey
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * under the same terms as Perl itself.
+ */
+