update controller code
This commit is contained in:
parent
2836d196da
commit
41f56fa6ed
54 changed files with 9688 additions and 214 deletions
|
|
@ -2,12 +2,13 @@
|
|||
#include <stdlib.h>
|
||||
#include <unity/unity.h>
|
||||
|
||||
#include "xce/errnox.h"
|
||||
#include "utils.h"
|
||||
#include "xce/errnox.h"
|
||||
|
||||
static void test_error_setget(void) {
|
||||
int myerrno =1;
|
||||
ectx_t *e;
|
||||
static void test_error_setget(void)
|
||||
{
|
||||
int myerrno = 1;
|
||||
ectx_t* e;
|
||||
|
||||
SET_ERROR(myerrno);
|
||||
e = get_ectx();
|
||||
|
|
@ -34,7 +35,8 @@ static void test_strerror_r(void) {
|
|||
}
|
||||
}
|
||||
#endif
|
||||
void test_error(void) {
|
||||
void test_error(void)
|
||||
{
|
||||
printf("\n>> error test\n\n");
|
||||
|
||||
RUN_TEST(test_error_setget);
|
||||
|
|
|
|||
|
|
@ -2,48 +2,52 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <unity/unity.h>
|
||||
#include "htab.h"
|
||||
#include <unity/unity.h>
|
||||
|
||||
static htab_t htab;
|
||||
static char *s = "Hello,world";
|
||||
static char* s = "Hello,world";
|
||||
|
||||
static void test_ht_add_string(void) {
|
||||
hent_t *e = NULL;
|
||||
static void test_ht_add_string(void)
|
||||
{
|
||||
hent_t* e = NULL;
|
||||
|
||||
e = ht_add(&(htab), (void *)s);
|
||||
e = ht_add(&(htab), (void*)s);
|
||||
TEST_ASSERT_NOT_NULL(e);
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void test_ht_get_string(void) {
|
||||
hent_t *e = NULL;
|
||||
static void test_ht_get_string(void)
|
||||
{
|
||||
hent_t* e = NULL;
|
||||
|
||||
e = ht_get(&htab, (void *)s);
|
||||
e = ht_get(&htab, (void*)s);
|
||||
TEST_ASSERT_NOT_NULL(e);
|
||||
|
||||
TEST_ASSERT_TRUE(0 == strcmp(e->key, s));
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void test_ht_del_string(void) {
|
||||
hent_t *e = NULL;
|
||||
|
||||
ht_del(&htab, (void *)s);
|
||||
static void test_ht_del_string(void)
|
||||
{
|
||||
hent_t* e = NULL;
|
||||
|
||||
ht_del(&htab, (void*)s);
|
||||
|
||||
e = ht_get(&htab, (void*)s);
|
||||
TEST_ASSERT_TRUE(e == NULL);
|
||||
|
||||
e = ht_get(&htab, (void *)s);
|
||||
TEST_ASSERT_TRUE( e == NULL);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void test_ht_string(void) {
|
||||
void test_ht_string(void)
|
||||
{
|
||||
printf("\n>> htab test string\n\n");
|
||||
|
||||
ht_init(&htab, 13, string_hash_key);
|
||||
|
||||
|
||||
RUN_TEST(test_ht_add_string);
|
||||
RUN_TEST(test_ht_get_string);
|
||||
RUN_TEST(test_ht_del_string);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <unity/unity.h>
|
||||
|
||||
#include "htab.h"
|
||||
|
|
@ -10,42 +10,46 @@ static htab_t htab;
|
|||
|
||||
uint64_t key = (uint64_t)0xfabcde6666666666;
|
||||
|
||||
static void test_ht_add_string(void) {
|
||||
hent_t *e = NULL;
|
||||
static void test_ht_add_string(void)
|
||||
{
|
||||
hent_t* e = NULL;
|
||||
|
||||
e = ht_add(&(htab), (void *)key);
|
||||
e = ht_add(&(htab), (void*)key);
|
||||
TEST_ASSERT_NOT_NULL(e);
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void test_ht_get_string(void) {
|
||||
hent_t *e = NULL;
|
||||
static void test_ht_get_string(void)
|
||||
{
|
||||
hent_t* e = NULL;
|
||||
|
||||
e = ht_get(&htab, (void *)key);
|
||||
e = ht_get(&htab, (void*)key);
|
||||
TEST_ASSERT_NOT_NULL(e);
|
||||
|
||||
TEST_ASSERT_TRUE((uint64_t)e->key == (uint64_t)key);
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void test_ht_del_string(void) {
|
||||
hent_t *e = NULL;
|
||||
|
||||
ht_del(&htab, (void *)key);
|
||||
static void test_ht_del_string(void)
|
||||
{
|
||||
hent_t* e = NULL;
|
||||
|
||||
ht_del(&htab, (void*)key);
|
||||
|
||||
e = ht_get(&htab, (void*)key);
|
||||
TEST_ASSERT_TRUE(e == NULL);
|
||||
|
||||
e = ht_get(&htab, (void *)key);
|
||||
TEST_ASSERT_TRUE( e == NULL);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void test_ht_int(void) {
|
||||
void test_ht_int(void)
|
||||
{
|
||||
printf("\n>> htab test int\n\n");
|
||||
|
||||
ht_init(&htab, 13, int_hash_key);
|
||||
|
||||
|
||||
RUN_TEST(test_ht_add_string);
|
||||
RUN_TEST(test_ht_get_string);
|
||||
RUN_TEST(test_ht_del_string);
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ void test_xstring_create(void)
|
|||
myobj_t* obj;
|
||||
|
||||
objmgr_init(&mgr);
|
||||
register_xstring(&mgr,4,4);
|
||||
register_xstring(&mgr, 4, 4);
|
||||
TEST_ASSERT_EQUAL(1, mgr.types.count);
|
||||
|
||||
s2 = create_obj_by_typename(&mgr, "xstring", s1);
|
||||
|
|
@ -37,7 +37,7 @@ void test_xstring_ref(void)
|
|||
myobj_t* obj;
|
||||
|
||||
objmgr_init(&mgr);
|
||||
register_xstring(&mgr,4,4);
|
||||
register_xstring(&mgr, 4, 4);
|
||||
TEST_ASSERT_EQUAL(1, mgr.types.count);
|
||||
|
||||
s1 = create_obj_by_typename(&mgr, "xstring",
|
||||
|
|
@ -63,7 +63,7 @@ void test_xstring_deref(void)
|
|||
myobj_t* obj;
|
||||
|
||||
objmgr_init(&mgr);
|
||||
register_xstring(&mgr,4,4);
|
||||
register_xstring(&mgr, 4, 4);
|
||||
TEST_ASSERT_EQUAL(1, mgr.types.count);
|
||||
|
||||
s2 = create_obj_by_typename(&mgr, "xstring", s1);
|
||||
|
|
@ -73,12 +73,12 @@ void test_xstring_deref(void)
|
|||
|
||||
TEST_ASSERT_EQUAL(0, rc);
|
||||
if (rc == 0) {
|
||||
objtype_t *typeval;
|
||||
objtype_t* typeval;
|
||||
|
||||
obj = TO_MYOBJ(s2);
|
||||
typeval = obj->type;
|
||||
obj = TO_MYOBJ(s2);
|
||||
typeval = obj->type;
|
||||
|
||||
obj_deref(s2);
|
||||
obj_deref(s2);
|
||||
|
||||
TEST_ASSERT_EQUAL(0, XSTRING_TYPE_STRINGS(typeval).count);
|
||||
}
|
||||
|
|
@ -95,7 +95,7 @@ void test_xstring_share(void)
|
|||
int rc = 0;
|
||||
|
||||
objmgr_init(&mgr);
|
||||
register_xstring(&mgr,4,4);
|
||||
register_xstring(&mgr, 4, 4);
|
||||
TEST_ASSERT_EQUAL(1, mgr.types.count);
|
||||
|
||||
s2 = create_obj_by_typename(&mgr, "xstring", s1);
|
||||
|
|
|
|||
|
|
@ -5,38 +5,41 @@
|
|||
|
||||
#include "zarray.h"
|
||||
|
||||
static void test_zarray_create(void) {
|
||||
static void test_zarray_create(void)
|
||||
{
|
||||
zarray_t array;
|
||||
|
||||
zarray_init(&array, 8, NULL);
|
||||
|
||||
TEST_ASSERT_EQUAL(0,array.count);
|
||||
TEST_ASSERT_EQUAL(0, array.count);
|
||||
TEST_ASSERT_NULL(array.data);
|
||||
}
|
||||
|
||||
static void test_zarray_store(void) {
|
||||
static void test_zarray_store(void)
|
||||
{
|
||||
zarray_t array;
|
||||
int idx;
|
||||
char *s1 = "hello";
|
||||
char *s2 = NULL;
|
||||
int idx;
|
||||
char* s1 = "hello";
|
||||
char* s2 = NULL;
|
||||
|
||||
zarray_init(&array, 8, NULL);
|
||||
idx = zarray_store(&array, (void *)s1);
|
||||
idx = zarray_store(&array, (void*)s1);
|
||||
TEST_ASSERT_TRUE(idx >= 0);
|
||||
s2 = (char *)zarray_get(&array, idx);
|
||||
s2 = (char*)zarray_get(&array, idx);
|
||||
TEST_ASSERT_NOT_NULL(s2);
|
||||
TEST_ASSERT_EQUAL(0, strcmp(s1, s2));
|
||||
|
||||
zarray_fini(&(array));
|
||||
}
|
||||
|
||||
static void test_zarray_del(void) {
|
||||
static void test_zarray_del(void)
|
||||
{
|
||||
zarray_t array;
|
||||
int idx;
|
||||
char *s1 = "hello";
|
||||
int idx;
|
||||
char* s1 = "hello";
|
||||
|
||||
zarray_init(&array, 8, NULL);
|
||||
idx = zarray_store(&array, (void *)s1);
|
||||
idx = zarray_store(&array, (void*)s1);
|
||||
TEST_ASSERT_TRUE(idx >= 0);
|
||||
TEST_ASSERT_TRUE(array.count == 1);
|
||||
zarray_del(&array, idx);
|
||||
|
|
@ -46,52 +49,56 @@ static void test_zarray_del(void) {
|
|||
zarray_fini(&array);
|
||||
}
|
||||
|
||||
static void test_zarray_put(void) {
|
||||
static void test_zarray_put(void)
|
||||
{
|
||||
zarray_t array;
|
||||
int idx;
|
||||
char *s1 = "hello";
|
||||
char *s2 = "test";
|
||||
int idx;
|
||||
char* s1 = "hello";
|
||||
char* s2 = "test";
|
||||
|
||||
zarray_init(&array, 8, NULL);
|
||||
idx = zarray_store(&array, (void *)s1);
|
||||
idx = zarray_store(&array, (void*)s1);
|
||||
TEST_ASSERT_TRUE(idx >= 0);
|
||||
TEST_ASSERT_TRUE(array.count == 1);
|
||||
TEST_ASSERT_TRUE(zarray_get(&array, idx) != NULL);
|
||||
|
||||
TEST_ASSERT_TRUE(strcmp((char *)zarray_get(&array, idx), s1) == 0);
|
||||
|
||||
zarray_put(&array, idx, (void *)s2);
|
||||
TEST_ASSERT_TRUE(strcmp((char*)zarray_get(&array, idx), s1) == 0);
|
||||
|
||||
zarray_put(&array, idx, (void*)s2);
|
||||
TEST_ASSERT_TRUE(zarray_get(&array, idx) != NULL);
|
||||
TEST_ASSERT_TRUE(strcmp((char *)zarray_get(&array, idx), s2) == 0);
|
||||
TEST_ASSERT_TRUE(strcmp((char*)zarray_get(&array, idx), s2) == 0);
|
||||
|
||||
zarray_fini(&array);
|
||||
}
|
||||
|
||||
static int sum_(void *arg1, void *arg2) {
|
||||
int *pv = (int *)arg1;
|
||||
int x = (int)((long)arg2);
|
||||
static int sum_(void* arg1, void* arg2)
|
||||
{
|
||||
int* pv = (int*)arg1;
|
||||
int x = (int)((long)arg2);
|
||||
|
||||
(*pv) += x;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void test_zarray_iter(void) {
|
||||
static void test_zarray_iter(void)
|
||||
{
|
||||
zarray_t array;
|
||||
int i;
|
||||
int val = 0;
|
||||
int i;
|
||||
int val = 0;
|
||||
|
||||
zarray_init(&array, 10, NULL);
|
||||
for(i = 0; i < 10; i ++) {
|
||||
zarray_store(&array, (void *)(long)i);
|
||||
for (i = 0; i < 10; i++) {
|
||||
zarray_store(&array, (void*)(long)i);
|
||||
}
|
||||
|
||||
zarray_iter(&array, (zarray_iter_fn_t)sum_, &val);
|
||||
|
||||
TEST_ASSERT_TRUE(val == 45);
|
||||
|
||||
|
||||
zarray_fini(&(array));
|
||||
}
|
||||
void test_zarray(void) {
|
||||
void test_zarray(void)
|
||||
{
|
||||
printf("\n>> zarray test\n\n");
|
||||
|
||||
RUN_TEST(test_zarray_create);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue