memory.c 932 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include <glib.h>
  2. #include "test.h"
  3. RESULT
  4. test_memory_zero_size_allocations ()
  5. {
  6. gpointer p;
  7. p = g_malloc (0);
  8. if (p)
  9. return FAILED ("Calling g_malloc with size zero should return NULL.");
  10. p = g_malloc0 (0);
  11. if (p)
  12. return FAILED ("Calling g_malloc0 with size zero should return NULL.");
  13. p = g_realloc (NULL, 0);
  14. if (p)
  15. return FAILED ("Calling g_realloc with size zero should return NULL.");
  16. p = g_new (int, 0);
  17. if (p)
  18. return FAILED ("Calling g_new with size zero should return NULL.");
  19. p = g_new0 (int, 0);
  20. if (p)
  21. return FAILED ("Calling g_new0 with size zero should return NULL.");
  22. return OK;
  23. }
  24. static Test memory_tests [] = {
  25. { "zero_size_allocations", test_memory_zero_size_allocations},
  26. {NULL, NULL}
  27. };
  28. DEFINE_TEST_GROUP_INIT(memory_tests_init, memory_tests)