Browse Source
the new testing framework works and the tests for cclass are done...actually i try to figure out how to tell autotools to build this correctly.
master
the new testing framework works and the tests for cclass are done...actually i try to figure out how to tell autotools to build this correctly.
master
15 changed files with 343 additions and 94 deletions
-
31createToken.c
-
9src/cclass.c
-
2src/dyntype.c
-
13tests/Makefile.am
-
97tests/cclassTest.c
-
33tests/cclass_test.c
-
2tests/crypt.c
-
2tests/decrypt.c
-
16tests/dyntype.c
-
12tests/hash.c
-
92tests/mock/class.c
-
30tests/mock/class.h
-
53tests/packet.c
-
39tests/runtest.c
-
6tests/runtest.h
@ -0,0 +1,97 @@ |
|||
#include <sys/types.h> |
|||
#include <json/json.h> |
|||
|
|||
#include "runtest.h" |
|||
#include "mock/class.h" |
|||
#include "token/cclass.h" |
|||
|
|||
|
|||
char testname[] = "cclassTest"; |
|||
struct MOCK_CLASS * mock = NULL; |
|||
|
|||
void |
|||
setUp() |
|||
{ |
|||
mock = NULL; |
|||
_reset(); |
|||
} |
|||
|
|||
void |
|||
tearDown() |
|||
{ |
|||
if (NULL != mock) { |
|||
delete(&mock); |
|||
} |
|||
} |
|||
|
|||
int |
|||
testNew(void) |
|||
{ |
|||
mock = new(MOCK_CLASS, 123); |
|||
|
|||
ASSERT_NOT_NULL(mock); |
|||
ASSERT_EQUAL(1, _called); |
|||
ASSERT_EQUAL(123, mock_class_getValue(mock)); |
|||
|
|||
return TEST_OK; |
|||
} |
|||
|
|||
int |
|||
testNewFromJson(void) |
|||
{ |
|||
struct json_object * json = json_object_new_int(123); |
|||
|
|||
mock = newFromJson(MOCK_CLASS, json); |
|||
json_object_put(json); |
|||
|
|||
ASSERT_NOT_NULL(mock); |
|||
ASSERT_EQUAL(1, _called); |
|||
ASSERT_EQUAL(123, mock_class_getValue(mock)); |
|||
|
|||
return TEST_OK; |
|||
} |
|||
|
|||
int |
|||
testDelete(void) |
|||
{ |
|||
mock = new(MOCK_CLASS, 123); |
|||
|
|||
ASSERT_NOT_NULL(mock); |
|||
|
|||
_reset(); |
|||
delete(&mock); |
|||
|
|||
ASSERT_NULL(mock); |
|||
ASSERT_EQUAL(1, _called); |
|||
|
|||
return TEST_OK; |
|||
} |
|||
|
|||
int |
|||
testToJson(void) |
|||
{ |
|||
struct json_object * json = NULL; |
|||
mock = new(MOCK_CLASS, 123); |
|||
int value; |
|||
|
|||
json = toJson(mock); |
|||
|
|||
ASSERT_NOT_NULL(json); |
|||
value = json_object_get_int(json); |
|||
json_object_put(json); |
|||
|
|||
ASSERT_EQUAL(123, value); |
|||
ASSERT_EQUAL(1, _called); |
|||
|
|||
return TEST_OK; |
|||
} |
|||
|
|||
testfunc tests[] = { |
|||
testNew, |
|||
testNewFromJson, |
|||
testDelete, |
|||
testToJson |
|||
}; |
|||
size_t count = FUNCS_COUNT(tests); |
|||
|
|||
// vim: set et ts=4 sw=4: |
|||
@ -1,33 +0,0 @@ |
|||
#include <sys/types.h> |
|||
|
|||
#include "runtest.h" |
|||
|
|||
|
|||
char testname[] = "cclass_test"; |
|||
|
|||
int |
|||
dummy_ok(void) |
|||
{ |
|||
return TEST_OK; |
|||
} |
|||
|
|||
int |
|||
dummy_failed(void) |
|||
{ |
|||
return TEST_FAILED; |
|||
} |
|||
|
|||
int |
|||
dummy_error(void) |
|||
{ |
|||
return TEST_ERROR; |
|||
} |
|||
|
|||
testfunc tests[] = { |
|||
dummy_ok, |
|||
dummy_failed, |
|||
dummy_error |
|||
}; |
|||
size_t count = FUNCS_COUNT(tests); |
|||
|
|||
// vim: set et ts=4 sw=4: |
|||
@ -0,0 +1,92 @@ |
|||
#include <assert.h> |
|||
#include <json/json.h> |
|||
|
|||
#include "token/cclass.h" |
|||
#include "class.h" |
|||
|
|||
char _called; |
|||
|
|||
void |
|||
inline |
|||
_reset() |
|||
{ |
|||
_called = 0; |
|||
} |
|||
|
|||
static |
|||
void |
|||
__construct(struct MOCK_CLASS * _this, va_list * params) |
|||
{ |
|||
_called = 1; |
|||
_this->value = va_arg(* params, int); |
|||
} |
|||
|
|||
static |
|||
void |
|||
__jsonConst(struct MOCK_CLASS * _this, json_object * json) |
|||
{ |
|||
_called = 1; |
|||
assert(json_type_int == json_object_get_type(json)); |
|||
|
|||
_this->value = json_object_get_int(json); |
|||
} |
|||
|
|||
static |
|||
void |
|||
__destruct(struct MOCK_CLASS * _this) |
|||
{ |
|||
_called = 1; |
|||
} |
|||
|
|||
static |
|||
struct json_object * |
|||
__toJson(struct MOCK_CLASS * _this) |
|||
{ |
|||
struct json_object * json = json_object_new_int(_this->value); |
|||
|
|||
_called = 1; |
|||
return json; |
|||
} |
|||
|
|||
static const |
|||
struct CCLASS _mock_class = { |
|||
sizeof(struct MOCK_CLASS), |
|||
(ctor)__construct, |
|||
(jCtor)__jsonConst, |
|||
(dtor)__destruct, |
|||
(jTo)__toJson |
|||
}; |
|||
|
|||
const struct CCLASS * const MOCK_CLASS = &_mock_class; |
|||
|
|||
/** |
|||
* ~~~ method implementations ~~~~~~~~ |
|||
*/ |
|||
|
|||
int |
|||
mock_class_getValue(struct MOCK_CLASS * _this) |
|||
{ |
|||
return _this->value; |
|||
} |
|||
|
|||
void |
|||
mock_class_setValue(struct MOCK_CLASS * _this, int value) |
|||
{ |
|||
_this->value = value; |
|||
} |
|||
|
|||
/** |
|||
* ~~~ helper for mock assertions ~~~~~~~~ |
|||
*/ |
|||
void * |
|||
getConstruct() |
|||
{ |
|||
return __construct; |
|||
} |
|||
|
|||
void * |
|||
getJsonConst() |
|||
{ |
|||
return __jsonConst; |
|||
} |
|||
// vim: set et ts=4 sw=4: |
|||
@ -0,0 +1,30 @@ |
|||
#ifndef __MOCK_CLASS_H__ |
|||
#define __MOCK_CLASS_H__ |
|||
|
|||
#include "token/cclass.h" |
|||
|
|||
|
|||
extern char _called; |
|||
|
|||
extern void inline |
|||
_reset() |
|||
{ |
|||
_called = 0; |
|||
} |
|||
|
|||
struct MOCK_CLASS { |
|||
const struct CCLASS * const class; |
|||
int value; |
|||
}; |
|||
|
|||
extern const struct CCLASS * const MOCK_CLASS; |
|||
|
|||
/** |
|||
* ~~~ method declarations ~~~~~~~~ |
|||
*/ |
|||
|
|||
int mock_class_getValue(struct MOCK_CLASS * _this); |
|||
void mock_class_setValue(struct MOCK_CLASS * _this, int value); |
|||
|
|||
#endif//__MOCK_CLASS_H__ |
|||
// vim: set et ts=4 sw=4: |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue