mirror of
				https://gitlab.gnome.org/GNOME/glib.git
				synced 2025-10-31 08:22:16 +01:00 
			
		
		
		
	Add testcase for environment functions
This commit is contained in:
		
							
								
								
									
										1
									
								
								glib/tests/.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								glib/tests/.gitignore
									
									
									
									
										vendored
									
									
								
							| @@ -6,6 +6,7 @@ collate | ||||
| convert | ||||
| date | ||||
| dir | ||||
| environment | ||||
| error | ||||
| fileutils | ||||
| gdatetime | ||||
|   | ||||
| @@ -148,6 +148,9 @@ TEST_PROGS          += gdatetime | ||||
| gdatetime_SOURCES    = gdatetime.c | ||||
| gdatetime_LDADD      = $(progs_ldadd) | ||||
|  | ||||
| TEST_PROGS       += environment | ||||
| environment_LDADD = $(progs_ldadd) | ||||
|  | ||||
| if OS_UNIX | ||||
|  | ||||
| # some testing of gtester funcitonality | ||||
|   | ||||
							
								
								
									
										51
									
								
								glib/tests/environment.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								glib/tests/environment.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,51 @@ | ||||
| #include <glib.h> | ||||
|  | ||||
| static void | ||||
| test_environment (void) | ||||
| { | ||||
|   GHashTable *table; | ||||
|   gchar **list; | ||||
|   gint i; | ||||
|  | ||||
|   table = g_hash_table_new_full (g_str_hash, g_str_equal, | ||||
|                                  g_free, g_free); | ||||
|  | ||||
|   list = g_get_environ (); | ||||
|   for (i = 0; list[i]; i++) | ||||
|     { | ||||
|       gchar **parts; | ||||
|  | ||||
|       parts = g_strsplit (list[i], "=", 2); | ||||
|       g_assert (g_hash_table_lookup (table, parts[0]) == NULL); | ||||
|       g_hash_table_insert (table, parts[0], parts[1]); | ||||
|       g_free (parts); | ||||
|     } | ||||
|   g_strfreev (list); | ||||
|  | ||||
|   g_assert_cmpint (g_hash_table_size (table), >, 0); | ||||
|  | ||||
|   list = g_listenv (); | ||||
|   for (i = 0; list[i]; i++) | ||||
|     { | ||||
|       const gchar *expected; | ||||
|       const gchar *value; | ||||
|  | ||||
|       expected = g_hash_table_lookup (table, list[i]); | ||||
|       value = g_getenv (list[i]); | ||||
|       g_assert_cmpstr (value, ==, expected); | ||||
|       g_hash_table_remove (table, list[i]); | ||||
|     } | ||||
|   g_assert_cmpint (g_hash_table_size (table), ==, 0); | ||||
|   g_hash_table_unref (table); | ||||
|   g_strfreev (list); | ||||
| } | ||||
|  | ||||
| int | ||||
| main (int argc, char **argv) | ||||
| { | ||||
|   g_test_init (&argc, &argv, NULL); | ||||
|  | ||||
|   g_test_add_func ("/glib/environment", test_environment); | ||||
|  | ||||
|   return g_test_run (); | ||||
| } | ||||
		Reference in New Issue
	
	Block a user