diff options
author | Sverker Eriksson <[email protected]> | 2019-04-03 21:16:59 +0200 |
---|---|---|
committer | Sverker Eriksson <[email protected]> | 2019-04-17 19:09:12 +0200 |
commit | 6465de7e3a5393a80ed0e2c63f012fd126de706f (patch) | |
tree | f85198d2afe765a8f3b7c94ed31b36830346b006 /lib/erl_interface/test/ei_decode_SUITE_data | |
parent | 46aa940b9d771c4806aacaf065c2f637474e9815 (diff) | |
download | otp-6465de7e3a5393a80ed0e2c63f012fd126de706f.tar.gz otp-6465de7e3a5393a80ed0e2c63f012fd126de706f.tar.bz2 otp-6465de7e3a5393a80ed0e2c63f012fd126de706f.zip |
erl_interface: Add bitstring and export fun support
Diffstat (limited to 'lib/erl_interface/test/ei_decode_SUITE_data')
-rw-r--r-- | lib/erl_interface/test/ei_decode_SUITE_data/ei_decode_test.c | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/lib/erl_interface/test/ei_decode_SUITE_data/ei_decode_test.c b/lib/erl_interface/test/ei_decode_SUITE_data/ei_decode_test.c index 66cdf2f502..d39970a857 100644 --- a/lib/erl_interface/test/ei_decode_SUITE_data/ei_decode_test.c +++ b/lib/erl_interface/test/ei_decode_SUITE_data/ei_decode_test.c @@ -317,6 +317,69 @@ static void decode_bin(int exp_size, const char* val, int exp_len) free_packet(buf); } +static void decode_bits(int exp_size, const char* val, size_t exp_bits) +{ + char p[1024]; + char *buf; + size_t bits; + int size1 = 0; + int size2 = 0; + int err; + message("ei_decode_bitstring should be %d bits", (int)exp_bits); + buf = read_packet(NULL); + err = ei_decode_bitstring(buf+1, &size1, NULL, sizeof(p), &bits); + message("err = %d, size = %d, len = %d, expected size = %d, expected bits = %d\n",\ + err,size1, (int)bits, exp_size, (int)exp_bits); + + if (err != 0) { + if (err != -1) { + fail("returned non zero but not -1 if NULL pointer"); + } else { + fail("returned non zero"); + } + return; + } + + if (bits != exp_bits) { + fail("number of bits is not correct"); + return; + } + + err = ei_decode_bitstring(buf+1, &size2, p, sizeof(p), &bits); + message("err = %d, size = %d, len = %d, expected size = %d, expected len = %d\n",\ + err,size2, (int)bits, exp_size, (int)exp_bits); + if (err != 0) { + if (err != -1) { + fail("returned non zero but not -1 if NULL pointer"); + } else { + fail("returned non zero"); + } + return; + } + + if (bits != exp_bits) { + fail("bits is not correct"); + return; + } + + if (memcmp(p, val, (exp_bits+7)/8) != 0) { + fail("value is not correct"); + return; + } + + if (size1 != size2) { + fail("size with and without pointer differs"); + return; + } + + if (size1 != exp_size) { + fail2("size of encoded data is incorrect %d != %d", size1, exp_size); + return; + } + free_packet(buf); +} + + /* ******************************************************************** */ TESTCASE(test_ei_decode_long) @@ -648,6 +711,14 @@ TESTCASE(test_ei_decode_misc) decode_bin(5, "", 0); decode_bin(11, "������", 6); +#define LAST_BYTE(V, BITS) ((V) << (8-(BITS))) + { + unsigned char bits1[] = {1, 2, LAST_BYTE(3,5) }; + unsigned char bits2[] = {LAST_BYTE(1,1) }; + decode_bits(9, bits1, 21); + decode_bits(7, bits2, 1); + } + /* FIXME check \0 in strings and atoms? */ /* EI_ENCODE_1(decode_tuple_header, 0); |