Snap for 8414339 from b8b6bd82dbb1a24173d9b7dbb3c7d0b8f61b5175 to tm-qpr1-release

Change-Id: I38465bcdcb2511e9edd5b4b2a607a24ff95b8f69
diff --git a/include/cppbor/cppbor.h b/include/cppbor/cppbor.h
index 9bad233..8338441 100644
--- a/include/cppbor/cppbor.h
+++ b/include/cppbor/cppbor.h
@@ -25,6 +25,20 @@
 #include <string>
 #include <string_view>
 #include <vector>
+#include <algorithm>
+
+#ifdef OS_WINDOWS
+#include <basetsd.h>
+
+#define ssize_t SSIZE_T
+#endif // OS_WINDOWS
+
+#ifdef TRUE
+#undef TRUE
+#endif // TRUE
+#ifdef FALSE
+#undef FALSE
+#endif // FALSE
 
 namespace cppbor {
 
@@ -705,7 +719,7 @@
      *
      * If the searched-for `key` is not present, returns `nullptr`.
      *
-     * Note that if the map is canonicalized (sorted), Map::get() peforms a binary search.  If your
+     * Note that if the map is canonicalized (sorted), Map::get() performs a binary search.  If your
      * map is large and you're searching in it many times, it may be worthwhile to canonicalize it
      * to make Map::get() faster.  Any use of a method that might modify the map disables the
      * speedup.
@@ -919,7 +933,7 @@
  * for unit tests.
  */
 std::string prettyPrint(const Item* item, size_t maxBStrSize = 32,
-                        const std::vector<std::string>& mapKeysNotToPrint = {});
+                        const std::vector<std::string>& mapKeysToNotPrint = {});
 
 /**
  * Returns pretty-printed CBOR for |value|.
@@ -934,7 +948,7 @@
  * for unit tests.
  */
 std::string prettyPrint(const std::vector<uint8_t>& encodedCbor, size_t maxBStrSize = 32,
-                        const std::vector<std::string>& mapKeysNotToPrint = {});
+                        const std::vector<std::string>& mapKeysToNotPrint = {});
 
 /**
  * Details. Mostly you shouldn't have to look below, except perhaps at the docstring for makeItem.
diff --git a/src/cppbor.cpp b/src/cppbor.cpp
index 0e9c939..9236d15 100644
--- a/src/cppbor.cpp
+++ b/src/cppbor.cpp
@@ -18,6 +18,7 @@
 
 #include <inttypes.h>
 #include <openssl/sha.h>
+#include <cstdint>
 
 #include "cppbor_parse.h"
 
@@ -132,9 +133,8 @@
                 const ViewBstr* viewBstr = item->asViewBstr();
                 assert(viewBstr != nullptr);
 
-                std::basic_string_view view = viewBstr->view();
-                valueData = view.data();
-                valueSize = view.size();
+                valueData = viewBstr->view().data();
+                valueSize = viewBstr->view().size();
             }
 
             if (valueSize > maxBStrSize) {
diff --git a/src/cppbor_parse.cpp b/src/cppbor_parse.cpp
index 9d388a3..a221cf4 100644
--- a/src/cppbor_parse.cpp
+++ b/src/cppbor_parse.cpp
@@ -16,6 +16,7 @@
 
 #include "cppbor_parse.h"
 
+#include <sstream>
 #include <stack>
 
 #ifndef __TRUSTY__
diff --git a/tests/cppbor_test.cpp b/tests/cppbor_test.cpp
index ebdcc02..68778dc 100644
--- a/tests/cppbor_test.cpp
+++ b/tests/cppbor_test.cpp
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#include <cstdint>
 #include <iomanip>
 #include <sstream>
 
@@ -27,13 +28,11 @@
 using namespace std;
 
 using ::testing::_;
-using ::testing::AllOf;
 using ::testing::ByRef;
 using ::testing::InSequence;
 using ::testing::IsNull;
 using ::testing::NotNull;
 using ::testing::Return;
-using ::testing::Truly;
 using ::testing::Unused;
 
 string hexDump(const string& str) {
@@ -254,7 +253,6 @@
               details::makeItem(s2)->toString());  // copy of const string
     EXPECT_EQ("\x65\x68\x65\x6c\x6c\x6f"s,
               details::makeItem(std::move(s1))->toString());  // move string
-    EXPECT_EQ(0U, s1.size());                                 // Prove string was moved, not copied.
 }
 
 TEST(MakeEntryTest, StdStringViews) {
@@ -716,7 +714,7 @@
 TEST(ConvertTest, Uint) {
     unique_ptr<Item> item = details::makeItem(10);
 
-    EXPECT_EQ(UINT, item->type());
+    EXPECT_EQ(cppbor::UINT, item->type());
     EXPECT_NE(nullptr, item->asInt());
     EXPECT_NE(nullptr, item->asUint());
     EXPECT_EQ(nullptr, item->asNint());
@@ -803,7 +801,7 @@
     EXPECT_EQ(nullptr, item->asViewTstr());
     EXPECT_EQ(nullptr, item->asViewBstr());
 
-    EXPECT_EQ(BOOLEAN, item->asSimple()->simpleType());
+    EXPECT_EQ(cppbor::BOOLEAN, item->asSimple()->simpleType());
     EXPECT_NE(nullptr, item->asSimple()->asBool());
     EXPECT_EQ(nullptr, item->asSimple()->asNull());
 
@@ -944,7 +942,7 @@
 
 TEST(ConvertTest, ViewBstr) {
     array<uint8_t, 3> vec{0x23, 0x24, 0x22};
-    basic_string_view sv(vec.data(), vec.size());
+    basic_string_view<uint8_t> sv(vec.data(), vec.size());
     unique_ptr<Item> item = details::makeItem(ViewBstr(sv));
 
     EXPECT_EQ(BSTR, item->type());
@@ -965,7 +963,7 @@
 TEST(CloningTest, Uint) {
     Uint item(10);
     auto clone = item.clone();
-    EXPECT_EQ(clone->type(), UINT);
+    EXPECT_EQ(clone->type(), cppbor::UINT);
     EXPECT_NE(clone->asUint(), nullptr);
     EXPECT_EQ(item, *clone->asUint());
     EXPECT_EQ(*clone->asUint(), Uint(10));
@@ -1025,7 +1023,7 @@
     auto clone = item.clone();
     EXPECT_EQ(clone->type(), SIMPLE);
     EXPECT_NE(clone->asSimple(), nullptr);
-    EXPECT_EQ(clone->asSimple()->simpleType(), BOOLEAN);
+    EXPECT_EQ(clone->asSimple()->simpleType(), cppbor::BOOLEAN);
     EXPECT_NE(clone->asSimple()->asBool(), nullptr);
     EXPECT_EQ(item, *clone->asSimple()->asBool());
     EXPECT_EQ(*clone->asSimple()->asBool(), Bool(true));
@@ -1081,7 +1079,7 @@
 
 TEST(CloningTest, ViewBstr) {
     array<uint8_t, 5> vec{1, 2, 3, 255, 0};
-    basic_string_view sv(vec.data(), vec.size());
+    basic_string_view<uint8_t> sv(vec.data(), vec.size());
     ViewBstr item(sv);
     auto clone = item.clone();
     EXPECT_EQ(clone->type(), BSTR);
@@ -1707,11 +1705,14 @@
 }
 
 TEST(FullParserTest, ViewBstr) {
-    ViewBstr val("\x00\x01\x02"s);
+    const std::string strVal = "\x00\x01\x02"s;
+    const ViewBstr val(strVal);
+    EXPECT_EQ(val.toString(), "\x43\x00\x01\x02"s);
 
     auto enc = val.encode();
     auto [item, pos, message] = parseWithViews(enc.data(), enc.size());
     EXPECT_THAT(item, MatchesItem(val));
+    EXPECT_EQ(hexDump(item->toString()), hexDump(val.toString()));
 }
 
 TEST(FullParserTest, ReservedAdditionalInformation) {