Home | History | Annotate | Download | only in tests
      1 #include <dlfcn.h>
      2 #include <dvr/dvr_api.h>
      3 
      4 #include <gtest/gtest.h>
      5 
      6 /** DvrTestBase loads the libdvr.so at runtime and get the Dvr API version 1. */
      7 class DvrApiTest : public ::testing::Test {
      8  protected:
      9   void SetUp() override {
     10     int flags = RTLD_NOW | RTLD_LOCAL;
     11 
     12     // Here we need to ensure that libdvr is loaded with RTLD_NODELETE flag set
     13     // (so that calls to `dlclose` don't actually unload the library). This is a
     14     // workaround for an Android NDK bug. See more detail:
     15     // https://github.com/android-ndk/ndk/issues/360
     16     flags |= RTLD_NODELETE;
     17     platform_handle_ = dlopen("libdvr.google.so", flags);
     18     ASSERT_NE(nullptr, platform_handle_) << "Dvr shared library missing.";
     19 
     20     auto dvr_get_api = reinterpret_cast<decltype(&dvrGetApi)>(
     21         dlsym(platform_handle_, "dvrGetApi"));
     22     ASSERT_NE(nullptr, dvr_get_api) << "Platform library missing dvrGetApi.";
     23 
     24     ASSERT_EQ(dvr_get_api(&api_, sizeof(api_), /*version=*/1), 0)
     25         << "Unable to find compatible Dvr API.";
     26   }
     27 
     28   void TearDown() override {
     29     if (platform_handle_ != nullptr) {
     30       dlclose(platform_handle_);
     31     }
     32   }
     33 
     34   void* platform_handle_ = nullptr;
     35   DvrApi_v1 api_;
     36 };
     37