tests: Fix some minor leaks in the unit tests
[platform/upstream/glib.git] / glib / tests / cache.c
index 364bb7d..ec34df9 100644 (file)
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
+/* We are testing some deprecated APIs here */
+#define GLIB_DISABLE_DEPRECATION_WARNINGS
+
 #include <glib.h>
 
 static gint value_create_count = 0;
@@ -88,6 +89,17 @@ key_foreach (gpointer valuep, gpointer keyp, gpointer data)
 }
 
 static void
+value_foreach (gpointer keyp, gpointer nodep, gpointer data)
+{
+  gint *count = data;
+  gint *key = keyp;
+
+  (*count)++;
+
+  g_assert_cmpint (*key, ==, 2);
+}
+
+static void
 test_cache_basic (void)
 {
   GCache *c;
@@ -114,6 +126,10 @@ test_cache_basic (void)
   g_cache_key_foreach (c, key_foreach, &count);
   g_assert_cmpint (count, ==, 1);
 
+  count = 0;
+  g_cache_value_foreach (c, value_foreach, &count);
+  g_assert_cmpint (count, ==, 1);
+
   value = g_cache_insert (c, key);
   g_assert_cmpint (*value, ==, 4);
   g_assert_cmpint (value_create_count, ==, 1);
@@ -132,7 +148,9 @@ test_cache_basic (void)
   g_assert_cmpint (value_create_count, ==, 2);
   g_assert_cmpint (value_destroy_count, ==, 1);
 
+  g_cache_remove (c, value);
   g_cache_destroy (c);
+  g_free (key);
 }
 
 int