From d4c2c6b47e1494760356a8f97dcd5a28781fe21a Mon Sep 17 00:00:00 2001 From: c9s Date: Sun, 18 May 2014 15:00:11 +0800 Subject: [PATCH] Add failing test to issue #10 --- src/edge.c | 6 ++++-- src/node.c | 9 +++++++-- tests/bench_str.csv | 8 ++++++++ tests/check_tree.c | 26 ++++++++++++++++++++++---- 4 files changed, 41 insertions(+), 8 deletions(-) diff --git a/src/edge.c b/src/edge.c index 2d338d8..993fa2a 100644 --- a/src/edge.c +++ b/src/edge.c @@ -45,7 +45,7 @@ void r3_edge_branch(edge *e, int dl) { int s1_len = 0; edge **tmp_edges = e->child->edges; - int tmp_r3_edge_len = e->child->edge_len; + int tmp_edge_len = e->child->edge_len; // the suffix edge of the leaf c1 = r3_tree_create(3); @@ -54,7 +54,7 @@ void r3_edge_branch(edge *e, int dl) { // printf("edge left: %s\n", e1->pattern); // Migrate the child edges to the new edge we just created. - for ( int i = 0 ; i < tmp_r3_edge_len ; i++ ) { + for ( int i = 0 ; i < tmp_edge_len ; i++ ) { r3_node_append_edge(c1, tmp_edges[i]); e->child->edges[i] = NULL; } @@ -65,6 +65,8 @@ void r3_edge_branch(edge *e, int dl) { r3_node_append_edge(e->child, e1); c1->endpoint++; + c1->data = e->child->data; // copy data pointer + e->child->data = NULL; } void r3_edge_free(edge * e) { diff --git a/src/node.c b/src/node.c index 64f7d12..78a766e 100644 --- a/src/node.c +++ b/src/node.c @@ -511,7 +511,12 @@ void r3_tree_dump(node * n, int level) { printf(" regexp:%s", n->combined_pattern); } - printf(" endpoint:%d\n", n->endpoint); + printf(" endpoint:%d", n->endpoint); + + if (n->data) { + printf(" data:%p", n->data); + } + printf("\n"); for ( int i = 0 ; i < n->edge_len ; i++ ) { edge * e = n->edges[i]; @@ -523,7 +528,7 @@ void r3_tree_dump(node * n, int level) { printf("%s", compile_slug(e->pattern, e->pattern_len) ); } - if ( e->child && e->child->edges ) { + if ( e->child ) { r3_tree_dump( e->child, level + 1); } printf("\n"); diff --git a/tests/bench_str.csv b/tests/bench_str.csv index 7dd3751..7161767 100644 --- a/tests/bench_str.csv +++ b/tests/bench_str.csv @@ -171,3 +171,11 @@ 1400394571,8615372.65 1400394590,10964999.94 1400394658,11173658.86 +1400395575,10502560.60 +1400396023,10925991.89 +1400396031,10299722.97 +1400396055,10781849.35 +1400396123,10746610.69 +1400396341,10811271.16 +1400396368,10631572.01 +1400396396,10442039.18 diff --git a/tests/check_tree.c b/tests/check_tree.c index a3098aa..f652c62 100644 --- a/tests/check_tree.c +++ b/tests/check_tree.c @@ -271,11 +271,24 @@ START_TEST(test_pcre_pattern_more) entry = match_entry_createl( "/user/123" , strlen("/user/123") ); node * n = r3_tree_create(10); - r3_tree_insert_pathl(n, "/user", strlen("/user"), NULL, NULL); - r3_tree_insert_pathl(n, "/user/{id:\\d+}", strlen("/user/{id:\\d+}"), NULL, NULL); - r3_tree_insert_pathl(n, "/user2/{id:\\d+}", strlen("/user2/{id:\\d+}"), NULL, NULL); - r3_tree_insert_pathl(n, "/user3/{id:\\d{3}}", strlen("/user3/{id:\\d{3}}"), NULL, NULL); + int var0 = 5; + int var1 = 100; + int var2 = 200; + int var3 = 300; + printf("var0: %p\n", &var0); + printf("var1: %p\n", &var1); + printf("var2: %p\n", &var2); + printf("var3: %p\n", &var3); + + r3_tree_insert_pathl(n, "/user/{id:\\d+}", strlen("/user/{id:\\d+}"), NULL, &var1); + r3_tree_dump(n, 0); + r3_tree_insert_pathl(n, "/user2/{id:\\d+}", strlen("/user2/{id:\\d+}"), NULL, &var2); + r3_tree_dump(n, 0); + r3_tree_insert_pathl(n, "/user3/{id:\\d{3}}", strlen("/user3/{id:\\d{3}}"), NULL, &var3); + r3_tree_dump(n, 0); + r3_tree_insert_pathl(n, "/user", strlen("/user"), NULL, &var0); + r3_tree_dump(n, 0); r3_tree_compile(n); r3_tree_dump(n, 0); node *matched; @@ -284,16 +297,21 @@ START_TEST(test_pcre_pattern_more) fail_if(matched == NULL); ck_assert_int_gt(entry->vars->len, 0); ck_assert_str_eq(entry->vars->tokens[0],"123"); + fail_if( *((int*) matched->data), var1); + /* matched = r3_tree_match(n, "/user2/123", strlen("/user2/123"), entry); fail_if(matched == NULL); ck_assert_int_gt(entry->vars->len, 0); ck_assert_str_eq(entry->vars->tokens[0],"123"); + fail_if( *((int*)matched->data), var2); matched = r3_tree_match(n, "/user3/123", strlen("/user3/123"), entry); fail_if(matched == NULL); ck_assert_int_gt(entry->vars->len, 0); ck_assert_str_eq(entry->vars->tokens[0],"123"); + fail_if( *((int*)matched->data), var3); + */ } END_TEST