gstcheck.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  1. /* GStreamer
  2. *
  3. * Common code for GStreamer unittests
  4. *
  5. * Copyright (C) <2004> Thomas Vander Stichele <thomas at apestaart dot org>
  6. * Copyright (C) <2008> Thijs Vermeir <thijsvermeir@gmail.com>
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Library General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2 of the License, or (at your option) any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Library General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Library General Public
  19. * License along with this library; if not, write to the
  20. * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
  21. * Boston, MA 02110-1301, USA.
  22. */
  23. #ifndef __GST_CHECK_H__
  24. #define __GST_CHECK_H__
  25. #include <signal.h>
  26. #include <string.h>
  27. #include <stdlib.h>
  28. #include <math.h>
  29. #include <gst/check/internal-check.h>
  30. #include <gst/gst.h>
  31. G_BEGIN_DECLS
  32. GST_DEBUG_CATEGORY_EXTERN (check_debug);
  33. #define GST_CAT_DEFAULT check_debug
  34. /* logging function for tests
  35. * a test uses g_message() to log a debug line
  36. * a gst unit test can be run with GST_TEST_DEBUG env var set to see the
  37. * messages
  38. */
  39. extern gboolean _gst_check_threads_running;
  40. extern gboolean _gst_check_raised_critical;
  41. extern gboolean _gst_check_raised_warning;
  42. extern gboolean _gst_check_expecting_log;
  43. /* global variables used in test methods */
  44. extern GList * buffers;
  45. extern GMutex check_mutex;
  46. extern GCond check_cond;
  47. typedef struct
  48. {
  49. const char *name;
  50. int size;
  51. int abi_size;
  52. }
  53. GstCheckABIStruct;
  54. void gst_check_init (int *argc, char **argv[]);
  55. GstFlowReturn gst_check_chain_func (GstPad * pad, GstObject * parent, GstBuffer * buffer);
  56. void gst_check_message_error (GstMessage * message, GstMessageType type,
  57. GQuark domain, gint code);
  58. GstElement *gst_check_setup_element (const gchar * factory);
  59. void gst_check_teardown_element (GstElement * element);
  60. GstPad *gst_check_setup_src_pad (GstElement * element,
  61. GstStaticPadTemplate * tmpl);
  62. GstPad *gst_check_setup_src_pad_from_template (GstElement * element,
  63. GstPadTemplate * tmpl);
  64. GstPad * gst_check_setup_src_pad_by_name (GstElement * element,
  65. GstStaticPadTemplate * tmpl, const gchar *name);
  66. GstPad * gst_check_setup_src_pad_by_name_from_template (GstElement * element,
  67. GstPadTemplate * tmpl, const gchar *name);
  68. GstPad *gst_check_setup_sink_pad (GstElement * element,
  69. GstStaticPadTemplate * tmpl);
  70. GstPad *gst_check_setup_sink_pad_from_template (GstElement * element,
  71. GstPadTemplate * tmpl);
  72. GstPad * gst_check_setup_sink_pad_by_name (GstElement * element,
  73. GstStaticPadTemplate * tmpl, const gchar *name);
  74. GstPad * gst_check_setup_sink_pad_by_name_from_template (GstElement * element,
  75. GstPadTemplate * tmpl, const gchar *name);
  76. void gst_check_teardown_pad_by_name (GstElement * element, const gchar *name);
  77. void gst_check_teardown_src_pad (GstElement * element);
  78. void gst_check_drop_buffers (void);
  79. void gst_check_caps_equal (GstCaps * caps1, GstCaps * caps2);
  80. void gst_check_buffer_data (GstBuffer * buffer, gconstpointer data, gsize size);
  81. void gst_check_element_push_buffer_list (const gchar * element_name,
  82. GList * buffer_in, GstCaps * caps_in, GList * buffer_out,
  83. GstCaps * caps_out, GstFlowReturn last_flow_return);
  84. void gst_check_element_push_buffer (const gchar * element_name,
  85. GstBuffer * buffer_in, GstCaps * caps_in, GstBuffer * buffer_out,
  86. GstCaps *caps_out);
  87. void gst_check_teardown_sink_pad (GstElement * element);
  88. void gst_check_abi_list (GstCheckABIStruct list[], gboolean have_abi_sizes);
  89. gint gst_check_run_suite (Suite * suite, const gchar * name,
  90. const gchar * fname);
  91. void gst_check_setup_events (GstPad * srcpad, GstElement * element,
  92. GstCaps * caps, GstFormat format);
  93. void gst_check_setup_events_with_stream_id (GstPad * srcpad,
  94. GstElement * element, GstCaps * caps, GstFormat format,
  95. const gchar * stream_id);
  96. void gst_check_objects_destroyed_on_unref (gpointer object_to_unref, gpointer first_object, ...)
  97. G_GNUC_NULL_TERMINATED;
  98. void gst_check_object_destroyed_on_unref (gpointer object_to_unref);
  99. #define fail_unless_message_error(msg, domain, code) \
  100. gst_check_message_error (msg, GST_MESSAGE_ERROR, \
  101. GST_ ## domain ## _ERROR, GST_ ## domain ## _ERROR_ ## code)
  102. #define assert_message_error(m, d, c) fail_unless_message_error(m, d, c)
  103. #ifdef GST_CHECK_TEST_ENVIRONMENT_BEACON
  104. #define GST_DO_CHECK_TEST_ENVIRONMENT \
  105. G_STMT_START { \
  106. if (g_getenv (GST_CHECK_TEST_ENVIRONMENT_BEACON) == NULL) \
  107. fail ("Test environment not set up correctly! Expected environment " \
  108. "variable '%s' to be set.", GST_CHECK_TEST_ENVIRONMENT_BEACON); \
  109. } G_STMT_END
  110. #else
  111. #define GST_DO_CHECK_TEST_ENVIRONMENT /* nothing to check */
  112. #endif
  113. /**
  114. * GST_START_TEST:
  115. * @__testname: test function name
  116. *
  117. * wrapper for checks START_TEST
  118. */
  119. /**
  120. * GST_END_TEST:
  121. *
  122. * wrapper for checks END_TEST
  123. */
  124. #define GST_START_TEST(__testname) \
  125. static void __testname (int G_GNUC_UNUSED __i__) \
  126. {\
  127. GST_DEBUG ("test start"); \
  128. GST_DO_CHECK_TEST_ENVIRONMENT; \
  129. tcase_fn_start (""# __testname, __FILE__, __LINE__);
  130. #define GST_END_TEST GST_LOG ("cleaning up tasks"); \
  131. gst_task_cleanup_all (); \
  132. END_TEST
  133. /* additional fail macros */
  134. /**
  135. * fail_unless_equals_int:
  136. * @a: a #gint value or expression
  137. * @b: a #gint value or expression
  138. *
  139. * This macro checks that @a and @b are equal and aborts if this is not the
  140. * case, printing both expressions and the values they evaluated to. This
  141. * macro is for use in unit tests.
  142. */
  143. #define fail_unless_equals_int(a, b) \
  144. G_STMT_START { \
  145. int first = a; \
  146. int second = b; \
  147. fail_unless(first == second, \
  148. "'" #a "' (%d) is not equal to '" #b"' (%d)", first, second); \
  149. } G_STMT_END;
  150. /**
  151. * assert_equals_int:
  152. * @a: a #gint value or expression
  153. * @b: a #gint value or expression
  154. *
  155. * This macro checks that @a and @b are equal and aborts if this is not the
  156. * case, printing both expressions and the values they evaluated to. This
  157. * macro is for use in unit tests.
  158. */
  159. #define assert_equals_int(a, b) fail_unless_equals_int(a, b)
  160. /**
  161. * fail_unless_equals_int_hex:
  162. * @a: a #gint value or expression
  163. * @b: a #gint value or expression
  164. *
  165. * This macro checks that @a and @b are equal and aborts if this is not the
  166. * case, printing both expressions and the values they evaluated to in
  167. * hexadecimal format. This macro is for use in unit tests.
  168. *
  169. * Since: 1.2
  170. */
  171. #define fail_unless_equals_int_hex(a, b) \
  172. G_STMT_START { \
  173. int first = a; \
  174. int second = b; \
  175. fail_unless(first == second, \
  176. "'" #a "' (0x%08x) is not equal to '" #b"' (0x%08x)", first, second);\
  177. } G_STMT_END;
  178. /**
  179. * assert_equals_int_hex:
  180. * @a: a #gint value or expression
  181. * @b: a #gint value or expression
  182. *
  183. * This macro checks that @a and @b are equal and aborts if this is not the
  184. * case, printing both expressions and the values they evaluated to in
  185. * hexadecimal format. This macro is for use in unit tests.
  186. *
  187. * Since: 1.2
  188. */
  189. #define assert_equals_int_hex(a, b) fail_unless_equals_int_hex(a, b)
  190. /**
  191. * fail_unless_equals_int64:
  192. * @a: a #gint64 value or expression
  193. * @b: a #gint64 value or expression
  194. *
  195. * This macro checks that @a and @b are equal and aborts if this is not the
  196. * case, printing both expressions and the values they evaluated to. This
  197. * macro is for use in unit tests.
  198. */
  199. #define fail_unless_equals_int64(a, b) \
  200. G_STMT_START { \
  201. gint64 first = a; \
  202. gint64 second = b; \
  203. fail_unless(first == second, \
  204. "'" #a "' (%" G_GINT64_FORMAT") is not equal to '" #b"' (%" \
  205. G_GINT64_FORMAT")", first, second); \
  206. } G_STMT_END;
  207. /**
  208. * assert_equals_int64:
  209. * @a: a #gint64 value or expression
  210. * @b: a #gint64 value or expression
  211. *
  212. * This macro checks that @a and @b are equal and aborts if this is not the
  213. * case, printing both expressions and the values they evaluated to. This
  214. * macro is for use in unit tests.
  215. */
  216. #define assert_equals_int64(a, b) fail_unless_equals_int64(a, b)
  217. /**
  218. * fail_unless_equals_int64_hex:
  219. * @a: a #gint64 value or expression
  220. * @b: a #gint64 value or expression
  221. *
  222. * This macro checks that @a and @b are equal and aborts if this is not the
  223. * case, printing both expressions and the values they evaluated to in
  224. * hexadecimal format. This macro is for use in unit tests.
  225. *
  226. * Since: 1.2
  227. */
  228. #define fail_unless_equals_int64_hex(a, b) \
  229. G_STMT_START { \
  230. gint64 first = a; \
  231. gint64 second = b; \
  232. fail_unless(first == second, \
  233. "'" #a "' (0x%016x) is not equal to '" #b"' (0x%016x)", first, second);\
  234. } G_STMT_END;
  235. /**
  236. * assert_equals_int64_hex:
  237. * @a: a #gint64 value or expression
  238. * @b: a #gint64 value or expression
  239. *
  240. * This macro checks that @a and @b are equal and aborts if this is not the
  241. * case, printing both expressions and the values they evaluated to in
  242. * hexadecimal format. This macro is for use in unit tests.
  243. *
  244. * Since: 1.2
  245. */
  246. #define assert_equals_int64_hex(a,b) fail_unless_equals_int64_hex(a,b)
  247. /**
  248. * fail_unless_equals_uint64:
  249. * @a: a #guint64 value or expression
  250. * @b: a #guint64 value or expression
  251. *
  252. * This macro checks that @a and @b are equal and aborts if this is not the
  253. * case, printing both expressions and the values they evaluated to. This
  254. * macro is for use in unit tests.
  255. */
  256. #define fail_unless_equals_uint64(a, b) \
  257. G_STMT_START { \
  258. guint64 first = a; \
  259. guint64 second = b; \
  260. fail_unless(first == second, \
  261. "'" #a "' (%" G_GUINT64_FORMAT ") is not equal to '" #b"' (%" \
  262. G_GUINT64_FORMAT ")", first, second); \
  263. } G_STMT_END;
  264. /**
  265. * assert_equals_uint64:
  266. * @a: a #guint64 value or expression
  267. * @b: a #guint64 value or expression
  268. *
  269. * This macro checks that @a and @b are equal and aborts if this is not the
  270. * case, printing both expressions and the values they evaluated to. This
  271. * macro is for use in unit tests.
  272. */
  273. #define assert_equals_uint64(a, b) fail_unless_equals_uint64(a, b)
  274. /**
  275. * fail_unless_equals_uint64_hex:
  276. * @a: a #gint64 value or expression
  277. * @b: a #gint64 value or expression
  278. *
  279. * This macro checks that @a and @b are equal and aborts if this is not the
  280. * case, printing both expressions and the values they evaluated to in
  281. * hexadecimal format. This macro is for use in unit tests.
  282. *
  283. * Since: 1.2
  284. */
  285. #define fail_unless_equals_uint64_hex(a, b) \
  286. G_STMT_START { \
  287. guint64 first = a; \
  288. guint64 second = b; \
  289. fail_unless(first == second, \
  290. "'" #a "' (0x%016x) is not equal to '" #b"' (0x%016x)", first, second);\
  291. } G_STMT_END;
  292. /**
  293. * assert_equals_uint64_hex:
  294. * @a: a #guint64 value or expression
  295. * @b: a #guint64 value or expression
  296. *
  297. * This macro checks that @a and @b are equal and aborts if this is not the
  298. * case, printing both expressions and the values they evaluated to in
  299. * hexadecimal format. This macro is for use in unit tests.
  300. *
  301. * Since: 1.2
  302. */
  303. #define assert_equals_uint64_hex(a,b) fail_unless_equals_uint64_hex(a,b)
  304. /**
  305. * fail_unless_equals_string:
  306. * @a: a string literal or expression
  307. * @b: a string literal or expression
  308. *
  309. * This macro checks that @a and @b are equal (as per strcmp) and aborts if
  310. * this is not the case, printing both expressions and the values they
  311. * evaluated to. This macro is for use in unit tests.
  312. */
  313. #define fail_unless_equals_string(a, b) \
  314. G_STMT_START { \
  315. const gchar * first = a; \
  316. const gchar * second = b; \
  317. fail_unless(g_strcmp0 (first, second) == 0, \
  318. "'" #a "' (%s) is not equal to '" #b"' (%s)", first, second); \
  319. } G_STMT_END;
  320. /**
  321. * assert_equals_string:
  322. * @a: a string literal or expression
  323. * @b: a string literal or expression
  324. *
  325. * This macro checks that @a and @b are equal (as per strcmp) and aborts if
  326. * this is not the case, printing both expressions and the values they
  327. * evaluated to. This macro is for use in unit tests.
  328. */
  329. #define assert_equals_string(a, b) fail_unless_equals_string(a, b)
  330. /**
  331. * fail_unless_equals_float:
  332. * @a: a #gdouble or #gfloat value or expression
  333. * @b: a #gdouble or #gfloat value or expression
  334. *
  335. * This macro checks that @a and @b are (almost) equal and aborts if this
  336. * is not the case, printing both expressions and the values they evaluated
  337. * to. This macro is for use in unit tests.
  338. */
  339. #define fail_unless_equals_float(a, b) \
  340. G_STMT_START { \
  341. double first = a; \
  342. double second = b; \
  343. /* This will only work for 'normal' values and values around 0, \
  344. * which should be good enough for our purposes here */ \
  345. fail_unless(fabs (first - second) < 0.0000001, \
  346. "'" #a "' (%g) is not equal to '" #b "' (%g)", first, second);\
  347. } G_STMT_END;
  348. /**
  349. * assert_equals_float:
  350. * @a: a #gdouble or #gfloat value or expression
  351. * @b: a #gdouble or #gfloat value or expression
  352. *
  353. * This macro checks that @a and @b are (almost) equal and aborts if this
  354. * is not the case, printing both expressions and the values they evaluated
  355. * to. This macro is for use in unit tests.
  356. */
  357. #define assert_equals_float(a, b) fail_unless_equals_float(a, b)
  358. /**
  359. * fail_unless_equals_pointer:
  360. * @a: a pointer value or expression
  361. * @b: a pointer value or expression
  362. *
  363. * This macro checks that @a and @b are equal and aborts if this
  364. * is not the case, printing both expressions and the values they
  365. * evaluated to. This macro is for use in unit tests.
  366. *
  367. * Since: 1.2
  368. */
  369. #define fail_unless_equals_pointer(a, b) \
  370. G_STMT_START { \
  371. gpointer first = a; \
  372. gpointer second = b; \
  373. fail_unless(first == second, \
  374. "'" #a "' (%p) is not equal to '" #b "' (%p)", first, second);\
  375. } G_STMT_END;
  376. /**
  377. * assert_equals_pointer:
  378. * @a: a pointer value or expression
  379. * @b: a pointer value or expression
  380. *
  381. * This macro checks that @a and @b are equal and aborts if this
  382. * is not the case, printing both expressions and the values they
  383. * evaluated to. This macro is for use in unit tests.
  384. *
  385. * Since: 1.2
  386. */
  387. #define assert_equals_pointer(a, b) fail_unless_equals_pointer(a, b)
  388. /***
  389. * thread test macros and variables
  390. */
  391. extern GList *thread_list;
  392. extern GMutex mutex;
  393. extern GCond start_cond; /* used to notify main thread of thread startups */
  394. extern GCond sync_cond; /* used to synchronize all threads and main thread */
  395. #define MAIN_START_THREADS(count, function, data) \
  396. MAIN_INIT(); \
  397. MAIN_START_THREAD_FUNCTIONS(count, function, data); \
  398. MAIN_SYNCHRONIZE();
  399. #define MAIN_INIT() \
  400. G_STMT_START { \
  401. g_mutex_init (&mutex); \
  402. g_cond_init (&start_cond); \
  403. g_cond_init (&sync_cond); \
  404. _gst_check_threads_running = TRUE; \
  405. } G_STMT_END;
  406. #define MAIN_START_THREAD_FUNCTIONS(count, function, data) \
  407. G_STMT_START { \
  408. int i; \
  409. for (i = 0; i < count; ++i) { \
  410. MAIN_START_THREAD_FUNCTION (i, function, data); \
  411. } \
  412. } G_STMT_END;
  413. #define MAIN_START_THREAD_FUNCTION(i, function, data) \
  414. G_STMT_START { \
  415. GThread *thread = NULL; \
  416. GST_DEBUG ("MAIN: creating thread %d", i); \
  417. g_mutex_lock (&mutex); \
  418. thread = g_thread_try_new ("gst-check", \
  419. (GThreadFunc) function, data, NULL); \
  420. /* wait for thread to signal us that it's ready */ \
  421. GST_DEBUG ("MAIN: waiting for thread %d", i); \
  422. g_cond_wait (&start_cond, &mutex); \
  423. g_mutex_unlock (&mutex); \
  424. \
  425. thread_list = g_list_append (thread_list, thread); \
  426. } G_STMT_END;
  427. #define MAIN_SYNCHRONIZE() \
  428. G_STMT_START { \
  429. GST_DEBUG ("MAIN: synchronizing"); \
  430. g_cond_broadcast (&sync_cond); \
  431. GST_DEBUG ("MAIN: synchronized"); \
  432. } G_STMT_END;
  433. #define MAIN_STOP_THREADS() \
  434. G_STMT_START { \
  435. _gst_check_threads_running = FALSE; \
  436. \
  437. /* join all threads */ \
  438. GST_DEBUG ("MAIN: joining"); \
  439. g_list_foreach (thread_list, (GFunc) g_thread_join, NULL); \
  440. g_list_free (thread_list); \
  441. thread_list = NULL; \
  442. g_mutex_clear (&mutex); \
  443. g_cond_clear (&start_cond); \
  444. g_cond_clear (&sync_cond); \
  445. GST_DEBUG ("MAIN: joined"); \
  446. } G_STMT_END;
  447. #define THREAD_START() \
  448. THREAD_STARTED(); \
  449. THREAD_SYNCHRONIZE();
  450. #define THREAD_STARTED() \
  451. G_STMT_START { \
  452. /* signal main thread that we started */ \
  453. GST_DEBUG ("THREAD %p: started", g_thread_self ()); \
  454. g_mutex_lock (&mutex); \
  455. g_cond_signal (&start_cond); \
  456. } G_STMT_END;
  457. #define THREAD_SYNCHRONIZE() \
  458. G_STMT_START { \
  459. /* synchronize everyone */ \
  460. GST_DEBUG ("THREAD %p: syncing", g_thread_self ()); \
  461. fail_if (g_mutex_trylock (&mutex), \
  462. "bug in unit test, mutex should be locked at this point");\
  463. g_cond_wait (&sync_cond, &mutex); \
  464. GST_DEBUG ("THREAD %p: synced", g_thread_self ()); \
  465. g_mutex_unlock (&mutex); \
  466. } G_STMT_END;
  467. #define THREAD_SWITCH() \
  468. G_STMT_START { \
  469. /* a minimal sleep is a context switch */ \
  470. g_usleep (1); \
  471. } G_STMT_END;
  472. #define THREAD_TEST_RUNNING() (!!_gst_check_threads_running)
  473. /* additional assertions */
  474. #define ASSERT_CRITICAL(code) \
  475. G_STMT_START { \
  476. _gst_check_expecting_log = TRUE; \
  477. _gst_check_raised_critical = FALSE; \
  478. code; \
  479. if (!_gst_check_raised_critical) \
  480. _ck_assert_failed (__FILE__, __LINE__, \
  481. "Expected g_critical, got nothing", NULL); \
  482. _gst_check_expecting_log = FALSE; \
  483. } G_STMT_END
  484. #define ASSERT_WARNING(code) \
  485. G_STMT_START { \
  486. _gst_check_expecting_log = TRUE; \
  487. _gst_check_raised_warning = FALSE; \
  488. code; \
  489. if (!_gst_check_raised_warning) \
  490. _ck_assert_failed (__FILE__, __LINE__, \
  491. "Expected g_warning, got nothing", NULL); \
  492. _gst_check_expecting_log = FALSE; \
  493. } G_STMT_END
  494. #define ASSERT_OBJECT_REFCOUNT(object, name, value) \
  495. G_STMT_START { \
  496. int rc; \
  497. rc = GST_OBJECT_REFCOUNT_VALUE (object); \
  498. fail_unless (rc == value, \
  499. "%s (%p) refcount is %d instead of %d", \
  500. name, object, rc, value); \
  501. } G_STMT_END
  502. #define ASSERT_OBJECT_REFCOUNT_BETWEEN(object, name, lower, upper) \
  503. G_STMT_START { \
  504. int rc = GST_OBJECT_REFCOUNT_VALUE (object); \
  505. int lo = lower; \
  506. int hi = upper; \
  507. \
  508. fail_unless (rc >= lo, \
  509. "%s (%p) refcount %d is smaller than %d", \
  510. name, object, rc, lo); \
  511. fail_unless (rc <= hi, \
  512. "%s (%p) refcount %d is bigger than %d", \
  513. name, object, rc, hi); \
  514. } G_STMT_END
  515. #define ASSERT_CAPS_REFCOUNT(caps, name, value) \
  516. ASSERT_MINI_OBJECT_REFCOUNT(caps, name, value)
  517. #define ASSERT_BUFFER_REFCOUNT(buffer, name, value) \
  518. ASSERT_MINI_OBJECT_REFCOUNT(buffer, name, value)
  519. #define ASSERT_MINI_OBJECT_REFCOUNT(miniobj, name, value) \
  520. G_STMT_START { \
  521. int rc; \
  522. rc = GST_MINI_OBJECT_REFCOUNT_VALUE (miniobj); \
  523. fail_unless (rc == value, \
  524. name " (%p) refcount is %d instead of %d", miniobj, rc, value); \
  525. } G_STMT_END
  526. #define ASSERT_SET_STATE(element, state, ret) \
  527. fail_unless (gst_element_set_state (GST_ELEMENT(element), \
  528. state) == ret, \
  529. "could not change state to " #state);
  530. #define GST_CHECK_MAIN(name) \
  531. int main (int argc, char **argv) \
  532. { \
  533. Suite *s; \
  534. gst_check_init (&argc, &argv); \
  535. s = name ## _suite (); \
  536. return gst_check_run_suite (s, # name, __FILE__); \
  537. }
  538. /* Hack to allow run-time selection of unit tests to run via the
  539. * GST_CHECKS environment variable (test function names globs, comma
  540. * separated), or GST_CHECKS_IGNORE with the same semantics */
  541. gboolean _gst_check_run_test_func (const gchar * func_name);
  542. static inline void
  543. __gst_tcase_add_test (TCase * tc, TFun tf, const char * fname, int signal,
  544. int allowed_exit_value, int start, int end)
  545. {
  546. if (_gst_check_run_test_func (fname)) {
  547. _tcase_add_test (tc, tf, fname, signal, allowed_exit_value, start, end);
  548. }
  549. }
  550. #define _tcase_add_test __gst_tcase_add_test
  551. /* A special variant to add broken tests. These are normally skipped, but can be
  552. * forced to run via GST_CHECKS */
  553. #define tcase_skip_broken_test(chain,test_func) \
  554. G_STMT_START { \
  555. const char *env = g_getenv ("GST_CHECKS"); \
  556. \
  557. if (env != NULL && g_pattern_match_simple (env, G_STRINGIFY (test_func))) { \
  558. tcase_add_test(chain,test_func); \
  559. } else { \
  560. g_printerr ("FIXME: skipping test %s because it's broken\n", G_STRINGIFY (test_func)); \
  561. } \
  562. } G_STMT_END
  563. #define tcase_skip_broken_loop_test(chain,test_func,a,b) \
  564. tcase_skip_broken_test (chain, test_func)
  565. G_END_DECLS
  566. #endif /* __GST_CHECK_H__ */