src.dualinventive.com/dinet/sec-multi-proxy/libdi/tests/drv_hl854x_mec.cpp

72 lines
1.7 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/mec.c"
static struct di_drv_hl854x_ctx ctx;
}
TEST(drv_hl854x_mec, cb_csq) {
struct {
std::string str;
int8_t rssi;
int8_t ber;
} cb_csq_expect[] = {
/* BER tests */
{ "99,0,-8", 0, 0 },
{ "99,1,-8", 0, 1 },
{ "99,2,-8", 0, 2 },
{ "99,3,-8", 0, 3 },
{ "99,4,-8", 0, 4 },
{ "99,5,-8", 0, 5 },
{ "99,6,-8", 0, 6 },
{ "99,7,-8", 0, 7 },
{ "99,8,-8", 0, 99 },
{ "99,99,-8", 0, 99 },
/* RSSI tests */
{ "0,0,-8", -113, 0 },
{ "1,2,-8", -111, 2 },
{ "2,99,-8", -109, 99 },
{ "11,99,-8", -91, 99 },
{ "30,99,-8", -53, 99 },
{ "31,99,-8", -51, 99 },
{ "32,99,-8", 0, 99 },
{ "98,99,-8", 0, 99 },
{ "99,99,-8", 0, 99 }
};
di_drv_hl854x_init(&ctx);
for (size_t n = 0; n < sizeof(cb_csq_expect)/sizeof(cb_csq_expect[0]); n++) {
ctx.me.match.str = const_cast<char *>(cb_csq_expect[n].str.c_str());
di_drv_hl854x_mec_cb_csq(&ctx.me);
EXPECT_EQ(cb_csq_expect[n].rssi, ctx.carrier.rssi);
EXPECT_EQ(cb_csq_expect[n].ber, ctx.carrier.ber);
}
}
TEST(drv_hl854x_mec, cb_cpin) {
di_drv_hl854x_init(&ctx);
struct {
std::string s_str;
enum di_drv_hl854x_sim_status s;
} cb_cpin_expect[] = {
{ "READY", HL854X_SIM_STATUS_READY },
{ "SIM PIN", HL854X_SIM_STATUS_SIM_PIN },
{ "SIM PUK", HL854X_SIM_STATUS_SIM_PUK },
{ "FOOBAR", HL854X_SIM_STATUS_UNKNOWN }
};
for (size_t n = 0; n < sizeof(cb_cpin_expect)/sizeof(cb_cpin_expect[0]); n++) {
ctx.me.match.str = const_cast<char *>(cb_cpin_expect[n].s_str.c_str());
di_drv_hl854x_mec_cb_cpin(&ctx.me);
EXPECT_EQ(cb_cpin_expect[n].s, ctx.sim.status);
}
}