chromium/base/native_library_unittest.cc

// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/native_library.h"

#include "base/check.h"
#include "base/files/file_path.h"
#include "base/path_service.h"
#include "base/test/native_library_test_utils.h"
#include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace base {

const FilePath::CharType kDummyLibraryPath[] =);

TEST(NativeLibraryTest, LoadFailure) {}

// |error| is optional and can be null.
TEST(NativeLibraryTest, LoadFailureWithNullError) {}

#if BUILDFLAG(IS_FUCHSIA)
TEST(NativeLibraryTest, LoadAbsolutePath) {
  EXPECT_TRUE(LoadNativeLibrary(FilePath("/pkg/lib/libtest_shared_library.so"),
                                nullptr));
}

TEST(NativeLibraryTest, LoadAbsolutePath_OutsideLibraryRoot) {
  NativeLibraryLoadError error;
  EXPECT_FALSE(LoadNativeLibrary(FilePath("/pkg/tmp/libtest_shared_library.so"),
                                 &error));
  std::string expected_error =
      "Absolute library paths must begin with /pkg/lib";
  EXPECT_EQ(error.ToString(), expected_error);
}
#endif

TEST(NativeLibraryTest, GetNativeLibraryName) {}

TEST(NativeLibraryTest, GetLoadableModuleName) {}

// We don't support dynamic loading on iOS, and ASAN will complain about our
// intentional ODR violation because of |g_native_library_exported_value| being
// defined globally both here and in the shared library.
#if !BUILDFLAG(IS_IOS) && !defined(ADDRESS_SANITIZER)

const char kTestLibraryName[] ="test_shared_library.dll";
#elif BUILDFLAG(IS_MAC)
    "libtest_shared_library.dylib";
#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
    "libtest_shared_library.so";
#endif

class TestLibrary {};

// NativeLibraaryTest.LoadLibrary is failing on M tablets only.
// crbug/641309
#if !BUILDFLAG(IS_ANDROID)

// Verifies that we can load a native library and resolve its exported symbols.
TEST(NativeLibraryTest, LoadLibrary) {}

#endif  // !BUILDFLAG(IS_ANDROID)

// Android dlopen() requires further investigation, as it might vary across
// versions with respect to symbol resolution scope.
// TSan and MSan error out on RTLD_DEEPBIND, https://crbug.com/705255
#if !BUILDFLAG(IS_ANDROID) && !defined(THREAD_SANITIZER) && \
    !defined(MEMORY_SANITIZER)

// Verifies that the |prefer_own_symbols| option satisfies its guarantee that
// a loaded library will always prefer local symbol resolution before
// considering global symbols.
TEST(NativeLibraryTest, LoadLibraryPreferOwnSymbols) {}

#endif  // !BUILDFLAG(IS_ANDROID) && !defined(THREAD_SANITIZER) && \
        // !defined(MEMORY_SANITIZER)

#endif  // !BUILDFLAG(IS_IOS) && !defined(ADDRESS_SANITIZER)

}  // namespace base