mirror of https://github.com/svaarala/duktape.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
1.8 KiB
83 lines
1.8 KiB
/*===
|
|
*** test_1 (duk_safe_call)
|
|
buffer: ptr-is-NULL=0, sz=1024
|
|
buffer
|
|
buffer: ptr-is-NULL=-1, sz=0
|
|
buffer
|
|
buffer: ptr-is-NULL=0, sz=1024
|
|
buffer
|
|
buffer: ptr-is-NULL=-1, sz=0
|
|
buffer
|
|
==> rc=0, result='undefined'
|
|
*** test_2 (duk_safe_call)
|
|
==> rc=1, result='TypeError: not buffer'
|
|
*** test_3 (duk_safe_call)
|
|
==> rc=1, result='TypeError: not buffer'
|
|
*** test_4 (duk_safe_call)
|
|
==> rc=1, result='TypeError: not buffer'
|
|
===*/
|
|
|
|
int test_1(duk_context *ctx) {
|
|
void *ptr;
|
|
size_t sz;
|
|
int i;
|
|
|
|
duk_set_top(ctx, 0);
|
|
duk_push_fixed_buffer(ctx, 1024);
|
|
duk_push_fixed_buffer(ctx, 0);
|
|
duk_push_dynamic_buffer(ctx, 1024);
|
|
duk_push_dynamic_buffer(ctx, 0);
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
sz = (size_t) 0xdeadbeef;
|
|
ptr = duk_require_buffer(ctx, i, &sz);
|
|
printf("buffer: ptr-is-NULL=%d, sz=%d\n", (sz == 0 ? -1 : (ptr == NULL ? 1 : 0)), (int) sz);
|
|
|
|
sz = (size_t) 0xdeadbeef;
|
|
ptr = duk_require_buffer(ctx, i, NULL);
|
|
printf("buffer\n");
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
int test_2(duk_context *ctx) {
|
|
void *ptr;
|
|
size_t sz;
|
|
|
|
duk_set_top(ctx, 0);
|
|
duk_push_null(ctx);
|
|
sz = (size_t) 0xdeadbeef;
|
|
ptr = duk_require_buffer(ctx, 0, &sz);
|
|
printf("buffer ok: %p\n", ptr); /* ok to print, should not be reached */
|
|
return 0;
|
|
}
|
|
|
|
int test_3(duk_context *ctx) {
|
|
void *ptr;
|
|
size_t sz;
|
|
|
|
duk_set_top(ctx, 0);
|
|
sz = (size_t) 0xdeadbeef;
|
|
ptr = duk_require_buffer(ctx, 0, &sz);
|
|
printf("buffer ok: %p\n", ptr); /* ok to print, should not be reached */
|
|
return 0;
|
|
}
|
|
|
|
int test_4(duk_context *ctx) {
|
|
void *ptr;
|
|
size_t sz;
|
|
|
|
duk_set_top(ctx, 0);
|
|
sz = (size_t) 0xdeadbeef;
|
|
ptr = duk_require_buffer(ctx, DUK_INVALID_INDEX, &sz);
|
|
printf("buffer ok: %p\n", ptr); /* ok to print, should not be reached */
|
|
return 0;
|
|
}
|
|
|
|
void test(duk_context *ctx) {
|
|
TEST_SAFE_CALL(test_1);
|
|
TEST_SAFE_CALL(test_2);
|
|
TEST_SAFE_CALL(test_3);
|
|
TEST_SAFE_CALL(test_4);
|
|
}
|
|
|