You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by nw...@apache.org on 2015/08/06 18:22:21 UTC

[5/5] lucy git commit: Port Lucy::Simple tests to C

Port Lucy::Simple tests to C


Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/7c09f4df
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/7c09f4df
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/7c09f4df

Branch: refs/heads/master
Commit: 7c09f4df572acc3949f9a8c409a00fa3876467aa
Parents: ebde55f
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Sat Aug 1 18:12:34 2015 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Wed Aug 5 15:26:15 2015 +0200

----------------------------------------------------------------------
 core/Lucy/Test.c              |   2 +
 core/Lucy/Test/TestSimple.c   | 112 +++++++++++++++++++++++++++++++++++++
 core/Lucy/Test/TestSimple.cfh |  29 ++++++++++
 perl/t/core/308-simple.t      |  23 ++++++++
 4 files changed, 166 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/7c09f4df/core/Lucy/Test.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Test.c b/core/Lucy/Test.c
index 3046494..0edda50 100644
--- a/core/Lucy/Test.c
+++ b/core/Lucy/Test.c
@@ -77,6 +77,7 @@
 #include "Lucy/Test/Store/TestRAMFileHandle.h"
 #include "Lucy/Test/Store/TestRAMFolder.h"
 #include "Lucy/Test/TestSchema.h"
+#include "Lucy/Test/TestSimple.h"
 #include "Lucy/Test/Util/TestFreezer.h"
 #include "Lucy/Test/Util/TestIndexFileNames.h"
 #include "Lucy/Test/Util/TestJson.h"
@@ -136,6 +137,7 @@ Test_create_test_suite() {
     TestSuite_Add_Batch(suite, (TestBatch*)TestFType_new());
     TestSuite_Add_Batch(suite, (TestBatch*)TestSeg_new());
     TestSuite_Add_Batch(suite, (TestBatch*)TestHighlighter_new());
+    TestSuite_Add_Batch(suite, (TestBatch*)TestSimple_new());
     TestSuite_Add_Batch(suite, (TestBatch*)TestSpan_new());
     TestSuite_Add_Batch(suite, (TestBatch*)TestHeatMap_new());
     TestSuite_Add_Batch(suite, (TestBatch*)TestTermQuery_new());

http://git-wip-us.apache.org/repos/asf/lucy/blob/7c09f4df/core/Lucy/Test/TestSimple.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Test/TestSimple.c b/core/Lucy/Test/TestSimple.c
new file mode 100644
index 0000000..6e8adfd
--- /dev/null
+++ b/core/Lucy/Test/TestSimple.c
@@ -0,0 +1,112 @@
+/* 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.
+ */
+
+#define C_TESTLUCY_TESTSIMPLE
+#define TESTLUCY_USE_SHORT_NAMES
+#include "Lucy/Util/ToolSet.h"
+
+#include "Lucy/Test/TestSimple.h"
+#include "Lucy/Simple.h"
+
+#include "Clownfish/TestHarness/TestBatchRunner.h"
+#include "Lucy/Document/Doc.h"
+#include "Lucy/Document/HitDoc.h"
+#include "Lucy/Store/RAMFolder.h"
+
+TestSimple*
+TestSimple_new() {
+    return (TestSimple*)Class_Make_Obj(TESTSIMPLE);
+}
+
+static void
+test_simple(TestBatchRunner *runner) {
+    RAMFolder *folder   = RAMFolder_new(NULL);
+    String    *language = SSTR_WRAP_UTF8("en", 2);
+    Simple    *lucy     = Simple_new((Obj*)folder, language);
+
+    String *food_field = SSTR_WRAP_UTF8("food", 4);
+
+    {
+        Doc *doc = Doc_new(NULL, 0);
+        String *value = SSTR_WRAP_UTF8("creamed corn", 12);
+        Doc_Store(doc, food_field, (Obj*)value);
+        Simple_Add_Doc(lucy, doc);
+        DECREF(doc);
+
+        String *query = SSTR_WRAP_UTF8("creamed", 7);
+        uint32_t num_results = Simple_Search(lucy, query, 0, 10);
+        TEST_INT_EQ(runner, num_results, 1, "Search works right after add");
+    }
+
+    {
+        Doc *doc = Doc_new(NULL, 0);
+        String *value = SSTR_WRAP_UTF8("creamed spinach", 15);
+        Doc_Store(doc, food_field, (Obj*)value);
+        Simple_Add_Doc(lucy, doc);
+        DECREF(doc);
+
+        String *query = SSTR_WRAP_UTF8("creamed", 7);
+        uint32_t num_results = Simple_Search(lucy, query, 0, 10);
+        TEST_INT_EQ(runner, num_results, 2, "Search returns total hits");
+    }
+
+    {
+        Doc *doc = Doc_new(NULL, 0);
+        String *value = SSTR_WRAP_UTF8("creamed broccoli", 16);
+        Doc_Store(doc, food_field, (Obj*)value);
+        Simple_Add_Doc(lucy, doc);
+        DECREF(doc);
+
+        DECREF(lucy);
+        lucy = Simple_new((Obj*)folder, language);
+
+        String *query = SSTR_WRAP_UTF8("cream", 5);
+        uint32_t num_results = Simple_Search(lucy, query, 0, 10);
+        TEST_INT_EQ(runner, num_results, 3, "commit upon destroy");
+
+        HitDoc *hit;
+        while ((hit = Simple_Next(lucy)) != NULL) {
+            String *food = (String*)HitDoc_Extract(hit, food_field);
+            TEST_TRUE(runner, Str_Starts_With_Utf8(food, "cream", 5), "Next");
+            DECREF(food);
+            DECREF(hit);
+        }
+    }
+
+    {
+        Doc *doc = Doc_new(NULL, 0);
+        String *band_field = SSTR_WRAP_UTF8("band", 4);
+        String *value = SSTR_WRAP_UTF8("Cream", 5);
+        Doc_Store(doc, band_field, (Obj*)value);
+        Simple_Add_Doc(lucy, doc);
+        DECREF(doc);
+
+        String *query = SSTR_WRAP_UTF8("cream", 5);
+        uint32_t num_results = Simple_Search(lucy, query, 0, 10);
+        TEST_INT_EQ(runner, num_results, 4,
+                    "Search uses correct EasyAnalyzer");
+    }
+
+    DECREF(lucy);
+    DECREF(folder);
+}
+
+void
+TestSimple_Run_IMP(TestSimple *self, TestBatchRunner *runner) {
+    TestBatchRunner_Plan(runner, (TestBatch*)self, 7);
+    test_simple(runner);
+}
+

http://git-wip-us.apache.org/repos/asf/lucy/blob/7c09f4df/core/Lucy/Test/TestSimple.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Test/TestSimple.cfh b/core/Lucy/Test/TestSimple.cfh
new file mode 100644
index 0000000..045fe8c
--- /dev/null
+++ b/core/Lucy/Test/TestSimple.cfh
@@ -0,0 +1,29 @@
+/* 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.
+ */
+
+parcel TestLucy;
+
+class Lucy::Test::TestSimple
+    inherits Clownfish::TestHarness::TestBatch {
+
+    inert incremented TestSimple*
+    new();
+
+    void
+    Run(TestSimple *self, TestBatchRunner *runner);
+}
+
+

http://git-wip-us.apache.org/repos/asf/lucy/blob/7c09f4df/perl/t/core/308-simple.t
----------------------------------------------------------------------
diff --git a/perl/t/core/308-simple.t b/perl/t/core/308-simple.t
new file mode 100644
index 0000000..5a558a1
--- /dev/null
+++ b/perl/t/core/308-simple.t
@@ -0,0 +1,23 @@
+# 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.
+
+use strict;
+use warnings;
+
+use Lucy::Test;
+my $success = Lucy::Test::run_tests("Lucy::Test::TestSimple");
+
+exit($success ? 0 : 1);
+