forked from svaarala/duktape
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-debugger-notify.c
More file actions
74 lines (59 loc) · 1.76 KB
/
test-debugger-notify.c
File metadata and controls
74 lines (59 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
* duk_debugger_notify()
*/
/*===
*** test_notify_not_attached (duk_safe_call)
top: 0
top: 0
top: 1
string: dummy below nvalues
final top: 1
==> rc=0, result='undefined'
===*/
static duk_ret_t test_notify_not_attached(duk_context *ctx, void *udata) {
(void) udata;
/* Not attached, ignored; no arguments. */
duk_debugger_notify(ctx, 0);
printf("top: %ld\n", (long) duk_get_top(ctx));
/* Not attached, ignored, two arguments. */
duk_push_string(ctx, "DummyNotify");
duk_push_int(ctx, 123);
duk_debugger_notify(ctx, 2);
printf("top: %ld\n", (long) duk_get_top(ctx));
/* Check that argument below 'nvalues' is untouched. */
duk_push_string(ctx, "dummy below nvalues");
duk_push_string(ctx, "DummyNotify");
duk_push_int(ctx, 123);
duk_debugger_notify(ctx, 2);
printf("top: %ld\n", (long) duk_get_top(ctx));
printf("string: %s\n", duk_safe_to_string(ctx, 0));
printf("final top: %ld\n", (long) duk_get_top(ctx));
return 0;
}
/*===
*** test_notify_invalid_count1 (duk_safe_call)
==> rc=1, result='RangeError: not enough stack values for notify'
===*/
static duk_ret_t test_notify_invalid_count1(duk_context *ctx, void *udata) {
(void) udata;
duk_push_string(ctx, "DummyNotify");
duk_debugger_notify(ctx, 2);
printf("final top: %ld\n", (long) duk_get_top(ctx));
return 0;
}
/*===
*** test_notify_invalid_count2 (duk_safe_call)
==> rc=1, result='RangeError: invalid count'
===*/
static duk_ret_t test_notify_invalid_count2(duk_context *ctx, void *udata) {
(void) udata;
duk_push_string(ctx, "DummyNotify");
duk_debugger_notify(ctx, -1);
printf("final top: %ld\n", (long) duk_get_top(ctx));
return 0;
}
void test(duk_context *ctx) {
TEST_SAFE_CALL(test_notify_not_attached);
TEST_SAFE_CALL(test_notify_invalid_count1);
TEST_SAFE_CALL(test_notify_invalid_count2);
}