Merge "Move digital_stroage.h to its own library"
This commit is contained in:
commit
101588127c
|
@ -67,6 +67,9 @@ cc_defaults {
|
|||
"libfs_mgr",
|
||||
"liblp",
|
||||
] + liblp_lib_deps,
|
||||
header_libs: [
|
||||
"libstorage_literals_headers",
|
||||
],
|
||||
stl: "libc++_static",
|
||||
srcs: [
|
||||
"builder_test.cpp",
|
||||
|
|
|
@ -17,11 +17,13 @@
|
|||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <liblp/builder.h>
|
||||
#include <storage_literals/storage_literals.h>
|
||||
|
||||
#include "liblp_test.h"
|
||||
#include "utility.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace android::storage_literals;
|
||||
using namespace android::fs_mgr;
|
||||
using namespace android::fs_mgr::testing;
|
||||
using ::testing::_;
|
||||
|
@ -591,13 +593,6 @@ TEST_F(BuilderTest, ChangeGroups) {
|
|||
ASSERT_NE(builder->Export(), nullptr);
|
||||
}
|
||||
|
||||
constexpr unsigned long long operator"" _GiB(unsigned long long x) { // NOLINT
|
||||
return x << 30;
|
||||
}
|
||||
constexpr unsigned long long operator"" _MiB(unsigned long long x) { // NOLINT
|
||||
return x << 20;
|
||||
}
|
||||
|
||||
TEST_F(BuilderTest, RemoveAndAddFirstPartition) {
|
||||
auto builder = MetadataBuilder::New(10_GiB, 65536, 2);
|
||||
ASSERT_NE(nullptr, builder);
|
||||
|
|
|
@ -103,4 +103,7 @@ cc_test {
|
|||
"libsparse",
|
||||
"libz",
|
||||
],
|
||||
header_libs: [
|
||||
"libstorage_literals_headers",
|
||||
],
|
||||
}
|
||||
|
|
|
@ -32,8 +32,8 @@
|
|||
#include <libfiemap/image_manager.h>
|
||||
#include <liblp/builder.h>
|
||||
#include <liblp/mock_property_fetcher.h>
|
||||
#include <storage_literals/storage_literals.h>
|
||||
|
||||
#include "digital_storage.h"
|
||||
#include "test_helpers.h"
|
||||
#include "utility.h"
|
||||
|
||||
|
@ -52,7 +52,7 @@ using android::fs_mgr::GetPartitionName;
|
|||
using android::fs_mgr::MetadataBuilder;
|
||||
using namespace ::testing;
|
||||
using namespace android::fs_mgr::testing;
|
||||
using namespace android::digital_storage;
|
||||
using namespace android::storage_literals;
|
||||
using namespace std::chrono_literals;
|
||||
using namespace std::string_literals;
|
||||
|
||||
|
@ -62,7 +62,7 @@ std::unique_ptr<SnapshotManager> sm;
|
|||
TestDeviceInfo* test_device = nullptr;
|
||||
std::string fake_super;
|
||||
|
||||
static constexpr uint64_t kSuperSize = (16_MiB).bytes();
|
||||
static constexpr uint64_t kSuperSize = 16_MiB;
|
||||
|
||||
class SnapshotTest : public ::testing::Test {
|
||||
public:
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
|
||||
cc_library_headers {
|
||||
name: "libstorage_literals_headers",
|
||||
host_supported: true,
|
||||
export_include_dirs: ["."],
|
||||
}
|
|
@ -18,25 +18,25 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
namespace android {
|
||||
namespace digital_storage {
|
||||
namespace storage_literals {
|
||||
|
||||
template <size_t Power>
|
||||
struct Size {
|
||||
static constexpr size_t power = Power;
|
||||
constexpr Size(uint64_t count) : value_(count) {}
|
||||
explicit constexpr Size(uint64_t count) : value_(count) {}
|
||||
|
||||
constexpr uint64_t bytes() const { return value_ << (Power * 10); }
|
||||
constexpr uint64_t bytes() const { return value_ << power; }
|
||||
constexpr uint64_t count() const { return value_; }
|
||||
operator uint64_t() const { return bytes(); }
|
||||
constexpr operator uint64_t() const { return bytes(); }
|
||||
|
||||
private:
|
||||
uint64_t value_;
|
||||
};
|
||||
|
||||
using B = Size<0>;
|
||||
using KiB = Size<1>;
|
||||
using MiB = Size<2>;
|
||||
using GiB = Size<3>;
|
||||
using KiB = Size<10>;
|
||||
using MiB = Size<20>;
|
||||
using GiB = Size<30>;
|
||||
|
||||
constexpr B operator""_B(unsigned long long v) { // NOLINT
|
||||
return B{v};
|
||||
|
@ -57,21 +57,21 @@ constexpr GiB operator""_GiB(unsigned long long v) { // NOLINT
|
|||
template <typename Dest, typename Src>
|
||||
constexpr Dest size_cast(Src src) {
|
||||
if (Src::power < Dest::power) {
|
||||
return Dest(src.count() >> ((Dest::power - Src::power) * 10));
|
||||
return Dest(src.count() >> (Dest::power - Src::power));
|
||||
}
|
||||
if (Src::power > Dest::power) {
|
||||
return Dest(src.count() << ((Src::power - Dest::power) * 10));
|
||||
return Dest(src.count() << (Src::power - Dest::power));
|
||||
}
|
||||
return Dest(src.count());
|
||||
}
|
||||
|
||||
static_assert((1_B).bytes() == 1);
|
||||
static_assert((1_KiB).bytes() == 1 << 10);
|
||||
static_assert((1_MiB).bytes() == 1 << 20);
|
||||
static_assert((1_GiB).bytes() == 1 << 30);
|
||||
static_assert(1_B == 1);
|
||||
static_assert(1_KiB == 1 << 10);
|
||||
static_assert(1_MiB == 1 << 20);
|
||||
static_assert(1_GiB == 1 << 30);
|
||||
static_assert(size_cast<KiB>(1_B).count() == 0);
|
||||
static_assert(size_cast<KiB>(1024_B).count() == 1);
|
||||
static_assert(size_cast<KiB>(1_MiB).count() == 1024);
|
||||
|
||||
} // namespace digital_storage
|
||||
} // namespace storage_literals
|
||||
} // namespace android
|
Loading…
Reference in New Issue