2021-01-09 02:24:51 +08:00
|
|
|
#include "common.h"
|
|
|
|
|
2019-11-30 12:33:00 +08:00
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include "util/buffer_util.h"
|
|
|
|
|
|
|
|
static void test_buffer_write16be(void) {
|
|
|
|
uint16_t val = 0xABCD;
|
|
|
|
uint8_t buf[2];
|
|
|
|
|
2022-02-12 16:12:46 +08:00
|
|
|
sc_write16be(buf, val);
|
2019-11-30 12:33:00 +08:00
|
|
|
|
|
|
|
assert(buf[0] == 0xAB);
|
|
|
|
assert(buf[1] == 0xCD);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_buffer_write32be(void) {
|
|
|
|
uint32_t val = 0xABCD1234;
|
|
|
|
uint8_t buf[4];
|
|
|
|
|
2022-02-12 16:12:46 +08:00
|
|
|
sc_write32be(buf, val);
|
2019-11-30 12:33:00 +08:00
|
|
|
|
|
|
|
assert(buf[0] == 0xAB);
|
|
|
|
assert(buf[1] == 0xCD);
|
|
|
|
assert(buf[2] == 0x12);
|
|
|
|
assert(buf[3] == 0x34);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_buffer_write64be(void) {
|
|
|
|
uint64_t val = 0xABCD1234567890EF;
|
|
|
|
uint8_t buf[8];
|
|
|
|
|
2022-02-12 16:12:46 +08:00
|
|
|
sc_write64be(buf, val);
|
2019-11-30 12:33:00 +08:00
|
|
|
|
|
|
|
assert(buf[0] == 0xAB);
|
|
|
|
assert(buf[1] == 0xCD);
|
|
|
|
assert(buf[2] == 0x12);
|
|
|
|
assert(buf[3] == 0x34);
|
|
|
|
assert(buf[4] == 0x56);
|
|
|
|
assert(buf[5] == 0x78);
|
|
|
|
assert(buf[6] == 0x90);
|
|
|
|
assert(buf[7] == 0xEF);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_buffer_read16be(void) {
|
|
|
|
uint8_t buf[2] = {0xAB, 0xCD};
|
|
|
|
|
2022-02-12 16:12:46 +08:00
|
|
|
uint16_t val = sc_read16be(buf);
|
2019-11-30 12:33:00 +08:00
|
|
|
|
|
|
|
assert(val == 0xABCD);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_buffer_read32be(void) {
|
|
|
|
uint8_t buf[4] = {0xAB, 0xCD, 0x12, 0x34};
|
|
|
|
|
2022-02-12 16:12:46 +08:00
|
|
|
uint32_t val = sc_read32be(buf);
|
2019-11-30 12:33:00 +08:00
|
|
|
|
|
|
|
assert(val == 0xABCD1234);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_buffer_read64be(void) {
|
|
|
|
uint8_t buf[8] = {0xAB, 0xCD, 0x12, 0x34,
|
|
|
|
0x56, 0x78, 0x90, 0xEF};
|
|
|
|
|
2022-02-12 16:12:46 +08:00
|
|
|
uint64_t val = sc_read64be(buf);
|
2019-11-30 12:33:00 +08:00
|
|
|
|
|
|
|
assert(val == 0xABCD1234567890EF);
|
|
|
|
}
|
|
|
|
|
2020-07-15 18:17:04 +08:00
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
(void) argc;
|
|
|
|
(void) argv;
|
|
|
|
|
2019-11-30 12:33:00 +08:00
|
|
|
test_buffer_write16be();
|
|
|
|
test_buffer_write32be();
|
|
|
|
test_buffer_write64be();
|
|
|
|
test_buffer_read16be();
|
|
|
|
test_buffer_read32be();
|
|
|
|
test_buffer_read64be();
|
|
|
|
return 0;
|
|
|
|
}
|