Fix build and tests

Signed-off-by: Alexey Polyudov <apolyudov@google.com>
Change-Id: I3671e40fd0f8f028e3c8e46c4a47de0d2cc9aeff
This commit is contained in:
Alexey Polyudov
2020-04-04 12:55:06 -07:00
parent a067c89eca
commit 18c09c5abe
15 changed files with 46 additions and 29 deletions
+5
View File
@@ -117,3 +117,8 @@ void check_compilation() {
} // namespace connections
} // namespace nearby
} // namespace location
int main() {
location::nearby::connections::check_compilation();
return 0;
}
+1 -1
View File
@@ -186,7 +186,7 @@ std::string BLEAdvertisement::hexBytesToColonDelimitedString(
ConstPtr<ByteArray> 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.
+5
View File
@@ -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
)
@@ -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<SamplePlatform> advertisement_read_result;
advertisement_read_result.recordLastReadStatus(/* is_success= */ true);
@@ -1,5 +1,7 @@
#include "core/internal/mediums/ble_advertisement.h"
#include <cstring>
#include "platform/logging.h"
namespace location {
@@ -1,5 +1,7 @@
#include "core/internal/mediums/ble_advertisement_header.h"
#include <cstring>
#include "platform/base64_utils.h"
#include "platform/byte_array.h"
#include "platform/logging.h"
+1
View File
@@ -1,5 +1,6 @@
#include "core/internal/mediums/ble_packet.h"
#include <cstring>
#include <limits>
#include "platform/logging.h"
+1 -1
View File
@@ -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 {
+1
View File
@@ -59,6 +59,7 @@ target_link_libraries(platform_test
absl::base
absl::strings
absl::time
gmock
gtest
gtest_main
platform_api
+8 -7
View File
@@ -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<ByteArray> 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<ByteArray> 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<ByteArray> Base64Utils::decode(const std::string& base64_string) {
return Ptr<ByteArray>();
}
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<ByteArray> Base64Utils::decode(const std::string& base64_string) {
return decode<Ptr<ByteArray>>(base64_string);
}
} // namespace nearby
+1 -7
View File
@@ -16,13 +16,7 @@ class Base64Utils {
template <typename T>
static T decode(const std::string& base64_string);
template <>
Ptr<ByteArray> decode(const std::string& base64_string);
template <>
ByteArray decode(const std::string& base64_string);
static Ptr<ByteArray> decode(const std::string& base64_string) {
return decode<Ptr<ByteArray>>(base64_string);
}
static Ptr<ByteArray> decode(const std::string& base64_string);
};
} // namespace nearby
+2 -6
View File
@@ -43,15 +43,11 @@ class ByteArray {
// Operator overloads when comparing ConstPtr<ByteArray>.
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_; }
+4 -4
View File
@@ -1,21 +1,22 @@
#include "platform/file_impl.h"
#include <cstdio>
#include <cstring>
#include <fstream>
#include <memory>
#include <ostream>
#include <unistd.h>
#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>(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<TempPath> temp_path_;
std::string path_;
std::fstream file_;
size_t size_ = 0;
+1 -1
View File
@@ -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 {
+2 -2
View File
@@ -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_