diff --git a/README.Win32 b/README.Win32 index 51943f7d..28097b26 100644 --- a/README.Win32 +++ b/README.Win32 @@ -23,3 +23,7 @@ is libcstl unit testing execute file. You will need cmockery.lib and google\*.h, the header files of cmockery libaray, in vc8/vc9 directory. +NOTE +----------------------------------------- +LIBCSTL WILL BE CANCEL MSVS SUPPORT IN FURTER VERSION, +BECAUSE THE MSVS DOES NOT SUPPORT C99 FULLY. diff --git a/cstl/cstl_def.h b/cstl/cstl_def.h index 71b5e6cb..9c47c1c4 100644 --- a/cstl/cstl_def.h +++ b/cstl/cstl_def.h @@ -39,6 +39,9 @@ extern "C" { #include #include #include +#ifndef _MSC_VER +# include +#endif /** constant declaration and macro section **/ #ifdef _CSTL_UNIT_TESTING @@ -73,13 +76,13 @@ extern "C" { #define CSTL_MINOR_VERSION 3 #define CSTL_REVISION_VERSION 0 +#ifdef _MSC_VER /** * for bool_t type */ -#define FALSE 0 /* declaration false bool type */ #define false 0 -#define TRUE 1 /* declaration true bool type */ #define true 1 +#endif /** data type declaration and struct, union, enum section **/ typedef unsigned char _byte_t; diff --git a/cstl/cstl_function.h b/cstl/cstl_function.h index 33a3afd8..6f23101c 100644 --- a/cstl/cstl_function.h +++ b/cstl/cstl_function.h @@ -388,6 +388,9 @@ extern void fun_less_equal_hash_multimap(const void* cpv_first, const void* cpv_ * @remarks The input and output must not be NULL, otherwise the behavior is undefined. */ extern void fun_logical_and_cstl_bool(const void* cpv_first, const void* cpv_second, void* pv_output); +#ifndef _MSC_VER +extern void fun_logical_and_bool(const void* cpv_first, const void* cpv_second, void* pv_output); +#endif /** * Logical or. @@ -398,6 +401,9 @@ extern void fun_logical_and_cstl_bool(const void* cpv_first, const void* cpv_sec * @remarks The input and output must not be NULL, otherwise the behavior is undefined. */ extern void fun_logical_or_cstl_bool(const void* cpv_first, const void* cpv_second, void* pv_output); +#ifndef _MSC_VER +extern void fun_logical_or_bool(const void* cpv_first, const void* cpv_second, void* pv_output); +#endif /** * Logical not. @@ -407,6 +413,9 @@ extern void fun_logical_or_cstl_bool(const void* cpv_first, const void* cpv_seco * @remarks The input and output must not be NULL, otherwise the behavior is undefined. */ extern void fun_logical_not_cstl_bool(const void* cpv_input, void* pv_output); +#ifndef _MSC_VER +extern void fun_logical_not_bool(const void* cpv_input, void* pv_output); +#endif /** * Random number. diff --git a/cstl/cstl_types.h b/cstl/cstl_types.h index b4e44203..0cdcfdc2 100644 --- a/cstl/cstl_types.h +++ b/cstl/cstl_types.h @@ -68,6 +68,7 @@ extern "C" { #define _POINTER_TYPE "void*" #define _CSTL_BOOL_TYPE "bool_t" +#define _BOOL_TYPE "_Bool" /* cstl type */ #define _VECTOR_TYPE "vector_t" #define _LIST_TYPE "list_t" diff --git a/doc/project/libcstl.bnf b/doc/project/libcstl.bnf index cf7b1b2a..5529f5a7 100644 --- a/doc/project/libcstl.bnf +++ b/doc/project/libcstl.bnf @@ -29,7 +29,7 @@ space : ' ' | '\t' | '\v' | '\f' | '\r' | '\n' keyword: void -char, int, short, long, float, double, signed, unsigned, bool_t, +char, int, short, long, float, double, signed, unsigned, bool_t, _Bool struct, enum, union, vector_t, list_t, slist_t, deque_t, stack_t, queue_t, priority_queue_t, set_t, map_t, multiset_t, multimap_t, @@ -65,7 +65,7 @@ C_BUILTIN -> char | signed char | long double | char* | void* | - bool_t + bool_t | _Bool USER_DEFINE -> USER_DEFINE_TYPE identifier | identifier USER_DEFINE_TYPE -> struct | enum | union CSTL_BUILTIN -> SEQUENCE | RELATION | string_t | ITERATOR @@ -81,7 +81,7 @@ RELATION -> RELATION_NAME < TYPE_DESCRIPT , TYPE_DESCRIPT > RELATION_NAME -> map_t | multimap_t | hash_map_t | hash_multimap_t | pair_t ======================================================================== C_BUILTIN -> SIMPLE_BUILTIN | SIGNED_BUILTIN | UNSIGNED_BUILTIN | POINTER_BUILTIN -SIMPLE_BUILTIN -> char | short | short int | int | long | long int | bool_t +SIMPLE_BUILTIN -> char | short | short int | int | long | long int | bool_t | _Bool float | double | long double SIGNED_BUILTIN -> signed char | signed short | signed short int | @@ -97,7 +97,7 @@ POINTER_BUILTIN -> char * | void * TYPE_DESCRIPT -> C_BUILTIN | USER_DEFINE | CSTL_BUILTIN C_BUILTIN -> SIMPLE_BUILTIN | SIGNED_BUILTIN | UNSIGNED_BUILTIN | POINTER_BUILTIN -SIMPLE_BUILTIN -> char POINTER_SUFFIX | short COMMON_SUFFIX | int | long SIMPLE_LONG_SUFFIX | float | double | bool_t +SIMPLE_BUILTIN -> char POINTER_SUFFIX | short COMMON_SUFFIX | int | long SIMPLE_LONG_SUFFIX | float | double | bool_t | _Bool SIGNED_BUILTIN -> signed COMPLEX_SUFFIX UNSIGNED_BUILTIN -> unsigned COMPLEX_SUFFIX POINTER_BUILTIN -> void * @@ -121,7 +121,7 @@ SEQUENCE_NAME -> vector_t | list_t | slist_t | deque_t | queue_t | stack_t | pri RELATION -> RELATION_NAME < TYPE_DESCRIPT , TYPE_DESCRIPT > RELATION_NAME -> map_t | multimap_t | hash_map_t | hash_multimap_t | pair_t --------------------------------------------------------------------------- -first(TYPE_DESCRIPT) = {char, short, int, long, float, double, signed, unsigned, void, bool_t, +first(TYPE_DESCRIPT) = {char, short, int, long, float, double, signed, unsigned, void, bool_t, _Bool, struct, enum, union, identifier, vector_t, list_t, slist_t, deque_t, queue_t, stack_t, priority_queue_t, set_t, map_t, multiset_t, multimap_t, hash_set_t, hash_map_t, hash_multiset_t, @@ -132,8 +132,8 @@ first(TYPE_DESCRIPT) = {char, short, int, long, float, double, signed, unsigned, string_iterator_t, input_iterator_t, output_iterator_t, forward_iterator_t, bidirectional_iterator_t, random_access_iterator_t} -first(C_BUILTIN) = {char, short, int, long, float, double, signed, unsigned, void, bool_t} -first(SIMPLE_BUILTIN) = {char, short, int, long, float, double, bool_t} +first(C_BUILTIN) = {char, short, int, long, float, double, signed, unsigned, void, bool_t, _Bool} +first(SIMPLE_BUILTIN) = {char, short, int, long, float, double, bool_t, _Bool} first(SIGNED_BUILTIN) = {signed} first(UNSIGNED_BUILTIN) = {unsigned} first(POINTER_BUILTIN) = {void} @@ -203,7 +203,7 @@ select(TYPE_DESCRIPT -> CSTL_BUILTIN) = {vector_t, list_t, slist_t, deque_t, que input_iterator_t, output_iterator_t, forward_iterator_t, bidirectional_iterator_t, random_access_iterator_t} -select(C_BUILTIN -> SIMPLE_BUILTIN) = {char, short, int, long, float, double, bool_t} +select(C_BUILTIN -> SIMPLE_BUILTIN) = {char, short, int, long, float, double, bool_t, _Bool} select(C_BUILTIN -> SIGNED_BUILTIN) = {signed} select(C_BUILTIN -> UNSIGNED_BUILTIN) = {unsigned} select(C_BUILTIN -> POINTER_BUILTIN) = {void} @@ -215,6 +215,7 @@ select(SIMPLE_BUILTIN -> long SIMPLE_LONG_SUFFIX) = {long} select(SIMPLE_BUILTIN -> float) = {float} select(SIMPLE_BUILTIN -> double) = {double} select(SIMPLE_BUILTIN -> bool_t) = {bool_t} +select(SIMPLE_BUILTIN -> _Bool) = {_Bool} selcet(SIGNED_BUILTIN -> signed COMPLEX_SUFFIX) = {signed} select(UNSIGNED_BUILTIN -> unsigned COMPLEX_SUFFIX) = {unsigned} diff --git a/src/cstl_function.c b/src/cstl_function.c index bc024bb5..899934ec 100644 --- a/src/cstl_function.c +++ b/src/cstl_function.c @@ -1837,6 +1837,15 @@ void fun_logical_and_cstl_bool(const void* cpv_first, const void* cpv_second, vo *(bool_t*)pv_output = *(bool_t*)cpv_first && *(bool_t*)cpv_second; } +#ifndef _MSC_VER +void fun_logical_and_bool(const void* cpv_first, const void* cpv_second, void* pv_output) +{ + assert(cpv_first != NULL && cpv_second != NULL && pv_output != NULL); + + *(bool_t*)pv_output = *(_Bool*)cpv_first && *(_Bool*)cpv_second; +} +#endif + /** * Logical or. */ @@ -1847,6 +1856,15 @@ void fun_logical_or_cstl_bool(const void* cpv_first, const void* cpv_second, voi *(bool_t*)pv_output = *(bool_t*)cpv_first || *(bool_t*)cpv_second; } +#ifndef _MSC_VER +void fun_logical_or_bool(const void* cpv_first, const void* cpv_second, void* pv_output) +{ + assert(cpv_first != NULL && cpv_second != NULL && pv_output != NULL); + + *(bool_t*)pv_output = *(_Bool*)cpv_first || *(_Bool*)cpv_second; +} +#endif + /** * Logical not. */ @@ -1857,6 +1875,15 @@ void fun_logical_not_cstl_bool(const void* cpv_input, void* pv_output) *(bool_t*)pv_output = !*(bool_t*)cpv_input; } +#ifndef _MSC_VER +void fun_logical_not_bool(const void* cpv_input, void* pv_output) +{ + assert(cpv_input != NULL && pv_output != NULL); + + *(bool_t*)pv_output = !*(_Bool*)cpv_input; +} +#endif + /** * Random number. */ diff --git a/src/cstl_function_private.c b/src/cstl_function_private.c index 4e416c95..ef5b7c2a 100644 --- a/src/cstl_function_private.c +++ b/src/cstl_function_private.c @@ -137,6 +137,12 @@ ufun_t _fun_get_unary(iterator_t it_iter, fun_type_t ftype_type) if (ftype_type == _LOGICAL_NOT_FUN) { return fun_logical_not_cstl_bool; } +#ifndef _MSC_VER + } else if (strncmp(s_typename, _BOOL_TYPE, _TYPE_NAME_SIZE) == 0) { /* _Bool */ + if (ftype_type == _LOGICAL_NOT_FUN) { + return fun_logical_not_bool; + } +#endif } return fun_default_unary; @@ -359,6 +365,14 @@ bfun_t _fun_get_binary(iterator_t it_iter, fun_type_t ftype_type) case _LOGICAL_OR_FUN: return fun_logical_or_cstl_bool; break; default: break; } +#ifndef _MSC_VER + } else if (strncmp(s_typename, _BOOL_TYPE, _TYPE_NAME_SIZE) == 0) { /* _Bool */ + switch (ftype_type) { + case _LOGICAL_AND_FUN: return fun_logical_and_bool; break; + case _LOGICAL_OR_FUN: return fun_logical_or_bool; break; + default: break; + } +#endif } else if (strncmp(s_typename, _VECTOR_TYPE, _TYPE_NAME_SIZE) == 0) { /* vector_t */ switch (ftype_type) { case _EQUAL_FUN: return fun_equal_vector; break; diff --git a/src/cstl_types.c b/src/cstl_types.c index 042c0240..42cd283a 100644 --- a/src/cstl_types.c +++ b/src/cstl_types.c @@ -552,6 +552,12 @@ void _type_get_varg_value(_typeinfo_t* pt_typeinfo, va_list val_elemlist, void* assert(b_result); memset(pv_output, 0x00, pt_typeinfo->_pt_type->_t_typesize); } +#ifndef _MSC_VER + } else if (strncmp(pt_typeinfo->_pt_type->_s_typename, _BOOL_TYPE, _TYPE_NAME_SIZE) == 0) { + /* _Bool */ + assert(pt_typeinfo->_pt_type->_t_typesize == sizeof(_Bool)); + *(_Bool*)pv_output = va_arg(val_elemlist, int); +#endif } else { /* invalid c builtin style */ assert(false); diff --git a/src/cstl_types_aux.c b/src/cstl_types_aux.c index 017d310f..b85b5dd2 100644 --- a/src/cstl_types_aux.c +++ b/src/cstl_types_aux.c @@ -1,6 +1,6 @@ /* * The implementation of cstl types auxiliary functions. - * Copyright (C) 2008 - 2012 Wangbo + * Copyright (C) 2008 - 2014 Wangbo * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -248,6 +248,12 @@ void _type_register_c_builtin(void) _TYPE_REGISTER_TYPE(void*, _POINTER_TYPE, pointer, _TYPE_C_BUILTIN); _TYPE_REGISTER_TYPE_NODE(void*, _POINTER_TYPE); +#ifndef _MSC_VER + /* register _Bool */ + _TYPE_REGISTER_TYPE(_Bool, _BOOL_TYPE, bool, _TYPE_C_BUILTIN); + _TYPE_REGISTER_TYPE_NODE(_Bool, _BOOL_TYPE); +#endif + _TYPE_REGISTER_END(); } diff --git a/src/cstl_types_builtin.c b/src/cstl_types_builtin.c index 7fe6a01e..ea8223b3 100644 --- a/src/cstl_types_builtin.c +++ b/src/cstl_types_builtin.c @@ -999,6 +999,34 @@ void _type_destroy_iterator(const void* cpv_input, void* pv_output) _type_destroy_default(cpv_input, pv_output); } +#ifndef _MSC_VER +/* _Bool */ +void _type_init_bool(const void* cpv_input, void* pv_output) +{ + assert(cpv_input != NULL && pv_output != NULL); + *(_Bool*)cpv_input = false; + *(bool_t*)pv_output = true; +} + +void _type_copy_bool(const void* cpv_first, const void* cpv_second, void* pv_output) +{ + assert(cpv_first != NULL && cpv_second != NULL && pv_output != NULL); + *(_Bool*)cpv_first = *(_Bool*)cpv_second; + *(bool_t*)pv_output = true; +} + +void _type_less_bool(const void* cpv_first, const void* cpv_second, void* pv_output) +{ + assert(cpv_first != NULL && cpv_second != NULL && pv_output != NULL); + *(bool_t*)pv_output = *(_Bool*)cpv_first < *(_Bool*)cpv_second ? true : false; +} + +void _type_destroy_bool(const void* cpv_input, void* pv_output) +{ + _type_destroy_default(cpv_input, pv_output); +} +#endif + /** local function implementation section **/ /** eof **/ diff --git a/src/cstl_types_builtin.h b/src/cstl_types_builtin.h index 57b244c2..9c9c7186 100644 --- a/src/cstl_types_builtin.h +++ b/src/cstl_types_builtin.h @@ -208,6 +208,14 @@ extern void _type_copy_iterator(const void* cpv_first, const void* cpv_second, v extern void _type_less_iterator(const void* cpv_first, const void* cpv_second, void* pv_output); extern void _type_destroy_iterator(const void* cpv_input, void* pv_output); +#ifndef _MSC_VER +/* _Bool */ +extern void _type_init_bool(const void* cpv_input, void* pv_output); +extern void _type_copy_bool(const void* cpv_first, const void* cpv_second, void* pv_output); +extern void _type_less_bool(const void* cpv_first, const void* cpv_second, void* pv_output); +extern void _type_destroy_bool(const void* cpv_input, void* pv_output); +#endif + #ifdef __cplusplus } #endif diff --git a/src/cstl_types_parse.c b/src/cstl_types_parse.c index c37897c2..0456e868 100644 --- a/src/cstl_types_parse.c +++ b/src/cstl_types_parse.c @@ -50,6 +50,7 @@ #define _TOKEN_TEXT_UNSIGNED "unsigned" #define _TOKEN_TEXT_VOID "void" #define _TOKEN_TEXT_CSTL_BOOL "bool_t" +#define _TOKEN_TEXT_BOOL "_Bool" #define _TOKEN_TEXT_STRUCT "struct" #define _TOKEN_TEXT_ENUM "enum" #define _TOKEN_TEXT_UNION "union" @@ -127,6 +128,7 @@ static keytable_t _sgt_table[] = { {_TOKEN_KEY_UNSIGNED, _TOKEN_TEXT_UNSIGNED}, {_TOKEN_KEY_VOID, _TOKEN_TEXT_VOID}, {_TOKEN_KEY_CSTL_BOOL, _TOKEN_TEXT_CSTL_BOOL}, + {_TOKEN_KEY_BOOL, _TOKEN_TEXT_BOOL}, {_TOKEN_KEY_STRUCT, _TOKEN_TEXT_STRUCT}, {_TOKEN_KEY_ENUM, _TOKEN_TEXT_ENUM}, {_TOKEN_KEY_UNION, _TOKEN_TEXT_UNION}, @@ -214,6 +216,7 @@ _typestyle_t _type_get_style(const char* s_typename, char* s_formalname) case _TOKEN_KEY_UNSIGNED: case _TOKEN_KEY_VOID: case _TOKEN_KEY_CSTL_BOOL: + case _TOKEN_KEY_BOOL: t_style = _type_parse_c_builtin(s_formalname) ? _TYPE_C_BUILTIN : _TYPE_INVALID; break; /* TYPE_DESCRIPT -> USER_DEFINE */ @@ -397,6 +400,7 @@ bool_t _type_parse_c_builtin(char* s_formalname) case _TOKEN_KEY_FLOAT: case _TOKEN_KEY_DOUBLE: case _TOKEN_KEY_CSTL_BOOL: + case _TOKEN_KEY_BOOL: return _type_parse_simple_builtin(s_formalname); break; /* C_BUILTIN -> SIGNED_BUILTIN */ @@ -510,7 +514,7 @@ bool_t _type_parse_simple_builtin(char* s_formalname) assert(s_formalname != NULL); /* * SIMPLE_BUILTIN -> char POINTER_SUFFIX | short COMMON_SUFFIX | int | - * long SIMPLE_LONG_SUFFIX | float | double | bool_t + * long SIMPLE_LONG_SUFFIX | float | double | bool_t | _Bool */ switch (_gt_typeanalysis._t_token) { /* SIMPLE_BUILTIN -> char POINTER_SUFFIX */ @@ -551,6 +555,11 @@ bool_t _type_parse_simple_builtin(char* s_formalname) _TOKEN_MATCH(_TOKEN_TEXT_CSTL_BOOL, s_formalname); return true; break; + /* SIMPLE_BUILTIN -> _Bool */ + case _TOKEN_KEY_BOOL: + _TOKEN_MATCH(_TOKEN_TEXT_BOOL, s_formalname); + return true; + break; default: return false; break; @@ -1025,6 +1034,7 @@ bool_t _type_parse_type_descript(char* s_formalname) case _TOKEN_KEY_UNSIGNED: case _TOKEN_KEY_VOID: case _TOKEN_KEY_CSTL_BOOL: + case _TOKEN_KEY_BOOL: return _type_parse_c_builtin(s_formalname); break; /* TYPE_DESCRIPT -> USER_DEFINE */ diff --git a/src/cstl_types_parse.h b/src/cstl_types_parse.h index 1eceef63..2d37f9e0 100644 --- a/src/cstl_types_parse.h +++ b/src/cstl_types_parse.h @@ -46,7 +46,7 @@ typedef enum _tagtypetoken /* c builtin */ _TOKEN_KEY_CHAR, _TOKEN_KEY_SHORT, _TOKEN_KEY_INT, _TOKEN_KEY_LONG, _TOKEN_KEY_FLOAT, _TOKEN_KEY_DOUBLE, _TOKEN_KEY_SIGNED, _TOKEN_KEY_UNSIGNED, _TOKEN_KEY_VOID, - _TOKEN_KEY_CSTL_BOOL, + _TOKEN_KEY_CSTL_BOOL, _TOKEN_KEY_BOOL, /* user define */ _TOKEN_KEY_STRUCT, _TOKEN_KEY_ENUM, _TOKEN_KEY_UNION, _TOKEN_IDENTIFIER, /* cstl container */ diff --git a/test/ut/ut_cstl_function_private.c b/test/ut/ut_cstl_function_private.c index eb0704af..ad52d1aa 100644 --- a/test/ut/ut_cstl_function_private.c +++ b/test/ut/ut_cstl_function_private.c @@ -484,7 +484,7 @@ void test__fun_get_unary__long_double_RANDOM_NUMBER(void** state) deque_destroy(pdeq); } -void test__fun_get_unary__bool_NEGATE(void** state) +void test__fun_get_unary__cstl_bool_NEGATE(void** state) { deque_t* pdeq = create_deque(bool_t); fun_type_t ftype = _NEGATE_FUN; @@ -494,7 +494,7 @@ void test__fun_get_unary__bool_NEGATE(void** state) deque_destroy(pdeq); } -void test__fun_get_unary__bool_INCREASE(void** state) +void test__fun_get_unary__cstl_bool_INCREASE(void** state) { deque_t* pdeq = create_deque(bool_t); fun_type_t ftype = _INCREASE_FUN; @@ -504,7 +504,7 @@ void test__fun_get_unary__bool_INCREASE(void** state) deque_destroy(pdeq); } -void test__fun_get_unary__bool_LOGICAL_NOT(void** state) +void test__fun_get_unary__cstl_bool_LOGICAL_NOT(void** state) { deque_t* pdeq = create_deque(bool_t); fun_type_t ftype = _LOGICAL_NOT_FUN; @@ -514,7 +514,7 @@ void test__fun_get_unary__bool_LOGICAL_NOT(void** state) deque_destroy(pdeq); } -void test__fun_get_unary__bool_RANDOM_NUMBER(void** state) +void test__fun_get_unary__cstl_bool_RANDOM_NUMBER(void** state) { deque_t* pdeq = create_deque(bool_t); fun_type_t ftype = _RANDOM_NUMBER_FUN; @@ -524,6 +524,48 @@ void test__fun_get_unary__bool_RANDOM_NUMBER(void** state) deque_destroy(pdeq); } +#ifndef _MSC_VER +void test__fun_get_unary__bool_NEGATE(void** state) +{ + deque_t* pdeq = create_deque(_Bool); + fun_type_t ftype = _NEGATE_FUN; + + deque_init(pdeq); + assert_true(_fun_get_unary(deque_begin(pdeq), ftype) == fun_default_unary); + deque_destroy(pdeq); +} + +void test__fun_get_unary__bool_INCREASE(void** state) +{ + deque_t* pdeq = create_deque(_Bool); + fun_type_t ftype = _INCREASE_FUN; + + deque_init(pdeq); + assert_true(_fun_get_unary(deque_begin(pdeq), ftype) == fun_default_unary); + deque_destroy(pdeq); +} + +void test__fun_get_unary__bool_LOGICAL_NOT(void** state) +{ + deque_t* pdeq = create_deque(_Bool); + fun_type_t ftype = _LOGICAL_NOT_FUN; + + deque_init(pdeq); + assert_true(_fun_get_unary(deque_begin(pdeq), ftype) == fun_logical_not_bool); + deque_destroy(pdeq); +} + +void test__fun_get_unary__bool_RANDOM_NUMBER(void** state) +{ + deque_t* pdeq = create_deque(_Bool); + fun_type_t ftype = _RANDOM_NUMBER_FUN; + + deque_init(pdeq); + assert_true(_fun_get_unary(deque_begin(pdeq), ftype) == fun_default_unary); + deque_destroy(pdeq); +} +#endif + /* * test _fun_get_binary */ @@ -1949,7 +1991,7 @@ void test__fun_get_binary__cstr_LOGICAL_OR(void** state) deque_destroy(pdeq); } -void test__fun_get_binary__bool_PLUS(void** state) +void test__fun_get_binary__cstl_bool_PLUS(void** state) { deque_t* pdeq = create_deque(bool_t); @@ -1958,7 +2000,7 @@ void test__fun_get_binary__bool_PLUS(void** state) deque_destroy(pdeq); } -void test__fun_get_binary__bool_MINUS(void** state) +void test__fun_get_binary__cstl_bool_MINUS(void** state) { deque_t* pdeq = create_deque(bool_t); @@ -1967,7 +2009,7 @@ void test__fun_get_binary__bool_MINUS(void** state) deque_destroy(pdeq); } -void test__fun_get_binary__bool_MULTIPLIES(void** state) +void test__fun_get_binary__cstl_bool_MULTIPLIES(void** state) { deque_t* pdeq = create_deque(bool_t); @@ -1976,7 +2018,7 @@ void test__fun_get_binary__bool_MULTIPLIES(void** state) deque_destroy(pdeq); } -void test__fun_get_binary__bool_DIVIDES(void** state) +void test__fun_get_binary__cstl_bool_DIVIDES(void** state) { deque_t* pdeq = create_deque(bool_t); @@ -1985,7 +2027,7 @@ void test__fun_get_binary__bool_DIVIDES(void** state) deque_destroy(pdeq); } -void test__fun_get_binary__bool_MODULUS(void** state) +void test__fun_get_binary__cstl_bool_MODULUS(void** state) { deque_t* pdeq = create_deque(bool_t); @@ -1994,7 +2036,7 @@ void test__fun_get_binary__bool_MODULUS(void** state) deque_destroy(pdeq); } -void test__fun_get_binary__bool_EQUAL(void** state) +void test__fun_get_binary__cstl_bool_EQUAL(void** state) { deque_t* pdeq = create_deque(bool_t); @@ -2003,7 +2045,7 @@ void test__fun_get_binary__bool_EQUAL(void** state) deque_destroy(pdeq); } -void test__fun_get_binary__bool_NOT_EQUAL(void** state) +void test__fun_get_binary__cstl_bool_NOT_EQUAL(void** state) { deque_t* pdeq = create_deque(bool_t); @@ -2012,7 +2054,7 @@ void test__fun_get_binary__bool_NOT_EQUAL(void** state) deque_destroy(pdeq); } -void test__fun_get_binary__bool_LESS(void** state) +void test__fun_get_binary__cstl_bool_LESS(void** state) { deque_t* pdeq = create_deque(bool_t); @@ -2021,7 +2063,7 @@ void test__fun_get_binary__bool_LESS(void** state) deque_destroy(pdeq); } -void test__fun_get_binary__bool_LESS_EQUAL(void** state) +void test__fun_get_binary__cstl_bool_LESS_EQUAL(void** state) { deque_t* pdeq = create_deque(bool_t); @@ -2030,7 +2072,7 @@ void test__fun_get_binary__bool_LESS_EQUAL(void** state) deque_destroy(pdeq); } -void test__fun_get_binary__bool_GREATER(void** state) +void test__fun_get_binary__cstl_bool_GREATER(void** state) { deque_t* pdeq = create_deque(bool_t); @@ -2039,7 +2081,7 @@ void test__fun_get_binary__bool_GREATER(void** state) deque_destroy(pdeq); } -void test__fun_get_binary__bool_GREATER_EQUAL(void** state) +void test__fun_get_binary__cstl_bool_GREATER_EQUAL(void** state) { deque_t* pdeq = create_deque(bool_t); @@ -2048,7 +2090,7 @@ void test__fun_get_binary__bool_GREATER_EQUAL(void** state) deque_destroy(pdeq); } -void test__fun_get_binary__bool_LOGICAL_AND(void** state) +void test__fun_get_binary__cstl_bool_LOGICAL_AND(void** state) { deque_t* pdeq = create_deque(bool_t); @@ -2057,7 +2099,7 @@ void test__fun_get_binary__bool_LOGICAL_AND(void** state) deque_destroy(pdeq); } -void test__fun_get_binary__bool_LOGICAL_OR(void** state) +void test__fun_get_binary__cstl_bool_LOGICAL_OR(void** state) { deque_t* pdeq = create_deque(bool_t); @@ -4120,3 +4162,122 @@ void test__fun_get_binary__pointer_LESS_EQUAL(void** state) assert_true(_fun_get_binary(deque_begin(pdeq), _LESS_EQUAL_FUN) == fun_less_equal_pointer); deque_destroy(pdeq); } + +#ifndef _MSC_VER +void test__fun_get_binary__bool_PLUS(void** state) +{ + deque_t* pdeq = create_deque(_Bool); + + deque_init(pdeq); + assert_true(_fun_get_binary(deque_begin(pdeq), _PLUS_FUN) == fun_default_binary); + deque_destroy(pdeq); +} + +void test__fun_get_binary__bool_MINUS(void** state) +{ + deque_t* pdeq = create_deque(_Bool); + + deque_init(pdeq); + assert_true(_fun_get_binary(deque_begin(pdeq), _MINUS_FUN) == fun_default_binary); + deque_destroy(pdeq); +} + +void test__fun_get_binary__bool_MULTIPLIES(void** state) +{ + deque_t* pdeq = create_deque(_Bool); + + deque_init(pdeq); + assert_true(_fun_get_binary(deque_begin(pdeq), _MULTIPLIES_FUN) == fun_default_binary); + deque_destroy(pdeq); +} + +void test__fun_get_binary__bool_DIVIDES(void** state) +{ + deque_t* pdeq = create_deque(_Bool); + + deque_init(pdeq); + assert_true(_fun_get_binary(deque_begin(pdeq), _DIVIDES_FUN) == fun_default_binary); + deque_destroy(pdeq); +} + +void test__fun_get_binary__bool_MODULUS(void** state) +{ + deque_t* pdeq = create_deque(_Bool); + + deque_init(pdeq); + assert_true(_fun_get_binary(deque_begin(pdeq), _MODULUS_FUN) == fun_default_binary); + deque_destroy(pdeq); +} + +void test__fun_get_binary__bool_EQUAL(void** state) +{ + deque_t* pdeq = create_deque(_Bool); + + deque_init(pdeq); + assert_true(_fun_get_binary(deque_begin(pdeq), _EQUAL_FUN) == fun_default_binary); + deque_destroy(pdeq); +} + +void test__fun_get_binary__bool_NOT_EQUAL(void** state) +{ + deque_t* pdeq = create_deque(_Bool); + + deque_init(pdeq); + assert_true(_fun_get_binary(deque_begin(pdeq), _NOT_EQUAL_FUN) == fun_default_binary); + deque_destroy(pdeq); +} + +void test__fun_get_binary__bool_LESS(void** state) +{ + deque_t* pdeq = create_deque(_Bool); + + deque_init(pdeq); + assert_true(_fun_get_binary(deque_begin(pdeq), _LESS_FUN) == fun_default_binary); + deque_destroy(pdeq); +} + +void test__fun_get_binary__bool_LESS_EQUAL(void** state) +{ + deque_t* pdeq = create_deque(_Bool); + + deque_init(pdeq); + assert_true(_fun_get_binary(deque_begin(pdeq), _LESS_EQUAL_FUN) == fun_default_binary); + deque_destroy(pdeq); +} + +void test__fun_get_binary__bool_GREATER(void** state) +{ + deque_t* pdeq = create_deque(_Bool); + + deque_init(pdeq); + assert_true(_fun_get_binary(deque_begin(pdeq), _GREATER_FUN) == fun_default_binary); + deque_destroy(pdeq); +} + +void test__fun_get_binary__bool_GREATER_EQUAL(void** state) +{ + deque_t* pdeq = create_deque(_Bool); + + deque_init(pdeq); + assert_true(_fun_get_binary(deque_begin(pdeq), _GREATER_EQUAL_FUN) == fun_default_binary); + deque_destroy(pdeq); +} + +void test__fun_get_binary__bool_LOGICAL_AND(void** state) +{ + deque_t* pdeq = create_deque(_Bool); + + deque_init(pdeq); + assert_true(_fun_get_binary(deque_begin(pdeq), _LOGICAL_AND_FUN) == fun_logical_and_bool); + deque_destroy(pdeq); +} + +void test__fun_get_binary__bool_LOGICAL_OR(void** state) +{ + deque_t* pdeq = create_deque(_Bool); + + deque_init(pdeq); + assert_true(_fun_get_binary(deque_begin(pdeq), _LOGICAL_OR_FUN) == fun_logical_or_bool); + deque_destroy(pdeq); +} +#endif diff --git a/test/ut/ut_cstl_function_private.h b/test/ut/ut_cstl_function_private.h index 4bca6e5a..6de08a13 100644 --- a/test/ut/ut_cstl_function_private.h +++ b/test/ut/ut_cstl_function_private.h @@ -53,10 +53,16 @@ void test__fun_get_unary__long_double_NEGATE(void** state); void test__fun_get_unary__long_double_LOGICAL_NOT(void** state); void test__fun_get_unary__long_double_INCREASE(void** state); void test__fun_get_unary__long_double_RANDOM_NUMBER(void** state); +void test__fun_get_unary__cstl_bool_NEGATE(void** state); +void test__fun_get_unary__cstl_bool_LOGICAL_NOT(void** state); +void test__fun_get_unary__cstl_bool_INCREASE(void** state); +void test__fun_get_unary__cstl_bool_RANDOM_NUMBER(void** state); +#ifndef _MSC_VER void test__fun_get_unary__bool_NEGATE(void** state); void test__fun_get_unary__bool_LOGICAL_NOT(void** state); void test__fun_get_unary__bool_INCREASE(void** state); void test__fun_get_unary__bool_RANDOM_NUMBER(void** state); +#endif /* * test _fun_get_binary */ @@ -219,19 +225,19 @@ void test__fun_get_binary__cstr_GREATER(void** state); void test__fun_get_binary__cstr_GREATER_EQUAL(void** state); void test__fun_get_binary__cstr_LOGICAL_AND(void** state); void test__fun_get_binary__cstr_LOGICAL_OR(void** state); -void test__fun_get_binary__bool_PLUS(void** state); -void test__fun_get_binary__bool_MINUS(void** state); -void test__fun_get_binary__bool_MULTIPLIES(void** state); -void test__fun_get_binary__bool_DIVIDES(void** state); -void test__fun_get_binary__bool_MODULUS(void** state); -void test__fun_get_binary__bool_EQUAL(void** state); -void test__fun_get_binary__bool_NOT_EQUAL(void** state); -void test__fun_get_binary__bool_LESS(void** state); -void test__fun_get_binary__bool_LESS_EQUAL(void** state); -void test__fun_get_binary__bool_GREATER(void** state); -void test__fun_get_binary__bool_GREATER_EQUAL(void** state); -void test__fun_get_binary__bool_LOGICAL_AND(void** state); -void test__fun_get_binary__bool_LOGICAL_OR(void** state); +void test__fun_get_binary__cstl_bool_PLUS(void** state); +void test__fun_get_binary__cstl_bool_MINUS(void** state); +void test__fun_get_binary__cstl_bool_MULTIPLIES(void** state); +void test__fun_get_binary__cstl_bool_DIVIDES(void** state); +void test__fun_get_binary__cstl_bool_MODULUS(void** state); +void test__fun_get_binary__cstl_bool_EQUAL(void** state); +void test__fun_get_binary__cstl_bool_NOT_EQUAL(void** state); +void test__fun_get_binary__cstl_bool_LESS(void** state); +void test__fun_get_binary__cstl_bool_LESS_EQUAL(void** state); +void test__fun_get_binary__cstl_bool_GREATER(void** state); +void test__fun_get_binary__cstl_bool_GREATER_EQUAL(void** state); +void test__fun_get_binary__cstl_bool_LOGICAL_AND(void** state); +void test__fun_get_binary__cstl_bool_LOGICAL_OR(void** state); void test__fun_get_binary__vector_PLUS(void** state); void test__fun_get_binary__vector_MINUS(void** state); void test__fun_get_binary__vector_MULTIPLIES(void** state); @@ -459,6 +465,21 @@ void test__fun_get_binary__pointer_GREATER(void** state); void test__fun_get_binary__pointer_GREATER_EQUAL(void** state); void test__fun_get_binary__pointer_LESS(void** state); void test__fun_get_binary__pointer_LESS_EQUAL(void** state); +#ifndef _MSC_VER +void test__fun_get_binary__bool_PLUS(void** state); +void test__fun_get_binary__bool_MINUS(void** state); +void test__fun_get_binary__bool_MULTIPLIES(void** state); +void test__fun_get_binary__bool_DIVIDES(void** state); +void test__fun_get_binary__bool_MODULUS(void** state); +void test__fun_get_binary__bool_EQUAL(void** state); +void test__fun_get_binary__bool_NOT_EQUAL(void** state); +void test__fun_get_binary__bool_LESS(void** state); +void test__fun_get_binary__bool_LESS_EQUAL(void** state); +void test__fun_get_binary__bool_GREATER(void** state); +void test__fun_get_binary__bool_GREATER_EQUAL(void** state); +void test__fun_get_binary__bool_LOGICAL_AND(void** state); +void test__fun_get_binary__bool_LOGICAL_OR(void** state); +#endif #define UT_CSTL_FUNCTION_PRIVATE_CASE\ UT_SUIT_BEGIN(cstl_function_private, test__fun_get_unary__invalid_iter),\ @@ -507,10 +528,10 @@ void test__fun_get_binary__pointer_LESS_EQUAL(void** state); UT_CASE(test__fun_get_unary__long_double_LOGICAL_NOT),\ UT_CASE(test__fun_get_unary__long_double_INCREASE),\ UT_CASE(test__fun_get_unary__long_double_RANDOM_NUMBER),\ - UT_CASE(test__fun_get_unary__bool_NEGATE),\ - UT_CASE(test__fun_get_unary__bool_LOGICAL_NOT),\ - UT_CASE(test__fun_get_unary__bool_INCREASE),\ - UT_CASE(test__fun_get_unary__bool_RANDOM_NUMBER),\ + UT_CASE(test__fun_get_unary__cstl_bool_NEGATE),\ + UT_CASE(test__fun_get_unary__cstl_bool_LOGICAL_NOT),\ + UT_CASE(test__fun_get_unary__cstl_bool_INCREASE),\ + UT_CASE(test__fun_get_unary__cstl_bool_RANDOM_NUMBER),\ UT_CASE_BEGIN(_fun_get_binary, test__fun_get_binary__invalid_iter),\ UT_CASE(test__fun_get_binary__invalid_type),\ UT_CASE(test__fun_get_binary__char_PLUS),\ @@ -669,19 +690,19 @@ void test__fun_get_binary__pointer_LESS_EQUAL(void** state); UT_CASE(test__fun_get_binary__cstr_GREATER_EQUAL),\ UT_CASE(test__fun_get_binary__cstr_LOGICAL_AND),\ UT_CASE(test__fun_get_binary__cstr_LOGICAL_OR),\ - UT_CASE(test__fun_get_binary__bool_PLUS),\ - UT_CASE(test__fun_get_binary__bool_MINUS),\ - UT_CASE(test__fun_get_binary__bool_MULTIPLIES),\ - UT_CASE(test__fun_get_binary__bool_DIVIDES),\ - UT_CASE(test__fun_get_binary__bool_MODULUS),\ - UT_CASE(test__fun_get_binary__bool_EQUAL),\ - UT_CASE(test__fun_get_binary__bool_NOT_EQUAL),\ - UT_CASE(test__fun_get_binary__bool_LESS),\ - UT_CASE(test__fun_get_binary__bool_LESS_EQUAL),\ - UT_CASE(test__fun_get_binary__bool_GREATER),\ - UT_CASE(test__fun_get_binary__bool_GREATER_EQUAL),\ - UT_CASE(test__fun_get_binary__bool_LOGICAL_AND),\ - UT_CASE(test__fun_get_binary__bool_LOGICAL_OR),\ + UT_CASE(test__fun_get_binary__cstl_bool_PLUS),\ + UT_CASE(test__fun_get_binary__cstl_bool_MINUS),\ + UT_CASE(test__fun_get_binary__cstl_bool_MULTIPLIES),\ + UT_CASE(test__fun_get_binary__cstl_bool_DIVIDES),\ + UT_CASE(test__fun_get_binary__cstl_bool_MODULUS),\ + UT_CASE(test__fun_get_binary__cstl_bool_EQUAL),\ + UT_CASE(test__fun_get_binary__cstl_bool_NOT_EQUAL),\ + UT_CASE(test__fun_get_binary__cstl_bool_LESS),\ + UT_CASE(test__fun_get_binary__cstl_bool_LESS_EQUAL),\ + UT_CASE(test__fun_get_binary__cstl_bool_GREATER),\ + UT_CASE(test__fun_get_binary__cstl_bool_GREATER_EQUAL),\ + UT_CASE(test__fun_get_binary__cstl_bool_LOGICAL_AND),\ + UT_CASE(test__fun_get_binary__cstl_bool_LOGICAL_OR),\ UT_CASE(test__fun_get_binary__vector_PLUS),\ UT_CASE(test__fun_get_binary__vector_MINUS),\ UT_CASE(test__fun_get_binary__vector_MULTIPLIES),\ @@ -910,5 +931,26 @@ void test__fun_get_binary__pointer_LESS_EQUAL(void** state); UT_CASE(test__fun_get_binary__pointer_LESS),\ UT_CASE(test__fun_get_binary__pointer_LESS_EQUAL) +#ifndef _MSC_VER +#define UT_CSTL_FUNCTION_PRIVATE_CASE_C99\ + UT_SUIT_BEGIN(cstl_function_private, test__fun_get_unary__bool_NEGATE),\ + UT_CASE(test__fun_get_unary__bool_LOGICAL_NOT),\ + UT_CASE(test__fun_get_unary__bool_INCREASE),\ + UT_CASE(test__fun_get_unary__bool_RANDOM_NUMBER),\ + UT_CASE_BEGIN(_fun_get_binary, test__fun_get_binary__cstl_bool_PLUS),\ + UT_CASE(test__fun_get_binary__cstl_bool_MINUS),\ + UT_CASE(test__fun_get_binary__cstl_bool_MULTIPLIES),\ + UT_CASE(test__fun_get_binary__cstl_bool_DIVIDES),\ + UT_CASE(test__fun_get_binary__cstl_bool_MODULUS),\ + UT_CASE(test__fun_get_binary__cstl_bool_EQUAL),\ + UT_CASE(test__fun_get_binary__cstl_bool_NOT_EQUAL),\ + UT_CASE(test__fun_get_binary__cstl_bool_LESS),\ + UT_CASE(test__fun_get_binary__cstl_bool_LESS_EQUAL),\ + UT_CASE(test__fun_get_binary__cstl_bool_GREATER),\ + UT_CASE(test__fun_get_binary__cstl_bool_GREATER_EQUAL),\ + UT_CASE(test__fun_get_binary__cstl_bool_LOGICAL_AND),\ + UT_CASE(test__fun_get_binary__cstl_bool_LOGICAL_OR) +#endif + #endif /* _UT_CSTL_FUNCTION_PRIVATE_H_ */ diff --git a/test/ut/ut_cstl_types.c b/test/ut/ut_cstl_types.c index 302f3c70..54b1da5f 100644 --- a/test/ut/ut_cstl_types.c +++ b/test/ut/ut_cstl_types.c @@ -1386,7 +1386,7 @@ void test__all_types__string(void** state) vector_destroy(pvec); } -void test__all_types__bool(void** state) +void test__all_types__cstl_bool(void** state) { vector_t* pvec = create_vector(bool_t); assert_true(pvec != NULL); @@ -1526,6 +1526,15 @@ void test__all_types__random_access_iterator(void** state) vector_destroy(pvec); } +#ifndef _MSC_VER +void test__all_types__bool(void** state) +{ + vector_t* pvec = create_vector(_Bool); + assert_true(pvec != NULL); + vector_destroy(pvec); +} +#endif + /* * test void* usage */ @@ -1628,3 +1637,106 @@ void test__pointer_usage__duplicate(void** state) vector_destroy(pvec); } +#ifndef _MSC_VER +/* + * test _Bool usage + */ +UT_CASE_DEFINATION(bool_usage) +void test__bool_usage__create(void** state) +{ + vector_t* pvec = create_vector(_Bool); + assert_true(pvec != NULL); + vector_destroy(pvec); +} + +void test__bool_usage__init_n(void** state) +{ + size_t i = 0; + vector_t* pvec = create_vector(_Bool); + vector_init_n(pvec, 10); + for (i = 0; i < vector_size(pvec); ++i) { + assert_true(*(_Bool*)vector_at(pvec, i) == false); + } + vector_destroy(pvec); +} + +void test__bool_usage__init_elem(void** state) +{ + size_t i = 0; + vector_t* pvec = create_vector(_Bool); + vector_init_elem(pvec, 10, true); + for (i = 0; i < vector_size(pvec); ++i) { + assert_true(*(_Bool*)vector_at(pvec, i) == true); + } + vector_destroy(pvec); +} + +void test__bool_usage__at(void** state) +{ + size_t i = 0; + vector_t* pvec = create_vector(_Bool); + vector_init_elem(pvec, 10, true); + for (i = 0; i < vector_size(pvec); ++i) { + assert_true(*(_Bool*)vector_at(pvec, i) == true); + *(_Bool*)vector_at(pvec, i) = false; + } + for (i = 0; i < vector_size(pvec); ++i) { + assert_true(*(_Bool*)vector_at(pvec, i) == false); + } + vector_destroy(pvec); +} + +void test__bool_usage__iterator(void** state) +{ + iterator_t it; + vector_t* pvec = create_vector(_Bool); + vector_init_elem(pvec, 10, true); + for (it = vector_begin(pvec); + !iterator_equal(it, vector_end(pvec)); + it = iterator_next(it)) { + _Bool b = false; + assert_true(*(_Bool*)iterator_get_pointer(it) == true); + iterator_get_value(it, &b); + assert_true(b); + } + vector_destroy(pvec); +} + +void test__bool_usage__copy(void** state) +{ + size_t i = 0; + vector_t* pvec1 = create_vector(_Bool); + vector_t* pvec2 = create_vector(_Bool); + vector_init_elem(pvec1, 10, true); + vector_init_copy_range(pvec2, vector_begin(pvec1), vector_end(pvec1)); + + for (i = 0; i < vector_size(pvec1); ++i) { + assert_true(*(_Bool*)vector_at(pvec1, i) == *(_Bool*)vector_at(pvec2, i)); + } + + vector_destroy(pvec1); + vector_destroy(pvec2); +} + +void test__bool_usage__less(void** state) +{ + vector_t* pvec1 = create_vector(_Bool); + vector_t* pvec2 = create_vector(_Bool); + vector_init_elem(pvec1, 10, false); + vector_init_elem(pvec2, 10, true); + assert_true(vector_less(pvec1, pvec2)); + vector_destroy(pvec1); + vector_destroy(pvec2); +} + +typedef _Bool my_bool; +void test__bool_usage__duplicate(void** state) +{ + vector_t* pvec = NULL; + + type_duplicate(my_bool, _Bool); + pvec = create_vector(my_bool); + assert_true(pvec != NULL); + vector_destroy(pvec); +} +#endif diff --git a/test/ut/ut_cstl_types.h b/test/ut/ut_cstl_types.h index f727e815..62acc4df 100644 --- a/test/ut/ut_cstl_types.h +++ b/test/ut/ut_cstl_types.h @@ -211,7 +211,7 @@ void test__all_types__hash_multimap(void** state); void test__all_types__pair(void** state); /* string_t, bool_t */ void test__all_types__string(void** state); -void test__all_types__bool(void** state); +void test__all_types__cstl_bool(void** state); /* ITERATOR */ void test__all_types__iterator(void** state); void test__all_types__vector_iterator(void** state); @@ -232,6 +232,9 @@ void test__all_types__output_iterator(void** state); void test__all_types__forward_iterator(void** state); void test__all_types__bidirectional_iterator(void** state); void test__all_types__random_access_iterator(void** state); +#ifndef _MSC_VER +void test__all_types__bool(void** state); +#endif /* * test void* usage */ @@ -244,6 +247,20 @@ void test__pointer_usage__at(void** state); void test__pointer_usage__copy(void** state); void test__pointer_usage__less(void** state); void test__pointer_usage__duplicate(void** state); +#ifndef _MSC_VER +/* + * test _Bool usage + */ +UT_CASE_DECLARATION(bool_usage) +void test__bool_usage__create(void** state); +void test__bool_usage__init_n(void** state); +void test__bool_usage__init_elem(void** state); +void test__bool_usage__iterator(void** state); +void test__bool_usage__at(void** state); +void test__bool_usage__copy(void** state); +void test__bool_usage__less(void** state); +void test__bool_usage__duplicate(void** state); +#endif #define UT_CSTL_TYPES_CASE\ UT_SUIT_BEGIN(cstl_types, test__all_types__char),\ @@ -292,7 +309,7 @@ void test__pointer_usage__duplicate(void** state); UT_CASE(test__all_types__hash_multimap),\ UT_CASE(test__all_types__pair),\ UT_CASE(test__all_types__string),\ - UT_CASE(test__all_types__bool),\ + UT_CASE(test__all_types__cstl_bool),\ UT_CASE(test__all_types__iterator),\ UT_CASE(test__all_types__vector_iterator),\ UT_CASE(test__all_types__list_iterator),\ @@ -427,5 +444,18 @@ void test__pointer_usage__duplicate(void** state); UT_CASE(test__pointer_usage__less),\ UT_CASE(test__pointer_usage__duplicate) +#ifndef _MSC_VER +#define UT_CSTL_TYPES_CASE_C99\ + UT_SUIT_BEGIN(cstl_types, test__all_types__bool),\ + UT_CASE_BEGIN(bool_usage, test__bool_usage__create),\ + UT_CASE(test__bool_usage__init_n),\ + UT_CASE(test__bool_usage__init_elem),\ + UT_CASE(test__bool_usage__at),\ + UT_CASE(test__bool_usage__iterator),\ + UT_CASE(test__bool_usage__copy),\ + UT_CASE(test__bool_usage__less),\ + UT_CASE(test__bool_usage__duplicate) +#endif + #endif /* _UT_CSTL_TYPES_H_ */ diff --git a/test/ut/ut_cstl_types_aux.c b/test/ut/ut_cstl_types_aux.c index 861f7387..e84e659c 100644 --- a/test/ut/ut_cstl_types_aux.c +++ b/test/ut/ut_cstl_types_aux.c @@ -149,6 +149,10 @@ void test__type_register_c_builtin__all(void** state) TEST__TYPE_REGISTER_TYPE(string_t, _C_STRING_TYPE, cstr, _TYPE_C_BUILTIN); /* void* */ TEST__TYPE_REGISTER_TYPE(void*, _POINTER_TYPE, pointer, _TYPE_C_BUILTIN); +#ifndef _MSC_VER + /* _Bool */ + TEST__TYPE_REGISTER_TYPE(_Bool, _BOOL_TYPE, bool, _TYPE_C_BUILTIN); +#endif TEST__TYPE_REGISTER_END(); } diff --git a/test/ut/ut_cstl_types_builtin.c b/test/ut/ut_cstl_types_builtin.c index d060221f..a00e6adc 100644 --- a/test/ut/ut_cstl_types_builtin.c +++ b/test/ut/ut_cstl_types_builtin.c @@ -7394,3 +7394,149 @@ void test__type_destroy_pointer__ok(void** state) assert_true(b_output); assert_true(p == 0x1234); } + +#ifndef _MSC_VER +/* + * test _type_init_bool + */ +UT_CASE_DEFINATION(_type_init_bool) +void test__type_init_bool__null_input(void** state) +{ + bool_t b_output = false; + expect_assert_failure(_type_init_bool(NULL, &b_output)); +} + +void test__type_init_bool__null_output(void** state) +{ + bool_t b_input = false; + expect_assert_failure(_type_init_bool(&b_input, NULL)); +} + +void test__type_init_bool__ok(void** state) +{ + _Bool b_input = true; + bool_t b_output = false; + _type_init_bool(&b_input, &b_output); + assert_false(b_input); + assert_true(b_output); +} + +/* + * test _type_copy_bool + */ +UT_CASE_DEFINATION(_type_copy_bool) +void test__type_copy_bool__null_first(void** state) +{ + _Bool b_second = true; + bool_t b_output = false; + expect_assert_failure(_type_copy_bool(NULL, &b_second, &b_output)); +} + +void test__type_copy_bool__null_second(void** state) +{ + _Bool b_first = true; + bool_t b_output = false; + expect_assert_failure(_type_copy_bool(&b_first, NULL, &b_output)); +} + +void test__type_copy_bool__null_output(void** state) +{ + _Bool b_first = true; + _Bool b_second = false; + expect_assert_failure(_type_copy_bool(&b_first, &b_second, NULL)); +} + +void test__type_copy_bool__ok(void** state) +{ + _Bool b_first = true; + _Bool b_second = false; + bool_t b_output = false; + _type_copy_bool(&b_first, &b_second, &b_output); + assert_false(b_first); + assert_false(b_second); + assert_true(b_output); +} + +/* + * test _type_less_bool + */ +UT_CASE_DEFINATION(_type_less_bool) +void test__type_less_bool__null_first(void** state) +{ + _Bool b_second = true; + bool_t b_output = false; + expect_assert_failure(_type_less_bool(NULL, &b_second, &b_output)); +} + +void test__type_less_bool__null_second(void** state) +{ + _Bool b_first = true; + bool_t b_output = false; + expect_assert_failure(_type_less_bool(&b_first, NULL, &b_output)); +} + +void test__type_less_bool__null_output(void** state) +{ + _Bool b_first = true; + _Bool b_second = false; + expect_assert_failure(_type_less_bool(&b_first, &b_second, NULL)); +} + +void test__type_less_bool__less(void** state) +{ + _Bool b_first = false; + _Bool b_second = true; + bool_t b_output = false; + _type_less_bool(&b_first, &b_second, &b_output); + assert_false(b_first); + assert_true(b_second); + assert_true(b_output); +} + +void test__type_less_bool__equal(void** state) +{ + _Bool b_first = false; + _Bool b_second = false; + bool_t b_output = false; + _type_less_bool(&b_first, &b_second, &b_output); + assert_false(b_first); + assert_false(b_second); + assert_false(b_output); +} + +void test__type_less_bool__greater(void** state) +{ + _Bool b_first = true; + _Bool b_second = false; + bool_t b_output = false; + _type_less_bool(&b_first, &b_second, &b_output); + assert_true(b_first); + assert_false(b_second); + assert_false(b_output); +} + +/* + * test _type_destroy_bool + */ +UT_CASE_DEFINATION(_type_destroy_bool) +void test__type_destroy_bool__null_input(void** state) +{ + bool_t b_output = false; + expect_assert_failure(_type_destroy_bool(NULL, &b_output)); +} + +void test__type_destroy_bool__null_output(void** state) +{ + _Bool b_input = false; + expect_assert_failure(_type_destroy_bool(&b_input, NULL)); +} + +void test__type_destroy_bool__ok(void** state) +{ + _Bool b_input = false; + bool_t b_output = false; + _type_destroy_bool(&b_input, &b_output); + assert_false(b_input); + assert_true(b_output); +} +#endif diff --git a/test/ut/ut_cstl_types_builtin.h b/test/ut/ut_cstl_types_builtin.h index b4a5ca4b..7a8aa491 100644 --- a/test/ut/ut_cstl_types_builtin.h +++ b/test/ut/ut_cstl_types_builtin.h @@ -1028,6 +1028,41 @@ void test__type_destroy_iterator__null_input(void** state); void test__type_destroy_iterator__null_output(void** state); void test__type_destroy_iterator__ok(void** state); +#ifndef _MSC_VER +/* + * test _type_init_bool + */ +UT_CASE_DECLARATION(_type_init_bool) +void test__type_init_bool__null_input(void** state); +void test__type_init_bool__null_output(void** state); +void test__type_init_bool__ok(void** state); +/* + * test _type_copy_bool + */ +UT_CASE_DECLARATION(_type_copy_bool) +void test__type_copy_bool__null_first(void** state); +void test__type_copy_bool__null_second(void** state); +void test__type_copy_bool__null_output(void** state); +void test__type_copy_bool__ok(void** state); +/* + * test _type_less_bool + */ +UT_CASE_DECLARATION(_type_less_bool) +void test__type_less_bool__null_first(void** state); +void test__type_less_bool__null_second(void** state); +void test__type_less_bool__null_output(void** state); +void test__type_less_bool__less(void** state); +void test__type_less_bool__equal(void** state); +void test__type_less_bool__greater(void** state); +/* + * test _type_destroy_bool + */ +UT_CASE_DECLARATION(_type_destroy_bool) +void test__type_destroy_bool__null_input(void** state); +void test__type_destroy_bool__null_output(void** state); +void test__type_destroy_bool__ok(void** state); +#endif + #define UT_CSTL_TYPES_BUILTIN_CASE\ UT_SUIT_BEGIN(cstl_types_builtin, test__type_init_char__null_input),\ UT_CASE(test__type_init_char__null_output),\ @@ -1542,5 +1577,25 @@ void test__type_destroy_iterator__ok(void** state); UT_CASE(test__type_destroy_pointer__null_output),\ UT_CASE(test__type_destroy_pointer__ok) +#ifndef _MSC_VER +#define UT_CSTL_TYPES_BUILTIN_CASE_C99\ + UT_SUIT_BEGIN(cstl_types_builtin, test__type_init_bool__null_input),\ + UT_CASE(test__type_init_bool__null_output),\ + UT_CASE(test__type_init_bool__ok),\ + UT_CASE_BEGIN(_type_copy_bool, test__type_copy_bool__null_first),\ + UT_CASE(test__type_copy_bool__null_second),\ + UT_CASE(test__type_copy_bool__null_output),\ + UT_CASE(test__type_copy_bool__ok),\ + UT_CASE_BEGIN(_type_less_bool, test__type_less_bool__null_first),\ + UT_CASE(test__type_less_bool__null_second),\ + UT_CASE(test__type_less_bool__null_output),\ + UT_CASE(test__type_less_bool__less),\ + UT_CASE(test__type_less_bool__equal),\ + UT_CASE(test__type_less_bool__greater),\ + UT_CASE_BEGIN(_type_destroy_bool, test__type_destroy_bool__null_input),\ + UT_CASE(test__type_destroy_bool__null_output),\ + UT_CASE(test__type_destroy_bool__ok) +#endif + #endif /* _UT_CSTL_TYPES_BUILTIN_H_ */ diff --git a/test/ut/ut_cstl_types_parse.c b/test/ut/ut_cstl_types_parse.c index d6b8974d..b0e2c1cc 100644 --- a/test/ut/ut_cstl_types_parse.c +++ b/test/ut/ut_cstl_types_parse.c @@ -191,7 +191,7 @@ void test__type_get_token__key_unsigned(void** state) assert_true(strncmp(_gt_typeanalysis._s_tokentext, "unsigned", _TYPE_NAME_SIZE) == 0); } -void test__type_get_token__key_bool(void** state) +void test__type_get_token__key_cstl_bool(void** state) { test_parse_setup("bool_t"); _type_get_token(); @@ -551,6 +551,17 @@ void test__type_get_token__key_random_access_iterator(void** state) assert_true(strncmp(_gt_typeanalysis._s_tokentext, "random_access_iterator_t", _TYPE_NAME_SIZE) == 0); } +#ifndef _MSC_VER +void test__type_get_token__key_bool(void** state) +{ + test_parse_setup("_Bool"); + _type_get_token(); + assert_true(_gt_typeanalysis._t_token == _TOKEN_KEY_BOOL); + assert_true(_gt_typeanalysis._t_index == 5); + assert_true(strncmp(_gt_typeanalysis._s_tokentext, "_Bool", _TYPE_NAME_SIZE) == 0); +} +#endif + /* * test _type_token_rollback */ @@ -1662,7 +1673,7 @@ void test__type_parse_simple_builtin__char_pointer(void** state) assert_true(strncmp(s_formalname, "char*", _TYPE_NAME_SIZE) == 0); } -void test__type_parse_simple_builtin__bool(void** state) +void test__type_parse_simple_builtin__cstl_bool(void** state) { const char* str = "bool_t"; char s_formalname[_TYPE_NAME_SIZE + 1] = {'\0'}; @@ -1682,6 +1693,18 @@ void test__type_parse_simple_builtin__invalid_token(void** state) assert_true(strncmp(s_formalname, "", _TYPE_NAME_SIZE) == 0); } +#ifndef _MSC_VER +void test__type_parse_simple_builtin__bool(void** state) +{ + const char* str = "_Bool"; + char s_formalname[_TYPE_NAME_SIZE + 1] = {'\0'}; + test_parse_setup_ex(str, _TOKEN_KEY_BOOL, strlen(str), str); + + assert_true(_type_parse_simple_builtin(s_formalname)); + assert_true(strncmp(s_formalname, "_Bool", _TYPE_NAME_SIZE) == 0); +} +#endif + /* * test _type_parse_c_builtin */ diff --git a/test/ut/ut_cstl_types_parse.h b/test/ut/ut_cstl_types_parse.h index b59d0ae9..3e3d2081 100644 --- a/test/ut/ut_cstl_types_parse.h +++ b/test/ut/ut_cstl_types_parse.h @@ -24,7 +24,7 @@ void test__type_get_token__key_double(void** state); void test__type_get_token__key_float(void** state); void test__type_get_token__key_signed(void** state); void test__type_get_token__key_unsigned(void** state); -void test__type_get_token__key_bool(void** state); +void test__type_get_token__key_cstl_bool(void** state); void test__type_get_token__key_struct(void** state); void test__type_get_token__key_enum(void** state); void test__type_get_token__key_union(void** state); @@ -64,6 +64,9 @@ void test__type_get_token__key_output_iterator(void** state); void test__type_get_token__key_forward_iterator(void** state); void test__type_get_token__key_bidirectional_iterator(void** state); void test__type_get_token__key_random_access_iterator(void** state); +#ifndef _MSC_VER +void test__type_get_token__key_bool(void** state); +#endif /* * test _type_token_rollback */ @@ -230,9 +233,12 @@ void test__type_parse_simple_builtin__long_double(void** state); void test__type_parse_simple_builtin__float(void** state); void test__type_parse_simple_builtin__double(void** state); void test__type_parse_simple_builtin__char_pointer(void** state); -void test__type_parse_simple_builtin__bool(void** state); +void test__type_parse_simple_builtin__cstl_bool(void** state); void test__type_parse_simple_builtin__invalid_token(void** state); void test__type_parse_simple_builtin__null(void** state); +#ifndef _MSC_VER +void test__type_parse_simple_builtin__bool(void** state); +#endif /* * test _type_parse_c_builtin */ @@ -319,7 +325,7 @@ void test__type_get_style__invalid(void** state); UT_CASE(test__type_get_token__key_float),\ UT_CASE(test__type_get_token__key_signed),\ UT_CASE(test__type_get_token__key_unsigned),\ - UT_CASE(test__type_get_token__key_bool),\ + UT_CASE(test__type_get_token__key_cstl_bool),\ UT_CASE(test__type_get_token__key_struct),\ UT_CASE(test__type_get_token__key_enum),\ UT_CASE(test__type_get_token__key_union),\ @@ -469,7 +475,7 @@ void test__type_get_style__invalid(void** state); UT_CASE(test__type_parse_simple_builtin__float),\ UT_CASE(test__type_parse_simple_builtin__double),\ UT_CASE(test__type_parse_simple_builtin__char_pointer),\ - UT_CASE(test__type_parse_simple_builtin__bool),\ + UT_CASE(test__type_parse_simple_builtin__cstl_bool),\ UT_CASE(test__type_parse_simple_builtin__invalid_token),\ UT_CASE(test__type_parse_simple_builtin__null),\ UT_CASE_BEGIN(_type_parse_c_builtin, test__type_parse_c_builtin__simple_builtin),\ @@ -516,5 +522,11 @@ void test__type_get_style__invalid(void** state); UT_CASE(test__type_get_style__cstl_builtin_invalid),\ UT_CASE(test__type_get_style__invalid) +#ifndef _MSC_VER +#define UT_CSTL_TYPES_PARSE_CASE_C99\ + UT_SUIT_BEGIN(cstl_types_parse, test__type_get_token__key_bool),\ + UT_CASE_BEGIN(_type_parse_simple_builtin, test__type_parse_simple_builtin__bool) +#endif + #endif /* _UT_CSTL_TYPES_PARSE_H_ */ diff --git a/test/ut/ut_main.c b/test/ut/ut_main.c index c2aff115..418e686e 100644 --- a/test/ut/ut_main.c +++ b/test/ut/ut_main.c @@ -189,6 +189,11 @@ int main(int argc, char* argv[]) UT_CSTL_TYPES_PARSE_CASE, UT_CSTL_TYPES_AUX_CASE, UT_CSTL_TYPES_CASE, +#ifndef _MSC_VER + UT_CSTL_TYPES_BUILTIN_CASE_C99, + UT_CSTL_TYPES_PARSE_CASE_C99, + UT_CSTL_TYPES_CASE_C99, +#endif UT_CSTL_ALGO_NONMUTATING_PRIVATE_CASE, UT_CSTL_ALGO_NONMUTATING_CASE, UT_CSTL_ALGO_MUTATING_AUX_CASE, @@ -203,6 +208,9 @@ int main(int argc, char* argv[]) UT_CSTL_NUMERIC_CASE, UT_CSTL_FUNCTION_PRIVATE_CASE, UT_CASE_FUNCTION_CASE, +#ifndef _MSC_VER + UT_CSTL_FUNCTION_PRIVATE_CASE_C99, +#endif UT_CSTL_PRIORITY_QUEUE_PRIVATE_CASE, UT_CSTL_PRIORITY_QUEUE_CASE };