diff options
Diffstat (limited to 'tools/aconfig/aconfig_storage_write_api/tests/storage_write_api_test.cpp')
-rw-r--r-- | tools/aconfig/aconfig_storage_write_api/tests/storage_write_api_test.cpp | 46 |
1 files changed, 15 insertions, 31 deletions
diff --git a/tools/aconfig/aconfig_storage_write_api/tests/storage_write_api_test.cpp b/tools/aconfig/aconfig_storage_write_api/tests/storage_write_api_test.cpp index bd39e9e1de..31183fa01b 100644 --- a/tools/aconfig/aconfig_storage_write_api/tests/storage_write_api_test.cpp +++ b/tools/aconfig/aconfig_storage_write_api/tests/storage_write_api_test.cpp @@ -22,11 +22,9 @@ #include "aconfig_storage/aconfig_storage_read_api.hpp" #include "aconfig_storage/aconfig_storage_write_api.hpp" #include <gtest/gtest.h> -#include <protos/aconfig_storage_metadata.pb.h> #include <android-base/file.h> #include <android-base/result.h> -using android::aconfig_storage_metadata::storage_files; using namespace android::base; namespace api = aconfig_storage; @@ -78,15 +76,12 @@ TEST_F(AconfigStorageTest, test_non_writable_storage_file_mapping) { TEST_F(AconfigStorageTest, test_boolean_flag_value_update) { auto mapped_file_result = api::map_mutable_storage_file(flag_val); ASSERT_TRUE(mapped_file_result.ok()); + auto mapped_file = std::unique_ptr<api::MutableMappedStorageFile>(*mapped_file_result); - auto mapped_file = *mapped_file_result; for (int offset = 0; offset < 8; ++offset) { - auto update_result = api::set_boolean_flag_value(mapped_file, offset, true); + auto update_result = api::set_boolean_flag_value(*mapped_file, offset, true); ASSERT_TRUE(update_result.ok()); - auto ro_mapped_file = api::MappedStorageFile(); - ro_mapped_file.file_ptr = mapped_file.file_ptr; - ro_mapped_file.file_size = mapped_file.file_size; - auto value = api::get_boolean_flag_value(ro_mapped_file, offset); + auto value = api::get_boolean_flag_value(*mapped_file, offset); ASSERT_TRUE(value.ok()); ASSERT_TRUE(*value); } @@ -96,9 +91,8 @@ TEST_F(AconfigStorageTest, test_boolean_flag_value_update) { TEST_F(AconfigStorageTest, test_invalid_boolean_flag_value_update) { auto mapped_file_result = api::map_mutable_storage_file(flag_val); ASSERT_TRUE(mapped_file_result.ok()); - auto mapped_file = *mapped_file_result; - - auto update_result = api::set_boolean_flag_value(mapped_file, 8, true); + auto mapped_file = std::unique_ptr<api::MutableMappedStorageFile>(*mapped_file_result); + auto update_result = api::set_boolean_flag_value(*mapped_file, 8, true); ASSERT_FALSE(update_result.ok()); ASSERT_EQ(update_result.error().message(), std::string("InvalidStorageFileOffset(Flag value offset goes beyond the end of the file.)")); @@ -108,27 +102,22 @@ TEST_F(AconfigStorageTest, test_invalid_boolean_flag_value_update) { TEST_F(AconfigStorageTest, test_flag_has_server_override_update) { auto mapped_file_result = api::map_mutable_storage_file(flag_info); ASSERT_TRUE(mapped_file_result.ok()); - auto mapped_file = *mapped_file_result; + auto mapped_file = std::unique_ptr<api::MutableMappedStorageFile>(*mapped_file_result); for (int offset = 0; offset < 8; ++offset) { auto update_result = api::set_flag_has_server_override( - mapped_file, api::FlagValueType::Boolean, offset, true); + *mapped_file, api::FlagValueType::Boolean, offset, true); ASSERT_TRUE(update_result.ok()) << update_result.error(); - auto ro_mapped_file = api::MappedStorageFile(); - ro_mapped_file.file_ptr = mapped_file.file_ptr; - ro_mapped_file.file_size = mapped_file.file_size; auto attribute = api::get_flag_attribute( - ro_mapped_file, api::FlagValueType::Boolean, offset); + *mapped_file, api::FlagValueType::Boolean, offset); ASSERT_TRUE(attribute.ok()); ASSERT_TRUE(*attribute & api::FlagInfoBit::HasServerOverride); update_result = api::set_flag_has_server_override( - mapped_file, api::FlagValueType::Boolean, offset, false); + *mapped_file, api::FlagValueType::Boolean, offset, false); ASSERT_TRUE(update_result.ok()); - ro_mapped_file.file_ptr = mapped_file.file_ptr; - ro_mapped_file.file_size = mapped_file.file_size; attribute = api::get_flag_attribute( - ro_mapped_file, api::FlagValueType::Boolean, offset); + *mapped_file, api::FlagValueType::Boolean, offset); ASSERT_TRUE(attribute.ok()); ASSERT_FALSE(*attribute & api::FlagInfoBit::HasServerOverride); } @@ -138,27 +127,22 @@ TEST_F(AconfigStorageTest, test_flag_has_server_override_update) { TEST_F(AconfigStorageTest, test_flag_has_local_override_update) { auto mapped_file_result = api::map_mutable_storage_file(flag_info); ASSERT_TRUE(mapped_file_result.ok()); - auto mapped_file = *mapped_file_result; + auto mapped_file = std::unique_ptr<api::MutableMappedStorageFile>(*mapped_file_result); for (int offset = 0; offset < 8; ++offset) { auto update_result = api::set_flag_has_local_override( - mapped_file, api::FlagValueType::Boolean, offset, true); + *mapped_file, api::FlagValueType::Boolean, offset, true); ASSERT_TRUE(update_result.ok()); - auto ro_mapped_file = api::MappedStorageFile(); - ro_mapped_file.file_ptr = mapped_file.file_ptr; - ro_mapped_file.file_size = mapped_file.file_size; auto attribute = api::get_flag_attribute( - ro_mapped_file, api::FlagValueType::Boolean, offset); + *mapped_file, api::FlagValueType::Boolean, offset); ASSERT_TRUE(attribute.ok()); ASSERT_TRUE(*attribute & api::FlagInfoBit::HasLocalOverride); update_result = api::set_flag_has_local_override( - mapped_file, api::FlagValueType::Boolean, offset, false); + *mapped_file, api::FlagValueType::Boolean, offset, false); ASSERT_TRUE(update_result.ok()); - ro_mapped_file.file_ptr = mapped_file.file_ptr; - ro_mapped_file.file_size = mapped_file.file_size; attribute = api::get_flag_attribute( - ro_mapped_file, api::FlagValueType::Boolean, offset); + *mapped_file, api::FlagValueType::Boolean, offset); ASSERT_TRUE(attribute.ok()); ASSERT_FALSE(*attribute & api::FlagInfoBit::HasLocalOverride); } |