diff options
author | ttate <ttate@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2002-05-20 09:38:23 +0000 |
---|---|---|
committer | ttate <ttate@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2002-05-20 09:38:23 +0000 |
commit | a2db8e72c10c5e5506f18314ac805cd8206a4181 (patch) | |
tree | b9026d4ea72cc59db8cda5c82e2bafa7f20f0e77 /ext/dl/test | |
parent | 077d92a044cb22bfa88f39bfef43ea77e89440db (diff) |
Get rid of the declaration of rb_str_cat2().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2475 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/dl/test')
-rw-r--r-- | ext/dl/test/test.c | 47 | ||||
-rw-r--r-- | ext/dl/test/test.rb | 21 |
2 files changed, 35 insertions, 33 deletions
diff --git a/ext/dl/test/test.c b/ext/dl/test/test.c index ed42b4d1a0..7321379390 100644 --- a/ext/dl/test/test.c +++ b/ext/dl/test/test.c @@ -148,30 +148,32 @@ test_append(char *ary[], int len, char *astr) }; }; -void +int test_init(int *argc, char **argv[]) { int i; - printf("test_init(0x%x,0x%x)\n",argc,argv); - printf("\t*(0x%x) => %d\n",argc,*argc); + char s[256]; + for( i=0; i < (*argc); i++ ){ - printf("\t(*(0x%x)[%d]) => %s\n", argv, i, (*argv)[i]); - }; -}; + sprintf(s, "arg%d", i); + if( strcmp((*argv)[i], s) != 0 ){ + return 1; + } + } + return 0; +} FILE * test_open(const char *filename, const char *mode) { FILE *file; file = fopen(filename,mode); - printf("test_open(%s,%s):0x%x\n",filename,mode,file); return file; }; void test_close(FILE *file) { - printf("test_close(0x%x)\n",file); fclose(file); }; @@ -182,26 +184,29 @@ test_gets(char *s, int size, FILE *f) }; typedef int callback1_t(int, char *); +#define CALLBACK_MSG "callback message" int test_callback1(int err, const char *msg) { - printf("internal callback function (err = %d, msg = '%s')\n", - err, msg ? msg : "(null)"); - return 1; -}; + if( strcmp(msg, CALLBACK_MSG) == 0 ){ + return 1; + } + else{ + return 0; + } +} int test_call_func1(callback1_t *func) { if( func ){ - return (*func)(0, "this is test_call_func1."); + return (*func)(0, CALLBACK_MSG); } else{ - printf("test_call_func1(func = 0)\n"); - return -1; + return 0; } -}; +} struct test_data * test_data_init() @@ -227,16 +232,6 @@ test_data_add(struct test_data *list, const char *name) list->next = data; }; -void -test_data_print(struct test_data *list) -{ - struct test_data *data; - - for( data = list->next; data; data = data->next ){ - printf("name = %s\n", data->name); - }; -}; - struct test_data * test_data_aref(struct test_data *list, int i) { diff --git a/ext/dl/test/test.rb b/ext/dl/test/test.rb index c4f1915387..316201a0b3 100644 --- a/ext/dl/test/test.rb +++ b/ext/dl/test/test.rb @@ -3,11 +3,16 @@ require 'dl' require 'dl/import' +$FAIL = 0 +$TOTAL = 0 + def assert(label, ty, *conds) + $TOTAL += 1 cond = !conds.include?(false) if( cond ) printf("succeed in `#{label}'\n") else + $FAIL += 1 case ty when :may printf("fail in `#{label}' ... expected\n") @@ -158,12 +163,12 @@ DL.dlopen($LIB){|h| debug r,rs assert("strcat", :must, rs[0].to_s == "abcx") - init = h["test_init","0iP"] + init = h["test_init","IiP"] debug init argc = 3 argv = ["arg0","arg1","arg2"].to_ptr r,rs = init[argc, argv.ref] - debug r,rs + assert("init", :must, r == 0) } @@ -203,9 +208,11 @@ assert("callback1", :must, r == 1) callback2 = DL.set_callback("LLP", 0){|arg1,arg2| ptr = arg2 # DL::PtrData.new(arg2) msg = ptr.to_s - print("user defined callback function", - "(err = #{arg1}, msg = '#{msg}')\n") - 2 + if( msg == "callback message" ) + 2 + else + 0 + end } debug callback2 r,rs = h["test_call_func1", "IP"][callback2] @@ -249,14 +256,12 @@ assert("set value", :must, ptr[:l] == lval) unless (Fixnum === :-) data_init = h["test_data_init", "P"] data_add = h["test_data_add", "0PS"] -data_print = h["test_data_print", "0P"] data_aref = h["test_data_aref", "PPI"] r,rs = data_init[] ptr = r data_add[ptr, "name1"] data_add[ptr, "name2"] data_add[ptr, "name3"] -data_print[ptr] r,rs = data_aref[ptr, 1] ptr = r @@ -288,3 +293,5 @@ assert("struct!", :must, ptr["l"] == 4) GC.start + +printf("fail/total = #{$FAIL}/#{$TOTAL}\n") |