Teonet library  0.4.7
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
test_cque.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <CUnit/Basic.h>
#include "ev_mgr.h"
#include "modules/cque.h"

Macros

#define kc_emul()
 Emulate ksnetEvMgrClass. More...
 

Functions

void test_4_1 ()
 Initialize and Destroy module class. More...
 
void kq_cb (uint32_t id, int type, void *data)
 Callback Queue callback. More...
 
void test_4_2 ()
 Add callback to QUEUE. More...
 
void test_4_3 ()
 Execute callback to emulate callback event. More...
 
int add_suite_4_tests (void)
 Add Callback QUEUE module tests. More...
 

Variables

CU_pSuite pSuite
 

Detailed Description

Author
Kirill Scherba kiril.nosp@m.l@sc.nosp@m.herba.nosp@m..ru

Callback QUEUE module tests suite

Test functions:

cUnit test suite code:

#include <stdio.h>
#include <stdlib.h>
#include <CUnit/Basic.h>
#include "ev_mgr.h"
#include "modules/cque.h"
extern CU_pSuite pSuite; // Test global variable
#define kc_emul() \
ksnetEvMgrClass ke_obj; \
ksnetEvMgrClass *ke = &ke_obj; \
ke->ev_loop = ev_loop_new (0)
void test_4_1() {
// Emulate ksnCoreClass
// Initialize module
ksnCQueClass *kq = ksnCQueInit(ke, 1);
CU_ASSERT_PTR_NOT_NULL_FATAL(kq);
CU_ASSERT_PTR_NOT_NULL_FATAL(kq->cque_map);
// Destroy module
CU_PASS("Destroy ksnPblKfClass done");
}
static void timeout_cb (EV_P_ ev_timer *w, int revents) {
//puts ("timeout");
// this causes the innermost ev_run to stop iterating
ev_break (EV_A_ EVBREAK_ONE);
}
void kq_cb(uint32_t id, int type, void *data) {
//printf("CQue callback id: %d, type: %d \n", id, type);
}
void test_4_2() {
// Emulate ksnCoreClass
// Initialize module
ksnCQueClass *kq = ksnCQueInit(ke, 1);
CU_ASSERT_PTR_NOT_NULL_FATAL(kq);
CU_ASSERT_PTR_NOT_NULL_FATAL(kq->cque_map);
// Add callback to queue
ksnCQueData *cq = ksnCQueAdd(kq, kq_cb, 0.050, NULL);
CU_ASSERT_PTR_NOT_NULL_FATAL(cq);
CU_ASSERT(pblMapSize(kq->cque_map) == 1);
cq = ksnCQueAdd(kq, kq_cb, 0.050, NULL);
CU_ASSERT_PTR_NOT_NULL_FATAL(cq);
CU_ASSERT(pblMapSize(kq->cque_map) == 2);
// Define timer to stop event loop after 1.0 sec
ev_timer timeout_watcher;
ev_timer_init (&timeout_watcher, timeout_cb, 0.250, 0.0);
ev_timer_start (ke->ev_loop, &timeout_watcher);
// Start event loop
ev_run (ke->ev_loop, 0);
CU_ASSERT(pblMapSize(kq->cque_map) == 0);
// Destroy module
CU_PASS("Destroy ksnPblKfClass done");
}
void test_4_3() {
// Emulate ksnCoreClass
// Initialize module
ksnCQueClass *kq = ksnCQueInit(ke, 1);
CU_ASSERT_PTR_NOT_NULL_FATAL(kq);
CU_ASSERT_PTR_NOT_NULL_FATAL(kq->cque_map);
// Add callback to queue
ksnCQueData *cq = ksnCQueAdd(kq, kq_cb, 0.050, NULL);
CU_ASSERT_PTR_NOT_NULL_FATAL(cq);
CU_ASSERT(pblMapSize(kq->cque_map) == 1);
cq = ksnCQueAdd(kq, kq_cb, 0.050, NULL);
CU_ASSERT_PTR_NOT_NULL_FATAL(cq);
CU_ASSERT(pblMapSize(kq->cque_map) == 2);
// Execute callback queue record
int rv = ksnCQueExec(kq, 1);
CU_ASSERT(rv == 0)
CU_ASSERT(pblMapSize(kq->cque_map) == 1);
rv = ksnCQueExec(kq, 2);
CU_ASSERT(rv == 0)
CU_ASSERT(pblMapSize(kq->cque_map) == 0);
// Destroy module
CU_PASS("Destroy ksnPblKfClass done");
}
int add_suite_4_tests(void) {
// Add the tests to the suite
if ((NULL == CU_add_test(pSuite, "Initialize/Destroy module class", test_4_1))
/*|| (NULL == CU_add_test(pSuite, "Add callback to QUEUE", test_4_2))*/
/*|| (NULL == CU_add_test(pSuite, "Execute callback to emulate callback event", test_4_3))*/) {
CU_cleanup_registry();
return CU_get_error();
}
return 0;
}

Created on Aug 22, 2015, 3:35:32 AM

Macro Definition Documentation

#define kc_emul ( )
Value:
ksnetEvMgrClass *ke = &ke_obj; \
ke->ev_loop = ev_loop_new (0)
struct ksnetEvMgrClass ksnetEvMgrClass
KSNet event manager functions data.
#define ke
KSNet event manager functions data.
Definition: ev_mgr.h:245

Emulate ksnetEvMgrClass.

Referenced by test_4_1(), test_4_2(), and test_4_3().

Function Documentation

int add_suite_4_tests ( void  )

Add Callback QUEUE module tests.

Returns

References pSuite, and test_4_1().

Referenced by main().

void kq_cb ( uint32_t  id,
int  type,
void *  data 
)

Callback Queue callback.

Parameters
idCalls ID
typeType: 0 - timeout callback; 1 - successful callback
dataUser data

Referenced by test_4_2(), and test_4_3().

void test_4_1 ( )

Initialize and Destroy module class.

References ksnCQueClass::cque_map, kc_emul, ke, ksnCQueDestroy(), and ksnCQueInit().

Referenced by add_suite_4_tests().

void test_4_2 ( )

Add callback to QUEUE.

References cq, ksnCQueClass::cque_map, kc_emul, ke, kq_cb(), ksnCQueAdd(), ksnCQueDestroy(), and ksnCQueInit().

void test_4_3 ( )

Execute callback to emulate callback event.

References cq, ksnCQueClass::cque_map, kc_emul, ke, kq_cb(), ksnCQueAdd(), ksnCQueDestroy(), ksnCQueExec(), and ksnCQueInit().

Variable Documentation

CU_pSuite pSuite

Referenced by add_suite_4_tests().