2828
2929#define DYNLINK_TEST_LIBRARY_PATH " DYNLINK_TEST_LIBRARY_PATH"
3030
31- typedef const char *(*dynlink_print_func )(void );
31+ typedef const char *(*mock_loader_print_func )(void );
3232
3333class dynlink_test : public testing ::Test
3434{
@@ -60,52 +60,6 @@ TEST_F(dynlink_test, DefaultConstructor)
6060
6161 log_write (" metacall" , LOG_LEVEL_DEBUG, " Dynamic linked shared object extension: %s" , dynlink_extension ());
6262
63- #if (!defined(NDEBUG) || defined(DEBUG) || defined(_DEBUG) || defined(__DEBUG) || defined(__DEBUG__))
64- const char library_name[] = " dynlinkd" ;
65- #else
66- const char library_name[] = " dynlink" ;
67- #endif
68-
69- char *path = environment_variable_path_create (DYNLINK_TEST_LIBRARY_PATH, NULL , 0 , NULL );
70-
71- ASSERT_NE ((char *)path, (char *)NULL );
72-
73- /* Test library loading */
74- {
75- dynlink handle = dynlink_load (path, library_name, DYNLINK_FLAGS_BIND_NOW | DYNLINK_FLAGS_BIND_GLOBAL);
76-
77- ASSERT_NE (handle, (dynlink)NULL );
78-
79- log_write (" metacall" , LOG_LEVEL_DEBUG, " Dynamic linked shared object file: %s" , dynlink_get_path (handle));
80-
81- EXPECT_EQ ((int )0 , (int )strcmp (library_name, dynlink_get_name (handle)));
82-
83- if (handle != NULL )
84- {
85- dynlink_symbol_addr dynlink_print_info_addr;
86-
87- EXPECT_EQ ((int )0 , dynlink_symbol (handle, " dynlink_print_info" , &dynlink_print_info_addr));
88-
89- if (dynlink_print_info_addr != NULL )
90- {
91- dynlink_print_func print = (dynlink_print_func)dynlink_print_info_addr;
92-
93- log_write (" metacall" , LOG_LEVEL_DEBUG, " Print function: %p" , (void *)print);
94-
95- log_write (" metacall" , LOG_LEVEL_DEBUG, " Symbol pointer: %p" , (void *)dynlink_print_info_addr);
96-
97- if (dynlink_print_info_addr != NULL )
98- {
99- log_write (" metacall" , LOG_LEVEL_DEBUG, " Pointer is valid" );
100- }
101-
102- log_write (" metacall" , LOG_LEVEL_DEBUG, " Print: %s" , print ());
103- }
104-
105- dynlink_unload (handle);
106- }
107- }
108-
10963 /* Test loading symbols from current process */
11064 {
11165 dynlink proc = dynlink_load_self (DYNLINK_FLAGS_BIND_GLOBAL | DYNLINK_FLAGS_BIND_LAZY);
@@ -127,51 +81,101 @@ TEST_F(dynlink_test, DefaultConstructor)
12781 dynlink_unload (proc); /* Should do nothing except by freeing the handle */
12882 }
12983
130- /* Test loading symbols from absolute path */
84+ # ifdef DYNLINK_TEST_MOCK_LOADER
13185 {
132- char library_name_platform[PORTABILITY_PATH_SIZE];
133- char absolute_path[PORTABILITY_PATH_SIZE];
86+ #if (!defined(NDEBUG) || defined(DEBUG) || defined(_DEBUG) || defined(__DEBUG) || defined(__DEBUG__))
87+ const char library_name[] = " mock_loaderd" ;
88+ #else
89+ const char library_name[] = " mock_loader" ;
90+ #endif
13491
135- dynlink_platform_name (library_name, library_name_platform );
92+ char *path = environment_variable_path_create (DYNLINK_TEST_LIBRARY_PATH, NULL , 0 , NULL );
13693
137- portability_path_join (path, strlen (path) + 1 , library_name_platform, strlen (library_name_platform) + 1 , absolute_path, PORTABILITY_PATH_SIZE );
94+ ASSERT_NE (( char *)path, ( char *) NULL );
13895
139- dynlink handle = dynlink_load_absolute (absolute_path, DYNLINK_FLAGS_BIND_NOW | DYNLINK_FLAGS_BIND_GLOBAL);
96+ /* Test library loading */
97+ {
98+ dynlink handle = dynlink_load (path, library_name, DYNLINK_FLAGS_BIND_NOW | DYNLINK_FLAGS_BIND_GLOBAL);
14099
141- ASSERT_NE (handle, (dynlink)NULL );
100+ ASSERT_NE (handle, (dynlink)NULL );
142101
143- log_write (" metacall" , LOG_LEVEL_DEBUG, " Dynamic linked shared object absolute path: %s" , absolute_path);
144- log_write (" metacall" , LOG_LEVEL_DEBUG, " Dynamic linked shared object file name: %s" , dynlink_get_path (handle));
145- log_write (" metacall" , LOG_LEVEL_DEBUG, " Dynamic linked shared object file: %s" , dynlink_get_name (handle));
102+ log_write (" metacall" , LOG_LEVEL_DEBUG, " Dynamic linked shared object file: %s" , dynlink_get_path (handle));
146103
147- EXPECT_EQ ((int )0 , (int )strcmp (absolute_path, dynlink_get_path (handle)));
148- EXPECT_EQ ((int )0 , (int )strcmp (library_name, dynlink_get_name (handle)));
104+ EXPECT_EQ ((int )0 , (int )strcmp (library_name, dynlink_get_name (handle)));
149105
150- if (handle != NULL )
106+ if (handle != NULL )
107+ {
108+ dynlink_symbol_addr mock_loader_print_info_addr;
109+
110+ EXPECT_EQ ((int )0 , dynlink_symbol (handle, " mock_loader_print_info" , &mock_loader_print_info_addr));
111+
112+ if (mock_loader_print_info_addr != NULL )
113+ {
114+ mock_loader_print_func print = (mock_loader_print_func)mock_loader_print_info_addr;
115+
116+ log_write (" metacall" , LOG_LEVEL_DEBUG, " Print function: %p" , (void *)print);
117+
118+ log_write (" metacall" , LOG_LEVEL_DEBUG, " Symbol pointer: %p" , (void *)mock_loader_print_info_addr);
119+
120+ if (mock_loader_print_info_addr != NULL )
121+ {
122+ log_write (" metacall" , LOG_LEVEL_DEBUG, " Pointer is valid" );
123+ }
124+
125+ log_write (" metacall" , LOG_LEVEL_DEBUG, " Print: %s" , print ());
126+ }
127+
128+ dynlink_unload (handle);
129+ }
130+ }
131+
132+ /* Test loading symbols from absolute path */
151133 {
152- dynlink_symbol_addr dynlink_print_info_addr;
134+ char library_name_platform[PORTABILITY_PATH_SIZE];
135+ char absolute_path[PORTABILITY_PATH_SIZE];
153136
154- EXPECT_EQ (( int ) 0 , dynlink_symbol (handle, " dynlink_print_info " , &dynlink_print_info_addr) );
137+ dynlink_platform_name (library_name, library_name_platform );
155138
156- if (dynlink_print_info_addr != NULL )
157- {
158- dynlink_print_func print = (dynlink_print_func)dynlink_print_info_addr;
139+ portability_path_join (path, strlen (path) + 1 , library_name_platform, strlen (library_name_platform) + 1 , absolute_path, PORTABILITY_PATH_SIZE);
159140
160- log_write ( " metacall " , LOG_LEVEL_DEBUG, " Print function: %p " , ( void *)print );
141+ dynlink handle = dynlink_load_absolute (absolute_path, DYNLINK_FLAGS_BIND_NOW | DYNLINK_FLAGS_BIND_GLOBAL );
161142
162- log_write ( " metacall " , LOG_LEVEL_DEBUG, " Symbol pointer: %p " , ( void *)dynlink_print_info_addr );
143+ ASSERT_NE (handle, (dynlink) NULL );
163144
164- if (dynlink_print_info_addr != NULL )
145+ log_write (" metacall" , LOG_LEVEL_DEBUG, " Dynamic linked shared object absolute path: %s" , absolute_path);
146+ log_write (" metacall" , LOG_LEVEL_DEBUG, " Dynamic linked shared object file name: %s" , dynlink_get_path (handle));
147+ log_write (" metacall" , LOG_LEVEL_DEBUG, " Dynamic linked shared object file: %s" , dynlink_get_name (handle));
148+
149+ EXPECT_EQ ((int )0 , (int )strcmp (absolute_path, dynlink_get_path (handle)));
150+ EXPECT_EQ ((int )0 , (int )strcmp (library_name, dynlink_get_name (handle)));
151+
152+ if (handle != NULL )
153+ {
154+ dynlink_symbol_addr mock_loader_print_info_addr;
155+
156+ EXPECT_EQ ((int )0 , dynlink_symbol (handle, " mock_loader_print_info" , &mock_loader_print_info_addr));
157+
158+ if (mock_loader_print_info_addr != NULL )
165159 {
166- log_write (" metacall" , LOG_LEVEL_DEBUG, " Pointer is valid" );
160+ mock_loader_print_func print = (mock_loader_print_func)mock_loader_print_info_addr;
161+
162+ log_write (" metacall" , LOG_LEVEL_DEBUG, " Print function: %p" , (void *)print);
163+
164+ log_write (" metacall" , LOG_LEVEL_DEBUG, " Symbol pointer: %p" , (void *)mock_loader_print_info_addr);
165+
166+ if (mock_loader_print_info_addr != NULL )
167+ {
168+ log_write (" metacall" , LOG_LEVEL_DEBUG, " Pointer is valid" );
169+ }
170+
171+ log_write (" metacall" , LOG_LEVEL_DEBUG, " Print: %s" , print ());
167172 }
168173
169- log_write ( " metacall " , LOG_LEVEL_DEBUG, " Print: %s " , print () );
174+ dynlink_unload (handle );
170175 }
171-
172- dynlink_unload (handle);
173176 }
174- }
175177
176- environment_variable_path_destroy (path);
178+ environment_variable_path_destroy (path);
179+ }
180+ #endif
177181}
0 commit comments