#include <server.h>
#include <plugin.h>
#include <core_object.h>
+#include <at.h>
+#include <hal.h>
+#include <queue.h>
+#include <user_request.h>
using ::testing::EmptyTestEventListener;
TReturn ret;
CoreObject *co;
TcorePlugin *test_plugin = tcore_plugin_new(NULL, NULL, NULL, NULL) ;
- g_assert(test_plugin);
+ EXPECT_TRUE(test_plugin);
co = tcore_object_new(test_plugin, "test1", NULL);
ASSERT_TRUE(co) << "tcore_object_new() failed" << std::endl;
ret = tcore_object_link_object(co, po);
EXPECT_EQ(ret, TCORE_RETURN_SUCCESS) << "tcore_object_link_object() is failed" << std::endl;
ref_po = (char *)tcore_object_ref_object(co);
- std::cout << " ref_object: " << ref_po << std::endl;
+ std::cout << std::endl << " ref_object: " << ref_po << std::endl;
EXPECT_EQ(strcmp(po, ref_po), 0) << "object is not matched" << std::endl;
ret = tcore_object_set_hal(co, NULL);
ret = tcore_object_link_user_data(co, userdata);
EXPECT_EQ(ret, TCORE_RETURN_SUCCESS) << "tcore_object_link_user_data() is failed" << std::endl;
ref_userdata = (char *)tcore_object_ref_user_data(co);
- std::cout << " ref_userdata: " << ref_userdata<< std::endl;
+ std::cout << std::endl << " ref_userdata: " << ref_userdata<< std::endl;
EXPECT_EQ(strcmp(userdata, ref_userdata), 0) << "userdata is not matched" << std::endl;
ret = tcore_object_set_name(co, "test2");
EXPECT_EQ(TCORE_RETURN_SUCCESS, ret) << "tcore_object_set_name() is failed" << std::endl;
- std::cout << " Name: " << tcore_object_ref_name(co) << std::endl;
+ std::cout << std::endl << " Name: " << tcore_object_ref_name(co) << std::endl;
EXPECT_EQ(strcmp(tcore_object_ref_name(co), "test2"), 0) << "object name is not matched" << std::endl;
tcore_object_set_type(co, CORE_OBJECT_TYPE_CUSTOM);
{
_event1_count++;
- g_assert(o);
- g_assert(event_info);
- g_assert_cmpstr((char *)event_info, ==, "ok");
+ EXPECT_TRUE(o);
+ EXPECT_TRUE(event_info);
+ EXPECT_EQ((char *)event_info, "ok");
return TRUE;
}
{
_event2_count++;
- g_assert(o);
- g_assert(event_info);
- g_assert_cmpstr((char *)event_info, ==, "ok");
+ EXPECT_TRUE(o);
+ EXPECT_TRUE(event_info);
+ EXPECT_EQ((char *)event_info, "ok");
return TRUE;
}
{
_event2_count++;
- g_assert(o);
- g_assert(event_info);
- g_assert_cmpstr((char *)event_info, ==, "ok");
+ EXPECT_TRUE(o);
+ EXPECT_TRUE(event_info);
+ EXPECT_EQ((char *)event_info, "ok");
return TRUE;
}
case 11:
g_assert(g_slist_length(key) == 2);
- g_assert(g_slist_find_custom(key, "foo",
- (GCompareFunc)g_strcmp0) != NULL);
+ g_assert(g_slist_find_custom(key, "foo", (GCompareFunc)g_strcmp0) != NULL);
g_assert(CORE_OBJECT_KEY_FIND(key, "bar") != NULL);
data = tcore_object_ref_property(co, "foo");
g_assert_cmpstr(data, ==, "1");
GSList *tmp_list;
co = tcore_object_new(NULL, "test", NULL);
- g_assert(co);
+ EXPECT_TRUE(co);
- tcore_object_add_callback(co, CORE_OBJECT_EVENT_PROPERTY_CHANGED,
- on_prop_changed, &mode);
+ tcore_object_add_callback(co, CORE_OBJECT_EVENT_PROPERTY_CHANGED, on_prop_changed, &mode);
raw = tcore_object_ref_property_hash(co);
- g_assert(raw);
+ EXPECT_TRUE(raw);
/* Case: Basic property set */
mode = 1;
tcore_object_set_property(co, "qqq", "1234");
- g_assert(g_hash_table_size(raw) == 1);
- g_assert(mode == 0);
+ EXPECT_EQ(g_hash_table_size(raw), 1);
+ EXPECT_EQ(mode, 0);
data = tcore_object_ref_property(co, "qqq");
g_assert_cmpstr(data, ==, "1234");
/* Case: Basic property remove */
mode = 2;
tcore_object_set_property(co, "qqq", NULL);
- g_assert(g_hash_table_size(raw) == 0);
- g_assert(mode == 0);
+ EXPECT_EQ(g_hash_table_size(raw), 0);
+ EXPECT_EQ(mode, 0);
data = tcore_object_ref_property(co, "qqq");
- g_assert(data == NULL);
+ EXPECT_TRUE(!data);
/* Case: Malloc property set */
mode = 3;
test = strdup("heap");
tcore_object_set_property(co, "www", test);
- g_assert(g_hash_table_size(raw) == 1);
- g_assert(mode == 0);
+ EXPECT_EQ(g_hash_table_size(raw), 1);
+ EXPECT_EQ(mode, 0);
free(test);
data = tcore_object_ref_property(co, "www");
/* Case: Malloc property remove */
mode = 4;
tcore_object_set_property(co, "www", NULL);
- g_assert(g_hash_table_size(raw) == 0);
- g_assert(mode == 0);
+ EXPECT_EQ(g_hash_table_size(raw), 0);
+ EXPECT_EQ(mode, 0);
data = tcore_object_ref_property(co, "www");
- g_assert(data == NULL);
+ EXPECT_TRUE(!data);
/* Case: Same key & Different value set */
mode = 5;
tcore_object_set_property(co, "key", "1");
- g_assert(g_hash_table_size(raw) == 1);
- g_assert(mode == 0);
+ EXPECT_EQ(g_hash_table_size(raw), 1);
+ EXPECT_EQ(mode, 0);
mode = 6;
tcore_object_set_property(co, "key", "2");
- g_assert(g_hash_table_size(raw) == 1);
- g_assert(mode == 0);
+ EXPECT_EQ(g_hash_table_size(raw), 1);
+ EXPECT_EQ(mode, 0);
/* Case: Same key & Same value set => No callback invocation */
mode = 7;
tcore_object_set_property(co, "key", "2");
- g_assert(g_hash_table_size(raw) == 1);
- g_assert(mode == 7);
+ EXPECT_EQ(g_hash_table_size(raw), 1);
+ EXPECT_EQ(mode, 7);
/* Case: Same key & Same value set & force event invocation */
mode = 8;
tcore_object_set_property(co, "key", "2");
- g_assert(g_hash_table_size(raw) == 1);
+ EXPECT_EQ(g_hash_table_size(raw), 1);
tmp_list = g_slist_append(NULL, (char *)"key");
tcore_object_emit_callback(co, CORE_OBJECT_EVENT_PROPERTY_CHANGED, tmp_list);
- g_assert(mode == 0);
+ EXPECT_EQ(mode, 0);
g_slist_free(tmp_list);
/* Case: Multiple property set */
mode = 9;
tcore_object_set_property(co, "foo", "1", "bar", "2");
- g_assert(g_hash_table_size(raw) == 3);
- g_assert(mode == 0);
+ EXPECT_EQ(g_hash_table_size(raw), 3);
+ EXPECT_EQ(mode, 0);
/* Case: Set key without value => same as key with NULL: remove key */
mode = 10;
tcore_object_set_property(co, "foo");
- g_assert(g_hash_table_size(raw) == 2);
- g_assert(mode == 0);
+ EXPECT_EQ(g_hash_table_size(raw), 2);
+ EXPECT_EQ(mode, 0);
/* Case: Multiple property set with unset (foo set, bar unset) */
mode = 11;
tcore_object_set_property(co, "foo", "1", "bar");
- g_assert(g_hash_table_size(raw) == 2);
- g_assert(mode == 0);
+ EXPECT_EQ(g_hash_table_size(raw), 2);
+ EXPECT_EQ(mode, 0);
tcore_object_free(co);
}
-
TEST(LIBTCORE_UTIL, test_util_marshal)
{
GHashTable *list;
ASSERT_TRUE(tcore_util_is_country_NA(plmn2) == FALSE);
}
-int main(int argc, char **argv) {
- InitGoogleTest(&argc, argv);
+TEST(LIBTCORE_AT, test_at_buf_write)
+{
+#define BUF_SIZE 1024
+ TcoreAT *at;
+ TReturn ret;
+ char *msg_1 = (char *)"ATOZ";
+ char msg_2[BUF_SIZE + 1];
+
+ at = tcore_at_new(NULL);
+ ASSERT_TRUE(at);
+
+ ret = tcore_at_buf_write(at, strlen(msg_1), msg_1);
+ EXPECT_EQ(ret, TCORE_RETURN_SUCCESS) << "tcore_at_buf_write() is failed" << std::endl;
+
+ memset(msg_2, '1', BUF_SIZE);
+ msg_2[BUF_SIZE] = '\0';
+ ret = tcore_at_buf_write(at, strlen(msg_2), msg_2);
+ EXPECT_EQ(ret, TCORE_RETURN_SUCCESS) << "tcore_at_buf_write() is failed" << std::endl;
+
+ tcore_at_free(at);
+}
+
+TEST(LIBTCORE_AT, test_at_tok)
+{
+ GSList *tokens;
+ char *buf;
+
+ /* test unsolicited message */
+ tokens = tcore_at_tok_new("CSQ: 31, 99");
+ EXPECT_TRUE(tokens);
+
+ g_assert_cmpstr((char *)g_slist_nth_data(tokens, 0), ==, "31");
+ g_assert_cmpstr(tcore_at_tok_nth(tokens, 1), ==, "99");;
+ EXPECT_TRUE(!g_slist_nth_data(tokens, 2));
+
+ tcore_at_tok_free(tokens);
+
+ /* test sub token (list type) */
+ tokens = tcore_at_tok_new("(2, \"T-Meego\", \"TTAU\", \"23401\", 2)");
+ ASSERT_TRUE(tokens);
+
+ g_assert_cmpstr((char *)g_slist_nth_data(tokens, 0), ==, "2");
+ g_assert_cmpstr(tcore_at_tok_nth(tokens, 1), ==, "\"T-Meego\"");
+ g_assert_cmpstr(tcore_at_tok_nth(tokens, 2), ==, "\"TTAU\"");
+ g_assert_cmpstr(tcore_at_tok_nth(tokens, 3), ==, "\"23401\"");
+ g_assert_cmpstr(tcore_at_tok_nth(tokens, 4), ==, "2");
+
+ /* test extract */
+ buf = tcore_at_tok_extract(tcore_at_tok_nth(tokens, 2));
+ EXPECT_TRUE(buf);
+ g_assert_cmpstr(buf, ==, "TTAU");
+ free(buf);
+
+ tcore_at_tok_free(tokens);
+
+ /* test extract */
+ buf = tcore_at_tok_extract("(haha)");
+ EXPECT_TRUE(buf);
+ g_assert_cmpstr(buf, ==, "haha");
+ free(buf);
+
+ /* test extract */
+ buf = tcore_at_tok_extract("(a)");
+ EXPECT_TRUE(buf);
+ g_assert_cmpstr(buf, ==, "a");
+ free(buf);
+
+ /* test extract */
+ buf = tcore_at_tok_extract("()");
+ EXPECT_TRUE(buf);
+ g_assert_cmpstr(buf, ==, "");
+ free(buf);
+
+ /* test extract */
+ buf = tcore_at_tok_extract("(");
+ EXPECT_TRUE(buf);
+ g_assert_cmpstr(buf, ==, "(");
+ free(buf);
+
+ /* test extract */
+ buf = tcore_at_tok_extract(")");
+ EXPECT_TRUE(buf);
+ g_assert_cmpstr(buf, ==, ")");
+ free(buf);
+
+ /* test extract */
+ buf = tcore_at_tok_extract("");
+ EXPECT_TRUE(buf);
+ g_assert_cmpstr(buf, ==, "");
+ free(buf);
+}
+
+TEST(LIBTCORE_AT, test_at_reqeust)
+{
+ TcoreAT *at;
+ TcoreATRequest *req;
+ TReturn ret;
+ char *msg;
+ gboolean bSuccess;
+
+ at = tcore_at_new(NULL);
+ ASSERT_TRUE(at);
+
+ req = tcore_at_request_new("AT+CMGR=1", "+CMGR", TCORE_AT_PDU);
+ ASSERT_TRUE(req);
+
+ ret = tcore_at_set_request(at, req, FALSE);
+ EXPECT_EQ(ret, TCORE_RETURN_SUCCESS);
+
+ TcoreATRequest *getReq = tcore_at_get_request(at);
+ if (getReq && getReq->cmd)
+ std::cout << std::endl << " ATRequest->cmd : " << getReq->cmd << std::endl;
+ else
+ std::cout << std::endl << " ATRequest is none" << std::endl;
+
+ msg = (char *)"+CMGR: 1,,105\r\n12345678901234567890\r\nOK\r\n";
+ bSuccess = tcore_at_process(at, strlen(msg), msg);
+ EXPECT_EQ(bSuccess, TRUE);
+
+ TcoreATResponse *getResp = tcore_at_get_response(at);
+ if (getResp && getResp->final_response)
+ std::cout << std::endl << " ATResponse->final_response : " << getResp->final_response<< std::endl;
+ else
+ std::cout << std::endl << " ATResponse is none" << std::endl;
+
+ tcore_at_free(at);
+}
+
+#if 0
+static gboolean __on_atcmd_cmti(TcoreAT *at, const GSList *lines, void *user_data)
+{
+ int *checked = (int *)user_data;
+
+ *checked = 1;
+
+ std::cout << std::endl;
+ std::cout <<" data = " << (char *)lines->data << std::endl;
+
+ return FALSE;
+}
+
+static gboolean __on_atcmd_cmt(TcoreAT *at, const GSList *lines, void *user_data)
+{
+ int *checked = (int *)user_data;
- return RUN_ALL_TESTS();
+ if (g_slist_length((GSList *)lines) != 2) {
+ printf("invalid message\n");
+ return TRUE;
+ }
+
+ *checked = 2;
+
+ std::cout << std::endl;
+ std::cout <<" data1 = " << (char *)lines->data << std::endl;
+ std::cout <<" data2 = " << (char *)lines->next->data << std::endl;
+
+ return TRUE;
}
+
+TEST(LIBTCORE_AT, test_at_notificatoin)
+{
+ TcoreAT *at;
+ TReturn ret;
+ int checked = 0;
+ char *msg = NULL;
+ gboolean bSuccess;
+
+ at = tcore_at_new(NULL);
+ ASSERT_TRUE(at);
+
+ ret = tcore_at_add_notification(at, "+CMTI:", FALSE, __on_atcmd_cmti, &checked);
+ EXPECT_EQ(ret, TCORE_RETURN_SUCCESS);
+
+ ret = tcore_at_add_notification(at, "+CMT:", TRUE, __on_atcmd_cmt, &checked);
+ EXPECT_EQ(ret, TCORE_RETURN_SUCCESS);
+
+ /* Non type PDU message */
+ msg = (char *)"+CMTI: \"SM\", 1\r\n";
+ bSuccess = tcore_at_process(at, strlen(msg), msg);
+ EXPECT_EQ(bSuccess, true);
+
+ /* callback check */
+ EXPECT_EQ(checked, 1);
+
+
+ /* Completed PDU message */
+ msg = (char *)"+CMT: 19\r\n038121F3100481214301112170137192410404F17B590E\r\n";
+ bSuccess = tcore_at_process(at, strlen(msg), msg);
+ EXPECT_EQ(bSuccess, true);
+
+ /* callback check */
+ EXPECT_EQ(checked, 2);
+
+
+ /* Split PDU message */
+ checked = 0;
+ msg = (char *)"+CMT: 19\r\n";
+ bSuccess = tcore_at_process(at, strlen(msg), msg);
+ EXPECT_EQ(bSuccess, true);
+
+ /* callback check */
+ EXPECT_EQ(checked, 0);
+
+ msg = (char *)"038121F310";
+ bSuccess = tcore_at_process(at, strlen(msg), msg);
+ EXPECT_EQ(bSuccess, true);
+
+ /* callback check */
+ EXPECT_EQ(checked, 0);
+
+ msg = (char *)"0481214301112170137192410404F17B590E\r\n";
+ bSuccess = tcore_at_process(at, strlen(msg), msg);
+ EXPECT_EQ(bSuccess, true);
+
+ /* callback check */
+ EXPECT_EQ(checked, 2);
+
+}
+#endif
+
+
+static enum tcore_hook_return __on_send_hook(TcoreHal *hal, guint data_len, void *data, void *user_data)
+{
+ std::cout << std::endl << " __on__send_hook()" << std::endl;
+ return TCORE_HOOK_RETURN_CONTINUE;
+}
+
+int g_flag;
+static void __on_recv_callback(TcoreHal *h, unsigned int data_len, const void *data, void *user_data)
+{
+ g_assert(data_len == 3);
+ g_assert_cmpstr((char *)data, ==, "123");
+ std::cout << std::endl << " hal_recv_callback()" << std::endl;
+
+ g_flag++;
+}
+
+
+TEST(LIBTCORE_HAL, test_hal_callback)
+{
+ TcoreHal *h;
+
+ h = tcore_hal_new(NULL, "test_hal", NULL, TCORE_HAL_MODE_CUSTOM);
+ ASSERT_TRUE(h);
+
+ TReturn ret;
+ ret = tcore_hal_set_name(h, "test_device1");
+ EXPECT_EQ(ret, TCORE_RETURN_SUCCESS);
+
+ char *hal_name = tcore_hal_get_name(h);
+ if(hal_name) {
+ std::cout << std::endl << " HAL name : " << hal_name << std::endl;
+ free(hal_name);
+ hal_name = NULL;
+ }
+
+ ret = tcore_hal_set_name(h, "test_device2");
+ EXPECT_EQ(ret, TCORE_RETURN_SUCCESS);
+
+ hal_name = tcore_hal_ref_name(h);
+ if(hal_name)
+ std::cout << std::endl << " HAL name : " << hal_name << std::endl;
+
+
+ TcoreAT *hal_at = tcore_hal_get_at(h);
+ EXPECT_TRUE(!hal_at);
+
+ ret = tcore_hal_set_mode(h, TCORE_HAL_MODE_AT);
+ EXPECT_EQ(ret, TCORE_RETURN_SUCCESS);
+
+ int hal_mode = tcore_hal_get_mode(h);
+ EXPECT_EQ(hal_mode, TCORE_HAL_MODE_AT);
+ std::cout << std::endl << " HAL mode : TCORE_HAL_MODE_AT" << std::endl;
+
+ ret = tcore_hal_set_mode(h, TCORE_HAL_MODE_CUSTOM);
+ EXPECT_EQ(ret, TCORE_RETURN_SUCCESS);
+ std::cout << std::endl << " HAL mode : TCORE_HAL_MODE_CUSTOM" << std::endl;
+
+ hal_mode = tcore_hal_get_mode(h);
+ EXPECT_EQ(hal_mode, TCORE_HAL_MODE_CUSTOM);
+
+ char userdata[] = "haltest_userdata";
+ char *ref_userdata = NULL;
+ ret = tcore_hal_link_user_data(h, userdata);
+ EXPECT_EQ(ret, TCORE_RETURN_SUCCESS) << "tcore_hal_link_user_data() is failed" << std::endl;
+
+ ref_userdata = (char *)tcore_hal_ref_user_data(h);
+ std::cout << std::endl << " ref_userdata: " << ref_userdata<< std::endl;
+ EXPECT_EQ(strcmp(userdata, ref_userdata), 0) << "userdata is not matched" << std::endl;
+
+ ret = tcore_hal_set_power_state(h, TRUE);
+ EXPECT_EQ(ret, TCORE_RETURN_SUCCESS);
+
+ gboolean power_state = tcore_hal_get_power_state(h);
+ EXPECT_EQ(power_state, TRUE);
+ std::cout << std::endl << " HAL power state : " <<power_state << std::endl;
+
+ tcore_hal_add_recv_callback(h, __on_recv_callback, NULL);
+
+ g_flag = 0;
+ tcore_hal_emit_recv_callback(h, 3, "123");
+ EXPECT_EQ(g_flag, 1);
+
+ tcore_hal_remove_recv_callback(h, __on_recv_callback);
+
+ g_flag = 0;
+ tcore_hal_emit_recv_callback(h, 3, "123");
+ EXPECT_EQ(g_flag, 0);
+
+ tcore_hal_free(h);
+}
+
+static TReturn __hal_power(TcoreHal *hal, gboolean enable)
+{
+ std::cout << std::endl << " __hal_power(): enable = " << enable << std::endl;
+ return TCORE_RETURN_SUCCESS;
+}
+
+static TReturn __hal_send(TcoreHal *hal, unsigned int data_len, void *data)
+{
+ std::cout << std::endl << " __hal_send()" << std::endl;
+ return TCORE_RETURN_SUCCESS;
+}
+
+static TReturn __hal_setup_netif(CoreObject *co, TcoreHalSetupNetifCallback func, void *user_data,
+ guint cid, gboolean enable)
+{
+ std::cout << std::endl << " __hal_setup_netif()" << std::endl;
+ return TCORE_RETURN_SUCCESS;
+}
+
+static TReturn __hal_control_nvdata(TcoreHal *hal, int option)
+{
+ std::cout << std::endl << " __hal_control_nvdata() : option = " << option << std::endl;
+ return TCORE_RETURN_SUCCESS;
+}
+
+static TReturn __hal_reset(TcoreHal *hal, int option)
+{
+ std::cout << std::endl << " __hal_reset(): option = " << option << std::endl;
+ return TCORE_RETURN_SUCCESS;
+}
+
+static struct tcore_hal_operations test_hal_ops = {
+ .power = __hal_power,
+ .send = __hal_send,
+ .setup_netif = __hal_setup_netif,
+ .control_nvdata = __hal_control_nvdata,
+ .reset = __hal_reset,
+};
+
+
+TEST(LIBTCORE_HAL, test_hal_pending)
+{
+ TcoreHal *h;
+ TcorePending *pending1;
+ TcorePending *pending2;
+ TcorePending *pending3;
+ TcorePending *pending = NULL;
+ TReturn ret;
+
+ h = tcore_hal_new(NULL, "test_hal_queue", &test_hal_ops, TCORE_HAL_MODE_CUSTOM);
+ ASSERT_TRUE(h);
+
+ ret = tcore_hal_set_power_state(h, TRUE);
+ EXPECT_EQ(ret, TCORE_RETURN_SUCCESS);
+
+ /* first item */
+ pending1 = tcore_pending_new(NULL, 1);
+ ASSERT_TRUE(pending1);
+ tcore_pending_set_priority(pending1, TCORE_PENDING_PRIORITY_IMMEDIATELY);
+
+ enum tcore_pending_priority result_priority;
+ ret = tcore_pending_get_priority(pending1, &result_priority);
+ EXPECT_EQ(ret, TCORE_RETURN_SUCCESS);
+ EXPECT_EQ(result_priority, TCORE_PENDING_PRIORITY_IMMEDIATELY);
+
+ unsigned int id = tcore_pending_get_id(pending1);
+ std::cout << std::endl << " pending1 id = " << id << std::endl;
+
+ /* second item */
+ pending2 = tcore_pending_new(NULL, 1);
+ ASSERT_TRUE(pending2);
+ tcore_pending_set_auto_free_status_after_sent(pending2, TRUE);
+
+ gboolean auto_free_status = tcore_pending_get_auto_free_status_after_sent(pending2);
+ std::cout << std::endl << " pending2 audo_free_status = " << auto_free_status << std::endl;
+ EXPECT_EQ(auto_free_status, TRUE);
+
+ /* third item */
+ pending3 = tcore_pending_new(NULL, 1);
+ ASSERT_TRUE(pending3);
+ tcore_pending_set_priority(pending3, TCORE_PENDING_PRIORITY_IMMEDIATELY);
+
+ ret = tcore_pending_set_timeout(pending3, 5000);
+ EXPECT_EQ(ret, TCORE_RETURN_SUCCESS);
+
+ unsigned int timeout = tcore_pending_get_timeout(pending3);
+ EXPECT_EQ(timeout, 5000);
+ std::cout << std::endl << " pending3 timeout = " << timeout << std::endl;
+
+ /* send pending1 */
+ ret = tcore_hal_send_request(h, pending1);
+ EXPECT_EQ(ret, TCORE_RETURN_SUCCESS);
+
+ /* send pending2 -> queue */
+ ret = tcore_hal_send_request(h, pending2);
+ EXPECT_EQ(ret, TCORE_RETURN_SUCCESS);
+
+ ret = tcore_hal_add_send_hook(h, __on_send_hook, NULL);
+ EXPECT_EQ(ret, TCORE_RETURN_SUCCESS);
+
+ EXPECT_EQ(tcore_hal_send_data(h, 0, NULL), TCORE_RETURN_SUCCESS);
+
+ ret = tcore_hal_remove_send_hook(h, __on_send_hook);
+ EXPECT_EQ(ret, TCORE_RETURN_SUCCESS);
+
+ /* remove pending1 */
+ ret = tcore_hal_dispatch_response_data(h, 1, 0, NULL);
+ EXPECT_EQ(ret, TCORE_RETURN_SUCCESS);
+
+ /* check next pending */
+ pending = tcore_queue_ref_pending_by_id(tcore_hal_ref_queue(h), 1);
+ EXPECT_EQ(pending, pending2);
+
+ /* force send */
+ tcore_hal_send_force(h);
+
+ /* check next pending (pending2 is auto free) */
+ pending = tcore_queue_ref_pending_by_id(tcore_hal_ref_queue(h), 1);
+ EXPECT_TRUE(!pending);
+
+ /* send pending3 */
+ ret = tcore_hal_send_request(h, pending3);
+ EXPECT_EQ(ret, TCORE_RETURN_SUCCESS);
+
+ pending = tcore_queue_ref_pending_by_id(tcore_hal_ref_queue(h), 1);
+ EXPECT_EQ(pending, pending3);
+
+ /* remove pending3 */
+ ret = tcore_hal_dispatch_response_data(h, 1, 0, NULL);
+ EXPECT_EQ(ret, TCORE_RETURN_SUCCESS);
+
+ /* check next pending (no more pending) */
+ pending = tcore_queue_ref_pending_by_id(tcore_hal_ref_queue(h), 1);
+ EXPECT_TRUE(!pending);
+
+ ret = tcore_hal_setup_netif(h, NULL, NULL, NULL, 0, FALSE);
+ EXPECT_EQ(ret, TCORE_RETURN_SUCCESS);
+
+ ret = tcore_hal_set_power(h, TRUE);
+ EXPECT_EQ(ret, TCORE_RETURN_SUCCESS);
+
+ ret = tcore_hal_control_nvdata(h, 2);
+ EXPECT_EQ(ret, TCORE_RETURN_SUCCESS);
+
+ ret = tcore_hal_reset(h, 1);
+ EXPECT_EQ(ret, TCORE_RETURN_SUCCESS);
+
+ TcorePlugin *ref_plugin = tcore_hal_ref_plugin(h);
+ EXPECT_TRUE(!ref_plugin);
+
+ tcore_hal_free(h);
+}
+
+TEST(LIBTCORE_QUEUE, test_queue_push)
+{
+ TcoreQueue *q;
+ TcorePending *pending1;
+ TcorePending *pending2;
+ TcorePending *pending3;
+ TcorePending *pending = NULL;
+ TReturn ret;
+
+ q = tcore_queue_new(NULL);
+ ASSERT_TRUE(q);
+
+ /* first item */
+ pending1 = tcore_pending_new(NULL, 1);
+ ASSERT_TRUE(pending1);
+ tcore_pending_set_priority(pending1, TCORE_PENDING_PRIORITY_IMMEDIATELY);
+
+ ret = tcore_queue_push(q, pending1);
+ EXPECT_EQ(ret, TCORE_RETURN_SUCCESS);
+ std::cout << std::endl << " pending1 is pushed into queue successufully " << std::endl;
+
+ /* second item */
+ pending2 = tcore_pending_new(NULL, 1);
+ ASSERT_TRUE(pending2);
+
+ ret = tcore_queue_push(q, pending2);
+ EXPECT_EQ(ret, TCORE_RETURN_SUCCESS);
+ std::cout << std::endl << " pending2 is pushed into queue successufully " << std::endl;
+
+ /* third item, but push to second item position */
+ pending3 = tcore_pending_new(NULL, 1);
+ ASSERT_TRUE(pending3);
+ tcore_pending_set_priority(pending3, TCORE_PENDING_PRIORITY_IMMEDIATELY);
+
+ ret = tcore_queue_push(q, pending3);
+ EXPECT_EQ(ret, TCORE_RETURN_SUCCESS);
+ std::cout << std::endl << " pending3 is pushed into queue successufully " << std::endl;
+
+ TcorePending *head = tcore_queue_ref_head(q);
+ EXPECT_EQ(head, pending1);
+ std::cout << std::endl << " head is pending1" << std::endl;
+
+ TcorePending *tail = tcore_queue_ref_tail(q);
+ EXPECT_EQ(tail, pending2);
+ std::cout << std::endl << " tail is pending2" << std::endl;
+
+ unsigned int q_len = tcore_queue_get_length(q);
+ std::cout << std::endl << " queue length is " << q_len << std::endl;
+
+ unsigned int q_normal_len = tcore_queue_get_normal_length(q);
+ std::cout << std::endl << " queue normal length is " << q_normal_len << std::endl;
+
+ /* pop test (order by priority) */
+ pending = tcore_queue_pop_by_id(q, 1);
+ EXPECT_EQ(pending, pending1);
+ std::cout << std::endl << " pending1 is poped from queue successufully " << std::endl;
+
+ pending = tcore_queue_pop_by_id(q, 1);
+ EXPECT_EQ(pending, pending3);
+ std::cout << std::endl << " pending3 is poped from queue successufully " << std::endl;
+
+ pending = tcore_queue_pop_by_id(q, 1);
+ EXPECT_EQ(pending, pending2);
+ std::cout << std::endl << " pending2 is poped from queue successufully " << std::endl;
+
+ tcore_queue_free(q);
+}
+
+int g_response_flag = 0;
+static void __on_pending_response_callback(TcorePending *pending, int data_len, const void *data, void *user_data)
+{
+ std::cout << std::endl << " __on_pending_response_callback() !!\n" << std::endl;
+ g_response_flag++;
+}
+
+TEST(LIBTCORE_QUEUE, test_hal_queue_callback)
+{
+ TcoreHal *h;
+ TcorePending *pending1;
+ TcorePending *pending2;
+ TcorePending *pending3;
+ TcorePending *p;
+ TReturn ret;
+ UserRequest *ur1;
+ UserRequest *ur2;
+
+ h = tcore_hal_new(NULL, "test_hal_queue_callback", &test_hal_ops, TCORE_HAL_MODE_CUSTOM);
+ ASSERT_TRUE(h);
+
+ ret = tcore_hal_set_power_state(h, TRUE);
+ EXPECT_EQ(ret, TCORE_RETURN_SUCCESS);
+
+ /* first item */
+ ur1 = tcore_user_request_new(NULL, NULL);
+ ASSERT_TRUE(ur1);
+
+ ret = tcore_user_request_set_command(ur1, TREQ_NETWORK_SEARCH);
+ EXPECT_EQ(ret, TCORE_RETURN_SUCCESS);
+
+ pending1 = tcore_pending_new(NULL, 1);
+ ASSERT_TRUE(pending1);
+
+ tcore_pending_set_response_callback(pending1, __on_pending_response_callback, NULL);
+ tcore_pending_link_user_request(pending1, ur1);
+
+ ret = tcore_hal_send_request(h, pending1);
+ EXPECT_EQ(ret, TCORE_RETURN_SUCCESS);
+
+ /* force update send state */
+ tcore_pending_emit_send_callback(pending1, TRUE);
+
+ /* second item */
+ ur2 = tcore_user_request_new(NULL, NULL);
+ ASSERT_TRUE(ur2);
+
+ tcore_user_request_set_command(ur2, TREQ_NETWORK_SEARCH);
+
+ pending2 = tcore_pending_new(NULL, 1);
+ ASSERT_TRUE(pending2);
+
+ tcore_pending_set_response_callback(pending2, __on_pending_response_callback, NULL);
+ tcore_pending_link_user_request(pending2, ur2);
+
+ ret = tcore_hal_send_request(h, pending2);
+ EXPECT_EQ(ret, TCORE_RETURN_SUCCESS);
+
+ /* third item */
+ pending3 = tcore_pending_new(NULL, 1);
+ ASSERT_TRUE(pending3);
+
+ ret = tcore_hal_send_request(h, pending3);
+ EXPECT_EQ(ret, TCORE_RETURN_SUCCESS);
+
+
+ /* search */
+ p = tcore_queue_search_by_command(tcore_hal_ref_queue(h), TREQ_NETWORK_SEARCH, TRUE);
+ EXPECT_EQ(p, pending1);
+
+ p = tcore_queue_search_by_command(tcore_hal_ref_queue(h), TREQ_NETWORK_SEARCH, FALSE);
+ EXPECT_EQ(p, pending2);
+
+ /* cancel */
+ g_response_flag = 0;
+ ret = tcore_queue_cancel_pending_by_command(tcore_hal_ref_queue(h), TREQ_NETWORK_SEARCH);
+ EXPECT_EQ(ret, TCORE_RETURN_SUCCESS);
+
+ EXPECT_EQ(g_response_flag, 2);
+
+ tcore_hal_free(h);
+
+}
+
+int main(int argc, char **argv)
+{
+ int ret = -1;
+
+ try {
+ testing::InitGoogleTest(&argc, argv);
+ } catch(...) {
+ std::cout << "Exception occurred." << std::endl;
+ }
+ try {
+ ret = RUN_ALL_TESTS();
+ } catch (const ::testing::internal::GoogleTestFailureException& e) {
+ ret = -1;
+ std::cout << "GoogleTestFailureException was thrown:" << e.what() << std::endl;
+ }
+ return ret;
+}
+