You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2013/07/17 16:12:43 UTC
[lucy-commits] [23/34] git commit: refs/heads/master - Migrate Lucy unit tests to
IVARS.
Migrate Lucy unit tests to IVARS.
Change all unit tests to access instance vars via an IVARS struct rather than
via `self`.
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/3a3bf226
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/3a3bf226
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/3a3bf226
Branch: refs/heads/master
Commit: 3a3bf226b81d2e6c984c0e0137667949ef9e2c09
Parents: 5d0cc09
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Thu Jul 11 15:12:59 2013 -0700
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Tue Jul 16 16:08:43 2013 -0700
----------------------------------------------------------------------
core/Lucy/Test/Search/TestQueryParser.c | 24 ++++----
core/Lucy/Test/Search/TestQueryParserLogic.c | 15 +++--
core/Lucy/Test/Search/TestQueryParserSyntax.c | 32 +++++-----
core/Lucy/Test/Search/TestSortSpec.c | 9 +--
core/Lucy/Test/Store/MockFileHandle.c | 5 +-
core/Lucy/Test/Store/TestFSFileHandle.c | 15 ++---
core/Lucy/Test/Store/TestIOChunks.c | 9 +--
core/Lucy/Test/Store/TestInStream.c | 43 +++++++------
core/Lucy/Test/Store/TestRAMFileHandle.c | 9 +--
core/Lucy/Test/TestSchema.c | 4 +-
core/Lucy/Test/Util/BBSortEx.c | 72 ++++++++++++----------
core/Lucy/Test/Util/TestMemoryPool.c | 10 +--
12 files changed, 138 insertions(+), 109 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/3a3bf226/core/Lucy/Test/Search/TestQueryParser.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Test/Search/TestQueryParser.c b/core/Lucy/Test/Search/TestQueryParser.c
index eef20e3..8129c74 100644
--- a/core/Lucy/Test/Search/TestQueryParser.c
+++ b/core/Lucy/Test/Search/TestQueryParser.c
@@ -40,39 +40,41 @@ TestQP_new(const char *query_string, Query *tree, Query *expanded,
TestQueryParser*
TestQP_init(TestQueryParser *self, const char *query_string, Query *tree,
Query *expanded, uint32_t num_hits) {
- self->query_string = query_string ? TestUtils_get_cb(query_string) : NULL;
- self->tree = tree ? tree : NULL;
- self->expanded = expanded ? expanded : NULL;
- self->num_hits = num_hits;
+ TestQueryParserIVARS *const ivars = TestQP_IVARS(self);
+ ivars->query_string = query_string ? TestUtils_get_cb(query_string) : NULL;
+ ivars->tree = tree ? tree : NULL;
+ ivars->expanded = expanded ? expanded : NULL;
+ ivars->num_hits = num_hits;
return self;
}
void
TestQP_destroy(TestQueryParser *self) {
- DECREF(self->query_string);
- DECREF(self->tree);
- DECREF(self->expanded);
+ TestQueryParserIVARS *const ivars = TestQP_IVARS(self);
+ DECREF(ivars->query_string);
+ DECREF(ivars->tree);
+ DECREF(ivars->expanded);
SUPER_DESTROY(self, TESTQUERYPARSER);
}
CharBuf*
TestQP_get_query_string(TestQueryParser *self) {
- return self->query_string;
+ return TestQP_IVARS(self)->query_string;
}
Query*
TestQP_get_tree(TestQueryParser *self) {
- return self->tree;
+ return TestQP_IVARS(self)->tree;
}
Query*
TestQP_get_expanded(TestQueryParser *self) {
- return self->expanded;
+ return TestQP_IVARS(self)->expanded;
}
uint32_t
TestQP_get_num_hits(TestQueryParser *self) {
- return self->num_hits;
+ return TestQP_IVARS(self)->num_hits;
}
http://git-wip-us.apache.org/repos/asf/lucy/blob/3a3bf226/core/Lucy/Test/Search/TestQueryParserLogic.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Test/Search/TestQueryParserLogic.c b/core/Lucy/Test/Search/TestQueryParserLogic.c
index 57049e5..22a86c1 100644
--- a/core/Lucy/Test/Search/TestQueryParserLogic.c
+++ b/core/Lucy/Test/Search/TestQueryParserLogic.c
@@ -899,7 +899,8 @@ TestQPLogic_run(TestQueryParserLogic *self, TestBatchRunner *runner) {
// Run logical tests with default boolop of OR.
for (i = 0; logical_test_funcs[i] != NULL; i++) {
Lucy_TestQPLogic_Logical_Test_t test_func = logical_test_funcs[i];
- TestQueryParser *test_case = test_func(BOOLOP_OR);
+ TestQueryParser *test_case_obj = test_func(BOOLOP_OR);
+ TestQueryParserIVARS *test_case = TestQP_IVARS(test_case_obj);
Query *tree = QParser_Tree(or_parser, test_case->query_string);
Query *parsed = QParser_Parse(or_parser, test_case->query_string);
Hits *hits = IxSearcher_Hits(searcher, (Obj*)parsed, 0, 10, NULL);
@@ -911,13 +912,14 @@ TestQPLogic_run(TestQueryParserLogic *self, TestBatchRunner *runner) {
DECREF(hits);
DECREF(parsed);
DECREF(tree);
- DECREF(test_case);
+ DECREF(test_case_obj);
}
// Run logical tests with default boolop of AND.
for (i = 0; logical_test_funcs[i] != NULL; i++) {
Lucy_TestQPLogic_Logical_Test_t test_func = logical_test_funcs[i];
- TestQueryParser *test_case = test_func(BOOLOP_AND);
+ TestQueryParser *test_case_obj = test_func(BOOLOP_AND);
+ TestQueryParserIVARS *test_case = TestQP_IVARS(test_case_obj);
Query *tree = QParser_Tree(and_parser, test_case->query_string);
Query *parsed = QParser_Parse(and_parser, test_case->query_string);
Hits *hits = IxSearcher_Hits(searcher, (Obj*)parsed, 0, 10, NULL);
@@ -929,13 +931,14 @@ TestQPLogic_run(TestQueryParserLogic *self, TestBatchRunner *runner) {
DECREF(hits);
DECREF(parsed);
DECREF(tree);
- DECREF(test_case);
+ DECREF(test_case_obj);
}
// Run tests for QParser_Prune().
for (i = 0; prune_test_funcs[i] != NULL; i++) {
Lucy_TestQPLogic_Prune_Test_t test_func = prune_test_funcs[i];
- TestQueryParser *test_case = test_func();
+ TestQueryParser *test_case_obj = test_func();
+ TestQueryParserIVARS *test_case = TestQP_IVARS(test_case_obj);
CharBuf *qstring = test_case->tree
? Query_To_String(test_case->tree)
: CB_new_from_trusted_utf8("(NULL)", 6);
@@ -956,7 +959,7 @@ TestQPLogic_run(TestQueryParserLogic *self, TestBatchRunner *runner) {
DECREF(expanded);
DECREF(pruned);
DECREF(qstring);
- DECREF(test_case);
+ DECREF(test_case_obj);
}
DECREF(and_parser);
http://git-wip-us.apache.org/repos/asf/lucy/blob/3a3bf226/core/Lucy/Test/Search/TestQueryParserSyntax.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Test/Search/TestQueryParserSyntax.c b/core/Lucy/Test/Search/TestQueryParserSyntax.c
index b0baf15..47dff21 100644
--- a/core/Lucy/Test/Search/TestQueryParserSyntax.c
+++ b/core/Lucy/Test/Search/TestQueryParserSyntax.c
@@ -398,17 +398,18 @@ test_query_parser_syntax(TestBatchRunner *runner) {
for (uint32_t i = 0; leaf_test_funcs[i] != NULL; i++) {
Lucy_TestQPSyntax_Test_t test_func = leaf_test_funcs[i];
TestQueryParser *test_case = test_func();
- Query *tree = QParser_Tree(qparser, test_case->query_string);
- Query *expanded = QParser_Expand_Leaf(qparser, test_case->tree);
- Query *parsed = QParser_Parse(qparser, test_case->query_string);
+ TestQueryParserIVARS *ivars = TestQP_IVARS(test_case);
+ Query *tree = QParser_Tree(qparser, ivars->query_string);
+ Query *expanded = QParser_Expand_Leaf(qparser, ivars->tree);
+ Query *parsed = QParser_Parse(qparser, ivars->query_string);
Hits *hits = IxSearcher_Hits(searcher, (Obj*)parsed, 0, 10, NULL);
- TEST_TRUE(runner, Query_Equals(tree, (Obj*)test_case->tree),
- "tree() %s", (char*)CB_Get_Ptr8(test_case->query_string));
- TEST_TRUE(runner, Query_Equals(expanded, (Obj*)test_case->expanded),
- "expand_leaf() %s", (char*)CB_Get_Ptr8(test_case->query_string));
- TEST_INT_EQ(runner, Hits_Total_Hits(hits), test_case->num_hits,
- "hits: %s", (char*)CB_Get_Ptr8(test_case->query_string));
+ TEST_TRUE(runner, Query_Equals(tree, (Obj*)ivars->tree),
+ "tree() %s", (char*)CB_Get_Ptr8(ivars->query_string));
+ TEST_TRUE(runner, Query_Equals(expanded, (Obj*)ivars->expanded),
+ "expand_leaf() %s", (char*)CB_Get_Ptr8(ivars->query_string));
+ TEST_INT_EQ(runner, Hits_Total_Hits(hits), ivars->num_hits,
+ "hits: %s", (char*)CB_Get_Ptr8(ivars->query_string));
DECREF(hits);
DECREF(parsed);
DECREF(expanded);
@@ -419,14 +420,15 @@ test_query_parser_syntax(TestBatchRunner *runner) {
for (uint32_t i = 0; syntax_test_funcs[i] != NULL; i++) {
Lucy_TestQPSyntax_Test_t test_func = syntax_test_funcs[i];
TestQueryParser *test_case = test_func();
- Query *tree = QParser_Tree(qparser, test_case->query_string);
- Query *parsed = QParser_Parse(qparser, test_case->query_string);
+ TestQueryParserIVARS *ivars = TestQP_IVARS(test_case);
+ Query *tree = QParser_Tree(qparser, ivars->query_string);
+ Query *parsed = QParser_Parse(qparser, ivars->query_string);
Hits *hits = IxSearcher_Hits(searcher, (Obj*)parsed, 0, 10, NULL);
- TEST_TRUE(runner, Query_Equals(tree, (Obj*)test_case->tree),
- "tree() %s", (char*)CB_Get_Ptr8(test_case->query_string));
- TEST_INT_EQ(runner, Hits_Total_Hits(hits), test_case->num_hits,
- "hits: %s", (char*)CB_Get_Ptr8(test_case->query_string));
+ TEST_TRUE(runner, Query_Equals(tree, (Obj*)ivars->tree),
+ "tree() %s", (char*)CB_Get_Ptr8(ivars->query_string));
+ TEST_INT_EQ(runner, Hits_Total_Hits(hits), ivars->num_hits,
+ "hits: %s", (char*)CB_Get_Ptr8(ivars->query_string));
DECREF(hits);
DECREF(parsed);
DECREF(tree);
http://git-wip-us.apache.org/repos/asf/lucy/blob/3a3bf226/core/Lucy/Test/Search/TestSortSpec.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Test/Search/TestSortSpec.c b/core/Lucy/Test/Search/TestSortSpec.c
index 841e9ba..990ac9d 100644
--- a/core/Lucy/Test/Search/TestSortSpec.c
+++ b/core/Lucy/Test/Search/TestSortSpec.c
@@ -154,10 +154,11 @@ TestReverseType*
TestReverseType_init2(TestReverseType *self, float boost, bool indexed,
bool stored, bool sortable) {
FType_init((FieldType*)self);
- self->boost = boost;
- self->indexed = indexed;
- self->stored = stored;
- self->sortable = sortable;
+ TestReverseTypeIVARS *const ivars = TestReverseType_IVARS(self);
+ ivars->boost = boost;
+ ivars->indexed = indexed;
+ ivars->stored = stored;
+ ivars->sortable = sortable;
return self;
}
http://git-wip-us.apache.org/repos/asf/lucy/blob/3a3bf226/core/Lucy/Test/Store/MockFileHandle.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Test/Store/MockFileHandle.c b/core/Lucy/Test/Store/MockFileHandle.c
index 3e3ba04..d4a203d 100644
--- a/core/Lucy/Test/Store/MockFileHandle.c
+++ b/core/Lucy/Test/Store/MockFileHandle.c
@@ -32,7 +32,8 @@ MockFileHandle*
MockFileHandle_init(MockFileHandle *self, const CharBuf *path,
int64_t length) {
FH_do_open((FileHandle*)self, path, 0);
- self->len = length;
+ MockFileHandleIVARS *const ivars = MockFileHandle_IVARS(self);
+ ivars->len = length;
return self;
}
@@ -53,7 +54,7 @@ MockFileHandle_release_window(MockFileHandle *self, FileWindow *window) {
int64_t
MockFileHandle_length(MockFileHandle *self) {
- return self->len;
+ return MockFileHandle_IVARS(self)->len;
}
bool
http://git-wip-us.apache.org/repos/asf/lucy/blob/3a3bf226/core/Lucy/Test/Store/TestFSFileHandle.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Test/Store/TestFSFileHandle.c b/core/Lucy/Test/Store/TestFSFileHandle.c
index d9ab78e..fe4f5fd 100644
--- a/core/Lucy/Test/Store/TestFSFileHandle.c
+++ b/core/Lucy/Test/Store/TestFSFileHandle.c
@@ -180,14 +180,14 @@ test_Close(TestBatchRunner *runner) {
SKIP(runner, "LUCY-155");
SKIP(runner, "LUCY-155");
#else
- int saved_fd = fh->fd;
- fh->fd = -1;
+ int saved_fd = FSFH_IVARS(fh)->fd;
+ FSFH_IVARS(fh)->fd = -1;
Err_set_error(NULL);
bool result = FSFH_Close(fh);
TEST_FALSE(runner, result, "Failed Close() returns false");
TEST_TRUE(runner, Err_get_error() != NULL,
"Failed Close() sets Err_error");
- fh->fd = saved_fd;
+ FSFH_IVARS(fh)->fd = saved_fd;
#endif /* _MSC_VER */
DECREF(fh);
@@ -203,6 +203,7 @@ test_Window(TestBatchRunner *runner) {
CharBuf *test_filename = (CharBuf*)ZCB_WRAP_STR("_fstest", 7);
FSFileHandle *fh;
FileWindow *window = FileWindow_new();
+ FileWindowIVARS *const window_ivars = FileWindow_IVARS(window);
uint32_t i;
remove((char*)CB_Get_Ptr8(test_filename));
@@ -233,14 +234,14 @@ test_Window(TestBatchRunner *runner) {
TEST_TRUE(runner, FSFH_Window(fh, window, 1021, 2),
"Window() returns true");
TEST_TRUE(runner,
- strncmp(window->buf - window->offset + 1021, "oo", 2) == 0,
+ strncmp(window_ivars->buf - window_ivars->offset + 1021, "oo", 2) == 0,
"Window()");
TEST_TRUE(runner, FSFH_Release_Window(fh, window),
"Release_Window() returns true");
- TEST_TRUE(runner, window->buf == NULL, "Release_Window() resets buf");
- TEST_TRUE(runner, window->offset == 0, "Release_Window() resets offset");
- TEST_TRUE(runner, window->len == 0, "Release_Window() resets len");
+ TEST_TRUE(runner, window_ivars->buf == NULL, "Release_Window() resets buf");
+ TEST_TRUE(runner, window_ivars->offset == 0, "Release_Window() resets offset");
+ TEST_TRUE(runner, window_ivars->len == 0, "Release_Window() resets len");
DECREF(window);
DECREF(fh);
http://git-wip-us.apache.org/repos/asf/lucy/blob/3a3bf226/core/Lucy/Test/Store/TestIOChunks.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Test/Store/TestIOChunks.c b/core/Lucy/Test/Store/TestIOChunks.c
index fe2fc61..7381b7e 100644
--- a/core/Lucy/Test/Store/TestIOChunks.c
+++ b/core/Lucy/Test/Store/TestIOChunks.c
@@ -86,24 +86,25 @@ test_Buf(TestBatchRunner *runner) {
OutStream_Close(outstream);
instream = InStream_open((Obj*)file);
+ InStreamIVARS *const ivars = InStream_IVARS(instream);
buf = InStream_Buf(instream, 5);
- TEST_INT_EQ(runner, instream->limit - buf, IO_STREAM_BUF_SIZE,
+ TEST_INT_EQ(runner, ivars->limit - buf, IO_STREAM_BUF_SIZE,
"Small request bumped up");
buf += IO_STREAM_BUF_SIZE - 10; // 10 bytes left in buffer.
InStream_Advance_Buf(instream, buf);
buf = InStream_Buf(instream, 10);
- TEST_INT_EQ(runner, instream->limit - buf, 10,
+ TEST_INT_EQ(runner, ivars->limit - buf, 10,
"Exact request doesn't trigger refill");
buf = InStream_Buf(instream, 11);
- TEST_INT_EQ(runner, instream->limit - buf, IO_STREAM_BUF_SIZE,
+ TEST_INT_EQ(runner, ivars->limit - buf, IO_STREAM_BUF_SIZE,
"Requesting over limit triggers refill");
int64_t expected = InStream_Length(instream) - InStream_Tell(instream);
char *buff = InStream_Buf(instream, 100000);
- int64_t got = PTR_TO_I64(instream->limit) - PTR_TO_I64(buff);
+ int64_t got = PTR_TO_I64(ivars->limit) - PTR_TO_I64(buff);
TEST_TRUE(runner, got == expected,
"Requests greater than file size get pared down");
http://git-wip-us.apache.org/repos/asf/lucy/blob/3a3bf226/core/Lucy/Test/Store/TestInStream.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Test/Store/TestInStream.c b/core/Lucy/Test/Store/TestInStream.c
index a09df9f..cc5ef78 100644
--- a/core/Lucy/Test/Store/TestInStream.c
+++ b/core/Lucy/Test/Store/TestInStream.c
@@ -43,6 +43,7 @@ test_refill(TestBatchRunner *runner) {
OutStream *outstream = OutStream_open((Obj*)file);
InStream *instream;
char scratch[5];
+ InStreamIVARS *ivars;
for (int32_t i = 0; i < 1023; i++) {
OutStream_Write_U8(outstream, 'x');
@@ -52,36 +53,41 @@ test_refill(TestBatchRunner *runner) {
OutStream_Close(outstream);
instream = InStream_open((Obj*)file);
+ ivars = InStream_IVARS(instream);
InStream_Refill(instream);
- TEST_INT_EQ(runner, instream->limit - instream->buf, IO_STREAM_BUF_SIZE,
+ TEST_INT_EQ(runner, ivars->limit - ivars->buf, IO_STREAM_BUF_SIZE,
"Refill");
TEST_INT_EQ(runner, (long)InStream_Tell(instream), 0,
"Correct file pos after standing-start Refill()");
DECREF(instream);
instream = InStream_open((Obj*)file);
+ ivars = InStream_IVARS(instream);
InStream_Fill(instream, 30);
- TEST_INT_EQ(runner, instream->limit - instream->buf, 30, "Fill()");
+ TEST_INT_EQ(runner, ivars->limit - ivars->buf, 30, "Fill()");
TEST_INT_EQ(runner, (long)InStream_Tell(instream), 0,
"Correct file pos after standing-start Fill()");
DECREF(instream);
instream = InStream_open((Obj*)file);
+ ivars = InStream_IVARS(instream);
InStream_Read_Bytes(instream, scratch, 5);
- TEST_INT_EQ(runner, instream->limit - instream->buf,
+ TEST_INT_EQ(runner, ivars->limit - ivars->buf,
IO_STREAM_BUF_SIZE - 5, "small read triggers refill");
DECREF(instream);
instream = InStream_open((Obj*)file);
+ ivars = InStream_IVARS(instream);
TEST_INT_EQ(runner, InStream_Read_U8(instream), 'x', "Read_U8");
InStream_Seek(instream, 1023);
- TEST_INT_EQ(runner, (long)instream->window->offset, 0,
+ TEST_INT_EQ(runner, (long)FileWindow_IVARS(ivars->window)->offset, 0,
"no unnecessary refill on Seek");
TEST_INT_EQ(runner, (long)InStream_Tell(instream), 1023, "Seek/Tell");
TEST_INT_EQ(runner, InStream_Read_U8(instream), 'y',
"correct data after in-buffer Seek()");
TEST_INT_EQ(runner, InStream_Read_U8(instream), 'z', "automatic Refill");
- TEST_TRUE(runner, (instream->window->offset != 0), "refilled");
+ TEST_TRUE(runner, (FileWindow_IVARS(ivars->window)->offset != 0),
+ "refilled");
DECREF(instream);
DECREF(outstream);
@@ -144,7 +150,7 @@ test_Close(TestBatchRunner *runner) {
RAMFile *file = RAMFile_new(NULL, false);
InStream *instream = InStream_open((Obj*)file);
InStream_Close(instream);
- TEST_TRUE(runner, instream->file_handle == NULL,
+ TEST_TRUE(runner, InStream_IVARS(instream)->file_handle == NULL,
"Close decrements FileHandle's refcount");
DECREF(instream);
DECREF(file);
@@ -158,49 +164,50 @@ test_Seek_and_Tell(TestBatchRunner *runner) {
int64_t gb12 = gb1 * 12;
FileHandle *fh = (FileHandle*)MockFileHandle_new(NULL, gb12);
InStream *instream = InStream_open((Obj*)fh);
+ InStreamIVARS *const ivars = InStream_IVARS(instream);
InStream_Buf(instream, 10000);
- TEST_TRUE(runner, instream->limit == ((char*)NULL) + 10000,
+ TEST_TRUE(runner, ivars->limit == ((char*)NULL) + 10000,
"InStream_Buf sets limit");
InStream_Seek(instream, gb6);
TEST_TRUE(runner, InStream_Tell(instream) == gb6,
"Tell after seek forwards outside buffer");
- TEST_TRUE(runner, instream->buf == NULL,
+ TEST_TRUE(runner, ivars->buf == NULL,
"Seek forwards outside buffer sets buf to NULL");
- TEST_TRUE(runner, instream->limit == NULL,
+ TEST_TRUE(runner, ivars->limit == NULL,
"Seek forwards outside buffer sets limit to NULL");
- TEST_TRUE(runner, instream->window->offset == gb6,
+ TEST_TRUE(runner, FileWindow_IVARS(ivars->window)->offset == gb6,
"Seek forwards outside buffer tracks pos in window offset");
InStream_Buf(instream, (size_t)gb1);
- TEST_TRUE(runner, instream->limit == ((char*)NULL) + gb1,
+ TEST_TRUE(runner, ivars->limit == ((char*)NULL) + gb1,
"InStream_Buf sets limit");
InStream_Seek(instream, gb6 + 10);
TEST_TRUE(runner, InStream_Tell(instream) == gb6 + 10,
"Tell after seek forwards within buffer");
- TEST_TRUE(runner, instream->buf == ((char*)NULL) + 10,
+ TEST_TRUE(runner, ivars->buf == ((char*)NULL) + 10,
"Seek within buffer sets buf");
- TEST_TRUE(runner, instream->limit == ((char*)NULL) + gb1,
+ TEST_TRUE(runner, ivars->limit == ((char*)NULL) + gb1,
"Seek within buffer leaves limit alone");
InStream_Seek(instream, gb6 + 1);
TEST_TRUE(runner, InStream_Tell(instream) == gb6 + 1,
"Tell after seek backwards within buffer");
- TEST_TRUE(runner, instream->buf == ((char*)NULL) + 1,
+ TEST_TRUE(runner, ivars->buf == ((char*)NULL) + 1,
"Seek backwards within buffer sets buf");
- TEST_TRUE(runner, instream->limit == ((char*)NULL) + gb1,
+ TEST_TRUE(runner, ivars->limit == ((char*)NULL) + gb1,
"Seek backwards within buffer leaves limit alone");
InStream_Seek(instream, gb3);
TEST_TRUE(runner, InStream_Tell(instream) == gb3,
"Tell after seek backwards outside buffer");
- TEST_TRUE(runner, instream->buf == NULL,
+ TEST_TRUE(runner, ivars->buf == NULL,
"Seek backwards outside buffer sets buf to NULL");
- TEST_TRUE(runner, instream->limit == NULL,
+ TEST_TRUE(runner, ivars->limit == NULL,
"Seek backwards outside buffer sets limit to NULL");
- TEST_TRUE(runner, instream->window->offset == gb3,
+ TEST_TRUE(runner, FileWindow_IVARS(ivars->window)->offset == gb3,
"Seek backwards outside buffer tracks pos in window offset");
DECREF(instream);
http://git-wip-us.apache.org/repos/asf/lucy/blob/3a3bf226/core/Lucy/Test/Store/TestRAMFileHandle.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Test/Store/TestRAMFileHandle.c b/core/Lucy/Test/Store/TestRAMFileHandle.c
index 4a4bfb5..47b0d9b 100644
--- a/core/Lucy/Test/Store/TestRAMFileHandle.c
+++ b/core/Lucy/Test/Store/TestRAMFileHandle.c
@@ -126,6 +126,7 @@ test_Window(TestBatchRunner *runner) {
RAMFile *file = RAMFile_new(NULL, false);
RAMFileHandle *fh = RAMFH_open(NULL, FH_WRITE_ONLY, file);
FileWindow *window = FileWindow_new();
+ FileWindowIVARS *const window_ivars = FileWindow_IVARS(window);
for (uint32_t i = 0; i < 1024; i++) {
RAMFH_Write(fh, "foo ", 4);
@@ -150,13 +151,13 @@ test_Window(TestBatchRunner *runner) {
TEST_TRUE(runner, RAMFH_Window(fh, window, 1021, 2),
"Window() returns true");
- TEST_TRUE(runner, strncmp(window->buf, "oo", 2) == 0, "Window()");
+ TEST_TRUE(runner, strncmp(window_ivars->buf, "oo", 2) == 0, "Window()");
TEST_TRUE(runner, RAMFH_Release_Window(fh, window),
"Release_Window() returns true");
- TEST_TRUE(runner, window->buf == NULL, "Release_Window() resets buf");
- TEST_TRUE(runner, window->offset == 0, "Release_Window() resets offset");
- TEST_TRUE(runner, window->len == 0, "Release_Window() resets len");
+ TEST_TRUE(runner, window_ivars->buf == NULL, "Release_Window() resets buf");
+ TEST_TRUE(runner, window_ivars->offset == 0, "Release_Window() resets offset");
+ TEST_TRUE(runner, window_ivars->len == 0, "Release_Window() resets len");
DECREF(window);
DECREF(fh);
http://git-wip-us.apache.org/repos/asf/lucy/blob/3a3bf226/core/Lucy/Test/TestSchema.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Test/TestSchema.c b/core/Lucy/Test/TestSchema.c
index 6dcb80e..2507bfb 100644
--- a/core/Lucy/Test/TestSchema.c
+++ b/core/Lucy/Test/TestSchema.c
@@ -73,8 +73,8 @@ test_Equals(TestBatchRunner *runner) {
TEST_FALSE(runner, TestSchema_Equals(schema, (Obj*)spec_differs),
"Equals spoiled by differing FieldType");
- DECREF(arch_differs->arch);
- arch_differs->arch = Arch_new();
+ DECREF(TestSchema_IVARS(arch_differs)->arch);
+ TestSchema_IVARS(arch_differs)->arch = Arch_new();
TEST_FALSE(runner, TestSchema_Equals(schema, (Obj*)arch_differs),
"Equals spoiled by differing Architecture");
http://git-wip-us.apache.org/repos/asf/lucy/blob/3a3bf226/core/Lucy/Test/Util/BBSortEx.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Test/Util/BBSortEx.c b/core/Lucy/Test/Util/BBSortEx.c
index cdff551..0e17b42 100644
--- a/core/Lucy/Test/Util/BBSortEx.c
+++ b/core/Lucy/Test/Util/BBSortEx.c
@@ -34,26 +34,29 @@ BBSortEx_new(uint32_t mem_threshold, VArray *external) {
BBSortEx*
BBSortEx_init(BBSortEx *self, uint32_t mem_threshold, VArray *external) {
SortEx_init((SortExternal*)self, sizeof(Obj*));
- self->external_tick = 0;
- self->external = (VArray*)INCREF(external);
- self->mem_consumed = 0;
+ BBSortExIVARS *const ivars = BBSortEx_IVARS(self);
+ ivars->external_tick = 0;
+ ivars->external = (VArray*)INCREF(external);
+ ivars->mem_consumed = 0;
BBSortEx_Set_Mem_Thresh(self, mem_threshold);
return self;
}
void
BBSortEx_destroy(BBSortEx *self) {
- DECREF(self->external);
+ BBSortExIVARS *const ivars = BBSortEx_IVARS(self);
+ DECREF(ivars->external);
SUPER_DESTROY(self, BBSORTEX);
}
void
BBSortEx_clear_cache(BBSortEx *self) {
- Obj **const cache = (Obj**)self->cache;
- for (uint32_t i = self->cache_tick, max = self->cache_max; i < max; i++) {
+ BBSortExIVARS *const ivars = BBSortEx_IVARS(self);
+ Obj **const cache = (Obj**)ivars->cache;
+ for (uint32_t i = ivars->cache_tick, max = ivars->cache_max; i < max; i++) {
DECREF(cache[i]);
}
- self->mem_consumed = 0;
+ ivars->mem_consumed = 0;
BBSortEx_Clear_Cache_t super_clear_cache
= SUPER_METHOD_PTR(BBSORTEX, TestLucy_BBSortEx_Clear_Cache);
super_clear_cache(self);
@@ -61,22 +64,24 @@ BBSortEx_clear_cache(BBSortEx *self) {
void
BBSortEx_feed(BBSortEx *self, void *data) {
+ BBSortExIVARS *const ivars = BBSortEx_IVARS(self);
BBSortEx_Feed_t super_feed
= SUPER_METHOD_PTR(BBSORTEX, TestLucy_BBSortEx_Feed);
super_feed(self, data);
// Flush() if necessary.
ByteBuf *bytebuf = (ByteBuf*)CERTIFY(*(ByteBuf**)data, BYTEBUF);
- self->mem_consumed += BB_Get_Size(bytebuf);
- if (self->mem_consumed >= self->mem_thresh) {
+ ivars->mem_consumed += BB_Get_Size(bytebuf);
+ if (ivars->mem_consumed >= ivars->mem_thresh) {
BBSortEx_Flush(self);
}
}
void
BBSortEx_flush(BBSortEx *self) {
- uint32_t cache_count = self->cache_max - self->cache_tick;
- Obj **cache = (Obj**)self->cache;
+ BBSortExIVARS *const ivars = BBSortEx_IVARS(self);
+ uint32_t cache_count = ivars->cache_max - ivars->cache_tick;
+ Obj **cache = (Obj**)ivars->cache;
VArray *elems;
if (!cache_count) { return; }
@@ -84,7 +89,7 @@ BBSortEx_flush(BBSortEx *self) {
// Sort, then create a new run.
BBSortEx_Sort_Cache(self);
- for (uint32_t i = self->cache_tick; i < self->cache_max; i++) {
+ for (uint32_t i = ivars->cache_tick; i < ivars->cache_max; i++) {
VA_Push(elems, cache[i]);
}
BBSortEx *run = BBSortEx_new(0, elems);
@@ -92,71 +97,74 @@ BBSortEx_flush(BBSortEx *self) {
BBSortEx_Add_Run(self, (SortExternal*)run);
// Blank the cache vars.
- self->cache_tick += cache_count;
+ ivars->cache_tick += cache_count;
BBSortEx_Clear_Cache(self);
}
uint32_t
BBSortEx_refill(BBSortEx *self) {
+ BBSortExIVARS *const ivars = BBSortEx_IVARS(self);
+
// Make sure cache is empty, then set cache tick vars.
- if (self->cache_max - self->cache_tick > 0) {
+ if (ivars->cache_max - ivars->cache_tick > 0) {
THROW(ERR, "Refill called but cache contains %u32 items",
- self->cache_max - self->cache_tick);
+ ivars->cache_max - ivars->cache_tick);
}
- self->cache_tick = 0;
- self->cache_max = 0;
+ ivars->cache_tick = 0;
+ ivars->cache_max = 0;
// Read in elements.
while (1) {
ByteBuf *elem = NULL;
- if (self->mem_consumed >= self->mem_thresh) {
- self->mem_consumed = 0;
+ if (ivars->mem_consumed >= ivars->mem_thresh) {
+ ivars->mem_consumed = 0;
break;
}
- else if (self->external_tick >= VA_Get_Size(self->external)) {
+ else if (ivars->external_tick >= VA_Get_Size(ivars->external)) {
break;
}
else {
- elem = (ByteBuf*)VA_Fetch(self->external, self->external_tick);
- self->external_tick++;
+ elem = (ByteBuf*)VA_Fetch(ivars->external, ivars->external_tick);
+ ivars->external_tick++;
// Should be + sizeof(ByteBuf), but that's ok.
- self->mem_consumed += BB_Get_Size(elem);
+ ivars->mem_consumed += BB_Get_Size(elem);
}
- if (self->cache_max == self->cache_cap) {
+ if (ivars->cache_max == ivars->cache_cap) {
BBSortEx_Grow_Cache(self,
- Memory_oversize(self->cache_max + 1, self->width));
+ Memory_oversize(ivars->cache_max + 1, ivars->width));
}
- Obj **cache = (Obj**)self->cache;
- cache[self->cache_max++] = INCREF(elem);
+ Obj **cache = (Obj**)ivars->cache;
+ cache[ivars->cache_max++] = INCREF(elem);
}
- return self->cache_max;
+ return ivars->cache_max;
}
void
BBSortEx_flip(BBSortEx *self) {
+ BBSortExIVARS *const ivars = BBSortEx_IVARS(self);
uint32_t run_mem_thresh = 65536;
BBSortEx_Flush(self);
// Recalculate the approximate mem allowed for each run.
- uint32_t num_runs = VA_Get_Size(self->runs);
+ uint32_t num_runs = VA_Get_Size(ivars->runs);
if (num_runs) {
- run_mem_thresh = (self->mem_thresh / 2) / num_runs;
+ run_mem_thresh = (ivars->mem_thresh / 2) / num_runs;
if (run_mem_thresh < 65536) {
run_mem_thresh = 65536;
}
}
for (uint32_t i = 0; i < num_runs; i++) {
- BBSortEx *run = (BBSortEx*)VA_Fetch(self->runs, i);
+ BBSortEx *run = (BBSortEx*)VA_Fetch(ivars->runs, i);
BBSortEx_Set_Mem_Thresh(run, run_mem_thresh);
}
// OK to fetch now.
- self->flipped = true;
+ ivars->flipped = true;
}
int
http://git-wip-us.apache.org/repos/asf/lucy/blob/3a3bf226/core/Lucy/Test/Util/TestMemoryPool.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Test/Util/TestMemoryPool.c b/core/Lucy/Test/Util/TestMemoryPool.c
index d671467..a13b577 100644
--- a/core/Lucy/Test/Util/TestMemoryPool.c
+++ b/core/Lucy/Test/Util/TestMemoryPool.c
@@ -35,6 +35,8 @@ TestMemPool_run(TestMemoryPool *self, TestBatchRunner *runner) {
MemoryPool *mem_pool = MemPool_new(0);
MemoryPool *other = MemPool_new(0);
+ MemoryPoolIVARS *const ivars = MemPool_IVARS(mem_pool);
+ MemoryPoolIVARS *const ovars = MemPool_IVARS(other);
char *ptr_a, *ptr_b;
ptr_a = (char*)MemPool_Grab(mem_pool, 10);
@@ -44,15 +46,15 @@ TestMemPool_run(TestMemoryPool *self, TestBatchRunner *runner) {
ptr_b = (char*)MemPool_Grab(mem_pool, 10);
TEST_STR_EQ(runner, ptr_b, "foo", "Recycle RAM on Release_All");
- ptr_a = mem_pool->buf;
+ ptr_a = ivars->buf;
MemPool_Resize(mem_pool, ptr_b, 6);
- TEST_TRUE(runner, mem_pool->buf < ptr_a, "Resize");
+ TEST_TRUE(runner, ivars->buf < ptr_a, "Resize");
ptr_a = (char*)MemPool_Grab(other, 20);
MemPool_Release_All(other);
MemPool_Eat(other, mem_pool);
- TEST_TRUE(runner, other->buf == mem_pool->buf, "Eat");
- TEST_TRUE(runner, other->buf != NULL, "Eat");
+ TEST_TRUE(runner, ovars->buf == ivars->buf, "Eat");
+ TEST_TRUE(runner, ovars->buf != NULL, "Eat");
DECREF(mem_pool);
DECREF(other);