55 lines
1.2 KiB
C++
55 lines
1.2 KiB
C++
#include <stdio.h>
|
|
#include <stdint.h>
|
|
#include <string.h>
|
|
|
|
#include <gtest/gtest.h>
|
|
#include <di/drv/hl854x.h>
|
|
|
|
extern "C" {
|
|
#include "drv/hl854x/tcp.c"
|
|
}
|
|
|
|
static uint8_t buffer[256];
|
|
static bool cb_is_executed = false;
|
|
static const char *read_cb_str = NULL;
|
|
static struct di_drv_hl854x_ctx _ctx;
|
|
|
|
size_t test_drv_hl854x_read_cb(void *buf, size_t nbyte)
|
|
{
|
|
if (nbyte < strlen(read_cb_str))
|
|
return 0;
|
|
|
|
memcpy(buf, read_cb_str, strlen(read_cb_str));
|
|
|
|
return strlen(read_cb_str);
|
|
}
|
|
|
|
void test_drv_hl854x_read_cb_set_str(const char *str)
|
|
{
|
|
read_cb_str = str;
|
|
}
|
|
|
|
void test_drv_hl854x_cme_error_cb(struct di_drv_hl854x_ctx *ctx)
|
|
{
|
|
(void)ctx;
|
|
cb_is_executed = true;
|
|
}
|
|
|
|
void test_hl854x_cme_error_init(const char *str)
|
|
{
|
|
di_drv_hl854x_init(&_ctx);
|
|
di_drv_hl854x_set_read(&_ctx, test_drv_hl854x_read_cb);
|
|
di_drv_hl854x_cme_error_set_callback(&_ctx, test_drv_hl854x_cme_error_cb);
|
|
test_drv_hl854x_read_cb_set_str(str);
|
|
|
|
memset(buffer, 0, sizeof(buffer));
|
|
}
|
|
|
|
TEST(drv_hl854x_cme_error, callback) {
|
|
test_hl854x_cme_error_init("+CME ERROR: 923\r\n");
|
|
di_drv_hl854x_read(&_ctx);
|
|
EXPECT_EQ(true, cb_is_executed);
|
|
EXPECT_EQ(HL854X_ERROR_CME, _ctx.error);
|
|
EXPECT_EQ(HL854X_CME_ERR_INVAL_TERM_PORT_DATA_MODE, _ctx.cme_error);
|
|
}
|