Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9966699a authored by David Anderson's avatar David Anderson
Browse files

liblp: Expose MockPropertyFetcher for liblp-dependent tests.

Bug: 139154795
Test: liblp_test_static builds
Change-Id: I22b15523a32272ed67a8fe16e386f41b3fcf0bb0
parent 3bd09415
Loading
Loading
Loading
Loading
+2 −11
Original line number Diff line number Diff line
@@ -19,29 +19,20 @@
#include <liblp/builder.h>

#include "liblp_test.h"
#include "mock_property_fetcher.h"
#include "utility.h"

using namespace std;
using namespace android::fs_mgr;
using ::android::fs_mgr::MockPropertyFetcher;
using namespace android::fs_mgr::testing;
using ::testing::_;
using ::testing::AnyNumber;
using ::testing::ElementsAre;
using ::testing::NiceMock;
using ::testing::Return;

void ResetPropertyFetcher() {
    IPropertyFetcher::OverrideForTesting(std::make_unique<NiceMock<MockPropertyFetcher>>());
}

MockPropertyFetcher* GetMockedPropertyFetcher() {
    return static_cast<MockPropertyFetcher*>(IPropertyFetcher::GetInstance());
}

class Environment : public ::testing::Environment {
  public:
    void SetUp() override { ResetPropertyFetcher(); }
    void SetUp() override { ResetMockPropertyFetcher(); }
};

int main(int argc, char** argv) {
+1 −1
Original line number Diff line number Diff line
@@ -24,9 +24,9 @@
#include <liblp/property_fetcher.h>

#include "liblp_test.h"
#include "mock_property_fetcher.h"

using namespace android::fs_mgr;
using namespace android::fs_mgr::testing;
using ::testing::Return;

// Compliance test on the actual device with dynamic partitions.
+11 −3
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@

namespace android {
namespace fs_mgr {
namespace testing {

class MockPropertyFetcher : public IPropertyFetcher {
  public:
@@ -41,8 +42,15 @@ class MockPropertyFetcher : public IPropertyFetcher {
    }
};

static inline void ResetMockPropertyFetcher() {
    IPropertyFetcher::OverrideForTesting(
            std::make_unique<::testing::NiceMock<MockPropertyFetcher>>());
}

static inline MockPropertyFetcher* GetMockedPropertyFetcher() {
    return static_cast<MockPropertyFetcher*>(IPropertyFetcher::GetInstance());
}

}  // namespace testing
}  // namespace fs_mgr
}  // namespace android

android::fs_mgr::MockPropertyFetcher* GetMockedPropertyFetcher();
void ResetPropertyFetcher();
+1 −1
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@

#include "images.h"
#include "liblp_test.h"
#include "mock_property_fetcher.h"
#include "reader.h"
#include "test_partition_opener.h"
#include "utility.h"
@@ -35,6 +34,7 @@

using namespace std;
using namespace android::fs_mgr;
using namespace android::fs_mgr::testing;
using ::testing::_;
using ::testing::Return;
using unique_fd = android::base::unique_fd;
+11 −3
Original line number Diff line number Diff line
@@ -18,10 +18,18 @@

#include <gtest/gtest.h>

#include "mock_property_fetcher.h"
#include <liblp/mock_property_fetcher.h>

namespace android {
namespace fs_mgr {
namespace testing {

class LiblpTest : public ::testing::Test {
  public:
    void SetUp() override { ResetPropertyFetcher(); }
    void TearDown() override { ResetPropertyFetcher(); }
    void SetUp() override { ResetMockPropertyFetcher(); }
    void TearDown() override { ResetMockPropertyFetcher(); }
};

}  // namespace testing
}  // namespace fs_mgr
}  // namespace android