]> git.ozlabs.org Git - ccan/blobdiff - ccan/ccan_tokenizer/test/run.c
htable: fix tools/speed.
[ccan] / ccan / ccan_tokenizer / test / run.c
index 9a4ae19ba9ce587ced48631c14011dbef6628f1b..92fe43c68a67d818bd64133bf681f9af11f66407 100644 (file)
         THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
-#include "ccan_tokenizer/read_cnumber.c"
-#include "ccan_tokenizer/read_cstring.c"
-#include "ccan_tokenizer/dict.c"
-#include "ccan_tokenizer/ccan_tokenizer.c"
-#include "ccan_tokenizer/queue.c"
-#include "ccan_tokenizer/charflag.c"
+#include <ccan/ccan_tokenizer/read_cnumber.c>
+#include <ccan/ccan_tokenizer/read_cstring.c>
+#include <ccan/ccan_tokenizer/dict.c>
+#include <ccan/ccan_tokenizer/ccan_tokenizer.c>
+#include <ccan/ccan_tokenizer/queue.c>
+#include <ccan/ccan_tokenizer/charflag.c>
 
-#include "ccan_tokenizer/ccan_tokenizer.h"
+#include <ccan/ccan_tokenizer/ccan_tokenizer.h>
 
-#include "tap/tap.h"
+#include <ccan/tap/tap.h>
 
 #include <math.h>
 
 #define array_count_pair(type, ...) (const type []){__VA_ARGS__}, sizeof((const type []){__VA_ARGS__})/sizeof(type)
 
 static void test_read_cstring(void) {
-       #define next() do {array_free(str); array_init(str, NULL); csp++;} while(0)
+       #define next() do {darray_free(str); darray_init(str); csp++;} while(0)
        #define cs (*csp)
        #define verify_quotechar(correct, correct_continuation_offset, quotechar) do { \
                const size_t s = sizeof(correct)-1; \
@@ -69,7 +69,7 @@ static void test_read_cstring(void) {
        };
        const char * const *csp = cstrings;
        const char *p;
-       array_char str = array_new(NULL);
+       darray_char str = darray_new();
        tok_message_queue mq;
        
        queue_init(mq, NULL);
@@ -107,7 +107,7 @@ static void test_read_cstring(void) {
        //Check a series of hex escapes
        verify("\x50\x35\x12\xEF\xFE\x12\x45", 32);
        
-       array_free(str);
+       darray_free(str);
        
        //tok_message_queue_dump(&mq);
        
@@ -147,7 +147,7 @@ static void test_read_cstring(void) {
                                queue_skip(mq);
                }
                if (i<e)
-                       printf("Item %u is incorrect\n", i);
+                       printf("Item %zu is incorrect\n", i);
                ok(i==e, "Is message queue correct?");
                ok(!queue_count(mq), "Message queue should be empty now.");
        }
@@ -685,7 +685,7 @@ static void test_scan_number_single(const char *str_pipes,
                return;
        }
        if (sn.dots_found != dots_found) {
-               fail("%s : sn.dots_found is %d; should be %d", str_pipes,
+               fail("%s : sn.dots_found is %zu; should be %zu", str_pipes,
                        sn.dots_found, dots_found);
                return;
        }
@@ -896,7 +896,7 @@ struct tokenizer_test {
 };
 
 #define T(txt, ...) {txt, sizeof(txt)-1, array_count_pair(struct token, __VA_ARGS__)}
-#define string(txt) {.string={.item = (txt), .size = sizeof(txt)-1}}
+#define string(txt) {.string=(darray_char[1]){{.item = (txt), .size = sizeof(txt)-1}}}
 #define opkw(v) {.opkw = (v)}
 #define txt(t) .txt = (t), .txt_size = sizeof(t)-1
 #define integer(...) {.integer={__VA_ARGS__}}
@@ -1226,7 +1226,7 @@ static void test_tokenizer_single(struct tokenizer_test *t, tok_message_queue *m
                goto done; \
        } while(0)
        
-       tl = tokenize(txt, txt_size, mq);
+       tl = tokenize(txt, txt, txt_size, mq);
        
        if (tl->orig != txt || tl->orig_size != txt_size)
                failed("tokenize() did not replicate orig/orig_size from arguments");
@@ -1271,10 +1271,10 @@ static void test_tokenizer_single(struct tokenizer_test *t, tok_message_queue *m
                        case TOK_CHAR:
                        case TOK_STRING:
                                //anything using string
-                               if (tok_gen->string.size != tok_correct->string.size ||
-                                       memcmp(tok_gen->string.item, tok_correct->string.item,
-                                       tok_gen->string.size) ||
-                                       tok_gen->string.item[tok_gen->string.size] != 0 )
+                               if (tok_gen->string->size != tok_correct->string->size ||
+                                       memcmp(tok_gen->string->item, tok_correct->string->item,
+                                       tok_gen->string->size) ||
+                                       tok_gen->string->item[tok_gen->string->size] != 0 )
                                        failed("Token \"%s\": String value incorrect", tok_correct->txt);
                                break;
                        case TOK_STRING_IQUOTE:
@@ -1309,7 +1309,7 @@ done:
 
 static void test_tokenizer_file(const char *file_name, tok_message_queue *mq) {
        FILE *f = fopen(file_name, "rb");
-       array_char text = array_new(NULL);
+       darray_char *text = talloc_darray(NULL);
        const size_t inc = 1024;
        struct token_list *tl;
        
@@ -1321,10 +1321,10 @@ static void test_tokenizer_file(const char *file_name, tok_message_queue *mq) {
        for (;;) {
                size_t read_len;
                
-               array_realloc(text, text.size+inc+1);
-               read_len = fread(text.item+text.size, 1, inc, f);
-               text.size += read_len;
-               text.item[text.size] = 0;
+               darray_realloc(*text, text->size+inc+1);
+               read_len = fread(text->item+text->size, 1, inc, f);
+               text->size += read_len;
+               text->item[text->size] = 0;
                
                if (read_len < inc)
                        break;
@@ -1335,7 +1335,7 @@ static void test_tokenizer_file(const char *file_name, tok_message_queue *mq) {
                goto end;
        }
        
-       tl = tokenize(text.item, text.size, mq);
+       tl = tokenize(text, text->item, text->size, mq);
        tl->filename = file_name;
        
        //printf("File '%s' has %zu tokens\n", file_name, token_list_count(tl));
@@ -1354,7 +1354,7 @@ static void test_tokenizer_file(const char *file_name, tok_message_queue *mq) {
        }*/
        
 end:
-       array_free(text);
+       talloc_free(text);
        if (f)
                fclose(f);
 }
@@ -1411,7 +1411,7 @@ static void test_tokenizer(void) {
        msg_fail:;
        }
        
-       test_tokenizer_file("ccan/ccan_tokenizer/test/run.c", &mq);
+       test_tokenizer_file("test/run.c", &mq);
        
        while (queue_count(mq)) {
                struct tok_message msg = dequeue(mq);