diff options
author | Sverker Eriksson <[email protected]> | 2014-03-06 12:25:05 +0100 |
---|---|---|
committer | Sverker Eriksson <[email protected]> | 2014-03-06 20:09:52 +0100 |
commit | 453cba0046ec8363a4c3cea97ce22a6f4ff0b75a (patch) | |
tree | 87e6750c1d89c67fddac48ee9ab08ac2f79ea417 /lib | |
parent | caeea720b52252bc37f1e60bf546333bfe3c2cf8 (diff) | |
download | otp-453cba0046ec8363a4c3cea97ce22a6f4ff0b75a.tar.gz otp-453cba0046ec8363a4c3cea97ce22a6f4ff0b75a.tar.bz2 otp-453cba0046ec8363a4c3cea97ce22a6f4ff0b75a.zip |
erl_interface: test decode_encode of tuples and lists
Diffstat (limited to 'lib')
-rw-r--r-- | lib/erl_interface/test/ei_decode_encode_SUITE.erl | 7 | ||||
-rw-r--r-- | lib/erl_interface/test/ei_decode_encode_SUITE_data/ei_decode_encode_test.c | 59 |
2 files changed, 63 insertions, 3 deletions
diff --git a/lib/erl_interface/test/ei_decode_encode_SUITE.erl b/lib/erl_interface/test/ei_decode_encode_SUITE.erl index c7830f58f2..b0952d4b04 100644 --- a/lib/erl_interface/test/ei_decode_encode_SUITE.erl +++ b/lib/erl_interface/test/ei_decode_encode_SUITE.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2013. All Rights Reserved. +%% Copyright Ericsson AB 2004-2014. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -127,6 +127,11 @@ test_ei_decode_encode(Config) when is_list(Config) -> send_rec(P, mk_ref({Atom,1}, [262143, 8723648, 24097245])), void end || Atom <- unicode_atom_data()], + + send_rec(P, {}), + send_rec(P, {atom, Pid, Port, Ref}), + send_rec(P, [atom, Pid, Port, Ref]), + send_rec(P, [atom | Fun]), ?line runner:recv_eot(P), ok. diff --git a/lib/erl_interface/test/ei_decode_encode_SUITE_data/ei_decode_encode_test.c b/lib/erl_interface/test/ei_decode_encode_SUITE_data/ei_decode_encode_test.c index 3e32be8087..9a50aef7b6 100644 --- a/lib/erl_interface/test/ei_decode_encode_SUITE_data/ei_decode_encode_test.c +++ b/lib/erl_interface/test/ei_decode_encode_SUITE_data/ei_decode_encode_test.c @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 2004-2013. All Rights Reserved. + * Copyright Ericsson AB 2004-2014. All Rights Reserved. * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in @@ -128,6 +128,45 @@ struct Type tuple_type = { my_encode_tuple_header, my_x_encode_tuple_header }; +int my_encode_list_header(char *buf, int *index, union my_obj* obj) +{ + return ei_encode_list_header(buf, index, obj->arity); +} +int my_x_encode_list_header(ei_x_buff* x, union my_obj* obj) +{ + return ei_x_encode_list_header(x, (long)obj->arity); +} + +struct Type list_type = { + "list_header", "arity", (decodeFT*)ei_decode_list_header, + my_encode_list_header, my_x_encode_list_header +}; + + +int my_decode_nil(const char *buf, int *index, union my_obj* dummy) +{ + int type, size, ret; + ret = ei_get_type(buf, index, &type, &size); + (*index)++; + return ret ? ret : !(type == ERL_NIL_EXT); + +} +int my_encode_nil(char *buf, int *index, union my_obj* dummy) +{ + return ei_encode_empty_list(buf, index); +} + +int my_x_encode_nil(ei_x_buff* x, union my_obj* dummy) +{ + return ei_x_encode_empty_list(x); +} + +struct Type nil_type = { + "empty_list", "nil", (decodeFT*)my_decode_nil, + my_encode_nil, my_x_encode_nil +}; + + #define BUFSZ 2000 void decode_encode(struct Type** tv, int nobj) @@ -186,7 +225,7 @@ void decode_encode(struct Type** tv, int nobj) return; } - if (t != &tuple_type) { + if (t != &tuple_type && t != &list_type) { size2 = 0; err = ei_skip_term(inp, &size2); if (err != 0) { @@ -389,6 +428,22 @@ TESTCASE(test_ei_decode_encode) decode_encode_one(&ref_type); } + decode_encode_one(&tuple_type); /* {} */ + { + struct Type* tpl[] = { &tuple_type, &my_atom_type, &pid_type, &port_type, &ref_type }; + decode_encode(tpl, 5); + } + + { + struct Type* list[] = { &list_type, &my_atom_type, &pid_type, &port_type, &ref_type, &nil_type }; + decode_encode(list, 6); + } + { + struct Type* list[] = { &list_type, &my_atom_type, &fun_type }; + decode_encode(list, 3); + } + + report(1); } |