static void test_construct() { bpd::file_handle fh1; BOOST_CHECK(!fh1.valid()); bpd::file_handle fh2(get_test_handle()); BOOST_CHECK(fh2.valid()); fh2.release(); }
static void test_copy() { bpd::file_handle fh1; bpd::file_handle fh2(get_test_handle()); bpd::file_handle fh3(fh2); BOOST_REQUIRE(!fh2.valid()); BOOST_REQUIRE(fh3.valid()); fh1 = fh3; BOOST_REQUIRE(!fh3.valid()); BOOST_REQUIRE(fh1.valid()); fh1.release(); }
char* get_string (char *lib_path) { void *handle; char *(*fh)(int, int); int (*fh2)(); char *ret; char *error; char *path = malloc(256); int len = strnlen(lib_path, 256)-4; strncpy(path, lib_path, len); path[len] = '\0'; strcat(path, "lib2.so"); handle = dlopen (path, RTLD_LAZY); if (!handle) { fprintf (stderr, "%s\n", dlerror()); exit(1); } dlerror(); /* Lookup undefined symbol */ fh = dlsym(handle, "abc"); if ((error = dlerror()) == NULL) { /* No error -> fail */ return "Error: lookup undef symbol not handled\n"; } /* Lookup defined symbol */ fh = dlsym(handle, "printTest"); if ((error = dlerror()) != NULL) { fprintf (stderr, "%s\n", error); exit(1); } /* Check if init called */ int init_called = (int)dlsym(handle, "init_called"); if ((error = dlerror()) != NULL) { fprintf (stderr, "%s\n", error); exit(1); } if (!init_called) { printf("Error: init not called\n"); exit(1); } /* Call function and check return value */ ret = (*fh)(1, 2); if (strcmp(ret, "ok")) return "\nError: test \"dynamic_loading\" failed.\n"; /* Close handle */ dlclose(handle); /* Check if fini called */ if (!fini_called) { printf("Error: fini not called\n"); exit(1); } /* Open nonexistent library */ handle = dlopen ("abc", RTLD_LAZY); if (handle) { /* No error -> fail */ return "Error: open nonexistent library not handled\n"; } /* Open library needing dynamic tls */ strncpy(path, lib_path, len); path[len] = '\0'; strcat(path, "lib_tls_dynamic.so"); handle = dlopen (path, RTLD_LAZY); if (!handle) { fprintf (stderr, "%s\n", dlerror()); exit(1); } dlerror(); fh2 = dlsym(handle, "get_data"); if ((error = dlerror()) != NULL) { fprintf (stderr, "%s\n", error); exit(1); } if (fh2() != 123) { return "\nError: return value of get_data form lib_tls_dynamic.so wrong\n"; } dlclose(handle); /* Open library needing dynamic _and_ static tls */ /* NOT SUPPORTED so do not test strncpy(path, lib_path, len); path[len] = '\0'; strcat(path, "libs/lib_tls.so"); handle = dlopen (path, RTLD_LAZY); if (!handle) { fprintf (stderr, "%s\n", dlerror()); exit(1); } dlerror(); fh2 = dlsym(handle, "get_data"); if ((error = dlerror()) != NULL) { fprintf (stderr, "%s\n", error); exit(1); } fh2(); */ /* Handle to main */ handle = dlopen (0, RTLD_LAZY); if (!handle) { fprintf (stderr, "%s\n", dlerror()); exit(1); } dlerror(); /* Lookup symbol in main object */ fh2 = dlsym(handle, "global_func"); if ((error = dlerror()) != NULL) { fprintf (stderr, "%s\n", error); exit(1); } fh2(); dlclose(handle); Dl_info *info = malloc(sizeof(Dl_info)); if (dladdr(fh2, info) != 0) { printf("name: %s, base: %p, sname: %s, saddr %p\n", info->dli_fname, info->dli_fbase, info->dli_sname, info->dli_saddr); } else { printf("Error dladdr\n"); exit(1); } return "\nTest \"dynamic_loading\" successful.\n"; }