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
+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_