Anna Schumaker
99faa0cf39
Valgrind told me that all calls to g_assert_cmpstr_free() weren't actually freeing the string. A closer look shows that if we pass a function as "lhs" then the function will be called twice, allocating twice as much memory. Fix this by storing the result of lhs in a temporary variable so functions are only ever called once. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
23 lines
514 B
C
23 lines
514 B
C
/*
|
|
* Copyright 2014 (c) Anna Schumaker.
|
|
*/
|
|
#ifndef OCARINA_TESTS_TEST_H
|
|
#define OCARINA_TESTS_TEST_H
|
|
|
|
#include <glib.h>
|
|
|
|
|
|
/*
|
|
* Compares two strings, and frees lhs before returning.
|
|
* NOTE: We store lhs in a temporary string so that "lhs" only gets
|
|
* evaluated once in the case that it is a function.
|
|
*/
|
|
#define g_assert_cmpstr_free(lhs, cmp, rhs) \
|
|
do { \
|
|
gchar *__tmp_str = lhs; \
|
|
g_assert_cmpstr(__tmp_str, cmp, rhs); \
|
|
g_free(__tmp_str); \
|
|
} while (0)
|
|
|
|
#endif /* OCARINA_TESTS_TEST_H */
|