Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| SHA1 Hash: | c1e38e8ce0d647014f646adffa47d74972532791 |
|---|---|
| Date: | 2009-06-08 20:52:42 |
| User: | stephan |
| Comment: | tinkering with the test code. |
Tags And Properties
- branch=trunk inherited from [2bd6172b61]
- sym-trunk inherited from [2bd6172b61]
Changes
Changes to test.c
| Old (65c58898d96b6066) | New (bbc3b447d99a2bc3) | |||
|---|---|---|---|---|
| 1 | #include <stdio.h> | < | ||
| 2 | #include <stdlib.h> | < | ||
| 3 | #include <string.h> | < | ||
| 4 | #include <ctype.h> | < | ||
| 5 | #include "whrc.h" | 1 | #include "whrc.h" | |
| 6 | #include "whst.h" | 2 | #include "whst.h" | |
| > | 3 | |||
| > | 4 | #include <assert.h> | ||
| > | 5 | #include <stdio.h> | ||
| > | 6 | #include <stdlib.h> //malloc() and co. | ||
| > | 7 | #include <string.h> //memset() | ||
| > | 8 | #include <ctype.h> | ||
| 7 | 9 | |||
| 8 | #if 1 | 10 | #if 1 | |
| 9 | #include <stdio.h> // only for debuggering | 11 | #include <stdio.h> // only for debuggering | |
| 10 | #define MARKER if(1) printf("MARKER: %s:%d:%s():\n",__FILE__,__LINE__,__func__); if(1) printf | 12 | #define MARKER if(1) printf("MARKER: %s:%d:%s():\n",__FILE__,__LINE__,__func__); if(1) printf | |
| 11 | #else | 13 | #else | |
| 12 | static void bogo_printf(char const * fmt, ...) {} | 14 | static void bogo_printf(char const * fmt, ...) {} | |
| 13 | #define MARKER if(0) bogo_printf | 15 | #define MARKER if(0) bogo_printf | |
| 14 | #endif | 16 | #endif | |
| 15 | 17 | |||
| > | 18 | void my_string_gc( void * x ) | ||
| > | 19 | { | ||
| > | 20 | MARKER("GCing string @%p: [%s]\n", x, (char const *)x); | ||
| > | 21 | free(x); | ||
| > | 22 | } | ||
| 16 | int test_one() | 23 | int test_one() | |
| 17 | { | 24 | { | |
| 18 | MARKER("starting test\n"); | 25 | MARKER("starting test\n"); | |
| 19 | whrc_context * cx = whrc_create_context(); | 26 | whrc_context * cx = whrc_create_context(); | |
| 20 | #define SLEN 20 | 27 | #define SLEN 20 | |
| 21 | char * str = (char *)malloc(SLEN+1); | 28 | char * str = (char *)malloc(SLEN+1); | |
| 22 | memset( str, 'x', SLEN ); | 29 | memset( str, 'x', SLEN ); | |
| 23 | str[SLEN] = 0; | 30 | str[SLEN] = 0; | |
| 24 | #undef SLEN | 31 | #undef SLEN | |
| 25 | whrc_register( cx, str, free ); | | | 32 | whrc_register( cx, str, my_string_gc ); |
| 26 | size_t rc = whrc_refcount(cx,str); // rc == 1 | 33 | size_t rc = whrc_refcount(cx,str); // rc == 1 | |
| 27 | MARKER("refcount=%u\n",rc); | 34 | MARKER("refcount=%u\n",rc); | |
| 28 | rc = whrc_addref(cx,str); //rc == 2 | 35 | rc = whrc_addref(cx,str); //rc == 2 | |
| > | 36 | assert( rc == 2 ); | ||
| 29 | MARKER("refcount=%u\n",rc); | 37 | MARKER("refcount=%u\n",rc); | |
| 30 | rc = whrc_rmref(cx,str); // rc == 1 | 38 | rc = whrc_rmref(cx,str); // rc == 1 | |
| > | 39 | assert( rc == 1 ); | ||
| 31 | MARKER("refcount=%u\n",rc); | 40 | MARKER("refcount=%u\n",rc); | |
| 32 | rc = whrc_rmref(cx,str); // rc == 0, free(str) is called | 41 | rc = whrc_rmref(cx,str); // rc == 0, free(str) is called | |
| > | 42 | assert( rc == 0 ); | ||
| 33 | MARKER("refcount=%u\n",rc); | 43 | MARKER("refcount=%u\n",rc); | |
| 34 | rc = whrc_rmref(cx,str); // rc == whrc_ref_err_val | 44 | rc = whrc_rmref(cx,str); // rc == whrc_ref_err_val | |
| > | 45 | assert( rc == whrc_ref_err_val ); | ||
| 35 | MARKER("refcount=%u\n",rc); | 46 | MARKER("refcount=%u\n",rc); | |
| 36 | whrc_destroy_context(cx,true); | 47 | whrc_destroy_context(cx,true); | |
| 37 | MARKER("ending test\n"); | 48 | MARKER("ending test\n"); | |
| 38 | return 0; | 49 | return 0; | |
| 39 | } | 50 | } | |
| 31 hidden lines | ||||
| 71 | } | 82 | } | |
| 72 | 83 | |||
| 73 | int main( int argc, char ** argv ) | 84 | int main( int argc, char ** argv ) | |
| 74 | { | 85 | { | |
| 75 | int rc = 0; | 86 | int rc = 0; | |
| 76 | //if(!rc) rc = test_one(); | | | 87 | if(!rc) rc = test_one(); |
| 77 | if(!rc) rc = test_whst(); | | | 88 | //if(!rc) rc = test_whst(); |
| 78 | printf("Done rc=%d=[%s].\n",rc, | 89 | printf("Done rc=%d=[%s].\n",rc, | |
| 79 | (0==rc) | 90 | (0==rc) | |
| 80 | ? "You win :)" | 91 | ? "You win :)" | |
| 81 | : "You lose :("); | 92 | : "You lose :("); | |
| 82 | return rc; | 93 | return rc; | |
| 83 | } | 94 | } | |