TEST_F(SharedLibraryTest, FindSymbol) {
    ScopedSharedLibrary lib(SharedLibrary::open(library_path()));
    EXPECT_TRUE(lib.get());

    if (lib.get()) {
        typedef int (*FooFunction)(void);

        FooFunction foo_func = reinterpret_cast<FooFunction>(
                lib->findSymbol("foo_function"));
        EXPECT_TRUE(foo_func);
        EXPECT_EQ(42, (*foo_func)());
    }
}
Exemple #2
0
void ObjectLibrary::processFolder(const char* filepath)
{
	// Create object library
	path library_path(filepath);
	if(is_directory(library_path))
	{
		recursive_directory_iterator iter(library_path);
		recursive_directory_iterator end;
		while(iter != end)
		{
			if(is_directory(iter->path()))
			{
				object_idx.push_back(images.size());
				object_names.push_back(iter->path().filename().generic_string());
				//std::cout << "Object: " <<  object_names.back() << " " << object_idx.back() << std::endl;

				// Handle Symlink Directories
				if(is_symlink(iter->path()))
				{
					iter = recursive_directory_iterator(canonical(read_symlink(iter->path()), library_path));
				}
			}
			else
			{
				// Initialize object feature
				Mat img_object = imread(iter->path().generic_string(), CV_LOAD_IMAGE_COLOR);
				if( !img_object.data )
				{ 
					throw std::runtime_error("Error Reading Image"); 
				}
				ImageData img = processImage(img_object);
				img.name = iter->path().stem().generic_string();
				//std::cout << "Object: " << object_names.back() << " Image: " << img.name << std::endl;

				if(img.name == object_names.back())
				{
					object_img_idx.push_back(images.size());
					//std::cout << object_names.back() << " " << images.size() << std::endl;
				}

				//-- Step 3: Add to object library
				images.push_back(std::move(img));
			}
			++iter;
		}
	}
	//std::cout << "Num Objects: " << object_idx.size() << std::endl;
}
  android_namespace_t* GetOrCreate(JNIEnv* env, jobject class_loader,
                                   bool is_shared,
                                   jstring java_library_path,
                                   jstring java_permitted_path) {
    ScopedUtfChars library_path(env, java_library_path);

    std::string permitted_path;
    if (java_permitted_path != nullptr) {
      ScopedUtfChars path(env, java_permitted_path);
      permitted_path = path.c_str();
    }

    if (!initialized_ && !InitPublicNamespace(library_path.c_str())) {
      return nullptr;
    }

    std::lock_guard<std::mutex> guard(mutex_);

    auto it = FindNamespaceByClassLoader(env, class_loader);

    if (it != namespaces_.end()) {
      return it->second;
    }

    uint64_t namespace_type = ANDROID_NAMESPACE_TYPE_ISOLATED;
    if (is_shared) {
      namespace_type |= ANDROID_NAMESPACE_TYPE_SHARED;
    }

    android_namespace_t* ns =
            android_create_namespace("classloader-namespace",
                                     nullptr,
                                     library_path.c_str(),
                                     namespace_type,
                                     java_permitted_path != nullptr ?
                                        permitted_path.c_str() :
                                        nullptr);

    namespaces_.push_back(std::make_pair(env->NewWeakGlobalRef(class_loader), ns));

    return ns;
  }
    android_namespace_t* Create(JNIEnv* env,
                                jobject class_loader,
                                bool is_shared,
                                jstring java_library_path,
                                jstring java_permitted_path) {
        ScopedUtfChars library_path(env, java_library_path);

        std::string permitted_path;
        if (java_permitted_path != nullptr) {
            ScopedUtfChars path(env, java_permitted_path);
            permitted_path = path.c_str();
        }

        if (!initialized_ && !InitPublicNamespace(library_path.c_str())) {
            return nullptr;
        }

        android_namespace_t* ns = FindNamespaceByClassLoader(env, class_loader);

        LOG_ALWAYS_FATAL_IF(ns != nullptr,
                            "There is already a namespace associated with this classloader");

        uint64_t namespace_type = ANDROID_NAMESPACE_TYPE_ISOLATED;
        if (is_shared) {
            namespace_type |= ANDROID_NAMESPACE_TYPE_SHARED;
        }

        ns = android_create_namespace("classloader-namespace",
                                      nullptr,
                                      library_path.c_str(),
                                      namespace_type,
                                      java_permitted_path != nullptr ?
                                      permitted_path.c_str() :
                                      nullptr);

        if (ns != nullptr) {
            namespaces_.push_back(std::make_pair(env->NewWeakGlobalRef(class_loader), ns));
        }

        return ns;
    }
TEST_F(SharedLibraryTest, OpenLibraryWithExtension) {
    std::string path = library_path();

    // test extension append
    ScopedSharedLibrary libNoExtension(SharedLibrary::open(path.c_str()));
    EXPECT_TRUE(libNoExtension.get());
    libNoExtension.release();

#ifdef _WIN32
    path += ".dll";
#elif defined(__APPLE__)
    // try to open the library without an extension

    path += ".dylib";
#else
    path += ".so";
#endif

    // test open with prepended extension
    ScopedSharedLibrary lib(SharedLibrary::open(path.c_str()));
    EXPECT_TRUE(lib.get());
}
TEST_F(SharedLibraryTest, Open) {
    ScopedSharedLibrary lib(SharedLibrary::open(library_path()));
    EXPECT_TRUE(lib.get());
}