forked from enlightenment/efl
* eina_magic: Test suite now work when magic debug is disabled.
SVN revision: 42150
This commit is contained in:
parent
a77cd76e1d
commit
49cb141f10
|
@ -35,12 +35,17 @@
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
typedef unsigned int Eina_Magic;
|
||||||
|
|
||||||
EAPI int eina_magic_string_init(void);
|
EAPI int eina_magic_string_init(void);
|
||||||
EAPI int eina_magic_string_shutdown(void);
|
EAPI int eina_magic_string_shutdown(void);
|
||||||
|
|
||||||
|
/**
|
||||||
#ifdef EINA_MAGIC_DEBUG
|
* @typedef Eina_Magic
|
||||||
|
* An abstract type for a magic number.
|
||||||
|
*/
|
||||||
|
EAPI const char* eina_magic_string_get(Eina_Magic magic) EINA_PURE EINA_WARN_UNUSED_RESULT;
|
||||||
|
EAPI void eina_magic_string_set(Eina_Magic magic, const char *magic_name) EINA_ARG_NONNULL(2);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @def EINA_MAGIC_NONE
|
* @def EINA_MAGIC_NONE
|
||||||
|
@ -52,6 +57,8 @@ EAPI int eina_magic_string_shutdown(void);
|
||||||
*/
|
*/
|
||||||
#define EINA_MAGIC_NONE 0x1234fedc
|
#define EINA_MAGIC_NONE 0x1234fedc
|
||||||
|
|
||||||
|
#ifdef EINA_MAGIC_DEBUG
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @def EINA_MAGIC
|
* @def EINA_MAGIC
|
||||||
* Declaration of a variable of type #Eina_Magic. To put in a structure
|
* Declaration of a variable of type #Eina_Magic. To put in a structure
|
||||||
|
@ -106,14 +113,6 @@ EAPI int eina_magic_string_shutdown(void);
|
||||||
*/
|
*/
|
||||||
#define EINA_MAGIC_FAIL(d, m) eina_magic_fail((void*)(d), (d) ? (d)->__magic : 0, (m), __FILE__, __FUNCTION__, __LINE__);
|
#define EINA_MAGIC_FAIL(d, m) eina_magic_fail((void*)(d), (d) ? (d)->__magic : 0, (m), __FILE__, __FUNCTION__, __LINE__);
|
||||||
|
|
||||||
/**
|
|
||||||
* @typedef Eina_Magic
|
|
||||||
* An abstract type for a magic number.
|
|
||||||
*/
|
|
||||||
typedef unsigned int Eina_Magic;
|
|
||||||
|
|
||||||
EAPI const char* eina_magic_string_get(Eina_Magic magic) EINA_PURE EINA_WARN_UNUSED_RESULT;
|
|
||||||
EAPI void eina_magic_string_set(Eina_Magic magic, const char *magic_name) EINA_ARG_NONNULL(2);
|
|
||||||
EAPI void eina_magic_fail(void *d, Eina_Magic m, Eina_Magic req_m,
|
EAPI void eina_magic_fail(void *d, Eina_Magic m, Eina_Magic req_m,
|
||||||
const char *file, const char *fnc, int line) EINA_ARG_NONNULL(4, 5);
|
const char *file, const char *fnc, int line) EINA_ARG_NONNULL(4, 5);
|
||||||
|
|
||||||
|
@ -123,14 +122,11 @@ EAPI void eina_magic_fail(void *d, Eina_Magic m, Eina_Magic req_m,
|
||||||
* @cond LOCAL
|
* @cond LOCAL
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define EINA_MAGIC_NONE ((void) 0)
|
|
||||||
#define EINA_MAGIC
|
#define EINA_MAGIC
|
||||||
#define EINA_MAGIC_SET(d, m) ((void) 0)
|
#define EINA_MAGIC_SET(d, m) ((void) 0)
|
||||||
#define EINA_MAGIC_CHECK(d, m) (1)
|
#define EINA_MAGIC_CHECK(d, m) (1)
|
||||||
#define EINA_MAGIC_FAIL(d, m) ((void) 0)
|
#define EINA_MAGIC_FAIL(d, m) ((void) 0)
|
||||||
|
|
||||||
#define eina_magic_string_get(Magic) (NULL)
|
|
||||||
#define eina_magic_string_set(Magic, Magic_Name) ((void) 0)
|
|
||||||
#define eina_magic_fail(d, m, req_m, file, fnx, line) ((void) 0)
|
#define eina_magic_fail(d, m, req_m, file, fnx, line) ((void) 0)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -41,8 +41,6 @@
|
||||||
* @cond LOCAL
|
* @cond LOCAL
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef EINA_MAGIC_DEBUG
|
|
||||||
|
|
||||||
typedef struct _Eina_Magic_String Eina_Magic_String;
|
typedef struct _Eina_Magic_String Eina_Magic_String;
|
||||||
struct _Eina_Magic_String
|
struct _Eina_Magic_String
|
||||||
{
|
{
|
||||||
|
@ -55,8 +53,6 @@ struct _Eina_Magic_String
|
||||||
static int _eina_magic_string_count = 0;
|
static int _eina_magic_string_count = 0;
|
||||||
static Eina_Inlist *strings = NULL;
|
static Eina_Inlist *strings = NULL;
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @endcond
|
* @endcond
|
||||||
*/
|
*/
|
||||||
|
@ -94,13 +90,9 @@ static Eina_Inlist *strings = NULL;
|
||||||
EAPI int
|
EAPI int
|
||||||
eina_magic_string_init(void)
|
eina_magic_string_init(void)
|
||||||
{
|
{
|
||||||
#ifdef EINA_MAGIC_DEBUG
|
|
||||||
++_eina_magic_string_count;
|
++_eina_magic_string_count;
|
||||||
|
|
||||||
return _eina_magic_string_count;
|
return _eina_magic_string_count;
|
||||||
#else
|
|
||||||
return 1;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -121,7 +113,6 @@ eina_magic_string_init(void)
|
||||||
EAPI int
|
EAPI int
|
||||||
eina_magic_string_shutdown(void)
|
eina_magic_string_shutdown(void)
|
||||||
{
|
{
|
||||||
#ifdef EINA_MAGIC_DEBUG
|
|
||||||
--_eina_magic_string_count;
|
--_eina_magic_string_count;
|
||||||
|
|
||||||
if (_eina_magic_string_count == 0)
|
if (_eina_magic_string_count == 0)
|
||||||
|
@ -140,13 +131,8 @@ eina_magic_string_shutdown(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
return _eina_magic_string_count;
|
return _eina_magic_string_count;
|
||||||
#else
|
|
||||||
return 0;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef EINA_MAGIC_DEBUG
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Return the string associated to the given magic identifier.
|
* @brief Return the string associated to the given magic identifier.
|
||||||
*
|
*
|
||||||
|
@ -208,6 +194,10 @@ eina_magic_string_set(Eina_Magic magic, const char *magic_name)
|
||||||
strings = eina_inlist_prepend(strings, EINA_INLIST_GET(ems));
|
strings = eina_inlist_prepend(strings, EINA_INLIST_GET(ems));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef eina_magic_fail
|
||||||
|
# undef eina_magic_fail
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Display a message or abort is a magic check failed.
|
* @brief Display a message or abort is a magic check failed.
|
||||||
*
|
*
|
||||||
|
@ -275,8 +265,6 @@ eina_magic_fail(void *d, Eina_Magic m, Eina_Magic req_m, const char *file, const
|
||||||
if (getenv("EINA_ERROR_ABORT")) abort();
|
if (getenv("EINA_ERROR_ABORT")) abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -65,6 +65,7 @@ START_TEST(eina_magic_simple)
|
||||||
fail_if(eina_magic_string_get(EINA_MAGIC_TEST) == NULL);
|
fail_if(eina_magic_string_get(EINA_MAGIC_TEST) == NULL);
|
||||||
fail_if(strcmp(eina_magic_string_get(EINA_MAGIC_TEST), EINA_MAGIC_STRING) != 0);
|
fail_if(strcmp(eina_magic_string_get(EINA_MAGIC_TEST), EINA_MAGIC_STRING) != 0);
|
||||||
|
|
||||||
|
#ifdef EINA_MAGIC_DEBUG
|
||||||
fail_if(EINA_MAGIC_CHECK(ems, EINA_MAGIC_TEST));
|
fail_if(EINA_MAGIC_CHECK(ems, EINA_MAGIC_TEST));
|
||||||
EINA_MAGIC_FAIL(ems, EINA_MAGIC_TEST);
|
EINA_MAGIC_FAIL(ems, EINA_MAGIC_TEST);
|
||||||
|
|
||||||
|
@ -79,6 +80,7 @@ START_TEST(eina_magic_simple)
|
||||||
|
|
||||||
EINA_MAGIC_SET(ems, 42424242);
|
EINA_MAGIC_SET(ems, 42424242);
|
||||||
EINA_MAGIC_FAIL(ems, EINA_MAGIC_TEST);
|
EINA_MAGIC_FAIL(ems, EINA_MAGIC_TEST);
|
||||||
|
#endif
|
||||||
|
|
||||||
eina_magic_string_shutdown();
|
eina_magic_string_shutdown();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue