Merge "Fix minor linter issues around includes and using."

This commit is contained in:
Treehugger Robot authored and Gerrit Code Review committed 2017-09-25 21:19:40 +00:00
commit cef30b3142
2 files changed
+13 -16

No files matched your search

+2 -4
View File
@@ -10,8 +10,6 @@
#include "bsdiff/test_utils.h"
using std::string;
using std::vector;
using test_utils::BsdiffPatchFile;
namespace bsdiff {
@@ -46,8 +44,8 @@ TEST_F(BsdiffTest, EqualEmptyFiles) {
}
TEST_F(BsdiffTest, EqualSmallFiles) {
string some_text = "Hello world!";
vector<uint8_t> vec_some_text(some_text.begin(), some_text.end());
std::string some_text = "Hello world!";
std::vector<uint8_t> vec_some_text(some_text.begin(), some_text.end());
test_utils::WriteFile(old_file_.filename(), vec_some_text);
EXPECT_EQ(0, bsdiff(old_file_.filename().c_str(),
new_file_.filename().c_str(),
+11 -12
View File
@@ -11,9 +11,7 @@
#include <unistd.h>
#include <gtest/gtest.h>
#include <vector>
using std::string;
using std::vector;
namespace {
@@ -22,17 +20,18 @@ namespace {
// leaves it as is. Otherwise, if TMPDIR is defined in the environment and is
// non-empty, prepends it to |path|. Otherwise, prepends /tmp. Returns the
// resulting path.
const string PrependTmpdir(const string& path) {
const std::string PrependTmpdir(const std::string& path) {
if (path[0] == '/')
return path;
const char* tmpdir = getenv("TMPDIR");
const string prefix = (tmpdir && *tmpdir ? tmpdir : "/tmp");
const std::string prefix = (tmpdir && *tmpdir ? tmpdir : "/tmp");
return prefix + "/" + path;
}
bool MakeTempFile(const string& base_filename_template, string* filename) {
const string filename_template = PrependTmpdir(base_filename_template);
bool MakeTempFile(const std::string& base_filename_template,
std::string* filename) {
const std::string filename_template = PrependTmpdir(base_filename_template);
vector<char> result(filename_template.size() + 1, '\0');
memcpy(result.data(), filename_template.data(), filename_template.size());
@@ -59,10 +58,10 @@ void BsdiffTestEnvironment::SetUp() {
mkdir(BSDIFF_TARGET_TMP_BASE, S_IRWXU | S_IRWXG | S_IROTH | S_IWOTH);
}
setenv("TMPDIR", BSDIFF_TARGET_TMP_BASE, 1);
#endif // defined (BSDIFF_TARGET_UNITTEST)
#endif // defined (BSDIFF_TARGET_UNITTEST)
}
bool ReadFile(const string& path, vector<uint8_t>* out) {
bool ReadFile(const std::string& path, vector<uint8_t>* out) {
FILE* fp = fopen(path.c_str(), "r");
if (!fp)
return false;
@@ -80,7 +79,7 @@ bool ReadFile(const string& path, vector<uint8_t>* out) {
return result;
}
bool WriteFile(const string& path, vector<uint8_t> contents) {
bool WriteFile(const std::string& path, vector<uint8_t> contents) {
FILE* fp = fopen(path.c_str(), "r");
if (!fp)
return false;
@@ -90,7 +89,7 @@ bool WriteFile(const string& path, vector<uint8_t> contents) {
return result;
}
ScopedTempFile::ScopedTempFile(const string& pattern) {
ScopedTempFile::ScopedTempFile(const std::string& pattern) {
EXPECT_TRUE(MakeTempFile(pattern, &filename_));
}
@@ -100,14 +99,14 @@ ScopedTempFile::~ScopedTempFile() {
}
}
bool BsdiffPatchFile::LoadFromFile(const string& filename) {
bool BsdiffPatchFile::LoadFromFile(const std::string& filename) {
vector<uint8_t> contents;
if (!ReadFile(filename, &contents))
return false;
file_size = contents.size();
// Check that the file includes at least the header.
TEST_AND_RETURN_FALSE(contents.size() >= kHeaderSize);
magic = string(contents.data(), contents.data() + 8);
magic = std::string(contents.data(), contents.data() + 8);
memcpy(&ctrl_len, contents.data() + 8, sizeof(ctrl_len));
memcpy(&diff_len, contents.data() + 16, sizeof(diff_len));
memcpy(&new_file_len, contents.data() + 24, sizeof(new_file_len));