static duk_ret_t test_pop_3a(duk_context *ctx, void *udata) { (void) udata; duk_pop_3(ctx); PRINTTOP(); duk_pop_3(ctx); PRINTTOP(); return 0; }
static duk_ret_t test_pop_3b(duk_context *ctx, void *udata) { (void) udata; duk_pop_3(ctx); PRINTTOP(); duk_pop_3(ctx); PRINTTOP(); /* no more entries, causes error */ duk_pop_3(ctx); PRINTTOP(); return 0; }
static duk_ret_t test_pop_na(duk_context *ctx, void *udata) { (void) udata; duk_pop_n(ctx, 0); PRINTTOP(); duk_pop_n(ctx, 1); PRINTTOP(); duk_pop_n(ctx, 10); PRINTTOP(); return 0; }
void test(duk_context *ctx) { duk_ret_t rc; /* Custom test macro, prints top after call. */ SETUP(2); PRINTTOP(); rc = duk_safe_call(ctx, test_pop_a, NULL, 2, 1); printf("test_pop_1 -> top=%ld, rc=%d, ret='%s'\n", (long) duk_get_top(ctx), (int) rc, duk_to_string(ctx, -1)); SETUP(2); PRINTTOP(); rc = duk_safe_call(ctx, test_pop_b, NULL, 2, 1); printf("test_pop_b -> top=%ld, rc=%d, ret='%s'\n", (long) duk_get_top(ctx), (int) rc, duk_to_string(ctx, -1)); SETUP(5); PRINTTOP(); rc = duk_safe_call(ctx, test_pop_2a, NULL, 5, 1); printf("test_pop_2a -> top=%ld, rc=%d, ret='%s'\n", (long) duk_get_top(ctx), (int) rc, duk_to_string(ctx, -1)); SETUP(5); PRINTTOP(); rc = duk_safe_call(ctx, test_pop_2b, NULL, 5, 1); printf("test_pop_2b -> top=%ld, rc=%d, ret='%s'\n", (long) duk_get_top(ctx), (int) rc, duk_to_string(ctx, -1)); SETUP(7); PRINTTOP(); rc = duk_safe_call(ctx, test_pop_3a, NULL, 7, 1); printf("test_pop_3a -> top=%ld, rc=%d, ret='%s'\n", (long) duk_get_top(ctx), (int) rc, duk_to_string(ctx, -1)); SETUP(7); PRINTTOP(); rc = duk_safe_call(ctx, test_pop_3b, NULL, 7, 1); printf("test_pop_3b -> top=%ld, rc=%d, ret='%s'\n", (long) duk_get_top(ctx), (int) rc, duk_to_string(ctx, -1)); SETUP(11); PRINTTOP(); rc = duk_safe_call(ctx, test_pop_na, NULL, 11, 1); printf("test_pop_na -> top=%ld, rc=%d, ret='%s'\n", (long) duk_get_top(ctx), (int) rc, duk_to_string(ctx, -1)); SETUP(11); PRINTTOP(); rc = duk_safe_call(ctx, test_pop_nb, NULL, 11, 1); printf("test_pop_nb -> top=%ld, rc=%d, ret='%s'\n", (long) duk_get_top(ctx), (int) rc, duk_to_string(ctx, -1)); PRINTTOP(); }
void test(duk_context *ctx) { const char *res; duk_push_undefined(ctx); PRINTTOP(); duk_push_null(ctx); PRINTTOP(); duk_push_true(ctx); PRINTTOP(); duk_push_false(ctx); PRINTTOP(); duk_push_boolean(ctx, -1); PRINTTOP(); duk_push_boolean(ctx, 0); PRINTTOP(); duk_push_boolean(ctx, 1); PRINTTOP(); duk_push_number(ctx, 123.4); PRINTTOP(); duk_push_int(ctx, 234); PRINTTOP(); duk_push_nan(ctx); PRINTTOP(); res = duk_push_string(ctx, "foo"); PRINTRESTOP(); res = duk_push_string(ctx, "foo\0bar\0"); PRINTRESTOP(); res = duk_push_string(ctx, ""); PRINTRESTOP(); /* pushes empty */ res = duk_push_string(ctx, NULL); PRINTRESTOP(); /* pushes a NULL */ res = duk_push_lstring(ctx, "foobar", 4); PRINTRESTOP(); res = duk_push_lstring(ctx, "foob\0\0", 6); PRINTRESTOP(); res = duk_push_lstring(ctx, "\0", 1); PRINTRESTOP(); /* pushes 1-byte string (0x00) */ res = duk_push_lstring(ctx, "\0", 0); PRINTRESTOP(); /* pushes empty */ res = duk_push_lstring(ctx, NULL, 0); PRINTRESTOP(); /* pushes empty */ res = duk_push_lstring(ctx, NULL, 10); PRINTRESTOP(); /* pushes empty */ res = duk_push_sprintf(ctx, "foo"); PRINTRESTOP(); res = duk_push_sprintf(ctx, "foo %d %s 0x%08lx", 123, "bar", (long) 0x1234cafe); PRINTRESTOP(); res = duk_push_sprintf(ctx, ""); PRINTRESTOP(); res = duk_push_sprintf(ctx, NULL); PRINTRESTOP(); res = test_vsprintf_3x_int(ctx, 2, 3, 5); PRINTRESTOP(); res = test_vsprintf_empty(ctx, 2, 3, 5); PRINTRESTOP(); res = test_vsprintf_null(ctx, 2, 3, 5); PRINTRESTOP(); duk_push_pointer(ctx, (void *) 0); PRINTTOP(); duk_push_pointer(ctx, (void *) 0xdeadbeef); PRINTTOP(); }