From 18c09c5abe14905cb91f1e05ff36221b0471f527 Mon Sep 17 00:00:00 2001 From: Alexey Polyudov Date: Thu, 2 Apr 2020 14:35:31 -0700 Subject: [PATCH] Fix build and tests Signed-off-by: Alexey Polyudov Change-Id: I3671e40fd0f8f028e3c8e46c4a47de0d2cc9aeff --- cpp/core/check_compilation.cc | 5 +++++ cpp/core/internal/ble_advertisement.cc | 2 +- cpp/core/internal/mediums/CMakeLists.txt | 5 +++++ .../mediums/advertisement_read_result_test.cc | 10 ++++++++++ cpp/core/internal/mediums/ble_advertisement.cc | 2 ++ .../internal/mediums/ble_advertisement_header.cc | 2 ++ cpp/core/internal/mediums/ble_packet.cc | 1 + cpp/core/internal/offline_frames.h | 2 +- cpp/platform/CMakeLists.txt | 1 + cpp/platform/base64_utils.cc | 15 ++++++++------- cpp/platform/base64_utils.h | 8 +------- cpp/platform/byte_array.h | 8 ++------ cpp/platform/file_impl_test.cc | 8 ++++---- cpp/platform/pipe_test.cc | 2 +- cpp/platform/port/config.h | 4 ++-- 15 files changed, 46 insertions(+), 29 deletions(-) diff --git a/cpp/core/check_compilation.cc b/cpp/core/check_compilation.cc index 23941a86..3d62e379 100644 --- a/cpp/core/check_compilation.cc +++ b/cpp/core/check_compilation.cc @@ -117,3 +117,8 @@ void check_compilation() { } // namespace connections } // namespace nearby } // namespace location + +int main() { + location::nearby::connections::check_compilation(); + return 0; +} diff --git a/cpp/core/internal/ble_advertisement.cc b/cpp/core/internal/ble_advertisement.cc index e97ba86b..aaf602f9 100644 --- a/cpp/core/internal/ble_advertisement.cc +++ b/cpp/core/internal/ble_advertisement.cc @@ -186,7 +186,7 @@ std::string BLEAdvertisement::hexBytesToColonDelimitedString( ConstPtr hex_bytes) { // Convert the hex bytes to a string. std::string colon_delimited_string(absl::BytesToHexString( - std::string(hex_bytes->getData(), hex_bytes->size()))); + hex_bytes->asString())); absl::AsciiStrToUpper(&colon_delimited_string); // Insert the colons. diff --git a/cpp/core/internal/mediums/CMakeLists.txt b/cpp/core/internal/mediums/CMakeLists.txt index e9d3b84b..311f7084 100644 --- a/cpp/core/internal/mediums/CMakeLists.txt +++ b/cpp/core/internal/mediums/CMakeLists.txt @@ -55,3 +55,8 @@ target_link_libraries(core_internal_mediums_test platform_impl_default platform_utils ) + +add_test( + NAME core_internal_mediums_test + COMMAND core_internal_mediums_test +) diff --git a/cpp/core/internal/mediums/advertisement_read_result_test.cc b/cpp/core/internal/mediums/advertisement_read_result_test.cc index dd3e7c8b..7ef20ffd 100644 --- a/cpp/core/internal/mediums/advertisement_read_result_test.cc +++ b/cpp/core/internal/mediums/advertisement_read_result_test.cc @@ -38,6 +38,16 @@ const absl::Duration kAdvertisementMaxBackoffDuration = absl::Milliseconds(6000); // 6 seconds const char kAdvertisementBytes[] = {0x0A, 0x0B, 0x0C}; +template<> +const std::int64_t AdvertisementReadResult< + SamplePlatform>::kAdvertisementBaseBackoffDurationMillis = + absl::ToInt64Milliseconds(kAdvertisementBaseBackoffDuration); + +template<> +const std::int64_t AdvertisementReadResult< + SamplePlatform>::kAdvertisementMaxBackoffDurationMillis = + absl::ToInt64Milliseconds(kAdvertisementMaxBackoffDuration); + TEST(AdvertisementReadResultTest, AdvertisementExists) { AdvertisementReadResult advertisement_read_result; advertisement_read_result.recordLastReadStatus(/* is_success= */ true); diff --git a/cpp/core/internal/mediums/ble_advertisement.cc b/cpp/core/internal/mediums/ble_advertisement.cc index 050c51a1..e83d8d3b 100644 --- a/cpp/core/internal/mediums/ble_advertisement.cc +++ b/cpp/core/internal/mediums/ble_advertisement.cc @@ -1,5 +1,7 @@ #include "core/internal/mediums/ble_advertisement.h" +#include + #include "platform/logging.h" namespace location { diff --git a/cpp/core/internal/mediums/ble_advertisement_header.cc b/cpp/core/internal/mediums/ble_advertisement_header.cc index e433877d..9935e9b3 100644 --- a/cpp/core/internal/mediums/ble_advertisement_header.cc +++ b/cpp/core/internal/mediums/ble_advertisement_header.cc @@ -1,5 +1,7 @@ #include "core/internal/mediums/ble_advertisement_header.h" +#include + #include "platform/base64_utils.h" #include "platform/byte_array.h" #include "platform/logging.h" diff --git a/cpp/core/internal/mediums/ble_packet.cc b/cpp/core/internal/mediums/ble_packet.cc index 3f5fad02..be7a9bb8 100644 --- a/cpp/core/internal/mediums/ble_packet.cc +++ b/cpp/core/internal/mediums/ble_packet.cc @@ -1,5 +1,6 @@ #include "core/internal/mediums/ble_packet.h" +#include #include #include "platform/logging.h" diff --git a/cpp/core/internal/offline_frames.h b/cpp/core/internal/offline_frames.h index 425bac06..e29699bf 100644 --- a/cpp/core/internal/offline_frames.h +++ b/cpp/core/internal/offline_frames.h @@ -13,7 +13,7 @@ // Detects the right usage. #include "google/protobuf/message_lite.h" -#define proto_ns google3_proto_compat +#define proto_ns google::protobuf namespace location { diff --git a/cpp/platform/CMakeLists.txt b/cpp/platform/CMakeLists.txt index de8405cc..f7a3c1d8 100644 --- a/cpp/platform/CMakeLists.txt +++ b/cpp/platform/CMakeLists.txt @@ -59,6 +59,7 @@ target_link_libraries(platform_test absl::base absl::strings absl::time + gmock gtest gtest_main platform_api diff --git a/cpp/platform/base64_utils.cc b/cpp/platform/base64_utils.cc index 51cb5635..2cb03359 100644 --- a/cpp/platform/base64_utils.cc +++ b/cpp/platform/base64_utils.cc @@ -1,6 +1,5 @@ #include "platform/base64_utils.h" -#include "strings/escaping.h" #include "absl/strings/escaping.h" namespace location { @@ -10,8 +9,7 @@ std::string Base64Utils::encode(ConstPtr bytes) { std::string base64_string; if (!bytes.isNull()) { - absl::WebSafeBase64Escape(std::string(bytes->getData(), bytes->size()), - &base64_string); + absl::WebSafeBase64Escape(bytes->asString(), &base64_string); } return base64_string; @@ -19,8 +17,7 @@ std::string Base64Utils::encode(ConstPtr bytes) { std::string Base64Utils::encode(const ByteArray& bytes) { std::string base64_string; - absl::WebSafeBase64Escape(std::string(bytes.getData(), bytes.size()), - &base64_string); + absl::WebSafeBase64Escape(bytes.asString(), &base64_string); return base64_string; } @@ -39,7 +36,7 @@ Ptr Base64Utils::decode(const std::string& base64_string) { return Ptr(); } - return MakePtr(new ByteArray(decoded_string.data(), decoded_string.size())); + return MakePtr(new ByteArray(decoded_string)); } template<> @@ -49,7 +46,11 @@ ByteArray Base64Utils::decode(const std::string& base64_string) { return ByteArray(); } - return ByteArray(decoded_string.data(), decoded_string.size()); + return ByteArray(decoded_string); +} + +Ptr Base64Utils::decode(const std::string& base64_string) { + return decode>(base64_string); } } // namespace nearby diff --git a/cpp/platform/base64_utils.h b/cpp/platform/base64_utils.h index 76b8cb7d..70704b82 100644 --- a/cpp/platform/base64_utils.h +++ b/cpp/platform/base64_utils.h @@ -16,13 +16,7 @@ class Base64Utils { template static T decode(const std::string& base64_string); - template <> - Ptr decode(const std::string& base64_string); - template <> - ByteArray decode(const std::string& base64_string); - static Ptr decode(const std::string& base64_string) { - return decode>(base64_string); - } + static Ptr decode(const std::string& base64_string); }; } // namespace nearby diff --git a/cpp/platform/byte_array.h b/cpp/platform/byte_array.h index a3ea830e..49f9bf88 100644 --- a/cpp/platform/byte_array.h +++ b/cpp/platform/byte_array.h @@ -43,15 +43,11 @@ class ByteArray { // Operator overloads when comparing ConstPtr. bool operator==(const ByteArray& rhs) const { - return this->size() == rhs.size() && - memcmp(this->getData(), rhs.getData(), this->size()) == 0; + return this->data_ == rhs.data_; } bool operator!=(const ByteArray& rhs) const { return !(*this == rhs); } bool operator<(const ByteArray& rhs) const { - if (this->size() != rhs.size()) { - return this->size() < rhs.size(); - } - return memcmp(this->getData(), rhs.getData(), this->size()) < 0; + return this->data_ < rhs.data_; } // TODO(b/149869249) : rename according to go/c-style std::string asString() const { return data_; } diff --git a/cpp/platform/file_impl_test.cc b/cpp/platform/file_impl_test.cc index f1397d5c..f37e0b91 100644 --- a/cpp/platform/file_impl_test.cc +++ b/cpp/platform/file_impl_test.cc @@ -1,21 +1,22 @@ #include "platform/file_impl.h" +#include #include #include #include #include +#include -#include "file/util/temp_path.h" #include "gtest/gtest.h" namespace location { namespace nearby { + class FileImplTest : public ::testing::Test { protected: void SetUp() override { - temp_path_ = std::make_unique(TempPath::Local); - path_ = temp_path_->path() + "/file.txt"; + path_ = std::tmpnam(nullptr);; std::ofstream output_file(path_); file_ = std::fstream(path_, std::fstream::in | std::fstream::out); } @@ -43,7 +44,6 @@ class FileImplTest : public ::testing::Test { static const int64_t kMaxSize = 3; - std::unique_ptr temp_path_; std::string path_; std::fstream file_; size_t size_ = 0; diff --git a/cpp/platform/pipe_test.cc b/cpp/platform/pipe_test.cc index 35b97a2d..f4f2799b 100644 --- a/cpp/platform/pipe_test.cc +++ b/cpp/platform/pipe_test.cc @@ -11,7 +11,7 @@ #include "platform/ptr.h" #include "platform/runnable.h" #include "gtest/gtest.h" -#include "absl/time/time.h" +#include "absl/time/clock.h" namespace location { namespace nearby { diff --git a/cpp/platform/port/config.h b/cpp/platform/port/config.h index 841168b0..19857578 100644 --- a/cpp/platform/port/config.h +++ b/cpp/platform/port/config.h @@ -12,11 +12,11 @@ // #endif #ifndef NEARBY_USE_STD_STRING -#define NEARBY_USE_STD_STRING 0 +#define NEARBY_USE_STD_STRING 1 #endif #ifndef NEARBY_USE_RTTI -#define NEARBY_USE_RTTI 1 +#define NEARBY_USE_RTTI 0 #endif #endif // PLATFORM_PORT_CONFIG_H_