free.c (1852B)
1/* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 20#include <CUnit/CUnit.h> 21#include <guacamole/mem.h> 22#include <stdint.h> 23 24/** 25 * Test which verifies that guac_mem_free() sets the provided pointer to NULL after 26 * freeing. 27 */ 28void test_mem__free_assigns_null() { 29 void* ptr = guac_mem_alloc(123); 30 CU_ASSERT_PTR_NOT_NULL(ptr); 31 guac_mem_free(ptr); 32 CU_ASSERT_PTR_NULL(ptr); 33} 34 35/** 36 * Test which verifies that guac_mem_free_const() can be used to free constant 37 * pointers, but that those pointers are not set to NULL after freeing. 38 */ 39void test_mem__free_const() { 40 const void* ptr = guac_mem_alloc(123); 41 CU_ASSERT_PTR_NOT_NULL(ptr); 42 guac_mem_free_const(ptr); 43 CU_ASSERT_PTR_NOT_NULL(ptr); 44} 45 46/** 47 * Test which verifies that guac_mem_free() does nothing if provided a NULL 48 * pointer. 49 */ 50void test_mem__free_null() { 51 void* ptr = NULL; 52 guac_mem_free(ptr); 53} 54 55/** 56 * Test which verifies that guac_mem_free_const() does nothing if provided a NULL 57 * pointer. 58 */ 59void test_mem__free_null_const() { 60 const void* ptr = NULL; 61 guac_mem_free_const(ptr); 62} 63