Skip to content
Snippets Groups Projects
Commit 4975adc7 authored by Anders Blomdell's avatar Anders Blomdell
Browse files

Added a few more tests.

parent 8cc26734
No related branches found
No related tags found
No related merge requests found
...@@ -42,18 +42,17 @@ static labcomm_decoder_t decoder = { ...@@ -42,18 +42,17 @@ static labcomm_decoder_t decoder = {
.data_size = sizeof(buffer), .data_size = sizeof(buffer),
.count = sizeof(buffer), .count = sizeof(buffer),
.pos = 0, .pos = 0,
// .error = 0,
.read = test_read, .read = test_read,
.ioctl = NULL, .ioctl = NULL,
.on_error = NULL, .on_error = NULL,
}, },
.do_register = NULL, .do_register = NULL,
// .do_decode = NULL,
.on_error = NULL, .on_error = NULL,
}; };
typedef unsigned int packed32; typedef unsigned int packed32;
typedef unsigned char boolean; typedef unsigned char boolean;
typedef unsigned char byte;
#define TEST_WRITE_READ(type, format, value, expect_count, expect_bytes) \ #define TEST_WRITE_READ(type, format, value, expect_count, expect_bytes) \
{ \ { \
...@@ -109,13 +108,20 @@ int main(void) ...@@ -109,13 +108,20 @@ int main(void)
TEST_WRITE_READ(packed32, "%d", 0xfffffff, 4, "\xef\xff\xff\xff"); TEST_WRITE_READ(packed32, "%d", 0xfffffff, 4, "\xef\xff\xff\xff");
TEST_WRITE_READ(packed32, "%d", 0x10000000, 5, "\xf0\x10\x00\x00\x00"); TEST_WRITE_READ(packed32, "%d", 0x10000000, 5, "\xf0\x10\x00\x00\x00");
TEST_WRITE_READ(packed32, "%d", 0xffffffff, 5, "\xf0\xff\xff\xff\xff"); TEST_WRITE_READ(packed32, "%d", 0xffffffff, 5, "\xf0\xff\xff\xff\xff");
TEST_WRITE_READ(boolean, "%d", 0, 1, "\00"); TEST_WRITE_READ(boolean, "%d", 0, 1, "\x00");
TEST_WRITE_READ(boolean, "%d", 1, 1, "\x01");
TEST_WRITE_READ(byte, "%d", 0, 1, "\x00");
TEST_WRITE_READ(byte, "%d", 1, 1, "\x01");
TEST_WRITE_READ(byte, "%d", 0xff, 1, "\xff");
TEST_WRITE_READ(short, "%d", 0, 2, "\x00\x00"); TEST_WRITE_READ(short, "%d", 0, 2, "\x00\x00");
TEST_WRITE_READ(short, "%d", 0x7fff, 2, "\x7f\xff"); TEST_WRITE_READ(short, "%d", 0x7fff, 2, "\x7f\xff");
TEST_WRITE_READ(short, "%d", -1, 2, "\xff\xff"); TEST_WRITE_READ(short, "%d", -1, 2, "\xff\xff");
TEST_WRITE_READ(int, "%d", 0, 4, "\x00\x00\x00\x00"); TEST_WRITE_READ(int, "%d", 0, 4, "\x00\x00\x00\x00");
TEST_WRITE_READ(int, "%d", 0x7fffffff, 4, "\x7f\xff\xff\xff"); TEST_WRITE_READ(int, "%d", 0x7fffffff, 4, "\x7f\xff\xff\xff");
TEST_WRITE_READ(int, "%d", -1, 4, "\xff\xff\xff\xff"); TEST_WRITE_READ(int, "%d", -1, 4, "\xff\xff\xff\xff");
TEST_WRITE_READ(long, "%ld", 0L, 8, "\x00\x00\x00\x00\x00\x00\x00\x00");
TEST_WRITE_READ(long, "%ld", 0x7fffffffffffffffL, 8, "\x7f\xff\xff\xff\xff\xff\xff\xff");
TEST_WRITE_READ(long, "%ld", -1L, 8, "\xff\xff\xff\xff\xff\xff\xff\xff");
TEST_WRITE_READ(float, "%f", 0.0, 4, "\x00\x00\x00\x00"); TEST_WRITE_READ(float, "%f", 0.0, 4, "\x00\x00\x00\x00");
TEST_WRITE_READ(float, "%f", 1.0, 4, "\x3f\x80\x00\x00"); TEST_WRITE_READ(float, "%f", 1.0, 4, "\x3f\x80\x00\x00");
TEST_WRITE_READ(float, "%f", 2.0, 4, "\x40\x00\x00\x00"); TEST_WRITE_READ(float, "%f", 2.0, 4, "\x40\x00\x00\x00");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment