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

Commit e0b2b759 authored by David Anderson's avatar David Anderson Committed by Gerrit Code Review
Browse files

Merge "liblp: Expose MockPropertyFetcher for liblp-dependent tests."

parents 8d0c132a 9966699a
Loading
Loading
Loading
Loading
+2 −11
Original line number Original line Diff line number Diff line
@@ -19,29 +19,20 @@
#include <liblp/builder.h>
#include <liblp/builder.h>


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


using namespace std;
using namespace std;
using namespace android::fs_mgr;
using namespace android::fs_mgr;
using ::android::fs_mgr::MockPropertyFetcher;
using namespace android::fs_mgr::testing;
using ::testing::_;
using ::testing::_;
using ::testing::AnyNumber;
using ::testing::AnyNumber;
using ::testing::ElementsAre;
using ::testing::ElementsAre;
using ::testing::NiceMock;
using ::testing::NiceMock;
using ::testing::Return;
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 {
class Environment : public ::testing::Environment {
  public:
  public:
    void SetUp() override { ResetPropertyFetcher(); }
    void SetUp() override { ResetMockPropertyFetcher(); }
};
};


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


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


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


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


namespace android {
namespace android {
namespace fs_mgr {
namespace fs_mgr {
namespace testing {


class MockPropertyFetcher : public IPropertyFetcher {
class MockPropertyFetcher : public IPropertyFetcher {
  public:
  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 fs_mgr
}  // namespace android
}  // namespace android

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


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


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


#include <gtest/gtest.h>
#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 {
class LiblpTest : public ::testing::Test {
  public:
  public:
    void SetUp() override { ResetPropertyFetcher(); }
    void SetUp() override { ResetMockPropertyFetcher(); }
    void TearDown() override { ResetPropertyFetcher(); }
    void TearDown() override { ResetMockPropertyFetcher(); }
};
};

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