aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShawn Willden <swillden@google.com>2020-12-15 00:02:49 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2020-12-15 00:02:49 +0000
commit4b1ec2b43b6f92c79d0a48b98fe90697d8549aa1 (patch)
tree8d84cfe31231ffaf35432df1b7313674b7ef5aa0
parent2c21661224d5643de379b5fc243caf22ded8aa84 (diff)
parentb6b24c2ab8f40a99f60edbce1c233c601c5166c9 (diff)
downloadlibcppbor-4b1ec2b43b6f92c79d0a48b98fe90697d8549aa1.tar.gz
Remove downcastItem<> am: f79067125c am: 7aa436b8ca am: b6b24c2ab8
Original change: https://android-review.googlesource.com/c/platform/external/libcppbor/+/1515384 MUST ONLY BE SUBMITTED BY AUTOMERGER Change-Id: Ia6ef3af33c73065b3f82864e400b222d85cf26b8
-rw-r--r--include/cppbor/cppbor.h16
-rw-r--r--tests/cppbor_test.cpp162
2 files changed, 0 insertions, 178 deletions
diff --git a/include/cppbor/cppbor.h b/include/cppbor/cppbor.h
index c33960b..f9d371e 100644
--- a/include/cppbor/cppbor.h
+++ b/include/cppbor/cppbor.h
@@ -779,22 +779,6 @@ std::string prettyPrint(const Item* item, size_t maxBStrSize = 32,
std::string prettyPrint(const std::vector<uint8_t>& encodedCbor, size_t maxBStrSize = 32,
const std::vector<std::string>& mapKeysNotToPrint = {});
-template <typename T>
-std::unique_ptr<T> downcastItem(std::unique_ptr<Item>&& v) {
- static_assert(std::is_base_of_v<Item, T> && !std::is_abstract_v<T>,
- "returned type is not an Item or is an abstract class");
- if (v && T::kMajorType == v->type()) {
- if constexpr (std::is_base_of_v<Simple, T>) {
- if (T::kSimpleType != v->asSimple()->simpleType()) {
- return nullptr;
- }
- }
- return std::unique_ptr<T>(static_cast<T*>(v.release()));
- } else {
- return nullptr;
- }
-}
-
/**
* Details. Mostly you shouldn't have to look below, except perhaps at the docstring for makeItem.
*/
diff --git a/tests/cppbor_test.cpp b/tests/cppbor_test.cpp
index ed4b94e..b45d804 100644
--- a/tests/cppbor_test.cpp
+++ b/tests/cppbor_test.cpp
@@ -1424,168 +1424,6 @@ TEST(FullParserTest, MapWithTruncatedEntry) {
EXPECT_EQ("Need 4 byte(s) for length field, have 3.", message);
}
-TEST(ItemDowncastingTest, Uint) {
- auto item = std::unique_ptr<Item>(new Uint(1));
- EXPECT_NE(downcastItem<Uint>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Nint>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Tstr>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Bstr>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Array>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Map>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Bool>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Null>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Semantic>(std::move(item)).get(), nullptr);
- // Uncommenting following lines should not compile
- // EXPECT_EQ(downcastItem<Int>(std::move(item)).get(), nullptr);
- // EXPECT_EQ(downcastItem<CompoundItem>(std::move(item)).get(), nullptr);
- // EXPECT_EQ(downcastItem<Simple>(std::move(item)).get(), nullptr);
- // EXPECT_EQ(downcastItem<Item>(std::move(item)).get(), nullptr);
-}
-
-TEST(ItemDowncastingTest, Nint) {
- auto item = std::unique_ptr<Item>(new Nint(-211));
- EXPECT_EQ(downcastItem<Uint>(std::move(item)).get(), nullptr);
- EXPECT_NE(downcastItem<Nint>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Tstr>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Bstr>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Array>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Map>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Bool>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Null>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Semantic>(std::move(item)).get(), nullptr);
- // Uncommenting following lines should not compile
- // EXPECT_EQ(downcastItem<Int>(std::move(item)).get(), nullptr);
- // EXPECT_EQ(downcastItem<CompoundItem>(std::move(item)).get(), nullptr);
- // EXPECT_EQ(downcastItem<Simple>(std::move(item)).get(), nullptr);
- // EXPECT_EQ(downcastItem<Item>(std::move(item)).get(), nullptr);
-}
-
-TEST(ItemDowncastingTest, Tstr) {
- auto item = std::unique_ptr<Item>(new Tstr("string"));
- EXPECT_EQ(downcastItem<Uint>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Nint>(std::move(item)).get(), nullptr);
- EXPECT_NE(downcastItem<Tstr>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Bstr>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Array>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Map>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Bool>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Null>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Semantic>(std::move(item)).get(), nullptr);
- // Uncommenting following lines should not compile
- // EXPECT_EQ(downcastItem<Int>(std::move(item)).get(), nullptr);
- // EXPECT_EQ(downcastItem<CompoundItem>(std::move(item)).get(), nullptr);
- // EXPECT_EQ(downcastItem<Simple>(std::move(item)).get(), nullptr);
- // EXPECT_EQ(downcastItem<Item>(std::move(item)).get(), nullptr);
-}
-
-TEST(ItemDowncastingTest, Bstr) {
- auto item = std::unique_ptr<Item>(new Bstr(std::vector<uint8_t>{1, 2, 3, 4, 5, 6}));
- EXPECT_EQ(downcastItem<Uint>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Nint>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Tstr>(std::move(item)).get(), nullptr);
- EXPECT_NE(downcastItem<Bstr>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Array>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Map>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Bool>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Null>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Semantic>(std::move(item)).get(), nullptr);
- // Uncommenting following lines should not compile
- // EXPECT_EQ(downcastItem<Int>(std::move(item)).get(), nullptr);
- // EXPECT_EQ(downcastItem<CompoundItem>(std::move(item)).get(), nullptr);
- // EXPECT_EQ(downcastItem<Simple>(std::move(item)).get(), nullptr);
- // EXPECT_EQ(downcastItem<Item>(std::move(item)).get(), nullptr);
-}
-
-TEST(ItemDowncastingTest, Array) {
- auto item = std::unique_ptr<Item>(new Array(1, 2, "3", "4", Array(5, "6")));
- EXPECT_EQ(downcastItem<Uint>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Nint>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Tstr>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Bstr>(std::move(item)).get(), nullptr);
- EXPECT_NE(downcastItem<Array>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Map>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Bool>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Null>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Semantic>(std::move(item)).get(), nullptr);
- // Uncommenting following lines should not compile
- // EXPECT_EQ(downcastItem<Int>(std::move(item)).get(), nullptr);
- // EXPECT_EQ(downcastItem<CompoundItem>(std::move(item)).get(), nullptr);
- // EXPECT_EQ(downcastItem<Simple>(std::move(item)).get(), nullptr);
- // EXPECT_EQ(downcastItem<Item>(std::move(item)).get(), nullptr);
-}
-
-TEST(ItemDowncastingTest, Map) {
- auto item = std::unique_ptr<Item>(new Map(1, 2, "key", "value"));
- EXPECT_EQ(downcastItem<Uint>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Nint>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Tstr>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Bstr>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Array>(std::move(item)).get(), nullptr);
- EXPECT_NE(downcastItem<Map>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Bool>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Null>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Semantic>(std::move(item)).get(), nullptr);
- // Uncommenting following lines should not compile
- // EXPECT_EQ(downcastItem<Int>(std::move(item)).get(), nullptr);
- // EXPECT_EQ(downcastItem<CompoundItem>(std::move(item)).get(), nullptr);
- // EXPECT_EQ(downcastItem<Simple>(std::move(item)).get(), nullptr);
- // EXPECT_EQ(downcastItem<Item>(std::move(item)).get(), nullptr);
-}
-
-TEST(ItemDowncastingTest, Bool) {
- auto item = std::unique_ptr<Item>(new Bool(false));
- EXPECT_EQ(downcastItem<Uint>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Nint>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Tstr>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Bstr>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Array>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Map>(std::move(item)).get(), nullptr);
- EXPECT_NE(downcastItem<Bool>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Null>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Semantic>(std::move(item)).get(), nullptr);
- // Uncommenting following lines should not compile
- // EXPECT_EQ(downcastItem<Int>(std::move(item)).get(), nullptr);
- // EXPECT_EQ(downcastItem<CompoundItem>(std::move(item)).get(), nullptr);
- // EXPECT_EQ(downcastItem<Simple>(std::move(item)).get(), nullptr);
- // EXPECT_EQ(downcastItem<Item>(std::move(item)).get(), nullptr);
-}
-
-TEST(ItemDowncastingTest, Null) {
- auto item = std::unique_ptr<Item>(new Null());
- EXPECT_EQ(downcastItem<Uint>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Nint>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Tstr>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Bstr>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Array>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Map>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Bool>(std::move(item)).get(), nullptr);
- EXPECT_NE(downcastItem<Null>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Semantic>(std::move(item)).get(), nullptr);
- // Uncommenting following lines should not compile
- // EXPECT_EQ(downcastItem<Int>(std::move(item)).get(), nullptr);
- // EXPECT_EQ(downcastItem<CompoundItem>(std::move(item)).get(), nullptr);
- // EXPECT_EQ(downcastItem<Simple>(std::move(item)).get(), nullptr);
- // EXPECT_EQ(downcastItem<Item>(std::move(item)).get(), nullptr);
-}
-
-TEST(ItemDowncastingTest, Semantic) {
- auto item = std::unique_ptr<Item>(new Semantic(11, Map("key", Array(1, 2, 3))));
- EXPECT_EQ(downcastItem<Uint>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Nint>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Tstr>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Bstr>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Array>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Map>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Bool>(std::move(item)).get(), nullptr);
- EXPECT_EQ(downcastItem<Null>(std::move(item)).get(), nullptr);
- EXPECT_NE(downcastItem<Semantic>(std::move(item)).get(), nullptr);
- // Uncommenting following lines should not compile
- // EXPECT_EQ(downcastItem<Int>(std::move(item)).get(), nullptr);
- // EXPECT_EQ(downcastItem<CompoundItem>(std::move(item)).get(), nullptr);
- // EXPECT_EQ(downcastItem<Simple>(std::move(item)).get(), nullptr);
- // EXPECT_EQ(downcastItem<Item>(std::move(item)).get(), nullptr);
-}
-
TEST(MapGetValueByKeyTest, Map) {
Array compoundItem(1, 2, 3, 4, 5, Map(4, 5, "a", "b"));
auto clone = compoundItem.clone();