2014-05-16 19:14:09 -04:00
|
|
|
#include "config.h"
|
2014-05-14 12:15:19 -04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <check.h>
|
2014-05-16 06:03:52 -04:00
|
|
|
#include <stdlib.h>
|
2014-05-16 08:22:25 -04:00
|
|
|
#include "r3.h"
|
2014-05-16 18:40:08 -04:00
|
|
|
#include "r3_str.h"
|
2014-05-16 08:22:25 -04:00
|
|
|
#include "str_array.h"
|
2014-05-21 02:59:07 -04:00
|
|
|
#include "zmalloc.h"
|
2014-05-16 19:48:22 -04:00
|
|
|
#include "bench.h"
|
2014-05-14 12:15:19 -04:00
|
|
|
|
2014-05-16 06:03:52 -04:00
|
|
|
|
|
|
|
|
2014-05-15 00:53:48 -04:00
|
|
|
START_TEST (test_ltrim_slash)
|
|
|
|
{
|
|
|
|
fail_if( strcmp( ltrim_slash("/blog") , "blog" ) != 0 );
|
|
|
|
fail_if( strcmp( ltrim_slash("blog") , "blog" ) != 0 );
|
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
2014-05-20 04:18:17 -04:00
|
|
|
START_TEST (test_r3_node_construct_and_free)
|
2014-05-15 01:39:50 -04:00
|
|
|
{
|
2014-05-16 06:57:36 -04:00
|
|
|
node * n = r3_tree_create(10);
|
2014-05-21 06:12:14 -04:00
|
|
|
node * another_tree = r3_tree_create(3);
|
2014-05-16 06:57:36 -04:00
|
|
|
r3_tree_free(n);
|
2014-05-21 06:12:14 -04:00
|
|
|
r3_tree_free(another_tree);
|
2014-05-15 01:39:50 -04:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
2014-05-16 06:57:36 -04:00
|
|
|
START_TEST (test_r3_node_find_edge)
|
2014-05-15 01:39:50 -04:00
|
|
|
{
|
2014-05-16 06:57:36 -04:00
|
|
|
node * n = r3_tree_create(10);
|
2014-05-15 01:39:50 -04:00
|
|
|
|
2014-05-16 06:57:36 -04:00
|
|
|
node * child = r3_tree_create(3);
|
2014-05-15 01:39:50 -04:00
|
|
|
|
2014-05-20 13:50:15 -04:00
|
|
|
fail_if( r3_node_add_child(n, zstrdup("/add") , child) == FALSE );
|
2014-05-15 01:39:50 -04:00
|
|
|
|
2014-05-16 06:57:36 -04:00
|
|
|
fail_if( r3_node_find_edge(n, "/add") == NULL );
|
|
|
|
fail_if( r3_node_find_edge(n, "/bar") != NULL );
|
2014-05-15 01:39:50 -04:00
|
|
|
|
2014-05-16 06:57:36 -04:00
|
|
|
r3_tree_free(n);
|
2014-05-15 01:39:50 -04:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
2014-05-15 00:53:48 -04:00
|
|
|
|
2014-05-16 02:05:51 -04:00
|
|
|
START_TEST (test_compile)
|
2014-05-15 09:17:30 -04:00
|
|
|
{
|
2014-05-16 06:03:52 -04:00
|
|
|
str_array *t;
|
2014-05-16 03:29:25 -04:00
|
|
|
node * n;
|
2014-05-16 06:57:36 -04:00
|
|
|
n = r3_tree_create(10);
|
2014-05-15 09:17:30 -04:00
|
|
|
|
|
|
|
|
2014-05-16 06:03:52 -04:00
|
|
|
node *m;
|
|
|
|
edge *e ;
|
2014-05-15 09:17:30 -04:00
|
|
|
|
2014-05-18 22:12:41 -04:00
|
|
|
r3_tree_insert_path(n, "/zoo", NULL);
|
|
|
|
r3_tree_insert_path(n, "/foo", NULL);
|
|
|
|
r3_tree_insert_path(n, "/bar", NULL);
|
2014-05-16 06:57:36 -04:00
|
|
|
r3_tree_compile(n);
|
2014-05-16 02:05:51 -04:00
|
|
|
fail_if( n->combined_pattern );
|
2014-05-16 06:57:36 -04:00
|
|
|
fail_if( NULL == r3_node_find_edge_str(n, "/", strlen("/") ) );
|
2014-05-15 09:17:30 -04:00
|
|
|
|
2014-05-16 06:03:52 -04:00
|
|
|
#ifdef DEBUG
|
2014-05-16 06:57:36 -04:00
|
|
|
r3_tree_dump(n, 0);
|
2014-05-16 06:03:52 -04:00
|
|
|
#endif
|
|
|
|
|
2014-05-18 22:12:41 -04:00
|
|
|
r3_tree_insert_path(n, "/foo/{id}", NULL);
|
|
|
|
r3_tree_insert_path(n, "/{id}", NULL);
|
2014-05-16 06:57:36 -04:00
|
|
|
r3_tree_compile(n);
|
|
|
|
r3_tree_compile(n); // test double compile
|
|
|
|
r3_tree_dump(n, 0);
|
2014-05-16 07:12:01 -04:00
|
|
|
match_entry * entry;
|
2014-05-16 02:24:00 -04:00
|
|
|
|
2014-05-17 11:54:18 -04:00
|
|
|
entry = match_entry_createl( "foo" , strlen("/foo") );
|
2014-05-18 22:34:48 -04:00
|
|
|
m = r3_tree_matchl( n , "/foo", strlen("/foo"), entry);
|
2014-05-21 06:31:51 -04:00
|
|
|
ck_assert( m );
|
2014-05-16 02:24:00 -04:00
|
|
|
|
2014-05-17 11:54:18 -04:00
|
|
|
entry = match_entry_createl( "/zoo" , strlen("/zoo") );
|
2014-05-18 22:34:48 -04:00
|
|
|
m = r3_tree_matchl( n , "/zoo", strlen("/zoo"), entry);
|
2014-05-21 06:31:51 -04:00
|
|
|
ck_assert( m );
|
2014-05-16 02:24:00 -04:00
|
|
|
|
2014-05-17 11:54:18 -04:00
|
|
|
entry = match_entry_createl( "/bar" , strlen("/bar") );
|
2014-05-18 22:34:48 -04:00
|
|
|
m = r3_tree_matchl( n , "/bar", strlen("/bar"), entry);
|
2014-05-21 06:31:51 -04:00
|
|
|
ck_assert( m );
|
2014-05-16 02:36:48 -04:00
|
|
|
|
2014-05-17 11:54:18 -04:00
|
|
|
entry = match_entry_createl( "/xxx" , strlen("/xxx") );
|
2014-05-18 22:34:48 -04:00
|
|
|
m = r3_tree_matchl( n , "/xxx", strlen("/xxx"), entry);
|
2014-05-21 06:31:51 -04:00
|
|
|
ck_assert( m );
|
2014-05-16 02:42:05 -04:00
|
|
|
|
2014-05-17 11:54:18 -04:00
|
|
|
entry = match_entry_createl( "/foo/xxx" , strlen("/foo/xxx") );
|
2014-05-18 22:34:48 -04:00
|
|
|
m = r3_tree_matchl( n , "/foo/xxx", strlen("/foo/xxx"), entry);
|
2014-05-21 06:31:51 -04:00
|
|
|
ck_assert( m );
|
2014-05-16 03:29:25 -04:00
|
|
|
|
2014-05-17 11:54:18 -04:00
|
|
|
entry = match_entry_createl( "/some_id" , strlen("/some_id") );
|
2014-05-18 22:34:48 -04:00
|
|
|
m = r3_tree_matchl( n , "/some_id", strlen("/some_id"), entry);
|
2014-05-21 06:31:51 -04:00
|
|
|
ck_assert( m );
|
2014-05-15 09:17:30 -04:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
2014-05-20 09:40:45 -04:00
|
|
|
START_TEST (test_pcre_patterns_insert)
|
2014-05-15 08:38:07 -04:00
|
|
|
{
|
2014-05-20 09:40:45 -04:00
|
|
|
node * n = r3_tree_create(10);
|
2014-05-15 09:17:30 -04:00
|
|
|
|
2014-05-20 09:40:45 -04:00
|
|
|
// r3_tree_insert_path(n, "/foo-{user}-{id}", NULL, NULL);
|
|
|
|
r3_tree_insert_path(n, "/post/{handle:\\d+}-{id:\\d+}", NULL);
|
|
|
|
r3_tree_compile(n);
|
|
|
|
// r3_tree_dump(n, 0);
|
2014-05-15 09:17:30 -04:00
|
|
|
|
2014-05-20 09:40:45 -04:00
|
|
|
node *matched;
|
|
|
|
matched = r3_tree_matchl(n, "/post/111-222", strlen("/post/111-222"), NULL);
|
2014-05-21 06:31:51 -04:00
|
|
|
ck_assert(matched);
|
2014-05-20 09:40:45 -04:00
|
|
|
ck_assert(matched->endpoint > 0);
|
2014-05-15 09:17:30 -04:00
|
|
|
|
2014-05-20 09:40:45 -04:00
|
|
|
// incomplete string shouldn't match
|
|
|
|
matched = r3_tree_matchl(n, "/post/111-", strlen("/post/111-"), NULL);
|
2014-05-20 12:37:27 -04:00
|
|
|
ck_assert(! matched);
|
2014-05-15 09:17:30 -04:00
|
|
|
|
2014-05-20 09:40:45 -04:00
|
|
|
r3_tree_free(n);
|
2014-05-15 08:38:07 -04:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
|
2014-05-20 09:40:45 -04:00
|
|
|
/**
|
2014-05-20 12:55:43 -04:00
|
|
|
* Test for \d{2}/\d{2}
|
2014-05-20 09:40:45 -04:00
|
|
|
*/
|
|
|
|
START_TEST (test_pcre_patterns_insert_2)
|
2014-05-18 06:58:31 -04:00
|
|
|
{
|
|
|
|
node * n = r3_tree_create(10);
|
2014-05-20 09:40:45 -04:00
|
|
|
r3_tree_insert_path(n, "/post/{idx:\\d{2}}/{idy:\\d{2}}", NULL);
|
2014-05-20 13:15:54 -04:00
|
|
|
r3_tree_insert_path(n, "/zoo", NULL);
|
|
|
|
r3_tree_insert_path(n, "/foo", NULL);
|
|
|
|
r3_tree_insert_path(n, "/bar", NULL);
|
2014-05-18 06:58:31 -04:00
|
|
|
r3_tree_compile(n);
|
|
|
|
r3_tree_dump(n, 0);
|
2014-05-18 08:08:43 -04:00
|
|
|
node *matched;
|
2014-05-20 09:40:45 -04:00
|
|
|
matched = r3_tree_match(n, "/post/11/22", NULL);
|
2014-05-21 03:50:37 -04:00
|
|
|
ck_assert((int)matched);
|
2014-05-20 03:10:09 -04:00
|
|
|
ck_assert(matched->endpoint > 0);
|
2014-05-20 12:37:27 -04:00
|
|
|
}
|
|
|
|
END_TEST
|
2014-05-18 08:08:43 -04:00
|
|
|
|
2014-05-20 12:37:27 -04:00
|
|
|
/**
|
2014-05-20 12:55:43 -04:00
|
|
|
* Test for (\d{2})/([^/]+)
|
2014-05-20 12:37:27 -04:00
|
|
|
*/
|
|
|
|
START_TEST (test_pcre_patterns_insert_3)
|
|
|
|
{
|
|
|
|
node * n = r3_tree_create(10);
|
2014-05-20 13:15:54 -04:00
|
|
|
printf("Inserting /post/{idx:\\d{2}}/{idy}\n");
|
2014-05-20 12:49:08 -04:00
|
|
|
r3_tree_insert_path(n, "/post/{idx:\\d{2}}/{idy}", NULL);
|
2014-05-20 13:15:54 -04:00
|
|
|
r3_tree_dump(n, 0);
|
|
|
|
|
|
|
|
printf("Inserting /zoo\n");
|
|
|
|
r3_tree_insert_path(n, "/zoo", NULL);
|
|
|
|
r3_tree_dump(n, 0);
|
|
|
|
|
|
|
|
r3_tree_insert_path(n, "/foo", NULL);
|
|
|
|
r3_tree_insert_path(n, "/bar", NULL);
|
2014-05-20 12:37:27 -04:00
|
|
|
r3_tree_compile(n);
|
|
|
|
r3_tree_dump(n, 0);
|
|
|
|
node *matched;
|
2014-05-20 13:15:54 -04:00
|
|
|
|
|
|
|
|
|
|
|
matched = r3_tree_match(n, "/post/11/22", NULL);
|
2014-05-21 03:50:37 -04:00
|
|
|
ck_assert((int)matched);
|
2014-05-20 13:15:54 -04:00
|
|
|
|
2014-05-20 12:49:08 -04:00
|
|
|
matched = r3_tree_match(n, "/post/11", NULL);
|
|
|
|
ck_assert(!matched);
|
|
|
|
|
2014-05-20 13:15:54 -04:00
|
|
|
|
2014-05-20 12:49:08 -04:00
|
|
|
matched = r3_tree_match(n, "/post/11/", NULL);
|
|
|
|
ck_assert(!matched);
|
|
|
|
|
2014-05-20 13:15:54 -04:00
|
|
|
/*
|
2014-05-20 12:49:08 -04:00
|
|
|
matched = r3_tree_match(n, "/post/113", NULL);
|
|
|
|
ck_assert(!matched);
|
2014-05-20 13:15:54 -04:00
|
|
|
*/
|
2014-05-18 06:58:31 -04:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-05-20 09:40:45 -04:00
|
|
|
|
|
|
|
|
2014-05-20 12:37:27 -04:00
|
|
|
|
2014-05-20 12:47:09 -04:00
|
|
|
START_TEST (testr3_tree_insert_pathl)
|
2014-05-15 06:02:10 -04:00
|
|
|
{
|
2014-05-16 06:57:36 -04:00
|
|
|
node * n = r3_tree_create(10);
|
2014-05-15 06:02:10 -04:00
|
|
|
|
2014-05-18 22:12:41 -04:00
|
|
|
r3_tree_insert_path(n, "/foo/bar", NULL);
|
2014-05-16 06:57:36 -04:00
|
|
|
// r3_tree_dump(n, 0);
|
2014-05-15 10:57:13 -04:00
|
|
|
|
2014-05-18 22:12:41 -04:00
|
|
|
r3_tree_insert_path(n, "/foo/zoo", NULL);
|
2014-05-16 06:57:36 -04:00
|
|
|
// r3_tree_dump(n, 0);
|
2014-05-15 10:57:13 -04:00
|
|
|
|
2014-05-18 22:12:41 -04:00
|
|
|
r3_tree_insert_path(n, "/f/id" , NULL);
|
2014-05-16 06:57:36 -04:00
|
|
|
// r3_tree_dump(n, 0);
|
2014-05-15 10:57:13 -04:00
|
|
|
|
2014-05-18 22:12:41 -04:00
|
|
|
r3_tree_insert_path(n, "/post/{id}", NULL);
|
2014-05-16 06:57:36 -04:00
|
|
|
// r3_tree_dump(n, 0);
|
2014-05-15 11:03:23 -04:00
|
|
|
|
2014-05-18 22:12:41 -04:00
|
|
|
r3_tree_insert_path(n, "/post/{handle}", NULL);
|
2014-05-15 11:03:23 -04:00
|
|
|
|
2014-05-18 22:12:41 -04:00
|
|
|
r3_tree_insert_path(n, "/post/{handle}-{id}", NULL);
|
2014-05-16 06:57:36 -04:00
|
|
|
r3_tree_compile(n);
|
2014-05-15 06:02:10 -04:00
|
|
|
|
2014-05-16 06:03:52 -04:00
|
|
|
#ifdef DEBUG
|
2014-05-16 06:57:36 -04:00
|
|
|
r3_tree_dump(n, 0);
|
2014-05-16 06:03:52 -04:00
|
|
|
#endif
|
2014-05-16 06:57:36 -04:00
|
|
|
r3_tree_free(n);
|
2014-05-15 06:02:10 -04:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-05-14 22:08:42 -04:00
|
|
|
|
2014-05-16 06:03:52 -04:00
|
|
|
START_TEST (test_str_array)
|
2014-05-14 22:08:42 -04:00
|
|
|
{
|
2014-05-16 06:03:52 -04:00
|
|
|
str_array * l = str_array_create(3);
|
2014-05-14 23:52:45 -04:00
|
|
|
fail_if( l == NULL );
|
2014-05-14 22:08:42 -04:00
|
|
|
|
2014-05-20 13:50:15 -04:00
|
|
|
fail_if( FALSE == str_array_append(l, zstrdup("abc") ) );
|
2014-05-15 00:53:48 -04:00
|
|
|
fail_if( l->len != 1 );
|
|
|
|
|
2014-05-20 13:50:15 -04:00
|
|
|
fail_if( FALSE == str_array_append(l, zstrdup("foo") ) );
|
2014-05-15 00:53:48 -04:00
|
|
|
fail_if( l->len != 2 );
|
|
|
|
|
2014-05-20 13:50:15 -04:00
|
|
|
fail_if( FALSE == str_array_append(l, zstrdup("bar") ) );
|
2014-05-15 00:53:48 -04:00
|
|
|
fail_if( l->len != 3 );
|
|
|
|
|
2014-05-20 13:50:15 -04:00
|
|
|
fail_if( FALSE == str_array_append(l, zstrdup("zoo") ) );
|
2014-05-15 00:53:48 -04:00
|
|
|
fail_if( l->len != 4 );
|
|
|
|
|
2014-05-16 06:03:52 -04:00
|
|
|
fail_if( FALSE == str_array_resize(l, l->cap * 2) );
|
|
|
|
|
|
|
|
str_array_free(l);
|
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
2014-05-17 23:59:30 -04:00
|
|
|
START_TEST(test_route_cmp)
|
|
|
|
{
|
2014-05-18 22:39:03 -04:00
|
|
|
route *r1 = r3_route_create("/blog/post");
|
2014-05-18 00:56:53 -04:00
|
|
|
match_entry * m = match_entry_create("/blog/post");
|
2014-05-17 23:59:30 -04:00
|
|
|
|
2014-05-18 22:39:03 -04:00
|
|
|
fail_if( r3_route_cmp(r1, m) == -1, "should match");
|
2014-05-17 23:59:30 -04:00
|
|
|
|
|
|
|
r1->request_method = METHOD_GET;
|
2014-05-18 00:56:53 -04:00
|
|
|
m->request_method = METHOD_GET;
|
2014-05-18 22:39:03 -04:00
|
|
|
fail_if( r3_route_cmp(r1, m) == -1, "should match");
|
2014-05-17 23:59:30 -04:00
|
|
|
|
|
|
|
r1->request_method = METHOD_GET;
|
2014-05-18 00:56:53 -04:00
|
|
|
m->request_method = METHOD_POST;
|
2014-05-18 22:39:03 -04:00
|
|
|
fail_if( r3_route_cmp(r1, m) == 0, "should be different");
|
2014-05-17 23:59:30 -04:00
|
|
|
|
2014-05-18 00:56:53 -04:00
|
|
|
r1->request_method = METHOD_GET;
|
|
|
|
m->request_method = METHOD_POST | METHOD_GET;
|
2014-05-18 22:39:03 -04:00
|
|
|
fail_if( r3_route_cmp(r1, m) == -1, "should match");
|
2014-05-18 00:24:07 -04:00
|
|
|
|
2014-05-18 22:39:03 -04:00
|
|
|
r3_route_free(r1);
|
2014-05-18 00:56:53 -04:00
|
|
|
match_entry_free(m);
|
2014-05-17 23:59:30 -04:00
|
|
|
}
|
|
|
|
END_TEST
|
2014-05-17 07:25:25 -04:00
|
|
|
|
|
|
|
|
2014-05-18 02:13:04 -04:00
|
|
|
START_TEST(test_pcre_pattern_simple)
|
|
|
|
{
|
|
|
|
match_entry * entry;
|
|
|
|
entry = match_entry_createl( "/user/123" , strlen("/user/123") );
|
2014-05-18 02:18:47 -04:00
|
|
|
node * n = r3_tree_create(10);
|
2014-05-18 22:12:41 -04:00
|
|
|
r3_tree_insert_path(n, "/user/{id:\\d+}", NULL);
|
|
|
|
r3_tree_insert_path(n, "/user", NULL);
|
2014-05-18 02:13:04 -04:00
|
|
|
r3_tree_compile(n);
|
2014-05-18 06:58:31 -04:00
|
|
|
// r3_tree_dump(n, 0);
|
2014-05-18 02:30:00 -04:00
|
|
|
node *matched;
|
2014-05-18 22:34:48 -04:00
|
|
|
matched = r3_tree_matchl(n, "/user/123", strlen("/user/123"), entry);
|
2014-05-21 06:31:51 -04:00
|
|
|
ck_assert(matched);
|
2014-05-20 03:10:09 -04:00
|
|
|
ck_assert(entry->vars->len > 0);
|
2014-05-18 02:30:00 -04:00
|
|
|
ck_assert_str_eq(entry->vars->tokens[0],"123");
|
2014-05-20 04:18:17 -04:00
|
|
|
r3_tree_free(n);
|
2014-05-18 02:30:00 -04:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
|
|
|
|
START_TEST(test_pcre_pattern_more)
|
|
|
|
{
|
|
|
|
match_entry * entry;
|
|
|
|
entry = match_entry_createl( "/user/123" , strlen("/user/123") );
|
|
|
|
node * n = r3_tree_create(10);
|
|
|
|
|
2014-05-18 03:00:11 -04:00
|
|
|
int var0 = 5;
|
|
|
|
int var1 = 100;
|
|
|
|
int var2 = 200;
|
|
|
|
int var3 = 300;
|
|
|
|
|
2014-05-18 03:06:11 -04:00
|
|
|
info("var0: %p\n", &var0);
|
|
|
|
info("var1: %p\n", &var1);
|
|
|
|
info("var2: %p\n", &var2);
|
|
|
|
info("var3: %p\n", &var3);
|
2014-05-18 02:13:04 -04:00
|
|
|
|
2014-05-18 22:12:41 -04:00
|
|
|
r3_tree_insert_path(n, "/user/{id:\\d+}", &var1);
|
|
|
|
r3_tree_insert_path(n, "/user2/{id:\\d+}", &var2);
|
|
|
|
r3_tree_insert_path(n, "/user3/{id:\\d{3}}", &var3);
|
|
|
|
r3_tree_insert_path(n, "/user", &var0);
|
2014-05-18 02:30:00 -04:00
|
|
|
r3_tree_compile(n);
|
2014-05-20 13:15:54 -04:00
|
|
|
r3_tree_dump(n, 0);
|
2014-05-18 02:13:04 -04:00
|
|
|
node *matched;
|
2014-05-18 02:30:00 -04:00
|
|
|
|
2014-05-18 22:34:48 -04:00
|
|
|
matched = r3_tree_matchl(n, "/user/123", strlen("/user/123"), entry);
|
2014-05-21 06:31:51 -04:00
|
|
|
ck_assert(matched);
|
2014-05-20 03:10:09 -04:00
|
|
|
ck_assert(entry->vars->len > 0);
|
2014-05-18 02:30:00 -04:00
|
|
|
ck_assert_str_eq(entry->vars->tokens[0],"123");
|
|
|
|
|
2014-05-18 03:06:11 -04:00
|
|
|
info("matched %p\n", matched->data);
|
|
|
|
info("matched %p\n", matched->data);
|
|
|
|
ck_assert_int_eq( *((int*) matched->data), var1);
|
|
|
|
|
2014-05-18 22:34:48 -04:00
|
|
|
matched = r3_tree_matchl(n, "/user2/123", strlen("/user2/123"), entry);
|
2014-05-21 06:31:51 -04:00
|
|
|
ck_assert(matched);
|
2014-05-20 03:10:09 -04:00
|
|
|
ck_assert(entry->vars->len > 0);
|
2014-05-18 02:30:00 -04:00
|
|
|
ck_assert_str_eq(entry->vars->tokens[0],"123");
|
2014-05-18 03:06:11 -04:00
|
|
|
ck_assert_int_eq( *((int*)matched->data), var2);
|
2014-05-18 02:30:00 -04:00
|
|
|
|
2014-05-18 22:34:48 -04:00
|
|
|
matched = r3_tree_matchl(n, "/user3/123", strlen("/user3/123"), entry);
|
2014-05-21 06:31:51 -04:00
|
|
|
ck_assert(matched);
|
2014-05-20 03:10:09 -04:00
|
|
|
ck_assert(entry->vars->len > 0);
|
2014-05-18 02:18:47 -04:00
|
|
|
ck_assert_str_eq(entry->vars->tokens[0],"123");
|
2014-05-18 03:06:11 -04:00
|
|
|
ck_assert_int_eq( *((int*)matched->data), var3);
|
2014-05-20 04:18:17 -04:00
|
|
|
|
|
|
|
r3_tree_free(n);
|
2014-05-18 02:13:04 -04:00
|
|
|
}
|
2014-05-18 02:18:47 -04:00
|
|
|
END_TEST
|
2014-05-17 07:25:25 -04:00
|
|
|
|
2014-05-18 02:30:00 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
2014-05-18 00:24:07 -04:00
|
|
|
START_TEST(test_insert_route)
|
|
|
|
{
|
|
|
|
int var1 = 22;
|
|
|
|
int var2 = 33;
|
2014-05-18 22:39:03 -04:00
|
|
|
route *r1 = r3_route_create("/blog/post");
|
|
|
|
route *r2 = r3_route_create("/blog/post");
|
2014-05-18 00:24:07 -04:00
|
|
|
r1->request_method = METHOD_GET;
|
|
|
|
r2->request_method = METHOD_POST;
|
2014-05-17 07:25:25 -04:00
|
|
|
|
2014-05-18 00:24:07 -04:00
|
|
|
match_entry * entry = match_entry_create("/blog/post");
|
2014-05-18 01:04:17 -04:00
|
|
|
entry->request_method = METHOD_GET;
|
2014-05-17 07:25:25 -04:00
|
|
|
|
2014-05-18 00:24:07 -04:00
|
|
|
node * n = r3_tree_create(2);
|
|
|
|
r3_tree_insert_route(n, r1, &var1);
|
|
|
|
r3_tree_insert_route(n, r2, &var2);
|
2014-05-17 07:25:25 -04:00
|
|
|
|
2014-05-18 22:34:48 -04:00
|
|
|
route *c = r3_tree_match_route(n, entry);
|
2014-05-18 00:56:53 -04:00
|
|
|
fail_if(c == NULL);
|
|
|
|
|
2014-05-18 00:24:07 -04:00
|
|
|
match_entry_free(entry);
|
2014-05-18 22:39:03 -04:00
|
|
|
r3_route_free(r1);
|
|
|
|
r3_route_free(r2);
|
2014-05-17 07:25:25 -04:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
2014-05-18 00:24:07 -04:00
|
|
|
|
|
|
|
|
2014-05-16 06:03:52 -04:00
|
|
|
START_TEST(benchmark_str)
|
|
|
|
{
|
2014-05-17 11:54:18 -04:00
|
|
|
match_entry * entry = match_entry_createl("/blog/post", strlen("/blog/post") );
|
2014-05-16 06:57:36 -04:00
|
|
|
node * n = r3_tree_create(1);
|
|
|
|
|
2014-05-16 20:01:49 -04:00
|
|
|
|
2014-05-18 01:06:36 -04:00
|
|
|
int route_data = 999;
|
2014-05-16 20:01:49 -04:00
|
|
|
|
2014-05-18 22:12:41 -04:00
|
|
|
r3_tree_insert_path(n, "/foo/bar/baz", NULL);
|
|
|
|
r3_tree_insert_path(n, "/foo/bar/qux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/foo/bar/quux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/foo/bar/corge", NULL);
|
|
|
|
r3_tree_insert_path(n, "/foo/bar/grault", NULL);
|
|
|
|
r3_tree_insert_path(n, "/foo/bar/garply", NULL);
|
|
|
|
r3_tree_insert_path(n, "/foo/baz/bar", NULL);
|
|
|
|
r3_tree_insert_path(n, "/foo/baz/qux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/foo/baz/quux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/foo/baz/corge", NULL);
|
|
|
|
r3_tree_insert_path(n, "/foo/baz/grault", NULL);
|
|
|
|
r3_tree_insert_path(n, "/foo/baz/garply", NULL);
|
|
|
|
r3_tree_insert_path(n, "/foo/qux/bar", NULL);
|
|
|
|
r3_tree_insert_path(n, "/foo/qux/baz", NULL);
|
|
|
|
r3_tree_insert_path(n, "/foo/qux/quux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/foo/qux/corge", NULL);
|
|
|
|
r3_tree_insert_path(n, "/foo/qux/grault", NULL);
|
|
|
|
r3_tree_insert_path(n, "/foo/qux/garply", NULL);
|
|
|
|
r3_tree_insert_path(n, "/foo/quux/bar", NULL);
|
|
|
|
r3_tree_insert_path(n, "/foo/quux/baz", NULL);
|
|
|
|
r3_tree_insert_path(n, "/foo/quux/qux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/foo/quux/corge", NULL);
|
|
|
|
r3_tree_insert_path(n, "/foo/quux/grault", NULL);
|
|
|
|
r3_tree_insert_path(n, "/foo/quux/garply", NULL);
|
|
|
|
r3_tree_insert_path(n, "/foo/corge/bar", NULL);
|
|
|
|
r3_tree_insert_path(n, "/foo/corge/baz", NULL);
|
|
|
|
r3_tree_insert_path(n, "/foo/corge/qux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/foo/corge/quux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/foo/corge/grault", NULL);
|
|
|
|
r3_tree_insert_path(n, "/foo/corge/garply", NULL);
|
|
|
|
r3_tree_insert_path(n, "/foo/grault/bar", NULL);
|
|
|
|
r3_tree_insert_path(n, "/foo/grault/baz", NULL);
|
|
|
|
r3_tree_insert_path(n, "/foo/grault/qux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/foo/grault/quux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/foo/grault/corge", NULL);
|
|
|
|
r3_tree_insert_path(n, "/foo/grault/garply", NULL);
|
|
|
|
r3_tree_insert_path(n, "/foo/garply/bar", NULL);
|
|
|
|
r3_tree_insert_path(n, "/foo/garply/baz", NULL);
|
|
|
|
r3_tree_insert_path(n, "/foo/garply/qux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/foo/garply/quux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/foo/garply/corge", NULL);
|
|
|
|
r3_tree_insert_path(n, "/foo/garply/grault", NULL);
|
|
|
|
r3_tree_insert_path(n, "/bar/foo/baz", NULL);
|
|
|
|
r3_tree_insert_path(n, "/bar/foo/qux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/bar/foo/quux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/bar/foo/corge", NULL);
|
|
|
|
r3_tree_insert_path(n, "/bar/foo/grault", NULL);
|
|
|
|
r3_tree_insert_path(n, "/bar/foo/garply", NULL);
|
|
|
|
r3_tree_insert_path(n, "/bar/baz/foo", NULL);
|
|
|
|
r3_tree_insert_path(n, "/bar/baz/qux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/bar/baz/quux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/bar/baz/corge", NULL);
|
|
|
|
r3_tree_insert_path(n, "/bar/baz/grault", NULL);
|
|
|
|
r3_tree_insert_path(n, "/bar/baz/garply", NULL);
|
|
|
|
r3_tree_insert_path(n, "/bar/qux/foo", NULL);
|
|
|
|
r3_tree_insert_path(n, "/bar/qux/baz", NULL);
|
|
|
|
r3_tree_insert_path(n, "/bar/qux/quux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/bar/qux/corge", NULL);
|
|
|
|
r3_tree_insert_path(n, "/bar/qux/grault", NULL);
|
|
|
|
r3_tree_insert_path(n, "/bar/qux/garply", NULL);
|
|
|
|
r3_tree_insert_path(n, "/bar/quux/foo", NULL);
|
|
|
|
r3_tree_insert_path(n, "/bar/quux/baz", NULL);
|
|
|
|
r3_tree_insert_path(n, "/bar/quux/qux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/bar/quux/corge", NULL);
|
|
|
|
r3_tree_insert_path(n, "/bar/quux/grault", NULL);
|
|
|
|
r3_tree_insert_path(n, "/bar/quux/garply", NULL);
|
|
|
|
r3_tree_insert_path(n, "/bar/corge/foo", NULL);
|
|
|
|
r3_tree_insert_path(n, "/bar/corge/baz", NULL);
|
|
|
|
r3_tree_insert_path(n, "/bar/corge/qux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/bar/corge/quux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/bar/corge/grault", NULL);
|
|
|
|
r3_tree_insert_path(n, "/bar/corge/garply", NULL);
|
|
|
|
r3_tree_insert_path(n, "/bar/grault/foo", NULL);
|
|
|
|
r3_tree_insert_path(n, "/bar/grault/baz", NULL);
|
|
|
|
r3_tree_insert_path(n, "/bar/grault/qux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/bar/grault/quux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/bar/grault/corge", NULL);
|
|
|
|
r3_tree_insert_path(n, "/bar/grault/garply", NULL);
|
|
|
|
r3_tree_insert_path(n, "/bar/garply/foo", NULL);
|
|
|
|
r3_tree_insert_path(n, "/bar/garply/baz", NULL);
|
|
|
|
r3_tree_insert_path(n, "/bar/garply/qux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/bar/garply/quux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/bar/garply/corge", NULL);
|
|
|
|
r3_tree_insert_path(n, "/bar/garply/grault", NULL);
|
|
|
|
r3_tree_insert_path(n, "/baz/foo/bar", NULL);
|
|
|
|
r3_tree_insert_path(n, "/baz/foo/qux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/baz/foo/quux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/baz/foo/corge", NULL);
|
|
|
|
r3_tree_insert_path(n, "/baz/foo/grault", NULL);
|
|
|
|
r3_tree_insert_path(n, "/baz/foo/garply", NULL);
|
|
|
|
r3_tree_insert_path(n, "/baz/bar/foo", NULL);
|
|
|
|
r3_tree_insert_path(n, "/baz/bar/qux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/baz/bar/quux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/baz/bar/corge", NULL);
|
|
|
|
r3_tree_insert_path(n, "/baz/bar/grault", NULL);
|
|
|
|
r3_tree_insert_path(n, "/baz/bar/garply", NULL);
|
|
|
|
r3_tree_insert_path(n, "/baz/qux/foo", NULL);
|
|
|
|
r3_tree_insert_path(n, "/baz/qux/bar", NULL);
|
|
|
|
r3_tree_insert_path(n, "/baz/qux/quux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/baz/qux/corge", NULL);
|
|
|
|
r3_tree_insert_path(n, "/baz/qux/grault", NULL);
|
|
|
|
r3_tree_insert_path(n, "/baz/qux/garply", NULL);
|
|
|
|
r3_tree_insert_path(n, "/baz/quux/foo", NULL);
|
|
|
|
r3_tree_insert_path(n, "/baz/quux/bar", NULL);
|
|
|
|
r3_tree_insert_path(n, "/baz/quux/qux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/baz/quux/corge", NULL);
|
|
|
|
r3_tree_insert_path(n, "/baz/quux/grault", NULL);
|
|
|
|
r3_tree_insert_path(n, "/baz/quux/garply", NULL);
|
|
|
|
r3_tree_insert_path(n, "/baz/corge/foo", NULL);
|
|
|
|
r3_tree_insert_path(n, "/baz/corge/bar", NULL);
|
|
|
|
r3_tree_insert_path(n, "/baz/corge/qux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/baz/corge/quux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/baz/corge/grault", NULL);
|
|
|
|
r3_tree_insert_path(n, "/baz/corge/garply", NULL);
|
|
|
|
r3_tree_insert_path(n, "/baz/grault/foo", NULL);
|
|
|
|
r3_tree_insert_path(n, "/baz/grault/bar", NULL);
|
|
|
|
r3_tree_insert_path(n, "/baz/grault/qux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/baz/grault/quux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/baz/grault/corge", NULL);
|
|
|
|
r3_tree_insert_path(n, "/baz/grault/garply", NULL);
|
|
|
|
r3_tree_insert_path(n, "/baz/garply/foo", NULL);
|
|
|
|
r3_tree_insert_path(n, "/baz/garply/bar", NULL);
|
|
|
|
r3_tree_insert_path(n, "/baz/garply/qux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/baz/garply/quux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/baz/garply/corge", NULL);
|
|
|
|
r3_tree_insert_path(n, "/baz/garply/grault", NULL);
|
|
|
|
r3_tree_insert_path(n, "/qux/foo/bar", NULL);
|
|
|
|
r3_tree_insert_path(n, "/qux/foo/baz", NULL);
|
|
|
|
r3_tree_insert_path(n, "/qux/foo/quux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/qux/foo/corge", NULL);
|
|
|
|
r3_tree_insert_path(n, "/qux/foo/grault", NULL);
|
|
|
|
r3_tree_insert_path(n, "/qux/foo/garply", NULL);
|
|
|
|
r3_tree_insert_path(n, "/qux/bar/foo", NULL);
|
|
|
|
r3_tree_insert_path(n, "/qux/bar/baz", NULL);
|
|
|
|
r3_tree_insert_path(n, "/qux/bar/quux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/qux/bar/corge", &route_data);
|
|
|
|
r3_tree_insert_path(n, "/qux/bar/grault", NULL);
|
|
|
|
r3_tree_insert_path(n, "/qux/bar/garply", NULL);
|
|
|
|
r3_tree_insert_path(n, "/qux/baz/foo", NULL);
|
|
|
|
r3_tree_insert_path(n, "/qux/baz/bar", NULL);
|
|
|
|
r3_tree_insert_path(n, "/qux/baz/quux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/qux/baz/corge", NULL);
|
|
|
|
r3_tree_insert_path(n, "/qux/baz/grault", NULL);
|
|
|
|
r3_tree_insert_path(n, "/qux/baz/garply", NULL);
|
|
|
|
r3_tree_insert_path(n, "/qux/quux/foo", NULL);
|
|
|
|
r3_tree_insert_path(n, "/qux/quux/bar", NULL);
|
|
|
|
r3_tree_insert_path(n, "/qux/quux/baz", NULL);
|
|
|
|
r3_tree_insert_path(n, "/qux/quux/corge", NULL);
|
|
|
|
r3_tree_insert_path(n, "/qux/quux/grault", NULL);
|
|
|
|
r3_tree_insert_path(n, "/qux/quux/garply", NULL);
|
|
|
|
r3_tree_insert_path(n, "/qux/corge/foo", NULL);
|
|
|
|
r3_tree_insert_path(n, "/qux/corge/bar", NULL);
|
|
|
|
r3_tree_insert_path(n, "/qux/corge/baz", NULL);
|
|
|
|
r3_tree_insert_path(n, "/qux/corge/quux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/qux/corge/grault", NULL);
|
|
|
|
r3_tree_insert_path(n, "/qux/corge/garply", NULL);
|
|
|
|
r3_tree_insert_path(n, "/qux/grault/foo", NULL);
|
|
|
|
r3_tree_insert_path(n, "/qux/grault/bar", NULL);
|
|
|
|
r3_tree_insert_path(n, "/qux/grault/baz", NULL);
|
|
|
|
r3_tree_insert_path(n, "/qux/grault/quux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/qux/grault/corge", NULL);
|
|
|
|
r3_tree_insert_path(n, "/qux/grault/garply", NULL);
|
|
|
|
r3_tree_insert_path(n, "/qux/garply/foo", NULL);
|
|
|
|
r3_tree_insert_path(n, "/qux/garply/bar", NULL);
|
|
|
|
r3_tree_insert_path(n, "/qux/garply/baz", NULL);
|
|
|
|
r3_tree_insert_path(n, "/qux/garply/quux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/qux/garply/corge", NULL);
|
|
|
|
r3_tree_insert_path(n, "/qux/garply/grault", NULL);
|
|
|
|
r3_tree_insert_path(n, "/quux/foo/bar", NULL);
|
|
|
|
r3_tree_insert_path(n, "/quux/foo/baz", NULL);
|
|
|
|
r3_tree_insert_path(n, "/quux/foo/qux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/quux/foo/corge", NULL);
|
|
|
|
r3_tree_insert_path(n, "/quux/foo/grault", NULL);
|
|
|
|
r3_tree_insert_path(n, "/quux/foo/garply", NULL);
|
|
|
|
r3_tree_insert_path(n, "/quux/bar/foo", NULL);
|
|
|
|
r3_tree_insert_path(n, "/quux/bar/baz", NULL);
|
|
|
|
r3_tree_insert_path(n, "/quux/bar/qux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/quux/bar/corge", NULL);
|
|
|
|
r3_tree_insert_path(n, "/quux/bar/grault", NULL);
|
|
|
|
r3_tree_insert_path(n, "/quux/bar/garply", NULL);
|
|
|
|
r3_tree_insert_path(n, "/quux/baz/foo", NULL);
|
|
|
|
r3_tree_insert_path(n, "/quux/baz/bar", NULL);
|
|
|
|
r3_tree_insert_path(n, "/quux/baz/qux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/quux/baz/corge", NULL);
|
|
|
|
r3_tree_insert_path(n, "/quux/baz/grault", NULL);
|
|
|
|
r3_tree_insert_path(n, "/quux/baz/garply", NULL);
|
|
|
|
r3_tree_insert_path(n, "/quux/qux/foo", NULL);
|
|
|
|
r3_tree_insert_path(n, "/quux/qux/bar", NULL);
|
|
|
|
r3_tree_insert_path(n, "/quux/qux/baz", NULL);
|
|
|
|
r3_tree_insert_path(n, "/quux/qux/corge", NULL);
|
|
|
|
r3_tree_insert_path(n, "/quux/qux/grault", NULL);
|
|
|
|
r3_tree_insert_path(n, "/quux/qux/garply", NULL);
|
|
|
|
r3_tree_insert_path(n, "/quux/corge/foo", NULL);
|
|
|
|
r3_tree_insert_path(n, "/quux/corge/bar", NULL);
|
|
|
|
r3_tree_insert_path(n, "/quux/corge/baz", NULL);
|
|
|
|
r3_tree_insert_path(n, "/quux/corge/qux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/quux/corge/grault", NULL);
|
|
|
|
r3_tree_insert_path(n, "/quux/corge/garply", NULL);
|
|
|
|
r3_tree_insert_path(n, "/quux/grault/foo", NULL);
|
|
|
|
r3_tree_insert_path(n, "/quux/grault/bar", NULL);
|
|
|
|
r3_tree_insert_path(n, "/quux/grault/baz", NULL);
|
|
|
|
r3_tree_insert_path(n, "/quux/grault/qux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/quux/grault/corge", NULL);
|
|
|
|
r3_tree_insert_path(n, "/quux/grault/garply", NULL);
|
|
|
|
r3_tree_insert_path(n, "/quux/garply/foo", NULL);
|
|
|
|
r3_tree_insert_path(n, "/quux/garply/bar", NULL);
|
|
|
|
r3_tree_insert_path(n, "/quux/garply/baz", NULL);
|
|
|
|
r3_tree_insert_path(n, "/quux/garply/qux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/quux/garply/corge", NULL);
|
|
|
|
r3_tree_insert_path(n, "/quux/garply/grault", NULL);
|
|
|
|
r3_tree_insert_path(n, "/corge/foo/bar", NULL);
|
|
|
|
r3_tree_insert_path(n, "/corge/foo/baz", NULL);
|
|
|
|
r3_tree_insert_path(n, "/corge/foo/qux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/corge/foo/quux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/corge/foo/grault", NULL);
|
|
|
|
r3_tree_insert_path(n, "/corge/foo/garply", NULL);
|
|
|
|
r3_tree_insert_path(n, "/corge/bar/foo", NULL);
|
|
|
|
r3_tree_insert_path(n, "/corge/bar/baz", NULL);
|
|
|
|
r3_tree_insert_path(n, "/corge/bar/qux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/corge/bar/quux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/corge/bar/grault", NULL);
|
|
|
|
r3_tree_insert_path(n, "/corge/bar/garply", NULL);
|
|
|
|
r3_tree_insert_path(n, "/corge/baz/foo", NULL);
|
|
|
|
r3_tree_insert_path(n, "/corge/baz/bar", NULL);
|
|
|
|
r3_tree_insert_path(n, "/corge/baz/qux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/corge/baz/quux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/corge/baz/grault", NULL);
|
|
|
|
r3_tree_insert_path(n, "/corge/baz/garply", NULL);
|
|
|
|
r3_tree_insert_path(n, "/corge/qux/foo", NULL);
|
|
|
|
r3_tree_insert_path(n, "/corge/qux/bar", NULL);
|
|
|
|
r3_tree_insert_path(n, "/corge/qux/baz", NULL);
|
|
|
|
r3_tree_insert_path(n, "/corge/qux/quux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/corge/qux/grault", NULL);
|
|
|
|
r3_tree_insert_path(n, "/corge/qux/garply", NULL);
|
|
|
|
r3_tree_insert_path(n, "/corge/quux/foo", NULL);
|
|
|
|
r3_tree_insert_path(n, "/corge/quux/bar", NULL);
|
|
|
|
r3_tree_insert_path(n, "/corge/quux/baz", NULL);
|
|
|
|
r3_tree_insert_path(n, "/corge/quux/qux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/corge/quux/grault", NULL);
|
|
|
|
r3_tree_insert_path(n, "/corge/quux/garply", NULL);
|
|
|
|
r3_tree_insert_path(n, "/corge/grault/foo", NULL);
|
|
|
|
r3_tree_insert_path(n, "/corge/grault/bar", NULL);
|
|
|
|
r3_tree_insert_path(n, "/corge/grault/baz", NULL);
|
|
|
|
r3_tree_insert_path(n, "/corge/grault/qux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/corge/grault/quux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/corge/grault/garply", NULL);
|
|
|
|
r3_tree_insert_path(n, "/corge/garply/foo", NULL);
|
|
|
|
r3_tree_insert_path(n, "/corge/garply/bar", NULL);
|
|
|
|
r3_tree_insert_path(n, "/corge/garply/baz", NULL);
|
|
|
|
r3_tree_insert_path(n, "/corge/garply/qux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/corge/garply/quux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/corge/garply/grault", NULL);
|
|
|
|
r3_tree_insert_path(n, "/grault/foo/bar", NULL);
|
|
|
|
r3_tree_insert_path(n, "/grault/foo/baz", NULL);
|
|
|
|
r3_tree_insert_path(n, "/grault/foo/qux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/grault/foo/quux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/grault/foo/corge", NULL);
|
|
|
|
r3_tree_insert_path(n, "/grault/foo/garply", NULL);
|
|
|
|
r3_tree_insert_path(n, "/grault/bar/foo", NULL);
|
|
|
|
r3_tree_insert_path(n, "/grault/bar/baz", NULL);
|
|
|
|
r3_tree_insert_path(n, "/grault/bar/qux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/grault/bar/quux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/grault/bar/corge", NULL);
|
|
|
|
r3_tree_insert_path(n, "/grault/bar/garply", NULL);
|
|
|
|
r3_tree_insert_path(n, "/grault/baz/foo", NULL);
|
|
|
|
r3_tree_insert_path(n, "/grault/baz/bar", NULL);
|
|
|
|
r3_tree_insert_path(n, "/grault/baz/qux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/grault/baz/quux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/grault/baz/corge", NULL);
|
|
|
|
r3_tree_insert_path(n, "/grault/baz/garply", NULL);
|
|
|
|
r3_tree_insert_path(n, "/grault/qux/foo", NULL);
|
|
|
|
r3_tree_insert_path(n, "/grault/qux/bar", NULL);
|
|
|
|
r3_tree_insert_path(n, "/grault/qux/baz", NULL);
|
|
|
|
r3_tree_insert_path(n, "/grault/qux/quux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/grault/qux/corge", NULL);
|
|
|
|
r3_tree_insert_path(n, "/grault/qux/garply", NULL);
|
|
|
|
r3_tree_insert_path(n, "/grault/quux/foo", NULL);
|
|
|
|
r3_tree_insert_path(n, "/grault/quux/bar", NULL);
|
|
|
|
r3_tree_insert_path(n, "/grault/quux/baz", NULL);
|
|
|
|
r3_tree_insert_path(n, "/grault/quux/qux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/grault/quux/corge", NULL);
|
|
|
|
r3_tree_insert_path(n, "/grault/quux/garply", NULL);
|
|
|
|
r3_tree_insert_path(n, "/grault/corge/foo", NULL);
|
|
|
|
r3_tree_insert_path(n, "/grault/corge/bar", NULL);
|
|
|
|
r3_tree_insert_path(n, "/grault/corge/baz", NULL);
|
|
|
|
r3_tree_insert_path(n, "/grault/corge/qux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/grault/corge/quux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/grault/corge/garply", NULL);
|
|
|
|
r3_tree_insert_path(n, "/grault/garply/foo", NULL);
|
|
|
|
r3_tree_insert_path(n, "/grault/garply/bar", NULL);
|
|
|
|
r3_tree_insert_path(n, "/grault/garply/baz", NULL);
|
|
|
|
r3_tree_insert_path(n, "/grault/garply/qux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/grault/garply/quux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/grault/garply/corge", NULL);
|
|
|
|
r3_tree_insert_path(n, "/garply/foo/bar", NULL);
|
|
|
|
r3_tree_insert_path(n, "/garply/foo/baz", NULL);
|
|
|
|
r3_tree_insert_path(n, "/garply/foo/qux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/garply/foo/quux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/garply/foo/corge", NULL);
|
|
|
|
r3_tree_insert_path(n, "/garply/foo/grault", NULL);
|
|
|
|
r3_tree_insert_path(n, "/garply/bar/foo", NULL);
|
|
|
|
r3_tree_insert_path(n, "/garply/bar/baz", NULL);
|
|
|
|
r3_tree_insert_path(n, "/garply/bar/qux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/garply/bar/quux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/garply/bar/corge", NULL);
|
|
|
|
r3_tree_insert_path(n, "/garply/bar/grault", NULL);
|
|
|
|
r3_tree_insert_path(n, "/garply/baz/foo", NULL);
|
|
|
|
r3_tree_insert_path(n, "/garply/baz/bar", NULL);
|
|
|
|
r3_tree_insert_path(n, "/garply/baz/qux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/garply/baz/quux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/garply/baz/corge", NULL);
|
|
|
|
r3_tree_insert_path(n, "/garply/baz/grault", NULL);
|
|
|
|
r3_tree_insert_path(n, "/garply/qux/foo", NULL);
|
|
|
|
r3_tree_insert_path(n, "/garply/qux/bar", NULL);
|
|
|
|
r3_tree_insert_path(n, "/garply/qux/baz", NULL);
|
|
|
|
r3_tree_insert_path(n, "/garply/qux/quux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/garply/qux/corge", NULL);
|
|
|
|
r3_tree_insert_path(n, "/garply/qux/grault", NULL);
|
|
|
|
r3_tree_insert_path(n, "/garply/quux/foo", NULL);
|
|
|
|
r3_tree_insert_path(n, "/garply/quux/bar", NULL);
|
|
|
|
r3_tree_insert_path(n, "/garply/quux/baz", NULL);
|
|
|
|
r3_tree_insert_path(n, "/garply/quux/qux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/garply/quux/corge", NULL);
|
|
|
|
r3_tree_insert_path(n, "/garply/quux/grault", NULL);
|
|
|
|
r3_tree_insert_path(n, "/garply/corge/foo", NULL);
|
|
|
|
r3_tree_insert_path(n, "/garply/corge/bar", NULL);
|
|
|
|
r3_tree_insert_path(n, "/garply/corge/baz", NULL);
|
|
|
|
r3_tree_insert_path(n, "/garply/corge/qux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/garply/corge/quux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/garply/corge/grault", NULL);
|
|
|
|
r3_tree_insert_path(n, "/garply/grault/foo", NULL);
|
|
|
|
r3_tree_insert_path(n, "/garply/grault/bar", NULL);
|
|
|
|
r3_tree_insert_path(n, "/garply/grault/baz", NULL);
|
|
|
|
r3_tree_insert_path(n, "/garply/grault/qux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/garply/grault/quux", NULL);
|
|
|
|
r3_tree_insert_path(n, "/garply/grault/corge", NULL);
|
2014-05-17 23:13:02 -04:00
|
|
|
|
2014-05-16 06:57:36 -04:00
|
|
|
|
|
|
|
r3_tree_compile(n);
|
|
|
|
// r3_tree_dump(n, 0);
|
2014-05-20 13:50:15 -04:00
|
|
|
// match_entry *entry = zcalloc( 1 );
|
2014-05-16 06:03:52 -04:00
|
|
|
|
|
|
|
node *m;
|
2014-05-18 22:34:48 -04:00
|
|
|
m = r3_tree_match(n , "/qux/bar/corge", NULL);
|
2014-05-16 06:03:52 -04:00
|
|
|
fail_if( m == NULL );
|
2014-05-16 06:57:36 -04:00
|
|
|
// r3_tree_dump( m, 0 );
|
2014-05-17 23:06:24 -04:00
|
|
|
ck_assert_int_eq( *((int*) m->data), 999 );
|
2014-05-16 06:03:52 -04:00
|
|
|
|
|
|
|
|
|
|
|
printf("Benchmarking...\n");
|
2014-05-16 19:48:22 -04:00
|
|
|
BENCHMARK(string_dispatch)
|
2014-05-18 23:04:19 -04:00
|
|
|
r3_tree_matchl(n , "/qux/bar/corge", strlen("/qux/bar/corge"), NULL);
|
2014-05-22 04:59:40 -04:00
|
|
|
END_BENCHMARK(string_dispatch)
|
2014-05-14 23:52:45 -04:00
|
|
|
|
2014-05-22 04:59:40 -04:00
|
|
|
BENCHMARK_SUMMARY(string_dispatch);
|
2014-05-22 05:00:22 -04:00
|
|
|
BENCHMARK_RECORD_CSV(string_dispatch, "bench_str.csv");
|
|
|
|
|
|
|
|
r3_tree_free(n);
|
2014-05-14 12:15:19 -04:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
2014-05-22 05:07:02 -04:00
|
|
|
START_TEST(test_feedback)
|
|
|
|
{
|
|
|
|
node * t = r3_tree_create(1);
|
|
|
|
r3_tree_insert_path(t, "/foo/bar/baz", NULL);
|
|
|
|
r3_tree_insert_path(t, "/foo/grault/bar", NULL);
|
|
|
|
r3_tree_insert_path(t, "/garply/corge/grault", NULL);
|
|
|
|
r3_tree_compile(t);
|
|
|
|
|
2014-05-22 05:22:54 -04:00
|
|
|
node * m1 = r3_tree_match(t, "/foo/grault/bar", NULL);
|
|
|
|
node * m2 = r3_tree_match(t, "/garply/corge/grault", NULL);
|
|
|
|
ck_assert(m1 != NULL);
|
|
|
|
ck_assert(m2 != NULL);
|
2014-05-22 05:07:02 -04:00
|
|
|
|
2014-05-22 05:22:54 -04:00
|
|
|
for ( int i = 0 ; i < 120 ; i++ ) {
|
|
|
|
r3_tree_feedback(t, m1);
|
|
|
|
}
|
|
|
|
|
|
|
|
for ( int i = 0 ; i < 200 ; i++ ) {
|
|
|
|
r3_tree_feedback(t, m2);
|
|
|
|
}
|
|
|
|
|
|
|
|
r3_tree_dump(t, 0);
|
2014-05-22 05:07:02 -04:00
|
|
|
|
|
|
|
r3_tree_free(t);
|
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
2014-05-17 07:25:25 -04:00
|
|
|
|
2014-05-14 22:08:42 -04:00
|
|
|
Suite* r3_suite (void) {
|
|
|
|
Suite *suite = suite_create("blah");
|
|
|
|
|
|
|
|
TCase *tcase = tcase_create("testcase");
|
2014-05-20 04:18:17 -04:00
|
|
|
tcase_add_test(tcase, test_r3_node_construct_and_free);
|
2014-05-16 06:03:52 -04:00
|
|
|
tcase_add_test(tcase, test_str_array);
|
2014-05-15 00:53:48 -04:00
|
|
|
tcase_add_test(tcase, test_ltrim_slash);
|
2014-05-16 06:57:36 -04:00
|
|
|
tcase_add_test(tcase, test_r3_node_find_edge);
|
2014-05-20 12:47:09 -04:00
|
|
|
tcase_add_test(tcase, testr3_tree_insert_pathl);
|
2014-05-16 02:05:51 -04:00
|
|
|
tcase_add_test(tcase, test_compile);
|
2014-05-17 23:59:30 -04:00
|
|
|
tcase_add_test(tcase, test_route_cmp);
|
2014-05-18 01:04:17 -04:00
|
|
|
tcase_add_test(tcase, test_insert_route);
|
2014-05-18 02:30:00 -04:00
|
|
|
tcase_add_test(tcase, test_pcre_pattern_simple);
|
|
|
|
tcase_add_test(tcase, test_pcre_pattern_more);
|
2014-05-18 08:08:43 -04:00
|
|
|
tcase_add_test(tcase, test_pcre_patterns_insert);
|
2014-05-20 09:40:45 -04:00
|
|
|
tcase_add_test(tcase, test_pcre_patterns_insert_2);
|
2014-05-20 12:49:08 -04:00
|
|
|
tcase_add_test(tcase, test_pcre_patterns_insert_3);
|
2014-05-22 05:22:54 -04:00
|
|
|
tcase_add_test(tcase, test_feedback);
|
2014-05-18 08:13:07 -04:00
|
|
|
tcase_add_test(tcase, benchmark_str);
|
2014-05-16 06:03:52 -04:00
|
|
|
|
2014-05-14 12:15:19 -04:00
|
|
|
suite_add_tcase(suite, tcase);
|
2014-05-14 22:08:42 -04:00
|
|
|
|
2014-05-14 12:15:19 -04:00
|
|
|
return suite;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main (int argc, char *argv[]) {
|
|
|
|
int number_failed;
|
2014-05-14 22:08:42 -04:00
|
|
|
Suite *suite = r3_suite();
|
2014-05-14 12:15:19 -04:00
|
|
|
SRunner *runner = srunner_create(suite);
|
|
|
|
srunner_run_all(runner, CK_NORMAL);
|
|
|
|
number_failed = srunner_ntests_failed(runner);
|
|
|
|
srunner_free(runner);
|
|
|
|
return number_failed;
|
|
|
|
}
|