liblp: Expose MockPropertyFetcher for liblp-dependent tests.
Bug: 139154795 Test: liblp_test_static builds Change-Id: I22b15523a32272ed67a8fe16e386f41b3fcf0bb0
This commit is contained in:
parent
3bd09415a3
commit
9966699af7
5 changed files with 26 additions and 19 deletions
|
@ -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) {
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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();
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue