Fix memory leaks in the unit tests
Making valgrind complain less should help finding actual memory leaks in the long run.
This commit is contained in:
		
							parent
							
								
									a3cce0ec2f
								
							
						
					
					
						commit
						f34b846041
					
				| @ -44,12 +44,17 @@ TEST test_ini_get_bool(void) | |||||||
| TEST test_ini_get_string(void) | TEST test_ini_get_string(void) | ||||||
| { | { | ||||||
|         char *string_section = "string"; |         char *string_section = "string"; | ||||||
|         ASSERT_STR_EQ("A simple string", ini_get_string(string_section, "simple", "")); |         char *ptr; | ||||||
|  |         ASSERT_STR_EQ("A simple string", (ptr = ini_get_string(string_section, "simple", ""))); | ||||||
|  |         free(ptr); | ||||||
| 
 | 
 | ||||||
|         ASSERT_STR_EQ("A quoted string", ini_get_string(string_section, "quoted", "")); |         ASSERT_STR_EQ("A quoted string", (ptr = ini_get_string(string_section, "quoted", ""))); | ||||||
|         ASSERT_STR_EQ("A string \"with quotes\"", ini_get_string(string_section, "quoted_with_quotes", "")); |         free(ptr); | ||||||
|  |         ASSERT_STR_EQ("A string \"with quotes\"", (ptr = ini_get_string(string_section, "quoted_with_quotes", ""))); | ||||||
|  |         free(ptr); | ||||||
| 
 | 
 | ||||||
|         ASSERT_STR_EQ("default value", ini_get_string(string_section, "nonexistent", "default value")); |         ASSERT_STR_EQ("default value", (ptr = ini_get_string(string_section, "nonexistent", "default value"))); | ||||||
|  |         free(ptr); | ||||||
| 
 | 
 | ||||||
|         PASS(); |         PASS(); | ||||||
| } | } | ||||||
| @ -83,9 +88,13 @@ TEST test_ini_get_double(void) | |||||||
| 
 | 
 | ||||||
| TEST test_cmdline_get_string(void) | TEST test_cmdline_get_string(void) | ||||||
| { | { | ||||||
|         ASSERT_STR_EQ("A simple string from the cmdline", cmdline_get_string("-string", "", "")); |         char *ptr; | ||||||
|         ASSERT_STR_EQ("Single_word_string", cmdline_get_string("-str/-s", "", "")); |         ASSERT_STR_EQ("A simple string from the cmdline", (ptr =cmdline_get_string("-string", "", ""))); | ||||||
|         ASSERT_STR_EQ("Default", cmdline_get_string("-nonexistent", "Default", "")); |         free(ptr); | ||||||
|  |         ASSERT_STR_EQ("Single_word_string", (ptr = cmdline_get_string("-str/-s", "", ""))); | ||||||
|  |         free(ptr); | ||||||
|  |         ASSERT_STR_EQ("Default", (ptr = cmdline_get_string("-nonexistent", "Default", ""))); | ||||||
|  |         free(ptr); | ||||||
|         PASS(); |         PASS(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -119,7 +128,7 @@ TEST test_cmdline_get_bool(void) | |||||||
| 
 | 
 | ||||||
| TEST test_cmdline_create_usage(void) | TEST test_cmdline_create_usage(void) | ||||||
| { | { | ||||||
|         cmdline_get_string("-msgstring/-ms", "", "A string to test usage creation"); |         g_free(cmdline_get_string("-msgstring/-ms", "", "A string to test usage creation")); | ||||||
|         cmdline_get_int("-msgint/-mi", 0, "An int to test usage creation"); |         cmdline_get_int("-msgint/-mi", 0, "An int to test usage creation"); | ||||||
|         cmdline_get_double("-msgdouble/-md", 0, "A double to test usage creation"); |         cmdline_get_double("-msgdouble/-md", 0, "A double to test usage creation"); | ||||||
|         cmdline_get_bool("-msgbool/-mb", false, "A bool to test usage creation"); |         cmdline_get_bool("-msgbool/-mb", false, "A bool to test usage creation"); | ||||||
| @ -139,13 +148,20 @@ TEST test_cmdline_create_usage(void) | |||||||
| TEST test_option_get_string(void) | TEST test_option_get_string(void) | ||||||
| { | { | ||||||
|         char *string_section = "string"; |         char *string_section = "string"; | ||||||
|  |         char *ptr; | ||||||
| 
 | 
 | ||||||
|         ASSERT_STR_EQ("A simple string", option_get_string(string_section, "simple", "-nonexistent", "", "")); |         ASSERT_STR_EQ("A simple string", (ptr =option_get_string(string_section, "simple", "-nonexistent", "", ""))); | ||||||
|         ASSERT_STR_EQ("Single_word_string", option_get_string(string_section, "simple", "-str/-s", "", "")); |         free(ptr); | ||||||
|         ASSERT_STR_EQ("A simple string from the cmdline", option_get_string(string_section, "simple", "-string", "", "")); |         ASSERT_STR_EQ("Single_word_string", (ptr = option_get_string(string_section, "simple", "-str/-s", "", ""))); | ||||||
|         ASSERT_STR_EQ("A simple string from the cmdline", option_get_string(string_section, "simple", "-string/-s", "", "")); |         free(ptr); | ||||||
|         ASSERT_STR_EQ("Single_word_string", option_get_string(string_section, "simple", "-s", "", "")); |         ASSERT_STR_EQ("A simple string from the cmdline", (ptr = option_get_string(string_section, "simple", "-string", "", ""))); | ||||||
|         ASSERT_STR_EQ("Default", option_get_string(string_section, "nonexistent", "-nonexistent", "Default", "")); |         free(ptr); | ||||||
|  |         ASSERT_STR_EQ("A simple string from the cmdline", (ptr = option_get_string(string_section, "simple", "-string/-s", "", ""))); | ||||||
|  |         free(ptr); | ||||||
|  |         ASSERT_STR_EQ("Single_word_string", (ptr = option_get_string(string_section, "simple", "-s", "", ""))); | ||||||
|  |         free(ptr); | ||||||
|  |         ASSERT_STR_EQ("Default", (ptr = option_get_string(string_section, "nonexistent", "-nonexistent", "Default", ""))); | ||||||
|  |         free(ptr); | ||||||
|         PASS(); |         PASS(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -79,6 +79,7 @@ TEST test_string_to_argv(void) | |||||||
|         char **argv = string_to_argv("argv"); |         char **argv = string_to_argv("argv"); | ||||||
|         ASSERT_STR_EQ("argv", argv[0]); |         ASSERT_STR_EQ("argv", argv[0]); | ||||||
|         ASSERT_EQ(    NULL,   argv[1]); |         ASSERT_EQ(    NULL,   argv[1]); | ||||||
|  |         free(argv[0]); | ||||||
|         free(argv); |         free(argv); | ||||||
|         argv = NULL; |         argv = NULL; | ||||||
| 
 | 
 | ||||||
| @ -86,6 +87,8 @@ TEST test_string_to_argv(void) | |||||||
|         ASSERT_STR_EQ("echo", argv[0]); |         ASSERT_STR_EQ("echo", argv[0]); | ||||||
|         ASSERT_STR_EQ("test", argv[1]); |         ASSERT_STR_EQ("test", argv[1]); | ||||||
|         ASSERT_EQ(    NULL,   argv[2]); |         ASSERT_EQ(    NULL,   argv[2]); | ||||||
|  |         free(argv[0]); | ||||||
|  |         free(argv[1]); | ||||||
|         free(argv); |         free(argv); | ||||||
|         argv = NULL; |         argv = NULL; | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Nikos Tsipinakis
						Nikos Tsipinakis