Skip to content
Browse files

change TEST_ macros to be more verbose

  • Loading branch information...
1 parent ac9561c commit 8d5086a541f315ffa63ac10901e29fc8a2677d56 @wmorgan committed Apr 14, 2012
Showing with 256 additions and 227 deletions.
  1. +29 −29 test-labels.c
  2. +5 −5 test-queries.c
  3. +96 −96 test-search.c
  4. +62 −62 test-segment.c
  5. +29 −29 test-snippets.c
  6. +2 −2 test-stringmap.c
  7. +1 −1 test-stringpool.c
  8. +2 −2 test-tokenizer.c
  9. +30 −1 test.h
View
58 test-labels.c
@@ -50,42 +50,42 @@ TEST(added_labels_appear_in_search) {
RELAY_ERROR(setup(&index));
RUN_QUERY("three");
- ASSERT(num_results == 3);
+ ASSERT_EQUALS_UINT(3, num_results);
RUN_QUERY("three ~bob");
- ASSERT(num_results == 0);
+ ASSERT_EQUALS_UINT(0, num_results);
RELAY_ERROR(wp_index_add_label(index, "bob", 1));
RUN_QUERY("three ~bob");
- ASSERT(num_results == 1);
+ ASSERT_EQUALS_UINT(1, num_results);
RELAY_ERROR(wp_index_add_label(index, "bob", 1));
RUN_QUERY("three ~bob");
- ASSERT(num_results == 1);
+ ASSERT_EQUALS_UINT(1, num_results);
RELAY_ERROR(wp_index_add_label(index, "bob", 2));
RUN_QUERY("three ~bob");
- ASSERT(num_results == 2);
+ ASSERT_EQUALS_UINT(2, num_results);
RUN_QUERY("four ~bob");
- ASSERT(num_results == 1);
+ ASSERT_EQUALS_UINT(1, num_results);
// now add some in reverse docid order
RELAY_ERROR(wp_index_add_label(index, "potato", 3));
RUN_QUERY("~potato");
- ASSERT(num_results == 1);
+ ASSERT_EQUALS_UINT(1, num_results);
RELAY_ERROR(wp_index_add_label(index, "potato", 2));
RELAY_ERROR(wp_index_add_label(index, "potato", 1));
RUN_QUERY("~potato");
- ASSERT(num_results == 3);
+ ASSERT_EQUALS_UINT(3, num_results);
RUN_QUERY("~potato ~bob");
- ASSERT(num_results == 2);
+ ASSERT_EQUALS_UINT(2, num_results);
RUN_QUERY("~potato -~bob");
- ASSERT(num_results == 1);
- ASSERT(results[0] == 3);
+ ASSERT_EQUALS_UINT(1, num_results);
+ ASSERT_EQUALS_UINT64(3, results[0]);
RELAY_ERROR(shutdown(index));
return NO_ERROR;
@@ -100,18 +100,18 @@ TEST(removing_labels_disappear_from_search) {
RELAY_ERROR(setup(&index));
RUN_QUERY("three");
- ASSERT(num_results == 3);
+ ASSERT_EQUALS_UINT(3, num_results);
RUN_QUERY("three ~bob");
- ASSERT(num_results == 0);
+ ASSERT_EQUALS_UINT(0, num_results);
RELAY_ERROR(wp_index_add_label(index, "bob", 1));
RUN_QUERY("three ~bob");
- ASSERT(num_results == 1);
+ ASSERT_EQUALS_UINT(1, num_results);
RELAY_ERROR(wp_index_remove_label(index, "bob", 1));
RUN_QUERY("three ~bob");
- ASSERT(num_results == 0);
+ ASSERT_EQUALS_UINT(0, num_results);
RELAY_ERROR(shutdown(index));
@@ -131,23 +131,23 @@ TEST(adding_and_removing_labels_are_reflected_in_search) {
RELAY_ERROR(wp_index_add_label(index, "bob", 3));
RUN_QUERY("~bob");
- ASSERT(num_results == 3);
+ ASSERT_EQUALS_UINT(3, num_results);
RELAY_ERROR(wp_index_remove_label(index, "bob", 2));
RUN_QUERY("~bob");
- ASSERT(num_results == 2);
+ ASSERT_EQUALS_UINT(2, num_results);
RELAY_ERROR(wp_index_remove_label(index, "bob", 2));
RUN_QUERY("~bob");
- ASSERT(num_results == 2);
+ ASSERT_EQUALS_UINT(2, num_results);
RELAY_ERROR(wp_index_add_label(index, "bob", 3));
RUN_QUERY("~bob");
- ASSERT(num_results == 2);
+ ASSERT_EQUALS_UINT(2, num_results);
RELAY_ERROR(wp_index_add_label(index, "bob", 2));
RUN_QUERY("~bob");
- ASSERT(num_results == 3);
+ ASSERT_EQUALS_UINT(3, num_results);
RELAY_ERROR(wp_index_add_label(index, "joe", 1));
RELAY_ERROR(wp_index_add_label(index, "joe", 2));
@@ -176,23 +176,23 @@ TEST(adding_and_removing_labels_are_reflected_in_search) {
// and dave is on everyone
RUN_QUERY("~dave");
- ASSERT(num_results == 3);
+ ASSERT_EQUALS_UINT(3, num_results);
RUN_QUERY("~dave ~bob");
- ASSERT(num_results == 1);
- ASSERT(results[0] == 2);
+ ASSERT_EQUALS_UINT(1, num_results);
+ ASSERT_EQUALS_UINT64(2, results[0]);
RUN_QUERY("~dave ~joe");
- ASSERT(num_results == 1);
- ASSERT(results[0] == 3);
+ ASSERT_EQUALS_UINT(1, num_results);
+ ASSERT_EQUALS_UINT64(3, results[0]);
RUN_QUERY("~joe ~bob ~harry");
- ASSERT(num_results == 0);
+ ASSERT_EQUALS_UINT(0, num_results);
RUN_QUERY("~dave -~harry");
- ASSERT(num_results == 2);
- ASSERT(results[0] == 3);
- ASSERT(results[1] == 2);
+ ASSERT_EQUALS_UINT(2, num_results);
+ ASSERT_EQUALS_UINT64(3, results[0]);
+ ASSERT_EQUALS_UINT64(2, results[1]);
RELAY_ERROR(shutdown(index));
return NO_ERROR;
View
10 test-queries.c
@@ -15,13 +15,13 @@ TEST(empty_queries) {
TEST(query_parsing) {
wp_query* q;
RELAY_ERROR(wp_query_parse("i eat mice", "body", &q));
- ASSERT(q->num_children == 3);
- ASSERT(q->type == WP_QUERY_CONJ);
- ASSERT(q->field == NULL);
- ASSERT(q->word == NULL);
+ ASSERT_EQUALS_UINT(3, q->num_children);
+ ASSERT_EQUALS_UINT(WP_QUERY_CONJ, q->type);
+ ASSERT_EQUALS_PTR(NULL, q->field);
+ ASSERT_EQUALS_PTR(NULL, q->word);
ASSERT(q->children != NULL);
- ASSERT(q->children->type == WP_QUERY_TERM);
+ ASSERT_EQUALS_UINT(WP_QUERY_TERM, q->children->type);
ASSERT(!strcmp(q->children->field, "body"));
ASSERT(!strcmp(q->children->word, "i"));
View
192 test-search.c
@@ -50,24 +50,24 @@ TEST(conjunctions) {
RELAY_ERROR(setup(&index));
RUN_QUERY("one two");
- ASSERT(num_results == 1);
- ASSERT(results[0] == 1);
+ ASSERT_EQUALS_UINT(1, num_results);
+ ASSERT_EQUALS_UINT64(1, results[0]);
RUN_QUERY("three five");
- ASSERT(num_results == 1);
- ASSERT(results[0] == 3);
+ ASSERT_EQUALS_UINT(1, num_results);
+ ASSERT_EQUALS_UINT64(3, results[0]);
RUN_QUERY("one five");
- ASSERT(num_results == 0);
+ ASSERT_EQUALS_UINT(0, num_results);
RUN_QUERY("three");
- ASSERT(num_results == 3);
+ ASSERT_EQUALS_UINT(3, num_results);
RUN_QUERY("one");
- ASSERT(num_results == 1);
+ ASSERT_EQUALS_UINT(1, num_results);
RUN_QUERY("one one one");
- ASSERT(num_results == 1);
+ ASSERT_EQUALS_UINT(1, num_results);
RELAY_ERROR(shutdown(index));
return NO_ERROR;
@@ -82,32 +82,32 @@ TEST(disjunctions) {
RELAY_ERROR(setup(&index));
RUN_QUERY("one OR two");
- ASSERT(num_results == 2);
- ASSERT(results[0] == 2);
- ASSERT(results[1] == 1);
+ ASSERT_EQUALS_UINT(2, num_results);
+ ASSERT_EQUALS_UINT64(2, results[0]);
+ ASSERT_EQUALS_UINT64(1, results[1]);
RUN_QUERY("one OR two OR three");
- ASSERT(num_results == 3);
- ASSERT(results[0] == 3);
- ASSERT(results[1] == 2);
- ASSERT(results[2] == 1);
+ ASSERT_EQUALS_UINT(3, num_results);
+ ASSERT_EQUALS_UINT64(3, results[0]);
+ ASSERT_EQUALS_UINT64(2, results[1]);
+ ASSERT_EQUALS_UINT64(1, results[2]);
RUN_QUERY("three OR two OR one");
- ASSERT(num_results == 3);
- ASSERT(results[0] == 3);
- ASSERT(results[1] == 2);
- ASSERT(results[2] == 1);
+ ASSERT_EQUALS_UINT(3, num_results);
+ ASSERT_EQUALS_UINT64(3, results[0]);
+ ASSERT_EQUALS_UINT64(2, results[1]);
+ ASSERT_EQUALS_UINT64(1, results[2]);
RUN_QUERY("one OR one OR one");
- ASSERT(num_results == 1);
- ASSERT(results[0] == 1);
+ ASSERT_EQUALS_UINT(1, num_results);
+ ASSERT_EQUALS_UINT64(1, results[0]);
RUN_QUERY("six OR one");
- ASSERT(num_results == 1);
- ASSERT(results[0] == 1);
+ ASSERT_EQUALS_UINT(1, num_results);
+ ASSERT_EQUALS_UINT64(1, results[0]);
RUN_QUERY("six OR nine");
- ASSERT(num_results == 0);
+ ASSERT_EQUALS_UINT(0, num_results);
RELAY_ERROR(shutdown(index));
return NO_ERROR;
@@ -122,31 +122,31 @@ TEST(phrases) {
RELAY_ERROR(setup(&index));
RUN_QUERY("\"one\"");
- ASSERT(num_results == 1);
- ASSERT(results[0] == 1);
+ ASSERT_EQUALS_UINT(1, num_results);
+ ASSERT_EQUALS_UINT64(1, results[0]);
RUN_QUERY("\"one two\"");
- ASSERT(num_results == 1);
- ASSERT(results[0] == 1);
+ ASSERT_EQUALS_UINT(1, num_results);
+ ASSERT_EQUALS_UINT64(1, results[0]);
RUN_QUERY("\"one two three\"");
- ASSERT(num_results == 1);
- ASSERT(results[0] == 1);
+ ASSERT_EQUALS_UINT(1, num_results);
+ ASSERT_EQUALS_UINT64(1, results[0]);
RUN_QUERY("\"one two three four\"");
- ASSERT(num_results == 0);
+ ASSERT_EQUALS_UINT(0, num_results);
RUN_QUERY("\"three four five\"");
- ASSERT(num_results == 1);
- ASSERT(results[0] == 3);
+ ASSERT_EQUALS_UINT(1, num_results);
+ ASSERT_EQUALS_UINT64(3, results[0]);
RUN_QUERY("\"two three\"");
- ASSERT(num_results == 2);
- ASSERT(results[0] == 2);
- ASSERT(results[1] == 1);
+ ASSERT_EQUALS_UINT(2, num_results);
+ ASSERT_EQUALS_UINT64(2, results[0]);
+ ASSERT_EQUALS_UINT64(1, results[1]);
RUN_QUERY("\"two two\"");
- ASSERT(num_results == 0);
+ ASSERT_EQUALS_UINT(0, num_results);
RELAY_ERROR(shutdown(index));
return NO_ERROR;
@@ -161,31 +161,31 @@ TEST(combinations) {
RELAY_ERROR(setup(&index));
RUN_QUERY("two (three OR one)");
- ASSERT(num_results == 2);
- ASSERT(results[0] == 2);
- ASSERT(results[1] == 1);
+ ASSERT_EQUALS_UINT(2, num_results);
+ ASSERT_EQUALS_UINT64(2, results[0]);
+ ASSERT_EQUALS_UINT64(1, results[1]);
RUN_QUERY("two (three OR four)");
- ASSERT(num_results == 2);
- ASSERT(results[0] == 2);
- ASSERT(results[1] == 1);
+ ASSERT_EQUALS_UINT(2, num_results);
+ ASSERT_EQUALS_UINT64(2, results[0]);
+ ASSERT_EQUALS_UINT64(1, results[1]);
RUN_QUERY("two (three OR four OR five)");
- ASSERT(num_results == 2);
- ASSERT(results[0] == 2);
- ASSERT(results[1] == 1);
+ ASSERT_EQUALS_UINT(2, num_results);
+ ASSERT_EQUALS_UINT64(2, results[0]);
+ ASSERT_EQUALS_UINT64(1, results[1]);
RUN_QUERY("\"two three\" OR four");
- ASSERT(num_results == 3);
+ ASSERT_EQUALS_UINT(3, num_results);
RUN_QUERY("\"two three\" one");
- ASSERT(num_results == 1);
- ASSERT(results[0] == 1);
+ ASSERT_EQUALS_UINT(1, num_results);
+ ASSERT_EQUALS_UINT64(1, results[0]);
RUN_QUERY("three -one");
- ASSERT(num_results == 2);
- ASSERT(results[0] == 3);
- ASSERT(results[1] == 2);
+ ASSERT_EQUALS_UINT(2, num_results);
+ ASSERT_EQUALS_UINT64(3, results[0]);
+ ASSERT_EQUALS_UINT64(2, results[1]);
RELAY_ERROR(shutdown(index));
return NO_ERROR;
@@ -203,19 +203,19 @@ TEST(resumability) {
RELAY_ERROR(wp_query_parse("three", "body", &query));
RELAY_ERROR(wp_index_setup_query(index, query));
RELAY_ERROR(wp_index_run_query(index, query, 1, &num_results, &results[0]));
- ASSERT(num_results == 1);
- ASSERT(results[0] == 3);
+ ASSERT_EQUALS_UINT(1, num_results);
+ ASSERT_EQUALS_UINT64(3, results[0]);
RELAY_ERROR(wp_index_run_query(index, query, 1, &num_results, &results[0]));
- ASSERT(num_results == 1);
- ASSERT(results[0] == 2);
+ ASSERT_EQUALS_UINT(1, num_results);
+ ASSERT_EQUALS_UINT64(2, results[0]);
RELAY_ERROR(wp_index_run_query(index, query, 1, &num_results, &results[0]));
- ASSERT(num_results == 1);
- ASSERT(results[0] == 1);
+ ASSERT_EQUALS_UINT(1, num_results);
+ ASSERT_EQUALS_UINT64(1, results[0]);
RELAY_ERROR(wp_index_run_query(index, query, 1, &num_results, &results[0]));
- ASSERT(num_results == 0);
+ ASSERT_EQUALS_UINT(0, num_results);
RELAY_ERROR(wp_index_teardown_query(index, query));
wp_query_free(query);
@@ -224,11 +224,11 @@ TEST(resumability) {
RELAY_ERROR(wp_query_parse("one", "body", &query));
RELAY_ERROR(wp_index_setup_query(index, query));
RELAY_ERROR(wp_index_run_query(index, query, 1, &num_results, &results[0]));
- ASSERT(num_results == 1);
- ASSERT(results[0] == 1);
+ ASSERT_EQUALS_UINT(1, num_results);
+ ASSERT_EQUALS_UINT64(1, results[0]);
RELAY_ERROR(wp_index_run_query(index, query, 1, &num_results, &results[0]));
- ASSERT(num_results == 0);
+ ASSERT_EQUALS_UINT(0, num_results);
RELAY_ERROR(wp_index_teardown_query(index, query));
wp_query_free(query);
@@ -249,8 +249,8 @@ TEST(phrases_against_multiple_matches_in_doc) {
RELAY_ERROR(add_string(index, "five four five six"));
RUN_QUERY("\"four five six\"");
- ASSERT(num_results == 1);
- ASSERT(results[0] == 4);
+ ASSERT_EQUALS_UINT(1, num_results);
+ ASSERT_EQUALS_UINT64(4, results[0]);
RELAY_ERROR(shutdown(index));
@@ -267,16 +267,16 @@ TEST(queries_against_an_empty_index) {
RELAY_ERROR(wp_index_create(&index, INDEX_PATH));
RUN_QUERY("hello");
- ASSERT(num_results == 0);
+ ASSERT_EQUALS_UINT(0, num_results);
RUN_QUERY("\"four five\"");
- ASSERT(num_results == 0);
+ ASSERT_EQUALS_UINT(0, num_results);
RUN_QUERY("four OR five");
- ASSERT(num_results == 0);
+ ASSERT_EQUALS_UINT(0, num_results);
RUN_QUERY("-hello");
- ASSERT(num_results == 0);
+ ASSERT_EQUALS_UINT(0, num_results);
RELAY_ERROR(shutdown(index));
@@ -311,40 +311,40 @@ TEST(fielded_queries) {
RELAY_ERROR(wp_entry_free(entry));
RUN_QUERY("subject:there");
- ASSERT(num_results == 1);
+ ASSERT_EQUALS_UINT(1, num_results);
RUN_QUERY("body:there");
- ASSERT(num_results == 0);
+ ASSERT_EQUALS_UINT(0, num_results);
RUN_QUERY("there");
- ASSERT(num_results == 0);
+ ASSERT_EQUALS_UINT(0, num_results);
RUN_QUERY("subject:hello");
- ASSERT(num_results == 2);
+ ASSERT_EQUALS_UINT(2, num_results);
RUN_QUERY("body:hello");
- ASSERT(num_results == 0);
+ ASSERT_EQUALS_UINT(0, num_results);
RUN_QUERY("hello");
- ASSERT(num_results == 0);
+ ASSERT_EQUALS_UINT(0, num_results);
RUN_QUERY("subject:vacation body:harry");
- ASSERT(num_results == 1);
+ ASSERT_EQUALS_UINT(1, num_results);
RUN_QUERY("subject:vacation harry");
- ASSERT(num_results == 1);
+ ASSERT_EQUALS_UINT(1, num_results);
RUN_QUERY("subject:vacation -body:harry");
- ASSERT(num_results == 0);
+ ASSERT_EQUALS_UINT(0, num_results);
RUN_QUERY("subject:hello -body:harry");
- ASSERT(num_results == 1);
+ ASSERT_EQUALS_UINT(1, num_results);
RUN_QUERY("subject:hello body:\"i am going\"");
- ASSERT(num_results == 1);
+ ASSERT_EQUALS_UINT(1, num_results);
RUN_QUERY("-subject:hello body:\"i am going\"");
- ASSERT(num_results == 0);
+ ASSERT_EQUALS_UINT(0, num_results);
return NO_ERROR;
}
@@ -360,13 +360,13 @@ TEST(utf8_chars) {
RELAY_ERROR(add_string(index, "hello 我 能 吞下 玻璃 而 不 傷 身體 。")); // pre-tokenized for your pleasure
RUN_QUERY("");
- ASSERT(num_results == 1);
+ ASSERT_EQUALS_UINT(1, num_results);
RUN_QUERY("吞下");
- ASSERT(num_results == 1);
+ ASSERT_EQUALS_UINT(1, num_results);
RUN_QUERY("\"不 傷 身體\"");
- ASSERT(num_results == 1);
+ ASSERT_EQUALS_UINT(1, num_results);
RELAY_ERROR(shutdown(index));
@@ -382,25 +382,25 @@ TEST(every_selector) {
RELAY_ERROR(setup(&index));
RUN_QUERY("*");
- ASSERT(num_results == 3);
- ASSERT(results[0] == 3);
- ASSERT(results[1] == 2);
- ASSERT(results[2] == 1);
+ ASSERT_EQUALS_UINT(3, num_results);
+ ASSERT_EQUALS_UINT64(3, results[0]);
+ ASSERT_EQUALS_UINT64(2, results[1]);
+ ASSERT_EQUALS_UINT64(1, results[2]);
RUN_QUERY("-*");
- ASSERT(num_results == 0);
+ ASSERT_EQUALS_UINT(0, num_results);
RUN_QUERY("* OR four");
- ASSERT(num_results == 3);
- ASSERT(results[0] == 3);
- ASSERT(results[1] == 2);
- ASSERT(results[2] == 1);
+ ASSERT_EQUALS_UINT(3, num_results);
+ ASSERT_EQUALS_UINT64(3, results[0]);
+ ASSERT_EQUALS_UINT64(2, results[1]);
+ ASSERT_EQUALS_UINT64(1, results[2]);
RUN_QUERY("* OR asdfasefs");
- ASSERT(num_results == 3);
- ASSERT(results[0] == 3);
- ASSERT(results[1] == 2);
- ASSERT(results[2] == 1);
+ ASSERT_EQUALS_UINT(3, num_results);
+ ASSERT_EQUALS_UINT64(3, results[0]);
+ ASSERT_EQUALS_UINT64(2, results[1]);
+ ASSERT_EQUALS_UINT64(1, results[2]);
RELAY_ERROR(shutdown(index));
return NO_ERROR;
View
124 test-segment.c
@@ -49,9 +49,9 @@ TEST(initial_state) {
RELAY_ERROR(setup(&segment));
segment_info* si = MMAP_OBJ(segment.seginfo, segment_info);
- ASSERT(si->num_docs == 0);
+ ASSERT_EQUALS_UINT(0, si->num_docs);
postings_region* pr = MMAP_OBJ(segment.postings, postings_region);
- ASSERT(pr->num_postings == 0);
+ ASSERT_EQUALS_UINT(0, pr->num_postings);
RELAY_ERROR(wp_segment_unload(&segment));
return NO_ERROR;
@@ -71,9 +71,9 @@ TEST(adding_a_doc_increments_counts) {
RELAY_ERROR(wp_segment_add_posting(&segment, "body", "there", doc_id, 1, positions));
segment_info* si = MMAP_OBJ(segment.seginfo, segment_info);
- ASSERT(si->num_docs == 1);
+ ASSERT_EQUALS_UINT(1, si->num_docs);
postings_region* pr = MMAP_OBJ(segment.postings, postings_region);
- ASSERT(pr->num_postings == 2);
+ ASSERT_EQUALS_UINT(2, pr->num_postings);
RELAY_ERROR(wp_segment_unload(&segment));
return NO_ERROR;
@@ -96,15 +96,15 @@ TEST(simple_term_queries) {
query = wp_query_new_term("body", "one");
RUN_QUERY(query);
- ASSERT(num_results == 1);
- ASSERT(results[0].doc_id == 1);
+ ASSERT_EQUALS_UINT(1, num_results);
+ ASSERT_EQUALS_UINT(1, results[0].doc_id);
query = wp_query_new_term("body", "two");
RUN_QUERY(query);
- ASSERT(num_results == 2);
- ASSERT(results[0].doc_id == 2);
- ASSERT(results[1].doc_id == 1);
+ ASSERT_EQUALS_UINT(2, num_results);
+ ASSERT_EQUALS_UINT(2, results[0].doc_id);
+ ASSERT_EQUALS_UINT(1, results[1].doc_id);
RELAY_ERROR(wp_segment_unload(&segment));
return NO_ERROR;
@@ -125,22 +125,22 @@ TEST(simple_conjunctive_queries) {
RUN_QUERY(query);
- ASSERT(num_results == 1);
- ASSERT(results[0].doc_id == 1);
+ ASSERT_EQUALS_UINT(1, num_results);
+ ASSERT_EQUALS_UINT(1, results[0].doc_id);
query = wp_query_new_conjunction();
query = wp_query_add(query, wp_query_new_term("body", "four"));
query = wp_query_add(query, wp_query_new_term("body", "two"));
RUN_QUERY(query);
- ASSERT(num_results == 1);
- ASSERT(results[0].doc_id == 2);
+ ASSERT_EQUALS_UINT(1, num_results);
+ ASSERT_EQUALS_UINT(2, results[0].doc_id);
// <empty>
query = wp_query_new_conjunction();
RUN_QUERY(query);
- ASSERT(num_results == 0);
+ ASSERT_EQUALS_UINT(0, num_results);
RELAY_ERROR(wp_segment_unload(&segment));
return NO_ERROR;
@@ -159,30 +159,30 @@ TEST(simple_phrasal_queries) {
query = wp_query_add(query, wp_query_new_term("body", "one"));
query = wp_query_add(query, wp_query_new_term("body", "two"));
RUN_QUERY(query);
- ASSERT(num_results == 1);
- ASSERT(results[0].doc_id == 1);
+ ASSERT_EQUALS_UINT(1, num_results);
+ ASSERT_EQUALS_UINT(1, results[0].doc_id);
query = wp_query_new_phrase();
query = wp_query_add(query, wp_query_new_term("body", "two"));
query = wp_query_add(query, wp_query_new_term("body", "one"));
RUN_QUERY(query);
- ASSERT(num_results == 0);
+ ASSERT_EQUALS_UINT(0, num_results);
query = wp_query_new_phrase();
query = wp_query_add(query, wp_query_new_term("body", "two"));
query = wp_query_add(query, wp_query_new_term("body", "three"));
RUN_QUERY(query);
- ASSERT(num_results == 2);
- ASSERT(results[0].doc_id == 2);
- ASSERT(results[1].doc_id == 1);
+ ASSERT_EQUALS_UINT(2, num_results);
+ ASSERT_EQUALS_UINT(2, results[0].doc_id);
+ ASSERT_EQUALS_UINT(1, results[1].doc_id);
query = wp_query_new_phrase();
query = wp_query_add(query, wp_query_new_term("body", "one"));
query = wp_query_add(query, wp_query_new_term("body", "two"));
query = wp_query_add(query, wp_query_new_term("body", "three"));
RUN_QUERY(query);
- ASSERT(num_results == 1);
- ASSERT(results[0].doc_id == 1);
+ ASSERT_EQUALS_UINT(1, num_results);
+ ASSERT_EQUALS_UINT(1, results[0].doc_id);
RELAY_ERROR(wp_segment_unload(&segment));
return NO_ERROR;
@@ -207,8 +207,8 @@ TEST(segment_conjuction_of_phrase_queries) {
query = wp_query_add(query, subquery);
RUN_QUERY(query);
- ASSERT(num_results == 1);
- ASSERT(results[0].doc_id == 1);
+ ASSERT_EQUALS_UINT(1, num_results);
+ ASSERT_EQUALS_UINT(1, results[0].doc_id);
// "two three" one
subquery = wp_query_new_phrase();
@@ -219,8 +219,8 @@ TEST(segment_conjuction_of_phrase_queries) {
query = wp_query_add(query, wp_query_new_term("body", "one"));
RUN_QUERY(query);
- ASSERT(num_results == 1);
- ASSERT(results[0].doc_id == 1);
+ ASSERT_EQUALS_UINT(1, num_results);
+ ASSERT_EQUALS_UINT(1, results[0].doc_id);
// one "three two"
subquery = wp_query_new_phrase();
@@ -231,7 +231,7 @@ TEST(segment_conjuction_of_phrase_queries) {
query = wp_query_add(query, subquery);
RUN_QUERY(query);
- ASSERT(num_results == 0);
+ ASSERT_EQUALS_UINT(0, num_results);
// two "two three"
subquery = wp_query_new_phrase();
@@ -242,9 +242,9 @@ TEST(segment_conjuction_of_phrase_queries) {
query = wp_query_add(query, subquery);
RUN_QUERY(query);
- ASSERT(num_results == 2);
- ASSERT(results[0].doc_id == 2);
- ASSERT(results[1].doc_id == 1);
+ ASSERT_EQUALS_UINT(2, num_results);
+ ASSERT_EQUALS_UINT(2, results[0].doc_id);
+ ASSERT_EQUALS_UINT(1, results[1].doc_id);
RELAY_ERROR(wp_segment_unload(&segment));
return NO_ERROR;
@@ -269,8 +269,8 @@ TEST(negation_queries) {
query = wp_query_add(query, subquery);
RUN_QUERY(query);
- ASSERT(num_results == 1);
- ASSERT(results[0].doc_id == 1);
+ ASSERT_EQUALS_UINT(1, num_results);
+ ASSERT_EQUALS_UINT(1, results[0].doc_id);
// "two three" one
subquery = wp_query_new_phrase();
@@ -281,8 +281,8 @@ TEST(negation_queries) {
query = wp_query_add(query, wp_query_new_term("body", "one"));
RUN_QUERY(query);
- ASSERT(num_results == 1);
- ASSERT(results[0].doc_id == 1);
+ ASSERT_EQUALS_UINT(1, num_results);
+ ASSERT_EQUALS_UINT(1, results[0].doc_id);
// one "three two"
subquery = wp_query_new_phrase();
@@ -293,7 +293,7 @@ TEST(negation_queries) {
query = wp_query_add(query, subquery);
RUN_QUERY(query);
- ASSERT(num_results == 0);
+ ASSERT_EQUALS_UINT(0, num_results);
// two "two three"
subquery = wp_query_new_phrase();
@@ -304,48 +304,48 @@ TEST(negation_queries) {
query = wp_query_add(query, subquery);
RUN_QUERY(query);
- ASSERT(num_results == 2);
- ASSERT(results[0].doc_id == 2);
- ASSERT(results[1].doc_id == 1);
+ ASSERT_EQUALS_UINT(2, num_results);
+ ASSERT_EQUALS_UINT(2, results[0].doc_id);
+ ASSERT_EQUALS_UINT(1, results[1].doc_id);
// <empty>
query = wp_query_new_conjunction();
RUN_QUERY(query);
- ASSERT(num_results == 0);
+ ASSERT_EQUALS_UINT(0, num_results);
// -one
subquery = wp_query_new_term("body", "one");
query = wp_query_new_negation();
query = wp_query_add(query, subquery);
RUN_QUERY(query);
- ASSERT(num_results == 2);
- ASSERT(results[0].doc_id == 3);
- ASSERT(results[1].doc_id == 2);
+ ASSERT_EQUALS_UINT(2, num_results);
+ ASSERT_EQUALS_UINT(3, results[0].doc_id);
+ ASSERT_EQUALS_UINT(2, results[1].doc_id);
// -two
subquery = wp_query_new_term("body", "two");
query = wp_query_new_negation();
query = wp_query_add(query, subquery);
RUN_QUERY(query);
- ASSERT(num_results == 1);
- ASSERT(results[0].doc_id == 3);
+ ASSERT_EQUALS_UINT(1, num_results);
+ ASSERT_EQUALS_UINT(3, results[0].doc_id);
// -three
subquery = wp_query_new_term("body", "three");
query = wp_query_new_negation();
query = wp_query_add(query, subquery);
RUN_QUERY(query);
- ASSERT(num_results == 0);
+ ASSERT_EQUALS_UINT(0, num_results);
// -potato
subquery = wp_query_new_term("body", "potato");
query = wp_query_new_negation();
query = wp_query_add(query, subquery);
RUN_QUERY(query);
- ASSERT(num_results == 3);
- ASSERT(results[0].doc_id == 3);
- ASSERT(results[1].doc_id == 2);
- ASSERT(results[2].doc_id == 1);
+ ASSERT_EQUALS_UINT(3, num_results);
+ ASSERT_EQUALS_UINT(3, results[0].doc_id);
+ ASSERT_EQUALS_UINT(2, results[1].doc_id);
+ ASSERT_EQUALS_UINT(1, results[2].doc_id);
// -"one two"
subquery = wp_query_new_conjunction();
@@ -354,9 +354,9 @@ TEST(negation_queries) {
query = wp_query_new_negation();
query = wp_query_add(query, subquery);
RUN_QUERY(query);
- ASSERT(num_results == 2);
- ASSERT(results[0].doc_id == 3);
- ASSERT(results[1].doc_id == 2);
+ ASSERT_EQUALS_UINT(2, num_results);
+ ASSERT_EQUALS_UINT(3, results[0].doc_id);
+ ASSERT_EQUALS_UINT(2, results[1].doc_id);
// -(AND one three)
subquery = wp_query_new_conjunction();
@@ -365,9 +365,9 @@ TEST(negation_queries) {
query = wp_query_new_negation();
query = wp_query_add(query, subquery);
RUN_QUERY(query);
- ASSERT(num_results == 2);
- ASSERT(results[0].doc_id == 3);
- ASSERT(results[1].doc_id == 2);
+ ASSERT_EQUALS_UINT(2, num_results);
+ ASSERT_EQUALS_UINT(3, results[0].doc_id);
+ ASSERT_EQUALS_UINT(2, results[1].doc_id);
// -"one three"
subquery = wp_query_new_phrase();
@@ -376,7 +376,7 @@ TEST(negation_queries) {
query = wp_query_new_negation();
query = wp_query_add(query, subquery);
RUN_QUERY(query);
- ASSERT(num_results == 3);
+ ASSERT_EQUALS_UINT(3, num_results);
// (AND -one three)
subquery = wp_query_new_negation();
@@ -385,9 +385,9 @@ TEST(negation_queries) {
query = wp_query_add(query, subquery);
query = wp_query_add(query, wp_query_new_term("body", "three"));
RUN_QUERY(query);
- ASSERT(num_results == 2);
- ASSERT(results[0].doc_id == 3);
- ASSERT(results[1].doc_id == 2);
+ ASSERT_EQUALS_UINT(2, num_results);
+ ASSERT_EQUALS_UINT(3, results[0].doc_id);
+ ASSERT_EQUALS_UINT(2, results[1].doc_id);
// (AND three -one)
subquery = wp_query_new_negation();
@@ -396,9 +396,9 @@ TEST(negation_queries) {
query = wp_query_add(query, wp_query_new_term("body", "three"));
query = wp_query_add(query, subquery);
RUN_QUERY(query);
- ASSERT(num_results == 2);
- ASSERT(results[0].doc_id == 3);
- ASSERT(results[1].doc_id == 2);
+ ASSERT_EQUALS_UINT(2, num_results);
+ ASSERT_EQUALS_UINT(3, results[0].doc_id);
+ ASSERT_EQUALS_UINT(2, results[1].doc_id);
RELAY_ERROR(wp_segment_unload(&segment));
return NO_ERROR;
View
58 test-snippets.c
@@ -22,7 +22,7 @@ TEST(empty_queries) {
RELAY_ERROR(wp_query_parse("", "body", &q));
RELAY_ERROR(wp_snippetize_string(q, "body", text, 10, &num_results, start_offsets, end_offsets));
- ASSERT(num_results == 0);
+ ASSERT_EQUALS_UINT(0, num_results);
return NO_ERROR;
}
@@ -35,10 +35,10 @@ TEST(terms) {
RELAY_ERROR(wp_query_parse("sing", "body", &q));
RELAY_ERROR(wp_snippetize_string(q, "body", text, 10, &num_results, start_offsets, end_offsets));
- ASSERT(num_results == 2);
+ ASSERT_EQUALS_UINT(2, num_results);
- ASSERT(start_offsets[0] == 0);
- ASSERT(end_offsets[0] == 4);
+ ASSERT_EQUALS_UINT(0, start_offsets[0]);
+ ASSERT_EQUALS_UINT(4, end_offsets[0]);
return NO_ERROR;
}
@@ -51,19 +51,19 @@ TEST(conjuctions) {
RELAY_ERROR(wp_query_parse("sing muse", "body", &q));
RELAY_ERROR(wp_snippetize_string(q, "body", text, 10, &num_results, start_offsets, end_offsets));
- ASSERT(num_results == 4);
+ ASSERT_EQUALS_UINT(4, num_results);
- ASSERT(start_offsets[0] == 0);
- ASSERT(end_offsets[0] == 4);
+ ASSERT_EQUALS_UINT(0, start_offsets[0]);
+ ASSERT_EQUALS_UINT(4, end_offsets[0]);
- ASSERT(start_offsets[1] == 23);
- ASSERT(end_offsets[1] == 27);
+ ASSERT_EQUALS_UINT(23, start_offsets[1]);
+ ASSERT_EQUALS_UINT(27, end_offsets[1]);
- ASSERT(start_offsets[2] == 549);
- ASSERT(end_offsets[2] == 553);
+ ASSERT_EQUALS_UINT(549, start_offsets[2]);
+ ASSERT_EQUALS_UINT(553, end_offsets[2]);
- ASSERT(start_offsets[3] == 603);
- ASSERT(end_offsets[3] == 607);
+ ASSERT_EQUALS_UINT(603, start_offsets[3]);
+ ASSERT_EQUALS_UINT(607, end_offsets[3]);
return NO_ERROR;
}
@@ -76,20 +76,20 @@ TEST(disjunctions) {
RELAY_ERROR(wp_query_parse("sing OR muse", "body", &q));
RELAY_ERROR(wp_snippetize_string(q, "body", text, 10, &num_results, start_offsets, end_offsets));
- ASSERT(num_results == 4);
+ ASSERT_EQUALS_UINT(4, num_results);
// same as above
- ASSERT(start_offsets[0] == 0);
- ASSERT(end_offsets[0] == 4);
+ ASSERT_EQUALS_UINT(0, start_offsets[0]);
+ ASSERT_EQUALS_UINT(4, end_offsets[0]);
- ASSERT(start_offsets[1] == 23);
- ASSERT(end_offsets[1] == 27);
+ ASSERT_EQUALS_UINT(23, start_offsets[1]);
+ ASSERT_EQUALS_UINT(27, end_offsets[1]);
- ASSERT(start_offsets[2] == 549);
- ASSERT(end_offsets[2] == 553);
+ ASSERT_EQUALS_UINT(549, start_offsets[2]);
+ ASSERT_EQUALS_UINT(553, end_offsets[2]);
- ASSERT(start_offsets[3] == 603);
- ASSERT(end_offsets[3] == 607);
+ ASSERT_EQUALS_UINT(603, start_offsets[3]);
+ ASSERT_EQUALS_UINT(607, end_offsets[3]);
return NO_ERROR;
}
@@ -102,10 +102,10 @@ TEST(phrases) {
RELAY_ERROR(wp_query_parse("\"sing to me of the man\"", "body", &q));
RELAY_ERROR(wp_snippetize_string(q, "body", text, 10, &num_results, start_offsets, end_offsets));
- ASSERT(num_results == 1);
+ ASSERT_EQUALS_UINT(1, num_results);
- ASSERT(start_offsets[0] == 0);
- ASSERT(end_offsets[0] == 21);
+ ASSERT_EQUALS_UINT(0, start_offsets[0]);
+ ASSERT_EQUALS_UINT(21, end_offsets[0]);
return NO_ERROR;
}
@@ -118,7 +118,7 @@ TEST(negations) {
RELAY_ERROR(wp_query_parse("-sing", "body", &q));
RELAY_ERROR(wp_snippetize_string(q, "body", text, 10, &num_results, start_offsets, end_offsets));
- ASSERT(num_results == 0);
+ ASSERT_EQUALS_UINT(0, num_results);
return NO_ERROR;
}
@@ -133,11 +133,11 @@ TEST(conjunctions_with_negations) {
RELAY_ERROR(wp_snippetize_string(q, "body", text, 10, &num_results, start_offsets, end_offsets));
//printf("got %d results\n", num_results);
- ASSERT(num_results == 1);
+ ASSERT_EQUALS_UINT(1, num_results);
//printf("got %d--%d\n", start_offsets[0], end_offsets[0]);
- ASSERT(start_offsets[0] == 441);
- ASSERT(end_offsets[0] == 449);
+ ASSERT_EQUALS_UINT(441, start_offsets[0]);
+ ASSERT_EQUALS_UINT(449, end_offsets[0]);
return NO_ERROR;
}
View
4 test-stringmap.c
@@ -19,7 +19,7 @@ static map_and_pool* setup() {
TEST(stringmap_initial_state) {
map_and_pool* mp = setup();
- ASSERT(mp->map->n_occupied == 0);
+ ASSERT_EQUALS_UINT(0, mp->map->n_occupied);
ASSERT(!stringmap_needs_bump(mp->map));
free(mp);
@@ -46,7 +46,7 @@ TEST(stringmap_multiple_adds) {
ASSERT(x != (uint32_t)-1);
RELAY_ERROR(stringmap_add(mp->map, mp->pool, "hot potato", &y));
ASSERT(y != (uint32_t)-1);
- ASSERT(x == y);
+ ASSERT_EQUALS_UINT(y, x);
free(mp);
return NO_ERROR;
View
2 test-stringpool.c
@@ -60,7 +60,7 @@ TEST(stringpool_detects_out_of_room) {
}
ret = stringpool_add(p, "12345");
- ASSERT(ret == (uint32_t)-1);
+ ASSERT_EQUALS_UINT((uint32_t)-1, ret);
return NO_ERROR;
}
View
4 test-tokenizer.c
@@ -3,13 +3,13 @@
#define ASSERT_NEXT_WORD(word) { \
int token_type = yylex(scanner); \
- ASSERT(token_type == TOK_WORD); \
+ ASSERT_EQUALS_UINT(TOK_WORD, token_type); \
ASSERT(!strcmp(word, yyget_text(scanner))); \
}
#define ASSERT_DONE { \
int token_type = yylex(scanner); \
- ASSERT(token_type == TOK_DONE); \
+ ASSERT_EQUALS_UINT(TOK_DONE, token_type); \
}
TEST(tokenizes_easy_words) {
View
31 test.h
@@ -1,6 +1,8 @@
#ifndef WP_TEST_H_
#define WP_TEST_H_
+#include <inttypes.h>
+
// whistlepig test header file
// (c) 2011 William Morgan. See COPYING for license terms.
//
@@ -9,7 +11,34 @@
#define ASSERT(x) do { \
(*asserts)++; \
if(!(x)) { \
- printf("-- test failure: (" #x ") is FALSE in %s (%s:%d)\n\n", __PRETTY_FUNCTION__, __FILE__, __LINE__); \
+ printf("-- test failure: (" #x ") is FALSE in %s (%s:%d)\n", __PRETTY_FUNCTION__, __FILE__, __LINE__); \
+ *fail = 1; \
+ return NO_ERROR; \
+ } \
+} while(0)
+
+#define ASSERT_EQUALS_UINT(truth, val) do { \
+ (*asserts)++; \
+ if(val != truth) { \
+ printf("-- test failure: " #val " == %u but should be %u in %s (%s:%d)\n", val, truth, __PRETTY_FUNCTION__, __FILE__, __LINE__); \
+ *fail = 1; \
+ return NO_ERROR; \
+ } \
+} while(0)
+
+#define ASSERT_EQUALS_UINT64(truth, val) do { \
+ (*asserts)++; \
+ if(val != truth) { \
+ printf("-- test failure: " #val " == %" PRIu64 " but should be %u in %s (%s:%d)\n", val, truth, __PRETTY_FUNCTION__, __FILE__, __LINE__); \
+ *fail = 1; \
+ return NO_ERROR; \
+ } \
+} while(0)
+
+#define ASSERT_EQUALS_PTR(truth, val) do { \
+ (*asserts)++; \
+ if(val != truth) { \
+ printf("-- test failure: " #val " == %p but should be %p in %s (%s:%d)\n", val, truth, __PRETTY_FUNCTION__, __FILE__, __LINE__); \
*fail = 1; \
return NO_ERROR; \
} \

0 comments on commit 8d5086a

Please sign in to comment.
Something went wrong with that request. Please try again.