Propchange: incubator/lucene4c/trunk/test/data/index/_c7.tii
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: incubator/lucene4c/trunk/test/data/index/_c7.tis
URL:
http://svn.apache.org/viewcvs/incubator/lucene4c/trunk/test/data/index/_c7.tis?view=auto&rev=155552
==============================================================================
Binary file - no diff available.
Propchange: incubator/lucene4c/trunk/test/data/index/_c7.tis
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: incubator/lucene4c/trunk/test/data/index/deletable
URL:
http://svn.apache.org/viewcvs/incubator/lucene4c/trunk/test/data/index/deletable?view=auto&rev=155552
==============================================================================
Binary file - no diff available.
Propchange: incubator/lucene4c/trunk/test/data/index/deletable
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: incubator/lucene4c/trunk/test/data/index/segments
URL:
http://svn.apache.org/viewcvs/incubator/lucene4c/trunk/test/data/index/segments?view=auto&rev=155552
==============================================================================
Binary file - no diff available.
Propchange: incubator/lucene4c/trunk/test/data/index/segments
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Propchange: incubator/lucene4c/trunk/test/index/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sat Feb 26 08:47:57 2005
@@ -0,0 +1,2 @@
+.deps
+.dirstamp
Added: incubator/lucene4c/trunk/test/index/fielddata_test.c
URL:
http://svn.apache.org/viewcvs/incubator/lucene4c/trunk/test/index/fielddata_test.c?view=auto&rev=155552
==============================================================================
--- incubator/lucene4c/trunk/test/index/fielddata_test.c (added)
+++ incubator/lucene4c/trunk/test/index/fielddata_test.c Sat Feb 26 08:47:57
2005
@@ -0,0 +1,82 @@
+/* Copyright 2004-2005 Garrett Rooney
+ *
+ * Licensed 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.
+ */
+
+#include "lcn_fielddata.h"
+
+#include "lcn_tests.h"
+
+#include "abts.h"
+
+static const lcn_char_t path[] = { 'p', 'a', 't', 'h', 0 };
+
+static const lcn_char_t modified[] = { 'm',
+ 'o',
+ 'd',
+ 'i',
+ 'f',
+ 'i',
+ 'e',
+ 'd',
+ 0 };
+
+static void
+test_fielddata_get_doc (abts_case *tc, void *data)
+{
+ lcn_char_t segment[] = { '_', 'c', '7', 0 };
+ apr_array_header_t *doc = NULL;
+ lcn_fielddata_t *fd = NULL;
+ lcn_directory_t *d;
+ lcn_error_t *err;
+
+ CHK_ERR (lcn_fs_directory_open (&d, "test/data/index", p));
+
+ CHK_ERR (lcn_fielddata_open (&fd, d, segment, p));
+
+ ABTS_PTR_NOTNULL (tc, fd);
+
+ err = lcn_fielddata_get_doc (&doc, fd, 1, p);
+
+ ABTS_PTR_NOTNULL (tc, doc);
+
+ if (doc == NULL) { return; }
+
+ ABTS_INT_EQUAL (tc, 2, doc->nelts);
+
+ ABTS_INT_EQUAL (tc,
+ 0,
+ lcn_strcmp (path,
+ lcn_field_name (APR_ARRAY_IDX (doc,
+ 0,
+ lcn_field_t *))));
+
+ ABTS_INT_EQUAL (tc,
+ 0,
+ lcn_strcmp (modified,
+ lcn_field_name (APR_ARRAY_IDX (doc,
+ 1,
+ lcn_field_t *))));
+
+ apr_pool_clear (p);
+}
+
+abts_suite *
+test_fielddata (abts_suite *suite)
+{
+ suite = ADD_SUITE (suite);
+
+ abts_run_test (suite, test_fielddata_get_doc, NULL);
+
+ return suite;
+}
Added: incubator/lucene4c/trunk/test/index/fieldinfos_test.c
URL:
http://svn.apache.org/viewcvs/incubator/lucene4c/trunk/test/index/fieldinfos_test.c?view=auto&rev=155552
==============================================================================
--- incubator/lucene4c/trunk/test/index/fieldinfos_test.c (added)
+++ incubator/lucene4c/trunk/test/index/fieldinfos_test.c Sat Feb 26 08:47:57
2005
@@ -0,0 +1,106 @@
+/* Copyright 2004-2005 Garrett Rooney
+ *
+ * Licensed 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.
+ */
+
+#include "lcn_index.h"
+#include "lcn_fieldinfos.h"
+
+#include "lcn_tests.h"
+
+#include "abts.h"
+
+static void
+test_fieldinfos_read (abts_case *tc, void *data)
+{
+ lcn_char_t segment[] = { '_', 'c', '7', 0 };
+ lcn_fieldinfos_t *fis;
+ lcn_fieldinfo_t *fi;
+ lcn_directory_t *d;
+
+ CHK_ERR (lcn_fs_directory_open (&d, "test/data/index", p));
+
+ CHK_ERR (lcn_fieldinfos_read (&fis, d, segment, p));
+
+ ABTS_INT_EQUAL (tc, 4, lcn_fieldinfos_get_count (fis));
+
+ fi = lcn_fieldinfos_get_by_number (fis, 0);
+
+ ABTS_INT_EQUAL (tc, 0, fi->name[0]);
+ ABTS_INT_EQUAL (tc, 0, fi->number);
+ ABTS_TRUE (tc, fi->is_indexed == FALSE);
+ ABTS_TRUE (tc, fi->store_term_vector == FALSE);
+
+ ABTS_PTR_EQUAL (tc, fi, lcn_fieldinfos_get_by_name (fis, fi->name));
+
+ fi = lcn_fieldinfos_get_by_number (fis, 1);
+
+ {
+ lcn_char_t contentsname[] = { 'c', 'o', 'n', 't', 'e', 'n', 't', 's', 0 };
+ ABTS_INT_EQUAL (tc,
+ 0,
+ memcmp (contentsname,
+ fi->name,
+ LCN_STRING_SIZE (fi->name)));
+ }
+
+ ABTS_INT_EQUAL (tc, 1, fi->number);
+ ABTS_TRUE (tc, fi->is_indexed == TRUE);
+ ABTS_TRUE (tc, fi->store_term_vector == FALSE);
+
+ ABTS_PTR_EQUAL (tc, fi, lcn_fieldinfos_get_by_name (fis, fi->name));
+
+ fi = lcn_fieldinfos_get_by_number (fis, 2);
+
+ {
+ lcn_char_t modifiedname[] = { 'm', 'o', 'd', 'i', 'f', 'i', 'e', 'd', 0 };
+ ABTS_INT_EQUAL (tc,
+ 0,
+ memcmp (modifiedname,
+ fi->name,
+ LCN_STRING_SIZE (fi->name)));
+ }
+
+ ABTS_INT_EQUAL (tc, 2, fi->number);
+ ABTS_TRUE (tc, fi->is_indexed == TRUE);
+ ABTS_TRUE (tc, fi->store_term_vector == FALSE);
+
+ ABTS_PTR_EQUAL (tc, fi, lcn_fieldinfos_get_by_name (fis, fi->name));
+
+ fi = lcn_fieldinfos_get_by_number (fis, 3);
+
+ {
+ lcn_char_t pathname[] = { 'p', 'a', 't', 'h', 0 };
+ ABTS_INT_EQUAL (tc,
+ 0,
+ memcmp (pathname,
+ fi->name,
+ LCN_STRING_SIZE (fi->name)));
+ }
+
+ ABTS_INT_EQUAL (tc, 3, fi->number);
+ ABTS_TRUE (tc, fi->is_indexed == TRUE);
+ ABTS_TRUE (tc, fi->store_term_vector == FALSE);
+
+ ABTS_PTR_EQUAL (tc, fi, lcn_fieldinfos_get_by_name (fis, fi->name));
+}
+
+abts_suite *
+test_fieldinfos (abts_suite *suite)
+{
+ suite = ADD_SUITE (suite);
+
+ abts_run_test (suite, test_fieldinfos_read, NULL);
+
+ return suite;
+}
Added: incubator/lucene4c/trunk/test/index/frequencies_test.c
URL:
http://svn.apache.org/viewcvs/incubator/lucene4c/trunk/test/index/frequencies_test.c?view=auto&rev=155552
==============================================================================
--- incubator/lucene4c/trunk/test/index/frequencies_test.c (added)
+++ incubator/lucene4c/trunk/test/index/frequencies_test.c Sat Feb 26 08:47:57
2005
@@ -0,0 +1,113 @@
+/* Copyright 2004-2005 Garrett Rooney
+ *
+ * Licensed 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.
+ */
+
+#include "lcn_frequencies.h"
+
+#include "lcn_tests.h"
+
+#include "abts.h"
+
+static const lcn_char_t termname[] = { 'a', 's', 's', 'u', 'm', 'e', 's', 0 };
+
+static const lcn_char_t termname2[] = { 'l', 'u', 'c', 'e', 'n', 'e', 0 };
+
+static const lcn_char_t fieldname[] = { 'c',
+ 'o',
+ 'n',
+ 't',
+ 'e',
+ 'n',
+ 't',
+ 's',
+ 0 };
+
+static lcn_term_t term = { (lcn_char_t *) termname,
+ (lcn_char_t *) fieldname };
+
+static lcn_term_t term2 = { (lcn_char_t *) termname2,
+ (lcn_char_t *) fieldname };
+
+static void
+test_frequencies_get_terminfo_data (abts_case *tc, void *data)
+{
+ lcn_frequencies_t *frq;
+ apr_pool_t *subpool;
+ lcn_directory_t *d;
+ lcn_error_t *err;
+
+ lcn_char_t segment[] = { '_', 'c', '7', 0 };
+
+ CHK_ERR (lcn_fs_directory_open (&d, "test/data/index", p));
+
+ err = lcn_frequencies_open (&frq, d, segment, p);
+
+ ABTS_PTR_EQUAL (tc, LCN_NO_ERROR, err);
+
+ if (err) { return; }
+
+ subpool = lcn_pool_create (p);
+
+ {
+ apr_uint32_t *docs, *freqs;
+ lcn_terminfos_t *tis;
+ lcn_terminfo_t *ti;
+
+ CHK_ERR (lcn_terminfos_open (&tis, d, segment, subpool));
+
+ CHK_ERR (lcn_terminfos_get_terminfo (&ti, tis, &term, subpool));
+
+ err = lcn_frequencies_get_terminfo_data (&docs, &freqs, frq, ti, subpool);
+
+ ABTS_PTR_EQUAL (tc, LCN_NO_ERROR, err);
+
+ if (err) { return; }
+
+ ABTS_INT_EQUAL (tc, 118, docs[0]);
+ }
+
+ apr_pool_clear (subpool);
+
+ {
+ apr_uint32_t *docs, *freqs;
+ lcn_terminfos_t *tis;
+ lcn_terminfo_t *ti;
+
+ CHK_ERR (lcn_terminfos_open (&tis, d, segment, subpool));
+
+ CHK_ERR (lcn_terminfos_get_terminfo (&ti, tis, &term2, subpool));
+
+ err = lcn_frequencies_get_terminfo_data (&docs, &freqs, frq, ti, subpool);
+
+ ABTS_PTR_EQUAL (tc, LCN_NO_ERROR, err);
+
+ if (err) { return; }
+
+ ABTS_INT_EQUAL (tc, 1, docs[0]);
+
+ ABTS_INT_EQUAL (tc, 4, docs[1]);
+ }
+
+ lcn_pool_destroy (subpool);
+}
+
+abts_suite *
+test_frequencies (abts_suite *suite)
+{
+ suite = ADD_SUITE (suite);
+
+ abts_run_test (suite, test_frequencies_get_terminfo_data, NULL);
+
+ return suite;
+}
Added: incubator/lucene4c/trunk/test/index/index_test.c
URL:
http://svn.apache.org/viewcvs/incubator/lucene4c/trunk/test/index/index_test.c?view=auto&rev=155552
==============================================================================
--- incubator/lucene4c/trunk/test/index/index_test.c (added)
+++ incubator/lucene4c/trunk/test/index/index_test.c Sat Feb 26 08:47:57 2005
@@ -0,0 +1,166 @@
+/* Copyright 2004-2005 Garrett Rooney
+ *
+ * Licensed 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.
+ */
+
+#include "lcn_index.h"
+
+#include "lcn_tests.h"
+
+#include "abts.h"
+
+static void
+test_index_open (abts_case *tc, void *data)
+{
+ lcn_index_t *idx;
+
+ CHK_ERR (lcn_index_open (&idx, "test/data/index", p));
+
+ apr_pool_clear (p);
+}
+
+static void
+test_index_max_docs (abts_case *tc, void *data)
+{
+ lcn_index_t *idx;
+ apr_uint32_t md;
+
+ CHK_ERR (lcn_index_open (&idx, "test/data/index", p));
+
+ md = lcn_index_max_docs (idx, p);
+
+ ABTS_INT_EQUAL (tc, 395, md);
+
+ CHK_ERR (lcn_index_open (&idx, "test/data/index-cfs", p));
+
+ md = lcn_index_max_docs (idx, p);
+
+ ABTS_INT_EQUAL (tc, 1969, md);
+
+ apr_pool_clear (p);
+}
+
+static void
+test_index_term_docs (abts_case *tc, void *data)
+{
+ lcn_term_t *term = lcn_term_create_cstring ("lucene", "contents", p);
+ lcn_doc_iter_t *itr;
+ lcn_index_t *idx;
+ lcn_error_t *err;
+ int count = 0;
+
+ CHK_ERR (lcn_index_open (&idx, "test/data/index", p));
+
+ CHK_ERR (lcn_index_term_docs (&itr, idx, term, p));
+
+ ABTS_INT_EQUAL (tc, 1, lcn_doc_iter_doc (itr));
+
+ while ((err = lcn_doc_iter_next (itr)) == LCN_NO_ERROR)
+ {
+ if (++count == 1)
+ {
+ ABTS_INT_EQUAL (tc, 4, lcn_doc_iter_doc (itr));
+ }
+ }
+
+ ABTS_INT_EQUAL (tc, APR_EOF, err->apr_err);
+
+ ABTS_INT_EQUAL (tc, 75, count);
+
+ apr_pool_clear (p);
+}
+
+static void
+test_index_term_docs_cfs (abts_case *tc, void *data)
+{
+ lcn_term_t *term = lcn_term_create_cstring ("lucene", "contents", p);
+ lcn_doc_iter_t *itr;
+ lcn_index_t *idx;
+ lcn_error_t *err;
+ int count = 0;
+
+ CHK_ERR (lcn_index_open (&idx, "test/data/index-cfs", p));
+
+ CHK_ERR (lcn_index_term_docs (&itr, idx, term, p));
+
+ ABTS_INT_EQUAL (tc, 0, lcn_doc_iter_doc (itr));
+
+ while ((err = lcn_doc_iter_next (itr)) == LCN_NO_ERROR)
+ {
+ if (++count == 1)
+ {
+ ABTS_INT_EQUAL (tc, 5, lcn_doc_iter_doc (itr));
+ }
+ }
+
+ ABTS_INT_EQUAL (tc, APR_EOF, err->apr_err);
+
+ ABTS_INT_EQUAL (tc, 487, count);
+
+ apr_pool_clear (p);
+}
+
+static const char *path
+ = "/Users/rooneg/Hacking/lucene4c/jakarta-lucene/src/demo/CVS/Repository";
+
+static void
+test_index_get_document (abts_case *tc, void *data)
+{
+ const lcn_char_t bogusfieldname[] = { 'a', 's', 'd', 'f', 0 };
+ const lcn_char_t fieldnamepath[] = { 'p', 'a', 't', 'h', 0 };
+ const lcn_field_t *f;
+ lcn_document_t *doc;
+ lcn_index_t *idx;
+
+ CHK_ERR (lcn_index_open (&idx, "test/data/index", p));
+
+ CHK_ERR (lcn_index_get_document (&doc, idx, 4, p));
+
+ f = lcn_document_field_by_num (doc, 0);
+
+ ABTS_PTR_NOTNULL (tc, f);
+
+ ABTS_TRUE (tc, lcn_strcmp (lcn_field_content (f),
+ lcn_str_from_cstring (path, p)) == 0);
+
+ f = lcn_document_field_by_name (doc, fieldnamepath);
+
+ ABTS_PTR_NOTNULL (tc, f);
+
+ ABTS_TRUE (tc, lcn_strcmp (lcn_field_content (f),
+ lcn_str_from_cstring (path, p)) == 0);
+
+ f = lcn_document_field_by_num (doc, 2);
+
+ ABTS_PTR_EQUAL (tc, f, NULL);
+
+ f = lcn_document_field_by_name (doc, bogusfieldname);
+
+ ABTS_PTR_EQUAL (tc, f, NULL);
+
+ apr_pool_clear (p);
+}
+
+abts_suite *
+test_index (abts_suite *suite)
+{
+ suite = ADD_SUITE (suite);
+
+ abts_run_test (suite, test_index_open, NULL);
+ abts_run_test (suite, test_index_max_docs, NULL);
+ abts_run_test (suite, test_index_term_docs, NULL);
+ abts_run_test (suite, test_index_term_docs_cfs, NULL);
+ abts_run_test (suite, test_index_get_document, NULL);
+
+ return suite;
+}
Added: incubator/lucene4c/trunk/test/index/segment_test.c
URL:
http://svn.apache.org/viewcvs/incubator/lucene4c/trunk/test/index/segment_test.c?view=auto&rev=155552
==============================================================================
--- incubator/lucene4c/trunk/test/index/segment_test.c (added)
+++ incubator/lucene4c/trunk/test/index/segment_test.c Sat Feb 26 08:47:57 2005
@@ -0,0 +1,59 @@
+/* Copyright 2004-2005 Garrett Rooney
+ *
+ * Licensed 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.
+ */
+
+#include "lcn_segment.h"
+
+#include "lcn_tests.h"
+
+#include "abts.h"
+
+static void
+test_segment_term_docs (abts_case *tc, void *which)
+{
+ lcn_char_t segname[] = { '_', 'c', '7', 0 };
+ apr_uint32_t doc_freq, *docs, *freqs;
+ lcn_directory_t *dir;
+ lcn_segment_t *seg;
+
+ CHK_ERR (lcn_fs_directory_open (&dir, "test/data/index", p));
+
+ CHK_ERR (lcn_segment_open (&seg, segname, 395, dir, p));
+
+ CHK_ERR (lcn_segment_term_docs (&doc_freq,
+ &docs,
+ &freqs,
+ seg,
+ lcn_term_create_cstring ("lucene",
+ "contents",
+ p),
+ p));
+
+ ABTS_INT_EQUAL (tc, 76, doc_freq);
+
+ ABTS_INT_EQUAL (tc, 1, docs[0]);
+ ABTS_INT_EQUAL (tc, 4, docs[1]);
+
+ apr_pool_clear (p);
+}
+
+abts_suite *
+test_segment (abts_suite *suite)
+{
+ suite = ADD_SUITE (suite);
+
+ abts_run_test (suite, test_segment_term_docs, NULL);
+
+ return suite;
+}
Added: incubator/lucene4c/trunk/test/index/segments_test.c
URL:
http://svn.apache.org/viewcvs/incubator/lucene4c/trunk/test/index/segments_test.c?view=auto&rev=155552
==============================================================================
--- incubator/lucene4c/trunk/test/index/segments_test.c (added)
+++ incubator/lucene4c/trunk/test/index/segments_test.c Sat Feb 26 08:47:57 2005
@@ -0,0 +1,95 @@
+/* Copyright 2004-2005 Garrett Rooney
+ *
+ * Licensed 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.
+ */
+
+#include "lcn_segments.h"
+
+#include "lcn_tests.h"
+
+#include "abts.h"
+
+static void
+test_segments_read (abts_case *tc, void *which)
+{
+ lcn_segments_t *segments;
+ lcn_directory_t *d;
+
+ CHK_ERR (lcn_fs_directory_open (&d, "test/data/index", p));
+
+ CHK_ERR (lcn_segments_read (&segments, d, p));
+
+ ABTS_INT_EQUAL (tc, 46, lcn_segments_version (segments));
+
+ ABTS_INT_EQUAL (tc, 1, lcn_segments_count (segments));
+
+ {
+ lcn_char_t segname[] = { '_', 'c', '7', 0 };
+ ABTS_INT_EQUAL (tc, 395, lcn_segments_segsize (segments, segname));
+ }
+}
+
+static void
+test_segments_read_cfs (abts_case *tc, void *which)
+{
+ lcn_segments_t *segments;
+ lcn_directory_t *d;
+
+ CHK_ERR (lcn_fs_directory_open (&d, "test/data/index-cfs", p));
+
+ CHK_ERR (lcn_segments_read (&segments, d, p));
+
+ ABTS_INT_EQUAL (tc, 220, lcn_segments_version (segments));
+
+ ABTS_INT_EQUAL (tc, 1, lcn_segments_count (segments));
+
+ {
+ lcn_char_t segname[] = { '_', '1', 'o', 'r', 0 };
+ ABTS_INT_EQUAL (tc, 1969, lcn_segments_segsize (segments, segname));
+ }
+}
+
+static void
+test_segments_names (abts_case *tc, void *data)
+{
+ lcn_char_t segname[] = { '_', 'c', '7', 0 };
+ apr_array_header_t *names;
+ lcn_segments_t *segments;
+ lcn_directory_t *d;
+
+ CHK_ERR (lcn_fs_directory_open (&d, "test/data/index", p));
+
+ CHK_ERR (lcn_segments_read (&segments, d, p));
+
+ names = lcn_segments_names (segments, p);
+
+ ABTS_INT_EQUAL (tc, 1, names->nelts);
+
+ ABTS_INT_EQUAL (tc,
+ 0,
+ memcmp (segname,
+ APR_ARRAY_IDX (names, 0, lcn_char_t *),
+ 4 * sizeof (lcn_char_t)));
+}
+
+abts_suite *
+test_segments (abts_suite *suite)
+{
+ suite = ADD_SUITE (suite);
+
+ abts_run_test (suite, test_segments_read, NULL);
+ abts_run_test (suite, test_segments_read_cfs, NULL);
+ abts_run_test (suite, test_segments_names, NULL);
+
+ return suite;
+}
Added: incubator/lucene4c/trunk/test/index/terminfos_test.c
URL:
http://svn.apache.org/viewcvs/incubator/lucene4c/trunk/test/index/terminfos_test.c?view=auto&rev=155552
==============================================================================
--- incubator/lucene4c/trunk/test/index/terminfos_test.c (added)
+++ incubator/lucene4c/trunk/test/index/terminfos_test.c Sat Feb 26 08:47:57
2005
@@ -0,0 +1,568 @@
+/* Copyright 2004-2005 Garrett Rooney
+ *
+ * Licensed 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.
+ */
+
+#include "lcn_terminfos.h"
+
+#include "lcn_tests.h"
+
+#include "abts.h"
+
+static apr_uint64_t freqs[] = {
+ 0,
+ 904,
+ 1716,
+ 2550,
+ 3883,
+ 4786,
+ 5288,
+ 5571,
+ 5952,
+ 6998,
+ 9009,
+ 10221,
+ 11217,
+ 12455,
+ 13777,
+ 15160,
+ 16713,
+ 17422,
+ 18900,
+ 20097,
+ 21291,
+ 22514,
+ 24183,
+ 25151,
+ 26395,
+ 27507,
+ 28224,
+ 29352,
+ 30938,
+ 32338,
+ 33671,
+ 34770,
+ 35696,
+ 36842,
+ 39541,
+ 40461,
+ 41755,
+ 42724,
+ 43932,
+ 45768,
+ 47052,
+ 48284,
+ 49240,
+ 50113,
+ 51619,
+ 52718,
+ 53295,
+ 54829,
+ 55514,
+ 56788,
+ 57600,
+ 59072,
+ 60317,
+ 61519,
+ 62361,
+ 63268,
+ 63968,
+ 64354,
+ 64816,
+ 65319,
+ 66389,
+ 67703,
+ 68124,
+ 69297,
+ 71640,
+ 73011,
+ 74706,
+ 75175,
+ 75540,
+ 75777,
+ 76033
+};
+
+static apr_uint64_t proxs[] = {
+ 0,
+ 6036,
+ 11457,
+ 13078,
+ 16305,
+ 23185,
+ 25247,
+ 27502,
+ 28119,
+ 29989,
+ 33391,
+ 36926,
+ 39857,
+ 43843,
+ 46452,
+ 48439,
+ 51043,
+ 52362,
+ 55124,
+ 57701,
+ 59767,
+ 61765,
+ 65457,
+ 67289,
+ 70271,
+ 72481,
+ 73757,
+ 75927,
+ 80319,
+ 82981,
+ 86973,
+ 89254,
+ 91441,
+ 94878,
+ 99275,
+ 101042,
+ 102998,
+ 105298,
+ 109076,
+ 113074,
+ 114223,
+ 116264,
+ 117748,
+ 119758,
+ 124041,
+ 126314,
+ 127236,
+ 130956,
+ 132172,
+ 134716,
+ 136046,
+ 138626,
+ 141180,
+ 143921,
+ 145444,
+ 147937,
+ 149172,
+ 149541,
+ 150143,
+ 150787,
+ 153064,
+ 156059,
+ 156722,
+ 158261,
+ 162122,
+ 164442,
+ 166518,
+ 166955,
+ 167230,
+ 167358,
+ 167486
+};
+
+static apr_uint32_t skips[] = {
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 43,
+ 43,
+ 43,
+ 43,
+ 43,
+ 43,
+ 43,
+ 43,
+ 43,
+ 43,
+ 43,
+ 43,
+ 43,
+ 43,
+ 38,
+ 38,
+ 38,
+ 38,
+ 38,
+ 38,
+ 38,
+ 38,
+ 38,
+ 38,
+ 38,
+ 38,
+ 38,
+ 38,
+ 38,
+ 38,
+ 38,
+ 38,
+ 38,
+ 38,
+ 38,
+ 38,
+ 38,
+ 38,
+ 38,
+ 38,
+ 38,
+ 38,
+ 38,
+ 38,
+ 38,
+ 38,
+ 38,
+ 38,
+ 38,
+ 38,
+ 38,
+ 38,
+ 72,
+ 72,
+ 72,
+ 72,
+ 72,
+ 72
+};
+
+static apr_uint32_t fieldnums[] = {
+ 0,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 2,
+ 3,
+ 3,
+ 3,
+};
+
+static apr_uint32_t docfreqs[] = {
+ 0,
+ 3,
+ 7,
+ 2,
+ 1,
+ 1,
+ 1,
+ 1,
+ 5,
+ 1,
+ 1,
+ 2,
+ 1,
+ 27,
+ 3,
+ 1,
+ 3,
+ 4,
+ 1,
+ 1,
+ 1,
+ 1,
+ 3,
+ 2,
+ 1,
+ 2,
+ 2,
+ 20,
+ 2,
+ 3,
+ 1,
+ 1,
+ 1,
+ 6,
+ 2,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 2,
+ 1,
+ 4,
+ 1,
+ 3,
+ 8,
+ 11,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 50,
+ 2,
+ 1,
+ 1,
+ 1,
+ 1,
+};
+
+static const lcn_char_t termname0[] = { 0 };
+
+static const lcn_char_t termname10[] = { 'a',
+ 's',
+ 's',
+ 'u',
+ 'm',
+ 'e',
+ 's',
+ 0 };
+
+static const lcn_char_t termname26[] = { 'g', 'o', 'o', 'd', 's', 0 };
+
+static const lcn_char_t fieldname[] = { 'c',
+ 'o',
+ 'n',
+ 't',
+ 'e',
+ 'n',
+ 't',
+ 's',
+ 0 };
+
+static const lcn_char_t fieldname0[] = { 0 };
+
+static lcn_term_t term0 = { (lcn_char_t *) termname0,
+ (lcn_char_t *) fieldname0 };
+
+static lcn_term_t term10 = { (lcn_char_t *) termname10,
+ (lcn_char_t *) fieldname };
+
+static lcn_term_t term26 = { (lcn_char_t *) termname26,
+ (lcn_char_t *) fieldname };
+
+void
+test_terminfos_idx_read (abts_case *tc, void *data)
+{
+ lcn_terminfos_idx_t *tisidx;
+ lcn_char_t segment[] = { '_', 'c', '7', 0 };
+ lcn_directory_t *d;
+ lcn_error_t *err;
+ apr_uint64_t i;
+
+ apr_pool_clear (p);
+
+ CHK_ERR (lcn_fs_directory_open (&d, "test/data/index", p));
+
+ err = lcn_terminfos_idx_read (&tisidx, d, segment, p);
+
+ ABTS_PTR_EQUAL (tc, LCN_NO_ERROR, err);
+
+ if (err) { return; }
+
+ ABTS_INT_EQUAL (tc, 71, lcn_terminfos_idx_get_count (tisidx));
+
+ for (i = 0; i < 71; ++i)
+ {
+ lcn_terminfo_t *ti;
+
+ CHK_ERR (lcn_terminfos_idx_get_terminfo (&ti, tisidx, i));
+
+ ABTS_INT_EQUAL (tc, freqs[i], lcn_terminfo_freq_position (ti));
+ ABTS_INT_EQUAL (tc, proxs[i], lcn_terminfo_prox_position (ti));
+ ABTS_INT_EQUAL (tc, skips[i], lcn_terminfo_skip_offset (ti));
+ ABTS_INT_EQUAL (tc, fieldnums[i], lcn_terminfo_field_num (ti));
+ ABTS_INT_EQUAL (tc, docfreqs[i], lcn_terminfo_doc_freq (ti));
+
+ /* no easy way to declare an array of terms, so we just pick a few */
+ switch (i)
+ {
+ case 0:
+ ABTS_INT_EQUAL (tc,
+ 0,
+ memcmp (term0.contents,
+ lcn_terminfo_term (ti)->contents,
+ LCN_STRING_SIZE (term0.contents)));
+ break;
+
+ case 10:
+ ABTS_INT_EQUAL (tc,
+ 0,
+ memcmp (term10.contents,
+ lcn_terminfo_term (ti)->contents,
+ LCN_STRING_SIZE (term10.contents)));
+ break;
+
+ case 26:
+ ABTS_INT_EQUAL (tc,
+ 0,
+ memcmp (term26.contents,
+ lcn_terminfo_term (ti)->contents,
+ LCN_STRING_SIZE (term26.contents)));
+ break;
+ }
+ }
+}
+
+void
+test_terminfos_get_terminfo (abts_case *tc, void *data)
+{
+ lcn_terminfos_t *tis;
+ lcn_terminfo_t *ti;
+ lcn_directory_t *d;
+ lcn_error_t *err;
+
+ lcn_char_t segment[] = { '_', 'c', '7', 0 };
+
+ CHK_ERR (lcn_fs_directory_open (&d, "test/data/index", p));
+
+ err = lcn_terminfos_open (&tis, d, segment, p);
+
+ ABTS_PTR_EQUAL (tc, LCN_NO_ERROR, err);
+
+ if (err) { return; }
+
+ err = lcn_terminfos_get_terminfo (&ti, tis, &term0, p);
+
+ ABTS_PTR_EQUAL (tc, LCN_NO_ERROR, err);
+
+ if (err) { return; }
+
+ ABTS_INT_EQUAL (tc, 0, lcn_strcmp (term0.contents,
+ lcn_terminfo_term (ti)->contents));
+
+ err = lcn_terminfos_get_terminfo (&ti, tis, &term10, p);
+
+ ABTS_PTR_EQUAL (tc, LCN_NO_ERROR, err);
+
+ if (err) { return; }
+
+ ABTS_INT_EQUAL (tc, 0, lcn_strcmp (term10.contents,
+ lcn_terminfo_term (ti)->contents));
+
+ {
+ /* ok, now one that isn't in the index... */
+
+ const lcn_char_t term[] = { 'l', 'u', 'c', 'e', 'n', 'e', 0 };
+ lcn_term_t t = { (lcn_char_t *) term, (lcn_char_t *) fieldname };
+
+ err = lcn_terminfos_get_terminfo (&ti, tis, &t, p);
+
+ ABTS_PTR_EQUAL (tc, LCN_NO_ERROR, err);
+
+ if (err) { return; }
+
+ ABTS_INT_EQUAL (tc, 0, lcn_strcmp (term,
+ lcn_terminfo_term (ti)->contents));
+
+ ABTS_INT_EQUAL (tc, 39981, lcn_terminfo_freq_position (ti));
+ }
+
+ {
+ /* ok, now one that isn't in the index... */
+
+ const lcn_char_t term[] = { 'q', 'u', 'i', 't', 0 };
+ lcn_term_t t = { (lcn_char_t *) term, (lcn_char_t *) fieldname };
+
+ err = lcn_terminfos_get_terminfo (&ti, tis, &t, p);
+
+ ABTS_TRUE (tc, LCN_NO_ERROR != err);
+
+ ABTS_INT_EQUAL (tc, APR_ENOENT, err->apr_err);
+
+ lcn_error_clear (err);
+ }
+}
+
+abts_suite *
+test_terminfos (abts_suite *suite)
+{
+ suite = ADD_SUITE (suite);
+
+ abts_run_test (suite, test_terminfos_idx_read, NULL);
+ abts_run_test (suite, test_terminfos_get_terminfo, NULL);
+
+ return suite;
+}
Added: incubator/lucene4c/trunk/test/lcn_tests.c
URL:
http://svn.apache.org/viewcvs/incubator/lucene4c/trunk/test/lcn_tests.c?view=auto&rev=155552
==============================================================================
--- incubator/lucene4c/trunk/test/lcn_tests.c (added)
+++ incubator/lucene4c/trunk/test/lcn_tests.c Sat Feb 26 08:47:57 2005
@@ -0,0 +1,31 @@
+/* Copyright 2004-2005 Garrett Rooney
+ *
+ * Licensed 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.
+ */
+
+#include "lcn_tests.h"
+
+#include <apr.h>
+#include <apr_pools.h>
+
+apr_pool_t *p;
+
+void
+initialize (void)
+{
+ apr_initialize ();
+
+ atexit (apr_terminate);
+
+ p = lcn_pool_create (NULL);
+}
Added: incubator/lucene4c/trunk/test/lcn_tests.h
URL:
http://svn.apache.org/viewcvs/incubator/lucene4c/trunk/test/lcn_tests.h?view=auto&rev=155552
==============================================================================
--- incubator/lucene4c/trunk/test/lcn_tests.h (added)
+++ incubator/lucene4c/trunk/test/lcn_tests.h Sat Feb 26 08:47:57 2005
@@ -0,0 +1,62 @@
+/* Copyright 2004-2005 Garrett Rooney
+ *
+ * Licensed 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.
+ */
+
+#ifndef LCN_TEST_H
+#define LCN_TEST_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#include <apr.h>
+#include <apr_pools.h>
+
+#include "lcn_types.h"
+
+#include "abts.h"
+
+apr_pool_t *p;
+
+#define CHK_ERR(expr) do { \
+ lcn_error_t *lcn__err = expr; \
+ ABTS_PTR_EQUAL (tc, LCN_NO_ERROR, lcn__err); \
+ if (lcn__err) \
+ { \
+ printf ("err = %d: %s\n", \
+ lcn__err->apr_err, \
+ lcn__err->message); \
+ return; \
+ } \
+ } while (0)
+
+void initialize (void);
+
+abts_suite *test_istream (abts_suite *);
+abts_suite *test_directory (abts_suite *);
+abts_suite *test_segments (abts_suite *);
+abts_suite *test_segment (abts_suite *);
+abts_suite *test_fieldinfos (abts_suite *);
+abts_suite *test_fielddata (abts_suite *);
+abts_suite *test_terminfos (abts_suite *);
+abts_suite *test_frequencies (abts_suite *);
+abts_suite *test_index (abts_suite *);
+abts_suite *test_string (abts_suite *);
+abts_suite *test_scorer (abts_suite *);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif
Propchange: incubator/lucene4c/trunk/test/search/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sat Feb 26 08:47:57 2005
@@ -0,0 +1,2 @@
+.deps
+.dirstamp
Added: incubator/lucene4c/trunk/test/search/scorer_test.c
URL:
http://svn.apache.org/viewcvs/incubator/lucene4c/trunk/test/search/scorer_test.c?view=auto&rev=155552
==============================================================================
--- incubator/lucene4c/trunk/test/search/scorer_test.c (added)
+++ incubator/lucene4c/trunk/test/search/scorer_test.c Sat Feb 26 08:47:57 2005
@@ -0,0 +1,126 @@
+/* Copyright 2004-2005 Garrett Rooney
+ *
+ * Licensed 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.
+ */
+
+#include "lcn_query.h"
+#include "lcn_scorer.h"
+
+#include "lcn_tests.h"
+
+#include "abts.h"
+
+static void
+test_term_scorer (abts_case *tc, void *data)
+{
+ lcn_query_t *query;
+ lcn_scorer_t *scorer;
+ lcn_index_t *index;
+ lcn_error_t *err;
+ int count = 0;
+
+ CHK_ERR (lcn_index_open (&index, "test/data/index", p));
+
+ CHK_ERR (lcn_term_query_create (&query,
+ lcn_term_create_cstring ("lucene",
+ "contents",
+ p),
+ p));
+
+ CHK_ERR (lcn_query_scorer (&scorer, query, index, p));
+
+ ABTS_INT_EQUAL (tc, 1, lcn_scorer_doc (scorer));
+
+ /* XXX check score */
+
+ while ((err = lcn_scorer_next (scorer)) == LCN_NO_ERROR)
+ {
+ if (++count == 1)
+ {
+ ABTS_INT_EQUAL (tc, 4, lcn_scorer_doc (scorer));
+
+ /* XXX check score */
+ }
+ }
+
+ ABTS_INT_EQUAL (tc, APR_EOF, err->apr_err);
+
+ lcn_error_clear (err);
+
+ ABTS_INT_EQUAL (tc, 75, count);
+
+ apr_pool_clear (p);
+}
+
+static void
+test_boolean_scorer (abts_case *tc, void *data)
+{
+ lcn_query_t *query, *tquery;
+ lcn_scorer_t *scorer;
+ lcn_index_t *index;
+ lcn_error_t *err;
+ int count = 0;
+
+ CHK_ERR (lcn_index_open (&index, "test/data/index", p));
+
+ CHK_ERR (lcn_boolean_query_create (&query, p));
+
+ CHK_ERR (lcn_term_query_create (&tquery,
+ lcn_term_create_cstring ("lucene",
+ "contents",
+ p),
+ p));
+
+ CHK_ERR (lcn_boolean_query_add (query, tquery, LCN_MUST));
+
+ CHK_ERR (lcn_term_query_create (&tquery,
+ lcn_term_create_cstring ("cutting",
+ "contents",
+ p),
+ p));
+
+ CHK_ERR (lcn_boolean_query_add (query, tquery, LCN_MUST));
+
+ CHK_ERR (lcn_query_scorer (&scorer, query, index, p));
+
+ ABTS_INT_EQUAL (tc, 40, lcn_scorer_doc (scorer));
+
+ while ((err = lcn_scorer_next (scorer)) == LCN_NO_ERROR)
+ {
+ if (count == 0)
+ ABTS_INT_EQUAL (tc, 175, lcn_scorer_doc (scorer));
+ else if (count == 1)
+ ABTS_INT_EQUAL (tc, 178, lcn_scorer_doc (scorer));
+ else if (count == 2)
+ ABTS_INT_EQUAL (tc, 239, lcn_scorer_doc (scorer));
+ else
+ ABTS_TRUE(tc, FALSE);
+
+ ++count;
+ }
+
+ ABTS_INT_EQUAL (tc, APR_EOF, err->apr_err);
+
+ apr_pool_clear (p);
+}
+
+abts_suite *
+test_scorer (abts_suite *suite)
+{
+ suite = ADD_SUITE (suite);
+
+ abts_run_test (suite, test_term_scorer, NULL);
+ abts_run_test (suite, test_boolean_scorer, NULL);
+
+ return suite;
+}
Propchange: incubator/lucene4c/trunk/test/store/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sat Feb 26 08:47:57 2005
@@ -0,0 +1,2 @@
+.deps
+.dirstamp
Added: incubator/lucene4c/trunk/test/store/directory_test.c
URL:
http://svn.apache.org/viewcvs/incubator/lucene4c/trunk/test/store/directory_test.c?view=auto&rev=155552
==============================================================================
--- incubator/lucene4c/trunk/test/store/directory_test.c (added)
+++ incubator/lucene4c/trunk/test/store/directory_test.c Sat Feb 26 08:47:57
2005
@@ -0,0 +1,664 @@
+/* Copyright 2005 Garrett Rooney
+ *
+ * Licensed 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.
+ */
+
+#include "lcn_directory.h"
+
+#include "lcn_tests.h"
+
+#include "abts.h"
+
+static void
+test_list (abts_case *tc, void *which)
+{
+ lcn_directory_entry_t filecontents;
+ apr_hash_t *c = apr_hash_make (p);
+ apr_array_header_t *a;
+ lcn_directory_t *d;
+
+ CHK_ERR (lcn_ram_directory_open (&d, c, p));
+
+ CHK_ERR (lcn_directory_list (&a, d, p));
+
+ ABTS_INT_EQUAL (tc, 0, a->nelts);
+
+ filecontents.bytes = "foo";
+ filecontents.len = strlen ("foo");
+
+ apr_hash_set (c, "filename", APR_HASH_KEY_STRING, &filecontents);
+
+ CHK_ERR (lcn_ram_directory_open (&d, c, p));
+
+ CHK_ERR (lcn_directory_list (&a, d, p));
+
+ ABTS_INT_EQUAL (tc, 1, a->nelts);
+
+ apr_pool_clear (p);
+}
+
+static void
+test_file_exists (abts_case *tc, void *which)
+{
+ lcn_directory_entry_t filecontents;
+ apr_hash_t *c = apr_hash_make (p);
+ lcn_boolean_t result;
+ lcn_directory_t *d;
+
+ CHK_ERR (lcn_ram_directory_open (&d, c, p));
+
+ CHK_ERR (lcn_directory_file_exists (&result, d, "not-there", p));
+
+ ABTS_TRUE (tc, !result);
+
+ filecontents.bytes = "foo";
+ filecontents.len = strlen ("foo");
+
+ apr_hash_set (c, "filename", APR_HASH_KEY_STRING, &filecontents);
+
+ CHK_ERR (lcn_ram_directory_open (&d, c, p));
+
+ CHK_ERR (lcn_directory_file_exists (&result, d, "filename", p));
+
+ ABTS_TRUE (tc, result);
+
+ apr_pool_clear (p);
+}
+
+static void
+test_file_modified (abts_case *tc, void *which)
+{
+ lcn_directory_entry_t filecontents;
+ apr_hash_t *c = apr_hash_make (p);
+ lcn_directory_t *d;
+ apr_time_t mtime;
+
+ filecontents.bytes = "foo";
+ filecontents.len = strlen ("foo");
+ filecontents.mtime = 47;
+
+ apr_hash_set (c, "filename", APR_HASH_KEY_STRING, &filecontents);
+
+ CHK_ERR (lcn_ram_directory_open (&d, c, p));
+
+ CHK_ERR (lcn_directory_file_modified (&mtime, d, "filename", p));
+
+ ABTS_INT_EQUAL (tc, 47, mtime);
+
+ apr_pool_clear (p);
+}
+
+static void
+test_touch_file (abts_case *tc, void *which)
+{
+ lcn_directory_entry_t filecontents;
+ apr_hash_t *c = apr_hash_make (p);
+ lcn_directory_t *d;
+ apr_time_t mtime;
+
+ filecontents.bytes = "foo";
+ filecontents.len = strlen ("foo");
+ filecontents.mtime = 47;
+
+ apr_hash_set (c, "filename", APR_HASH_KEY_STRING, &filecontents);
+
+ CHK_ERR (lcn_ram_directory_open (&d, c, p));
+
+ CHK_ERR (lcn_directory_file_modified (&mtime, d, "filename", p));
+
+ ABTS_INT_EQUAL (tc, 47, mtime);
+
+ CHK_ERR (lcn_directory_touch_file (d, "filename", p));
+
+ CHK_ERR (lcn_directory_file_modified (&mtime, d, "filename", p));
+
+ ABTS_TRUE (tc, mtime > 47);
+
+ apr_pool_clear (p);
+}
+
+static void
+test_delete_file (abts_case *tc, void *which)
+{
+ lcn_directory_entry_t filecontents;
+ apr_hash_t *c = apr_hash_make (p);
+ lcn_boolean_t result;
+ lcn_directory_t *d;
+
+ filecontents.bytes = "foo";
+ filecontents.len = strlen ("foo");
+ filecontents.mtime = 47;
+
+ apr_hash_set (c, "filename", APR_HASH_KEY_STRING, &filecontents);
+
+ CHK_ERR (lcn_ram_directory_open (&d, c, p));
+
+ CHK_ERR (lcn_directory_file_exists (&result, d, "filename", p));
+
+ ABTS_TRUE (tc, result);
+
+ CHK_ERR (lcn_directory_delete_file (d, "filename", p));
+
+ CHK_ERR (lcn_directory_file_exists (&result, d, "filename", p));
+
+ ABTS_TRUE (tc, !result);
+
+ apr_pool_clear (p);
+}
+
+static void
+test_rename_file (abts_case *tc, void *which)
+{
+ lcn_directory_entry_t filecontents;
+ apr_hash_t *c = apr_hash_make (p);
+ lcn_boolean_t result;
+ lcn_directory_t *d;
+
+ filecontents.bytes = "foo";
+ filecontents.len = strlen ("foo");
+ filecontents.mtime = 47;
+
+ apr_hash_set (c, "filename", APR_HASH_KEY_STRING, &filecontents);
+
+ CHK_ERR (lcn_ram_directory_open (&d, c, p));
+
+ CHK_ERR (lcn_directory_file_exists (&result, d, "filename", p));
+
+ ABTS_TRUE (tc, result);
+
+ CHK_ERR (lcn_directory_rename_file (d, "filename", "to", p));
+
+ CHK_ERR (lcn_directory_file_exists (&result, d, "filename", p));
+
+ ABTS_TRUE (tc, !result);
+
+ CHK_ERR (lcn_directory_file_exists (&result, d, "to", p));
+
+ ABTS_TRUE (tc, result);
+
+ apr_pool_clear (p);
+}
+
+static void
+test_open_file (abts_case *tc, void *which)
+{
+ lcn_directory_entry_t filecontents;
+ apr_hash_t *c = apr_hash_make (p);
+ lcn_istream_t *stream;
+ lcn_boolean_t result;
+ lcn_directory_t *d;
+ char b;
+
+ filecontents.bytes = "foo";
+ filecontents.len = strlen ("foo");
+ filecontents.mtime = 47;
+
+ apr_hash_set (c, "filename", APR_HASH_KEY_STRING, &filecontents);
+
+ CHK_ERR (lcn_ram_directory_open (&d, c, p));
+
+ CHK_ERR (lcn_directory_file_exists (&result, d, "filename", p));
+
+ ABTS_TRUE (tc, result);
+
+ CHK_ERR (lcn_directory_open_file (&stream, d, "filename", p));
+
+ CHK_ERR (lcn_istream_read_byte (stream, &b, p));
+
+ ABTS_INT_EQUAL (tc, 'f', b);
+
+ CHK_ERR (lcn_istream_read_byte (stream, &b, p));
+
+ ABTS_INT_EQUAL (tc, 'o', b);
+
+ CHK_ERR (lcn_istream_read_byte (stream, &b, p));
+
+ ABTS_INT_EQUAL (tc, 'o', b);
+
+ {
+ lcn_error_t *err = lcn_istream_read_byte (stream, &b, p);
+
+ ABTS_PTR_NOTNULL (tc, err);
+
+ if (err)
+ ABTS_INT_EQUAL (tc, err->apr_err, APR_EOF);
+ }
+
+ apr_pool_clear (p);
+}
+
+static void
+test_close (abts_case *tc, void *which)
+{
+ lcn_directory_entry_t filecontents;
+ apr_hash_t *c = apr_hash_make (p);
+ lcn_directory_t *d;
+
+ filecontents.bytes = "foo";
+ filecontents.len = strlen ("foo");
+ filecontents.mtime = 47;
+
+ apr_hash_set (c, "filename", APR_HASH_KEY_STRING, &filecontents);
+
+ CHK_ERR (lcn_ram_directory_open (&d, c, p));
+
+ CHK_ERR (lcn_directory_close (d, p));
+
+ apr_pool_clear (p);
+}
+
+static void
+test_fs_list (abts_case *tc, void *which)
+{
+ lcn_boolean_t found_it = FALSE;
+ apr_array_header_t *c;
+ lcn_directory_t *d;
+ int i;
+
+ CHK_ERR (lcn_fs_directory_open (&d, "test/data/index", p));
+
+ CHK_ERR (lcn_directory_list (&c, d, p));
+
+ ABTS_TRUE (tc, (c->nelts == 15) || (c->nelts == 14));
+
+ for (i = 0; i < c->nelts; ++i)
+ {
+ if (strcmp (APR_ARRAY_IDX (c, i, const char *), "_c7.f1") == 0)
+ found_it = TRUE;
+ }
+
+ ABTS_TRUE (tc, found_it);
+
+ apr_pool_clear (p);
+}
+
+static void
+test_fs_file_exists (abts_case *tc, void *which)
+{
+ lcn_directory_t *d;
+ lcn_boolean_t exists;
+
+ CHK_ERR (lcn_fs_directory_open (&d, "test/data/index", p));
+
+ CHK_ERR (lcn_directory_file_exists (&exists, d, "_c7.f1", p));
+
+ ABTS_TRUE (tc, exists);
+
+ CHK_ERR (lcn_directory_file_exists (&exists, d, "foo", p));
+
+ ABTS_TRUE (tc, ! exists);
+
+ apr_pool_clear (p);
+}
+
+static void
+test_fs_file_modified (abts_case *tc, void *which)
+{
+ lcn_directory_t *d;
+ apr_time_t now = apr_time_now ();
+ apr_time_t result;
+
+ CHK_ERR (lcn_fs_directory_open (&d, "test/data/index", p));
+
+ CHK_ERR (lcn_directory_file_modified (&result, d, "_c7.f1", p));
+
+ ABTS_TRUE (tc, result < now);
+
+ apr_pool_clear (p);
+}
+
+static void
+test_fs_touch_file (abts_case *tc, void *which)
+{
+ apr_time_t before, after;
+ lcn_directory_t *d;
+
+ CHK_ERR (lcn_fs_directory_open (&d, "test/data/index", p));
+
+ CHK_ERR (lcn_directory_file_modified (&before, d, "_c7.f2", p));
+
+ ABTS_TRUE (tc, before < apr_time_now ());
+
+ CHK_ERR (lcn_directory_touch_file (d, "_c7.f2", p));
+
+ CHK_ERR (lcn_directory_file_modified (&after, d, "_c7.f2", p));
+
+ ABTS_TRUE (tc, after > before);
+
+ apr_pool_clear (p);
+}
+
+static void
+test_fs_delete (abts_case *tc, void *which)
+{
+ lcn_boolean_t exists;
+ lcn_directory_t *d;
+ apr_file_t *file;
+
+ CHK_ERR (lcn_fs_directory_open (&d, "test/data", p));
+
+ apr_file_open (&file,
+ "test/data/foo",
+ APR_WRITE|APR_CREATE,
+ APR_OS_DEFAULT,
+ p);
+
+ CHK_ERR (lcn_directory_file_exists (&exists, d, "foo", p));
+
+ ABTS_TRUE (tc, exists);
+
+ CHK_ERR (lcn_directory_delete_file (d, "foo", p));
+
+ CHK_ERR (lcn_directory_file_exists (&exists, d, "foo", p));
+
+ ABTS_TRUE (tc, ! exists);
+
+ apr_pool_clear (p);
+}
+
+static void
+test_fs_rename (abts_case *tc, void *which)
+{
+ lcn_boolean_t exists;
+ lcn_directory_t *d;
+ apr_file_t *file;
+
+ CHK_ERR (lcn_fs_directory_open (&d, "test/data", p));
+
+ apr_file_open (&file,
+ "test/data/foo",
+ APR_WRITE|APR_CREATE,
+ APR_OS_DEFAULT,
+ p);
+
+ CHK_ERR (lcn_directory_file_exists (&exists, d, "foo", p));
+
+ ABTS_TRUE (tc, exists);
+
+ CHK_ERR (lcn_directory_file_exists (&exists, d, "bar", p));
+
+ ABTS_TRUE (tc, ! exists);
+
+ CHK_ERR (lcn_directory_rename_file (d, "foo", "bar", p));
+
+ CHK_ERR (lcn_directory_file_exists (&exists, d, "foo", p));
+
+ ABTS_TRUE (tc, ! exists);
+
+ CHK_ERR (lcn_directory_file_exists (&exists, d, "bar", p));
+
+ ABTS_TRUE (tc, exists);
+
+ CHK_ERR (lcn_directory_delete_file (d, "bar", p));
+
+ apr_pool_clear (p);
+}
+
+static void
+test_fs_open_file (abts_case *tc, void *which)
+{
+ lcn_istream_t *stream;
+ lcn_directory_t *d;
+ char b;
+
+ CHK_ERR (lcn_fs_directory_open (&d, "test/data/index", p));
+
+ CHK_ERR (lcn_directory_open_file (&stream, d, "_c7.f1", p));
+
+ CHK_ERR (lcn_istream_read_byte (stream, &b, p));
+
+ ABTS_INT_EQUAL (tc, 'u', b);
+
+ CHK_ERR (lcn_istream_read_byte (stream, &b, p));
+
+ ABTS_INT_EQUAL (tc, 'w', b);
+
+ CHK_ERR (lcn_istream_read_byte (stream, &b, p));
+
+ ABTS_INT_EQUAL (tc, 'x', b);
+
+ apr_pool_clear (p);
+}
+
+static void
+test_fs_close (abts_case *tc, void *which)
+{
+ lcn_directory_t *d;
+
+ CHK_ERR (lcn_fs_directory_open (&d, "test/data/index", p));
+
+ CHK_ERR (lcn_directory_close (d, p));
+
+ apr_pool_clear (p);
+}
+
+static void
+test_cfs_open (abts_case *tc, void *which)
+{
+ lcn_istream_t *cfsstream;
+ apr_file_t *cfsfile;
+ lcn_directory_t *d;
+ lcn_error_t *err;
+
+ apr_file_open (&cfsfile,
+ "test/data/index-cfs/_1or.cfs",
+ APR_READ,
+ APR_OS_DEFAULT,
+ p);
+
+ cfsstream = lcn_file_istream_create (cfsfile, p);
+
+ err = lcn_cfs_directory_open (&d, cfsstream, p);
+
+ ABTS_PTR_EQUAL (tc, LCN_NO_ERROR, err);
+
+ apr_pool_clear (p);
+}
+
+static void
+test_cfs_unsupported (abts_case *tc, void *which)
+{
+ lcn_istream_t *cfsstream;
+ apr_file_t *cfsfile;
+ lcn_directory_t *d;
+ apr_time_t result;
+ lcn_error_t *err;
+
+ apr_file_open (&cfsfile,
+ "test/data/index-cfs/_1or.cfs",
+ APR_READ,
+ APR_OS_DEFAULT,
+ p);
+
+ cfsstream = lcn_file_istream_create (cfsfile, p);
+
+ CHK_ERR (lcn_cfs_directory_open (&d, cfsstream, p));
+
+ err = lcn_directory_delete_file (d, "foo", p);
+
+ ABTS_PTR_NOTNULL (tc, err);
+
+ if (err)
+ ABTS_INT_EQUAL (tc, APR_ENOTIMPL, err->apr_err);
+
+ err = lcn_directory_rename_file (d, "foo", "bar", p);
+
+ ABTS_PTR_NOTNULL (tc, err);
+
+ if (err)
+ ABTS_INT_EQUAL (tc, APR_ENOTIMPL, err->apr_err);
+
+ err = lcn_directory_file_modified (&result, d, "foo", p);
+
+ ABTS_PTR_NOTNULL (tc, err);
+
+ if (err)
+ ABTS_INT_EQUAL (tc, APR_ENOTIMPL, err->apr_err);
+
+ err = lcn_directory_touch_file (d, "foo", p);
+
+ ABTS_PTR_NOTNULL (tc, err);
+
+ if (err)
+ ABTS_INT_EQUAL (tc, APR_ENOTIMPL, err->apr_err);
+
+ apr_pool_clear (p);
+}
+
+static void
+test_cfs_list (abts_case *tc, void *which)
+{
+ lcn_boolean_t found = FALSE;
+ lcn_istream_t *cfsstream;
+ apr_array_header_t *c;
+ apr_file_t *cfsfile;
+ lcn_directory_t *d;
+ int idx;
+
+ apr_file_open (&cfsfile,
+ "test/data/index-cfs/_1or.cfs",
+ APR_READ,
+ APR_OS_DEFAULT,
+ p);
+
+ cfsstream = lcn_file_istream_create (cfsfile, p);
+
+ CHK_ERR (lcn_cfs_directory_open (&d, cfsstream, p));
+
+ CHK_ERR (lcn_directory_list (&c, d, p));
+
+ ABTS_INT_EQUAL (tc, 10, c->nelts);
+
+ for (idx = 0; idx < c->nelts; ++idx)
+ {
+ const char *fname = APR_ARRAY_IDX (c, idx, const char *);
+
+ if (strcmp (fname, "_1or.fnm") == 0)
+ found = TRUE;
+ }
+
+ ABTS_TRUE (tc, found);
+
+ apr_pool_clear (p);
+}
+
+static void
+test_cfs_file_exists (abts_case *tc, void *which)
+{
+ lcn_istream_t *cfsstream;
+ lcn_boolean_t result;
+ apr_file_t *cfsfile;
+ lcn_directory_t *d;
+
+ apr_file_open (&cfsfile,
+ "test/data/index-cfs/_1or.cfs",
+ APR_READ,
+ APR_OS_DEFAULT,
+ p);
+
+ cfsstream = lcn_file_istream_create (cfsfile, p);
+
+ CHK_ERR (lcn_cfs_directory_open (&d, cfsstream, p));
+
+ CHK_ERR (lcn_directory_file_exists (&result, d, "_1or.fnm", p));
+
+ ABTS_TRUE (tc, result);
+
+ CHK_ERR (lcn_directory_file_exists (&result, d, "foo", p));
+
+ ABTS_TRUE (tc, ! result);
+
+ apr_pool_clear (p);
+}
+
+static void
+test_cfs_close (abts_case *tc, void *which)
+{
+ lcn_istream_t *cfsstream;
+ apr_file_t *cfsfile;
+ lcn_directory_t *d;
+
+ apr_file_open (&cfsfile,
+ "test/data/index-cfs/_1or.cfs",
+ APR_READ,
+ APR_OS_DEFAULT,
+ p);
+
+ cfsstream = lcn_file_istream_create (cfsfile, p);
+
+ CHK_ERR (lcn_cfs_directory_open (&d, cfsstream, p));
+
+ CHK_ERR (lcn_directory_close (d, p));
+
+ apr_pool_clear (p);
+}
+
+static void
+test_cfs_open_file (abts_case *tc, void *which)
+{
+ lcn_istream_t *cfsstream, *file;
+ apr_uint32_t field_count;
+ apr_file_t *cfsfile;
+ lcn_directory_t *d;
+
+ apr_file_open (&cfsfile,
+ "test/data/index-cfs/_1or.cfs",
+ APR_READ,
+ APR_OS_DEFAULT,
+ p);
+
+ cfsstream = lcn_file_istream_create (cfsfile, p);
+
+ CHK_ERR (lcn_cfs_directory_open (&d, cfsstream, p));
+
+ CHK_ERR (lcn_directory_open_file (&file, d, "_1or.fnm", p));
+
+ CHK_ERR (lcn_istream_read_vint (file, &field_count, p));
+
+ ABTS_INT_EQUAL (tc, 3, field_count);
+
+ apr_pool_clear (p);
+}
+
+abts_suite *
+test_directory (abts_suite *suite)
+{
+ suite = ADD_SUITE (suite);
+
+ abts_run_test (suite, test_list, NULL);
+ abts_run_test (suite, test_file_exists, NULL);
+ abts_run_test (suite, test_file_modified, NULL);
+ abts_run_test (suite, test_touch_file, NULL);
+ abts_run_test (suite, test_delete_file, NULL);
+ abts_run_test (suite, test_rename_file, NULL);
+ abts_run_test (suite, test_open_file, NULL);
+ abts_run_test (suite, test_close, NULL);
+
+ abts_run_test (suite, test_fs_list, NULL);
+ abts_run_test (suite, test_fs_file_exists, NULL);
+ abts_run_test (suite, test_fs_file_modified, NULL);
+ abts_run_test (suite, test_fs_touch_file, NULL);
+ abts_run_test (suite, test_fs_delete, NULL);
+ abts_run_test (suite, test_fs_rename, NULL);
+ abts_run_test (suite, test_fs_open_file, NULL);
+ abts_run_test (suite, test_fs_close, NULL);
+
+ abts_run_test (suite, test_cfs_open, NULL);
+ abts_run_test (suite, test_cfs_unsupported, NULL);
+ abts_run_test (suite, test_cfs_list, NULL);
+ abts_run_test (suite, test_cfs_file_exists, NULL);
+ abts_run_test (suite, test_cfs_open_file, NULL);
+ abts_run_test (suite, test_cfs_close, NULL);
+
+ return suite;
+}
Added: incubator/lucene4c/trunk/test/store/istream_test.c
URL:
http://svn.apache.org/viewcvs/incubator/lucene4c/trunk/test/store/istream_test.c?view=auto&rev=155552
==============================================================================
--- incubator/lucene4c/trunk/test/store/istream_test.c (added)
+++ incubator/lucene4c/trunk/test/store/istream_test.c Sat Feb 26 08:47:57 2005
@@ -0,0 +1,380 @@
+/* Copyright 2004-2005 Garrett Rooney
+ *
+ * Licensed 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.
+ */
+
+#include "lcn_istream.h"
+
+#include "lcn_tests.h"
+
+#include "abts.h"
+
+#include <apr_file_io.h>
+#include <apr_strings.h>
+
+/* indicators as to which type of istream we should create in the test. */
+int test_uses_ram = 0;
+int test_uses_file = 1;
+
+#define USE_RAM &test_uses_ram
+#define USE_FILE &test_uses_file
+
+/* the current temp file we're using. yes, it's a global, deal with it. */
+int file_num = 0;
+
+static lcn_istream_t *
+open_istream (void *which,
+ const char *contents,
+ apr_size_t length,
+ apr_pool_t *pool)
+{
+ switch (*(int *)which) {
+ case 0:
+ return lcn_ram_istream_create (contents, length, pool);
+ case 1:
+ {
+ char *fname = apr_psprintf (pool, "temp%d", file_num++);
+ apr_file_t *file = NULL;
+
+ apr_file_open (&file, fname, APR_WRITE|APR_CREATE, APR_OS_DEFAULT, pool);
+
+ apr_file_write (file, contents, &length);
+
+ apr_file_close (file);
+
+ file = NULL;
+
+ apr_file_open (&file, fname, APR_READ, APR_OS_DEFAULT, pool);
+
+ return lcn_file_istream_create (file, pool);
+ }
+ default:
+ abort ();
+ }
+}
+
+static void
+cleanup_temp_file (void *which)
+{
+ if (which == USE_FILE)
+ {
+ char *fname = apr_psprintf (p, "temp%d", file_num - 1);
+ apr_file_remove (fname, p);
+ }
+}
+
+static void
+test_read_byte (abts_case *tc, void *which)
+{
+ char buffer[] = { 'a', 's', 'd', 'f' };
+
+ int i;
+
+ lcn_istream_t *ris = open_istream (which, buffer, sizeof (buffer), p);
+
+ for (i = 0; i < sizeof (buffer); ++i)
+ {
+ char b;
+
+ CHK_ERR (lcn_istream_read_byte (ris, &b, p));
+
+ ABTS_INT_EQUAL (tc, buffer[i], b);
+ }
+
+ cleanup_temp_file (which);
+}
+
+static void
+test_read_bytes (abts_case *tc, void *which)
+{
+ char buffer[] = { 'a', 's', 'd', 'f', '1', '2', '3', '4' };
+
+ int i;
+
+ lcn_istream_t *ris = open_istream (which, buffer, sizeof (buffer), p);
+
+ for (i = 0; i < 2; ++i)
+ {
+ char b[4];
+
+ CHK_ERR (lcn_istream_read_bytes (ris, b, sizeof (b), p));
+
+ ABTS_INT_EQUAL (tc, buffer[i * 4 + 0], b[0]);
+ ABTS_INT_EQUAL (tc, buffer[i * 4 + 1], b[1]);
+ ABTS_INT_EQUAL (tc, buffer[i * 4 + 2], b[2]);
+ ABTS_INT_EQUAL (tc, buffer[i * 4 + 3], b[3]);
+ }
+
+ cleanup_temp_file (which);
+}
+
+static void
+test_read_int (abts_case *tc, void *which)
+{
+ apr_uint32_t end[] = { 0, 10, 2000, 198410, 16909060, 4294967295U };
+
+ unsigned char start[] = { 0, 0, 0, 0,
+ 0, 0, 0, 10,
+ 0, 0, 7, 208,
+ 0, 3, 7, 10,
+ 1, 2, 3, 4,
+ 255, 255, 255, 255 };
+ int i;
+
+ lcn_istream_t *ris = open_istream (which, start, sizeof (start), p);
+
+ for (i = 0; i < (sizeof (end) / sizeof (end[0])); ++i)
+ {
+ apr_uint32_t tmp = 0;
+
+ CHK_ERR (lcn_istream_read_int (ris, &tmp, p));
+
+ ABTS_INT_EQUAL (tc, end[i], tmp);
+ }
+
+ cleanup_temp_file (which);
+}
+
+static void
+test_read_vint (abts_case *tc, void *which)
+{
+ char start[] = { 0,
+ 1,
+ 2,
+ 127,
+ 128, 1,
+ 129, 1,
+ 130, 1,
+ 255, 127,
+ 128, 128, 1,
+ 129, 128, 1 };
+
+ apr_uint32_t end[] = { 0, 1, 2, 127, 128, 129, 130, 16383, 16384, 16385 };
+
+ int i;
+
+ lcn_istream_t *ris = open_istream (which, start, sizeof (start), p);
+
+ for (i = 0; i < (sizeof (end) / sizeof (end[0])); ++i)
+ {
+ apr_uint32_t tmp = 0;
+
+ CHK_ERR (lcn_istream_read_vint (ris, &tmp, p));
+
+ ABTS_INT_EQUAL (tc, end[i], tmp);
+ }
+
+ cleanup_temp_file (which);
+}
+
+static void
+test_read_long (abts_case *tc, void *which)
+{
+ apr_uint64_t end[] = { 0,
+ 10,
+ 2000,
+ 198410,
+ 16909060,
+ 4294967295U,
+ 4294967296ULL };
+
+ unsigned char start[] = { 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 10,
+ 0, 0, 0, 0, 0, 0, 7, 208,
+ 0, 0, 0, 0, 0, 3, 7, 10,
+ 0, 0, 0, 0, 1, 2, 3, 4,
+ 0, 0, 0, 0, 255, 255, 255, 255,
+ 0, 0, 0, 1, 0, 0, 0, 0 };
+ int i;
+
+ lcn_istream_t *ris = open_istream (which, start, sizeof (start), p);
+
+ for (i = 0; i < (sizeof (end) / sizeof (end[0])); ++i)
+ {
+ apr_uint64_t tmp = 0;
+
+ CHK_ERR (lcn_istream_read_long (ris, &tmp, p));
+
+ ABTS_INT_EQUAL (tc, end[i], tmp);
+ }
+
+ cleanup_temp_file (which);
+}
+
+static void
+test_read_vlong (abts_case *tc, void *which)
+{
+ char start[] = { 0,
+ 1,
+ 2,
+ 127,
+ 128, 1,
+ 129, 1,
+ 130, 1,
+ 255, 127,
+ 128, 128, 1,
+ 129, 128, 1,
+ 128, 128, 128, 128, 128, 128, 128, 1,
+ 129, 128, 128, 128, 128, 128, 128, 1 };
+
+ apr_uint64_t end[] = { 0,
+ 1,
+ 2,
+ 127,
+ 128,
+ 129,
+ 130,
+ 16383,
+ 16384,
+ 16385,
+ 562949953421312ULL,
+ 562949953421313ULL };
+
+ int i;
+
+ lcn_istream_t *ris = open_istream (which, start, sizeof (start), p);
+
+ for (i = 0; i < (sizeof (end) / sizeof (end[0])); ++i)
+ {
+ apr_uint64_t tmp = 0;
+
+ CHK_ERR (lcn_istream_read_vlong (ris, &tmp, p));
+
+ ABTS_INT_EQUAL (tc, end[i], tmp);
+ }
+
+ cleanup_temp_file (which);
+}
+
+static void
+test_read_string (abts_case *tc, void *which)
+{
+ char start[] = { 5, 'h', 'e', 'l', 'l', 'o', 0 };
+ lcn_char_t res[] = { 'h', 'e', 'l', 'l', 'o', 0 };
+ lcn_char_t *str;
+
+ lcn_istream_t *ris = open_istream (which,
+ start,
+ sizeof (start) - 1, /* no 0 */
+ p);
+
+ CHK_ERR (lcn_istream_read_string (ris, &str, p));
+
+ ABTS_INT_EQUAL (tc, memcmp (res, str, 10), 0);
+
+ cleanup_temp_file (which);
+}
+
+static void
+test_seek (abts_case *tc, void *which)
+{
+ char start[] = { 5, 'h', 'e', 'l', 'l', 'o', 0 };
+ char byte;
+
+ lcn_istream_t *ris = open_istream (which, start, sizeof (start), p);
+
+ CHK_ERR (lcn_istream_read_byte (ris, &byte, p));
+
+ CHK_ERR (lcn_istream_seek (ris, 0, p));
+
+ CHK_ERR (lcn_istream_read_byte (ris, &byte, p));
+
+ ABTS_INT_EQUAL (tc, start[0], byte);
+
+ cleanup_temp_file (which);
+}
+
+static void
+test_close (abts_case *tc, void *which)
+{
+ char start[] = { 5, 'h', 'e', 'l', 'l', 'o', 0 };
+
+ lcn_istream_t *ris = open_istream (which, start, sizeof (start), p);
+
+ CHK_ERR (lcn_istream_close (ris, p));
+
+ ABTS_TRUE (tc, 1);
+
+ cleanup_temp_file (which);
+}
+
+static void
+test_length (abts_case *tc, void *which)
+{
+ char start[] = { 5, 'h', 'e', 'l', 'l', 'o', 0 };
+
+ lcn_istream_t *ris = open_istream (which, start, sizeof (start), p);
+
+ apr_size_t length;
+
+ CHK_ERR (lcn_istream_length (ris, &length, p));
+
+ ABTS_INT_EQUAL (tc, sizeof (start), length);
+
+ cleanup_temp_file (which);
+}
+
+static void
+test_offset (abts_case *tc, void *which)
+{
+ char start[] = { 5, 'h', 'e', 'l', 'l', 'o', 0 };
+
+ lcn_istream_t *ris = open_istream (which, start, sizeof (start), p);
+
+ apr_off_t offset = 0;
+ char b;
+
+ CHK_ERR (lcn_istream_offset (ris, &offset, p));
+
+ ABTS_INT_EQUAL (tc, 0, offset);
+
+ CHK_ERR (lcn_istream_read_byte (ris, &b, p));
+
+ CHK_ERR (lcn_istream_offset (ris, &offset, p));
+
+ ABTS_INT_EQUAL (tc, 1, offset);
+
+ cleanup_temp_file (which);
+}
+
+abts_suite *
+test_istream (abts_suite *suite)
+{
+ suite = ADD_SUITE (suite);
+
+ abts_run_test (suite, test_read_byte, USE_RAM);
+ abts_run_test (suite, test_read_bytes, USE_RAM);
+ abts_run_test (suite, test_read_int, USE_RAM);
+ abts_run_test (suite, test_read_vint, USE_RAM);
+ abts_run_test (suite, test_read_long, USE_RAM);
+ abts_run_test (suite, test_read_vlong, USE_RAM);
+ abts_run_test (suite, test_read_string, USE_RAM);
+ abts_run_test (suite, test_seek, USE_RAM);
+ abts_run_test (suite, test_close, USE_RAM);
+ abts_run_test (suite, test_length, USE_RAM);
+ abts_run_test (suite, test_offset, USE_RAM);
+
+ abts_run_test (suite, test_read_byte, USE_FILE);
+ abts_run_test (suite, test_read_bytes, USE_FILE);
+ abts_run_test (suite, test_read_int, USE_FILE);
+ abts_run_test (suite, test_read_vint, USE_FILE);
+ abts_run_test (suite, test_read_long, USE_FILE);
+ abts_run_test (suite, test_read_vlong, USE_FILE);
+ abts_run_test (suite, test_read_string, USE_FILE);
+ abts_run_test (suite, test_seek, USE_FILE);
+ abts_run_test (suite, test_close, USE_FILE);
+ abts_run_test (suite, test_length, USE_FILE);
+ abts_run_test (suite, test_offset, USE_FILE);
+
+ return suite;
+}
Propchange: incubator/lucene4c/trunk/test/util/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sat Feb 26 08:47:57 2005
@@ -0,0 +1,2 @@
+.deps
+.dirstamp
Added: incubator/lucene4c/trunk/test/util/string_test.c
URL:
http://svn.apache.org/viewcvs/incubator/lucene4c/trunk/test/util/string_test.c?view=auto&rev=155552
==============================================================================
--- incubator/lucene4c/trunk/test/util/string_test.c (added)
+++ incubator/lucene4c/trunk/test/util/string_test.c Sat Feb 26 08:47:57 2005
@@ -0,0 +1,80 @@
+/* Copyright 2004-2005 Garrett Rooney
+ *
+ * Licensed 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.
+ */
+
+#include "lcn_types.h"
+
+#include "lcn_tests.h"
+
+#include "abts.h"
+
+static void
+test_strlen (abts_case *tc, void *data)
+{
+ lcn_char_t foo[] = { 'f', 'o', 'o', 0 };
+ lcn_char_t foobar[] = { 'f', 'o', 'o', 'b', 'a', 'r', 0 };
+
+ ABTS_INT_EQUAL (tc, 3, lcn_strlen (foo));
+ ABTS_INT_EQUAL (tc, 6, lcn_strlen (foobar));
+}
+
+static void
+test_strcmp (abts_case *tc, void *data)
+{
+ lcn_char_t foo[] = { 'f', 'o', 'o', 0 };
+ lcn_char_t bar[] = { 'b', 'a', 'r', 0 };
+ lcn_char_t foobar[] = { 'f', 'o', 'o', 'b', 'a', 'r', 0 };
+
+ ABTS_INT_EQUAL (tc, 4, lcn_strcmp (foo, bar));
+ ABTS_INT_EQUAL (tc, -4, lcn_strcmp (bar, foo));
+ ABTS_INT_EQUAL (tc, 0, lcn_strcmp (bar, bar));
+ ABTS_INT_EQUAL (tc, -4, lcn_strcmp (bar, foobar));
+ ABTS_INT_EQUAL (tc, -98, lcn_strcmp (foo, foobar));
+ ABTS_INT_EQUAL (tc, 98, lcn_strcmp (foobar, foo));
+ ABTS_INT_EQUAL (tc, 4, lcn_strcmp (foobar, bar));
+}
+
+static void
+test_to_cstring (abts_case *tc, void *data)
+{
+ lcn_char_t foo[] = { 'f', 'o', 'o', 0 };
+ lcn_char_t bar[] = { 'b', 'a', 'r', 0 };
+ lcn_char_t foobar[] = { 'f', 'o', 'o', 'b', 'a', 'r', 0 };
+
+ char *cstring;
+
+ CHK_ERR (lcn_str_to_cstring (&cstring, foo, p));
+
+ ABTS_STR_EQUAL (tc, "foo", cstring);
+
+ CHK_ERR (lcn_str_to_cstring (&cstring, bar, p));
+
+ ABTS_STR_EQUAL (tc, "bar", cstring);
+
+ CHK_ERR (lcn_str_to_cstring (&cstring, foobar, p));
+
+ ABTS_STR_EQUAL (tc, "foobar", cstring);
+}
+
+abts_suite *
+test_string (abts_suite *suite)
+{
+ suite = ADD_SUITE (suite);
+
+ abts_run_test (suite, test_strlen, NULL);
+ abts_run_test (suite, test_strcmp, NULL);
+ abts_run_test (suite, test_to_cstring, NULL);
+
+ return suite;
+}
Added: incubator/lucene4c/trunk/www/index.xhtml
URL:
http://svn.apache.org/viewcvs/incubator/lucene4c/trunk/www/index.xhtml?view=auto&rev=155552
==============================================================================
--- incubator/lucene4c/trunk/www/index.xhtml (added)
+++ incubator/lucene4c/trunk/www/index.xhtml Sat Feb 26 08:47:57 2005
@@ -0,0 +1,88 @@
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <title>Lucene4c</title>
+ <style type="text/css">
+ body {
+ background: white;
+ margin: 0.5in;
+ font-family: arial,helvetica,sans-serif;
+ }
+ </style>
+ </head>
+ <body>
+ <h1>Lucene4c</h1>
+ <p>
+ The Lucene4c project is an implementation of the <a
+ href="http://jakarta.apache.org/lucene/">Lucene</a> search engine in
+ C, built on top of the <a
+ href="http://apr.apache.org/">Apache Portable Runtime</a>.
+ </p>
+ <p>
+ Unlike some other Lucene ports, Lucene4c does not stick to the API
+ used in the original Java based Lucene when a more idiomatic APR and
+ C API makes more sense. The goal is to remain compatible with the
+ on-disk format used by Java Lucene (currently that of Lucene 1.4.x)
+ but to provide an API that makes sense to programmers used to coding
+ in C with APR.
+ </p>
+ <p>
+ Currently Lucene4c is read-only, and only the lowest level portions
+ of the search engine has been implemented. The goal is to implement
+ the remaining parts of the search side of Lucene4c first, and then
+ to begin work on indexing support. In the meantime the Java Lucene
+ must be used to create the index searched by Lucene4c.
+ </p>
+ <h2>News</h2>
+ <ul>
+ <li>
+ 21 Feb 2005 - Version 0.03 of Lucene4c has been released, adding
+ several higher level interfaces for working with an entire index
+ instead of a single segment, improved error message and algorithms,
+ many bug fixes and most importantly doxygen documentation for the
+ public APIs.
+ </li>
+ <li>
+ 13 Feb 2005 - Version 0.02 of Lucene4c has been released, adding
+ support for the compressed file stream directory format used by
+ current versions of Lucene and fixing many bugs.
+ </li>
+ <li>
+ 26 Dec 2004 - Version 0.01 of Lucene4c has been released, with
+ support for reading many parts of a Lucene 1.4.x segment.
+ </li>
+ </ul>
+ <h2>Downloads</h2>
+ <ul>
+ <li><a href="lucene4c-0.03.tar.gz">lucene4c-0.03.tar.gz</a></li>
+ <li><a href="lucene4c-0.02.tar.gz">lucene4c-0.02.tar.gz</a></li>
+ <li><a href="lucene4c-0.01.tar.gz">lucene4c-0.01.tar.gz</a></li>
+ </ul>
+ <h2>Documentation</h2>
+ <p>
+ There is <a href="apidocs/">API documentation</a> generated via
+ <a href="http://doxygen.org/">Doxygen</a> comments in the public
+ header files.
+ </p>
+ <p>
+ Other than that, you can always "Use the source, Luke". The file
+ <tt>src/cmdline/main.c</tt> contains some good high level use of
+ the APIs and would probably be the best place to start.
+ </p>
+ <h2>Development</h2>
+ <p>
+ Grab the current development version of Lucene4c from its Subversion
+ repository at <tt>svn://rooneg.dyndns.org/dev/lucene4c/trunk</tt>.
+ </p>
+ <p>
+ The project doesn't have a mailing list yet, but if you're interested
+ in contributing please email the author and he'll look into setting
+ one up.
+ </p>
+ <h2>Authors</h2>
+ <ul>
+ <li>
+ <a href="mailto:rooneg at electricjellyfish.net">Garrett Rooney</a>
+ </li>
+ </ul>
+ </body>
+</html>