Commit 8acbe9a6 authored by Etienne Pierre-Doray's avatar Etienne Pierre-Doray Committed by Commit Bot

[Zucchini] Retroactive CR for 560657

Applying corrections upon grt@ review for 560657:

- Fix comments and style.
- Fix includes (remove unused, add missing).
- Switch from cstd* to std*.h.

Bug: 729154
Change-Id: Id63bdaf64e2e468e30f4615f7ea62ef817268b9a
Reviewed-on: https://chromium-review.googlesource.com/579582Reviewed-by: default avatarSamuel Huang <huangs@chromium.org>
Reviewed-by: default avatarGreg Thompson <grt@chromium.org>
Commit-Queue: Etienne Pierre-Doray <etiennep@chromium.org>
Cr-Commit-Position: refs/heads/master@{#488672}
parent 8af7f593
......@@ -5,9 +5,9 @@
#ifndef CHROME_INSTALLER_ZUCCHINI_BUFFER_SINK_H_
#define CHROME_INSTALLER_ZUCCHINI_BUFFER_SINK_H_
#include <stdint.h>
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <iterator>
#include "base/logging.h"
......@@ -28,12 +28,11 @@ class BufferSink : public MutableBufferView {
BufferSink() = default;
explicit BufferSink(MutableBufferView buffer);
BufferSink(const BufferSink&) = default;
BufferSink& operator=(BufferSink&&) = default;
// If sufficient space is available, writes the binary representation of
// |value| starting at cursor, while advancing the cursor beyond the written
// region, and returns true. Otherwise returns false.
// |value| starting at the cursor, while advancing the cursor beyond the
// written region, and returns true. Otherwise returns false.
template <class T>
bool PutValue(const T& value) {
DCHECK_NE(begin(), nullptr);
......@@ -45,8 +44,8 @@ class BufferSink : public MutableBufferView {
}
// If sufficient space is available, writes the raw bytes [|first|, |last|)
// starting at cursor, while advancing the cursor beyond the written region,
// and returns true. Otherwise returns false.
// starting at the cursor, while advancing the cursor beyond the written
// region, and returns true. Otherwise returns false.
template <class It>
bool PutRange(It first, It last) {
static_assert(sizeof(typename std::iterator_traits<It>::value_type) ==
......
......@@ -6,7 +6,6 @@
#include <vector>
#include "base/test/gtest_util.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace zucchini {
......@@ -15,10 +14,8 @@ constexpr uint8_t kUninit = 0xFF;
class BufferSinkTest : public testing::Test {
protected:
void SetUp() override {
buffer_ = std::vector<uint8_t>(10, kUninit);
sink_ = BufferSink(buffer_.data(), buffer_.size());
}
BufferSinkTest()
: buffer_(10, kUninit), sink_(buffer_.data(), buffer_.size()) {}
std::vector<uint8_t> buffer_;
BufferSink sink_;
......
......@@ -5,12 +5,13 @@
#ifndef CHROME_INSTALLER_ZUCCHINI_BUFFER_SOURCE_H_
#define CHROME_INSTALLER_ZUCCHINI_BUFFER_SOURCE_H_
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <stddef.h>
#include <stdint.h>
#include <initializer_list>
#include <type_traits>
#include "base/logging.h"
#include "chrome/installer/zucchini/buffer_view.h"
namespace zucchini {
......@@ -30,10 +31,9 @@ class BufferSource : public ConstBufferView {
BufferSource() = default;
explicit BufferSource(ConstBufferView buffer);
BufferSource(const BufferSource&) = default;
BufferSource& operator=(BufferSource&&) = default;
// Moves cursor forward by |n| bytes, or until end if data is exhausted.
// Moves the cursor forward by |n| bytes, or to the end if data is exhausted.
// Returns a reference to *this, to allow chaining, e.g.:
// if (!buffer_source.Skip(1024).GetValue<uint32_t>(&value)) {
// ... // Handle error.
......@@ -41,8 +41,8 @@ class BufferSource : public ConstBufferView {
// Notice that Skip() defers error handling to GetValue().
BufferSource& Skip(size_type n);
// Returns true if |value| matches data starting at cursor when reinterpreted
// as the integral type |T|.
// Returns true if |value| matches data starting at the cursor when
// reinterpreted as the integral type |T|.
template <class T>
bool CheckNextValue(const T& value) const {
static_assert(std::is_integral<T>::value,
......@@ -62,9 +62,9 @@ class BufferSource : public ConstBufferView {
// successfull.
bool ConsumeBytes(std::initializer_list<uint8_t> bytes);
// Tries to reinterpret data as type |T|, starting at cursor and to write the
// result into |value|, while moving the cursor forward by sizeof(T). Returns
// true if sufficient data is available, and false otherwise.
// Tries to reinterpret data as type |T|, starting at the cursor and to write
// the result into |value|, while moving the cursor forward by sizeof(T).
// Returns true if sufficient data is available, and false otherwise.
template <class T>
bool GetValue(T* value) {
static_assert(std::is_standard_layout<T>::value,
......@@ -78,7 +78,7 @@ class BufferSource : public ConstBufferView {
return true;
}
// Tries to reinterpret data as type |T| at cursor and to return a
// Tries to reinterpret data as type |T| at the cursor and to return a
// reinterpreted pointer of type |T| pointing into the underlying data, while
// moving the cursor forward by sizeof(T). Returns nullptr if insufficient
// data is available.
......@@ -96,7 +96,7 @@ class BufferSource : public ConstBufferView {
}
// Tries to reinterpret data as an array of type |T| with |count| elements,
// starting at cursor, and to return a reinterpreted pointer of type |T|
// starting at the cursor, and to return a reinterpreted pointer of type |T|
// pointing into the underlying data, while advancing the cursor beyond the
// array. Returns nullptr if insufficient data is available.
template <class T>
......@@ -112,7 +112,7 @@ class BufferSource : public ConstBufferView {
}
// If sufficient data is available, assigns |buffer| to point to a region of
// |size| bytes starting at cursor, while advancing the cursor beyond the
// |size| bytes starting at the cursor, while advancing the cursor beyond the
// region, and returns true. Otherwise returns false.
bool GetRegion(size_type size, ConstBufferView* buffer);
......
......@@ -4,19 +4,20 @@
#include "chrome/installer/zucchini/buffer_source.h"
#include <cstdint>
#include <stdint.h>
#include <iterator>
#include <vector>
#include "base/test/gtest_util.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace zucchini {
using vec = std::vector<uint8_t>;
static constexpr size_t kLen = 10;
constexpr const uint8_t bytes[kLen] = {0x10, 0x32, 0x54, 0x76, 0x98,
0xBA, 0xDC, 0xFE, 0x10, 0x00};
constexpr size_t kLen = 10;
constexpr uint8_t bytes[kLen] = {0x10, 0x32, 0x54, 0x76, 0x98,
0xBA, 0xDC, 0xFE, 0x10, 0x00};
class BufferSourceTest : public testing::Test {
protected:
......
......@@ -5,8 +5,9 @@
#ifndef CHROME_INSTALLER_ZUCCHINI_BUFFER_VIEW_H_
#define CHROME_INSTALLER_ZUCCHINI_BUFFER_VIEW_H_
#include <cstddef>
#include <cstdint>
#include <stddef.h>
#include <stdint.h>
#include <type_traits>
#include "base/logging.h"
......
......@@ -5,7 +5,7 @@
#ifndef CHROME_INSTALLER_ZUCCHINI_CRC32_H_
#define CHROME_INSTALLER_ZUCCHINI_CRC32_H_
#include <cstdint>
#include <stdint.h>
namespace zucchini {
......
......@@ -4,7 +4,8 @@
#include "chrome/installer/zucchini/crc32.h"
#include <cstdint>
#include <stdint.h>
#include <iterator>
#include "base/test/gtest_util.h"
......
......@@ -5,7 +5,7 @@
#ifndef CHROME_INSTALLER_ZUCCHINI_IMAGE_UTILS_H_
#define CHROME_INSTALLER_ZUCCHINI_IMAGE_UTILS_H_
#include <cstdint>
#include <stdint.h>
#include "chrome/installer/zucchini/typed_value.h"
......
......@@ -5,7 +5,8 @@
#ifndef CHROME_INSTALLER_ZUCCHINI_PATCH_UTILS_H_
#define CHROME_INSTALLER_ZUCCHINI_PATCH_UTILS_H_
#include <cstdint>
#include <stdint.h>
#include <type_traits>
#include "base/logging.h"
......
......@@ -4,7 +4,8 @@
#include "chrome/installer/zucchini/patch_utils.h"
#include <cstdint>
#include <stdint.h>
#include <iterator>
#include <vector>
......
......@@ -6,7 +6,6 @@
#define CHROME_INSTALLER_ZUCCHINI_SUFFIX_ARRAY_H_
#include <algorithm>
#include <cassert>
#include <iterator>
#include <numeric>
#include <vector>
......
......@@ -4,8 +4,9 @@
#include "chrome/installer/zucchini/suffix_array.h"
#include <stddef.h>
#include <algorithm>
#include <cstddef>
#include <initializer_list>
#include <string>
#include <vector>
......
......@@ -5,8 +5,6 @@
#ifndef CHROME_INSTALLER_ZUCCHINI_TYPED_VALUE_H_
#define CHROME_INSTALLER_ZUCCHINI_TYPED_VALUE_H_
#include <cstdint>
namespace zucchini {
// Strong typed values, with compare and convert functions for underlying data.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment