Преглед на файлове

2008-08-04 Bill Holmes <[email protected]>

	* test/tests.h, test/Makefile.am, test/memory.c : Adding memory tests to test
	  allocation routines return NULL when 0 size is passed in.

	Contributed under MIT/X11 license.

svn path=/trunk/mono/; revision=109599
Bill Holmes преди 17 години
родител
ревизия
87ca655071
променени са 4 файла, в които са добавени 51 реда и са изтрити 1 реда
  1. 7 0
      eglib/ChangeLog
  2. 2 1
      eglib/test/Makefile.am
  3. 40 0
      eglib/test/memory.c
  4. 2 0
      eglib/test/tests.h

+ 7 - 0
eglib/ChangeLog

@@ -1,3 +1,10 @@
+2008-08-04  Bill Holmes  <[email protected]>
+
+	* test/tests.h, test/Makefile.am, test/memory.c : Adding memory tests to test
+	  allocation routines return NULL when 0 size is passed in.
+
+	Contributed under MIT/X11 license.
+
 2008-08-04  Bill Holmes  <[email protected]>
 
 	* src/glib.h : Changing the allocation routines to return null if 0 size is

+ 2 - 1
eglib/test/Makefile.am

@@ -23,7 +23,8 @@ SOURCES = \
 	markup.c	\
 	utf8.c		\
 	endian.c	\
-	module.c
+	module.c	\
+	memory.c
 
 test_eglib_SOURCES = $(SOURCES)
 

+ 40 - 0
eglib/test/memory.c

@@ -0,0 +1,40 @@
+
+#include <glib.h>
+#include "test.h"
+
+RESULT
+test_memory_zero_size_allocations ()
+{
+	gpointer p;
+
+	p = g_malloc (0);
+        if (p)
+                return FAILED ("Calling g_malloc with size zero should return NULL.");
+
+	p = g_malloc0 (0);
+        if (p)
+                return FAILED ("Calling g_malloc0 with size zero should return NULL.");
+
+	p = g_realloc (NULL, 0);
+        if (p)
+                return FAILED ("Calling g_realloc with size zero should return NULL.");
+
+	p = g_new (int, 0);
+        if (p)
+                return FAILED ("Calling g_new with size zero should return NULL.");
+
+	p = g_new0 (int, 0);
+        if (p)
+                return FAILED ("Calling g_new0 with size zero should return NULL.");
+
+        return OK;
+}
+
+
+static Test memory_tests [] = {
+        {       "zero_size_allocations", test_memory_zero_size_allocations},
+        {NULL, NULL}
+};
+
+DEFINE_TEST_GROUP_INIT(memory_tests_init, memory_tests)
+

+ 2 - 0
eglib/test/tests.h

@@ -21,6 +21,7 @@ DEFINE_TEST_GROUP_INIT_H(markup_tests_init);
 DEFINE_TEST_GROUP_INIT_H(utf8_tests_init);
 DEFINE_TEST_GROUP_INIT_H(endian_tests_init);
 DEFINE_TEST_GROUP_INIT_H(module_tests_init);
+DEFINE_TEST_GROUP_INIT_H(memory_tests_init);
 
 static Group test_groups [] = {	
 	{"string",    string_tests_init}, 
@@ -44,6 +45,7 @@ static Group test_groups [] = {
 	{"utf8",      utf8_tests_init},
 	{"endian",    endian_tests_init},
 	{"module",    module_tests_init},
+	{"memory",    memory_tests_init},
 	{NULL, NULL}
 };