73 lines
2.0 KiB
C++
73 lines
2.0 KiB
C++
#include <stdio.h>
|
|
#include <stdint.h>
|
|
#include <string.h>
|
|
|
|
#include <gtest/gtest.h>
|
|
#include <di/drv/hl854x.h>
|
|
|
|
static struct di_drv_hl854x_ctx ctx;
|
|
static char *read_cb_testdata = NULL;
|
|
|
|
size_t test_drv_hl854x_read_cb(void *buf, size_t nbyte)
|
|
{
|
|
size_t _nbyte = strlen(read_cb_testdata);
|
|
|
|
if (nbyte < _nbyte)
|
|
return 0;
|
|
|
|
memcpy(buf, read_cb_testdata, _nbyte);
|
|
|
|
return _nbyte;
|
|
}
|
|
|
|
void test_hl854x_reset(void)
|
|
{
|
|
di_drv_hl854x_init(&ctx);
|
|
di_drv_hl854x_set_read(&ctx, test_drv_hl854x_read_cb);
|
|
}
|
|
|
|
TEST(drv_hl854x, req_modem_revision) {
|
|
char test[] = "RHL85xx.5.5.14.0.201502091756.x6250_1\r\r\n\r\r\nOK\r\r\n";
|
|
|
|
test_hl854x_reset();
|
|
|
|
read_cb_testdata = test;
|
|
di_drv_hl854x_req_modem_revision(&ctx);
|
|
|
|
EXPECT_EQ(HL854X_REPLY_OK, ctx.reply);
|
|
EXPECT_STREQ(static_cast<const char *>("RHL85xx.5.5.14.0.201502091756.x6250_1"), ctx.modem.revision);
|
|
}
|
|
|
|
TEST(drv_hl854x, req_modem_revision_cmd_echo) {
|
|
char test[] = "AT+CGMR\r\r\nRHL85xx.5.5.14.0.201502091756.x6250_1\r\r\n\r\nOK\r\r\n";
|
|
|
|
test_hl854x_reset();
|
|
|
|
read_cb_testdata = test;
|
|
di_drv_hl854x_req_modem_revision(&ctx);
|
|
|
|
EXPECT_EQ(HL854X_REPLY_OK, ctx.reply);
|
|
EXPECT_STREQ(static_cast<const char *>("RHL85xx.5.5.14.0.201502091756.x6250_1"), ctx.modem.revision);
|
|
}
|
|
|
|
TEST(drv_hl854x, req_modem_revision_cmd_leading_r_n) {
|
|
char test[] = "\r\nRHL85xx.5.5.22.0.201603171544.x6250_3\r\n\r\nOK\r\n";
|
|
|
|
test_hl854x_reset();
|
|
|
|
read_cb_testdata = test;
|
|
di_drv_hl854x_req_modem_revision(&ctx);
|
|
|
|
EXPECT_EQ(HL854X_REPLY_OK, ctx.reply);
|
|
EXPECT_STREQ(static_cast<const char *>("RHL85xx.5.5.22.0.201603171544.x6250_3"), ctx.modem.revision);
|
|
}
|
|
|
|
TEST(drv_hl854x, req_modem_revision_overflow) {
|
|
char test[] = "AT+CGMR\r\r\nUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU\r\r\n\r\nOK\r\r\n";
|
|
|
|
test_hl854x_reset();
|
|
|
|
read_cb_testdata = test;
|
|
di_drv_hl854x_req_modem_revision(&ctx);
|
|
}
|