awtk/tests/fscript_endian_test.cc

81 lines
1.6 KiB
C++
Raw Normal View History

2021-01-04 10:44:15 +08:00
#include "tkc/fscript.h"
#include "tkc/object_default.h"
#include "gtest/gtest.h"
TEST(FExr, is_little) {
value_t v;
tk_object_t* obj = object_default_create();
2021-01-20 13:41:57 +08:00
2021-01-04 10:44:15 +08:00
fscript_eval(obj, "is_little()", &v);
ASSERT_EQ(value_bool(&v), TRUE);
value_reset(&v);
TK_OBJECT_UNREF(obj);
2021-01-04 10:44:15 +08:00
}
TEST(FExr, endian_htons) {
value_t v;
tk_object_t* obj = object_default_create();
2021-01-04 10:44:15 +08:00
fscript_eval(obj, "htons(0x1122)", &v);
ASSERT_EQ(value_int(&v), 0x2211);
value_reset(&v);
2021-01-20 13:41:57 +08:00
TK_OBJECT_UNREF(obj);
2021-01-04 10:44:15 +08:00
}
TEST(FExr, endian_htonl) {
value_t v;
tk_object_t* obj = object_default_create();
2021-01-04 10:44:15 +08:00
fscript_eval(obj, "htonl(0x11223344)", &v);
2021-09-16 16:06:55 +08:00
ASSERT_EQ(value_uint32(&v), 0x44332211u);
2021-01-04 10:44:15 +08:00
value_reset(&v);
2021-01-20 13:41:57 +08:00
TK_OBJECT_UNREF(obj);
2021-01-04 10:44:15 +08:00
}
TEST(FExr, endian_htonf) {
value_t v;
tk_object_t* obj = object_default_create();
2021-01-04 10:44:15 +08:00
fscript_eval(obj, "ntohf(htonf(100))", &v);
ASSERT_EQ(value_int(&v), 100);
value_reset(&v);
2021-01-20 13:41:57 +08:00
TK_OBJECT_UNREF(obj);
2021-01-04 10:44:15 +08:00
}
TEST(FExr, endian_ntohs) {
value_t v;
tk_object_t* obj = object_default_create();
2021-01-04 10:44:15 +08:00
fscript_eval(obj, "ntohs(0x1122)", &v);
ASSERT_EQ(value_int(&v), 0x2211);
value_reset(&v);
2021-01-20 13:41:57 +08:00
TK_OBJECT_UNREF(obj);
2021-01-04 10:44:15 +08:00
}
TEST(FExr, endian_ntohl) {
value_t v;
tk_object_t* obj = object_default_create();
2021-01-04 10:44:15 +08:00
fscript_eval(obj, "ntohl(0x11223344)", &v);
2021-09-16 16:06:55 +08:00
ASSERT_EQ(value_uint32(&v), 0x44332211u);
2021-01-04 10:44:15 +08:00
value_reset(&v);
2021-01-20 13:41:57 +08:00
TK_OBJECT_UNREF(obj);
2021-01-04 10:44:15 +08:00
}
2021-01-04 17:22:32 +08:00
TEST(FExr, endian_ntohll) {
value_t v;
tk_object_t* obj = object_default_create();
2021-01-04 17:22:32 +08:00
fscript_eval(obj, "ntohll(0x1122334455667788)", &v);
2021-09-16 16:06:55 +08:00
ASSERT_EQ(value_uint64(&v), 0x8877665544332211u);
2021-01-04 17:22:32 +08:00
value_reset(&v);
2021-01-20 13:41:57 +08:00
TK_OBJECT_UNREF(obj);
2021-01-04 17:22:32 +08:00
}