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 @@ ...@@ -5,9 +5,9 @@
#ifndef CHROME_INSTALLER_ZUCCHINI_BUFFER_SINK_H_ #ifndef CHROME_INSTALLER_ZUCCHINI_BUFFER_SINK_H_
#define CHROME_INSTALLER_ZUCCHINI_BUFFER_SINK_H_ #define CHROME_INSTALLER_ZUCCHINI_BUFFER_SINK_H_
#include <stdint.h>
#include <algorithm> #include <algorithm>
#include <cstddef>
#include <cstdint>
#include <iterator> #include <iterator>
#include "base/logging.h" #include "base/logging.h"
...@@ -28,12 +28,11 @@ class BufferSink : public MutableBufferView { ...@@ -28,12 +28,11 @@ class BufferSink : public MutableBufferView {
BufferSink() = default; BufferSink() = default;
explicit BufferSink(MutableBufferView buffer); explicit BufferSink(MutableBufferView buffer);
BufferSink(const BufferSink&) = default; BufferSink(const BufferSink&) = default;
BufferSink& operator=(BufferSink&&) = default; BufferSink& operator=(BufferSink&&) = default;
// If sufficient space is available, writes the binary representation of // If sufficient space is available, writes the binary representation of
// |value| starting at cursor, while advancing the cursor beyond the written // |value| starting at the cursor, while advancing the cursor beyond the
// region, and returns true. Otherwise returns false. // written region, and returns true. Otherwise returns false.
template <class T> template <class T>
bool PutValue(const T& value) { bool PutValue(const T& value) {
DCHECK_NE(begin(), nullptr); DCHECK_NE(begin(), nullptr);
...@@ -45,8 +44,8 @@ class BufferSink : public MutableBufferView { ...@@ -45,8 +44,8 @@ class BufferSink : public MutableBufferView {
} }
// If sufficient space is available, writes the raw bytes [|first|, |last|) // If sufficient space is available, writes the raw bytes [|first|, |last|)
// starting at cursor, while advancing the cursor beyond the written region, // starting at the cursor, while advancing the cursor beyond the written
// and returns true. Otherwise returns false. // region, and returns true. Otherwise returns false.
template <class It> template <class It>
bool PutRange(It first, It last) { bool PutRange(It first, It last) {
static_assert(sizeof(typename std::iterator_traits<It>::value_type) == static_assert(sizeof(typename std::iterator_traits<It>::value_type) ==
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#include <vector> #include <vector>
#include "base/test/gtest_util.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace zucchini { namespace zucchini {
...@@ -15,10 +14,8 @@ constexpr uint8_t kUninit = 0xFF; ...@@ -15,10 +14,8 @@ constexpr uint8_t kUninit = 0xFF;
class BufferSinkTest : public testing::Test { class BufferSinkTest : public testing::Test {
protected: protected:
void SetUp() override { BufferSinkTest()
buffer_ = std::vector<uint8_t>(10, kUninit); : buffer_(10, kUninit), sink_(buffer_.data(), buffer_.size()) {}
sink_ = BufferSink(buffer_.data(), buffer_.size());
}
std::vector<uint8_t> buffer_; std::vector<uint8_t> buffer_;
BufferSink sink_; BufferSink sink_;
......
...@@ -5,12 +5,13 @@ ...@@ -5,12 +5,13 @@
#ifndef CHROME_INSTALLER_ZUCCHINI_BUFFER_SOURCE_H_ #ifndef CHROME_INSTALLER_ZUCCHINI_BUFFER_SOURCE_H_
#define CHROME_INSTALLER_ZUCCHINI_BUFFER_SOURCE_H_ #define CHROME_INSTALLER_ZUCCHINI_BUFFER_SOURCE_H_
#include <algorithm> #include <stddef.h>
#include <cstddef> #include <stdint.h>
#include <cstdint>
#include <initializer_list> #include <initializer_list>
#include <type_traits> #include <type_traits>
#include "base/logging.h"
#include "chrome/installer/zucchini/buffer_view.h" #include "chrome/installer/zucchini/buffer_view.h"
namespace zucchini { namespace zucchini {
...@@ -30,10 +31,9 @@ class BufferSource : public ConstBufferView { ...@@ -30,10 +31,9 @@ class BufferSource : public ConstBufferView {
BufferSource() = default; BufferSource() = default;
explicit BufferSource(ConstBufferView buffer); explicit BufferSource(ConstBufferView buffer);
BufferSource(const BufferSource&) = default; BufferSource(const BufferSource&) = default;
BufferSource& operator=(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.: // Returns a reference to *this, to allow chaining, e.g.:
// if (!buffer_source.Skip(1024).GetValue<uint32_t>(&value)) { // if (!buffer_source.Skip(1024).GetValue<uint32_t>(&value)) {
// ... // Handle error. // ... // Handle error.
...@@ -41,8 +41,8 @@ class BufferSource : public ConstBufferView { ...@@ -41,8 +41,8 @@ class BufferSource : public ConstBufferView {
// Notice that Skip() defers error handling to GetValue(). // Notice that Skip() defers error handling to GetValue().
BufferSource& Skip(size_type n); BufferSource& Skip(size_type n);
// Returns true if |value| matches data starting at cursor when reinterpreted // Returns true if |value| matches data starting at the cursor when
// as the integral type |T|. // reinterpreted as the integral type |T|.
template <class T> template <class T>
bool CheckNextValue(const T& value) const { bool CheckNextValue(const T& value) const {
static_assert(std::is_integral<T>::value, static_assert(std::is_integral<T>::value,
...@@ -62,9 +62,9 @@ class BufferSource : public ConstBufferView { ...@@ -62,9 +62,9 @@ class BufferSource : public ConstBufferView {
// successfull. // successfull.
bool ConsumeBytes(std::initializer_list<uint8_t> bytes); bool ConsumeBytes(std::initializer_list<uint8_t> bytes);
// Tries to reinterpret data as type |T|, starting at cursor and to write the // Tries to reinterpret data as type |T|, starting at the cursor and to write
// result into |value|, while moving the cursor forward by sizeof(T). Returns // the result into |value|, while moving the cursor forward by sizeof(T).
// true if sufficient data is available, and false otherwise. // Returns true if sufficient data is available, and false otherwise.
template <class T> template <class T>
bool GetValue(T* value) { bool GetValue(T* value) {
static_assert(std::is_standard_layout<T>::value, static_assert(std::is_standard_layout<T>::value,
...@@ -78,7 +78,7 @@ class BufferSource : public ConstBufferView { ...@@ -78,7 +78,7 @@ class BufferSource : public ConstBufferView {
return true; 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 // reinterpreted pointer of type |T| pointing into the underlying data, while
// moving the cursor forward by sizeof(T). Returns nullptr if insufficient // moving the cursor forward by sizeof(T). Returns nullptr if insufficient
// data is available. // data is available.
...@@ -96,7 +96,7 @@ class BufferSource : public ConstBufferView { ...@@ -96,7 +96,7 @@ class BufferSource : public ConstBufferView {
} }
// Tries to reinterpret data as an array of type |T| with |count| elements, // 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 // pointing into the underlying data, while advancing the cursor beyond the
// array. Returns nullptr if insufficient data is available. // array. Returns nullptr if insufficient data is available.
template <class T> template <class T>
...@@ -112,7 +112,7 @@ class BufferSource : public ConstBufferView { ...@@ -112,7 +112,7 @@ class BufferSource : public ConstBufferView {
} }
// If sufficient data is available, assigns |buffer| to point to a region of // 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. // region, and returns true. Otherwise returns false.
bool GetRegion(size_type size, ConstBufferView* buffer); bool GetRegion(size_type size, ConstBufferView* buffer);
......
...@@ -4,18 +4,19 @@ ...@@ -4,18 +4,19 @@
#include "chrome/installer/zucchini/buffer_source.h" #include "chrome/installer/zucchini/buffer_source.h"
#include <cstdint> #include <stdint.h>
#include <iterator> #include <iterator>
#include <vector> #include <vector>
#include "base/test/gtest_util.h" #include "testing/gtest/include/gtest/gtest.h"
namespace zucchini { namespace zucchini {
using vec = std::vector<uint8_t>; using vec = std::vector<uint8_t>;
static constexpr size_t kLen = 10; constexpr size_t kLen = 10;
constexpr const uint8_t bytes[kLen] = {0x10, 0x32, 0x54, 0x76, 0x98, constexpr uint8_t bytes[kLen] = {0x10, 0x32, 0x54, 0x76, 0x98,
0xBA, 0xDC, 0xFE, 0x10, 0x00}; 0xBA, 0xDC, 0xFE, 0x10, 0x00};
class BufferSourceTest : public testing::Test { class BufferSourceTest : public testing::Test {
......
...@@ -5,8 +5,9 @@ ...@@ -5,8 +5,9 @@
#ifndef CHROME_INSTALLER_ZUCCHINI_BUFFER_VIEW_H_ #ifndef CHROME_INSTALLER_ZUCCHINI_BUFFER_VIEW_H_
#define CHROME_INSTALLER_ZUCCHINI_BUFFER_VIEW_H_ #define CHROME_INSTALLER_ZUCCHINI_BUFFER_VIEW_H_
#include <cstddef> #include <stddef.h>
#include <cstdint> #include <stdint.h>
#include <type_traits> #include <type_traits>
#include "base/logging.h" #include "base/logging.h"
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#ifndef CHROME_INSTALLER_ZUCCHINI_CRC32_H_ #ifndef CHROME_INSTALLER_ZUCCHINI_CRC32_H_
#define CHROME_INSTALLER_ZUCCHINI_CRC32_H_ #define CHROME_INSTALLER_ZUCCHINI_CRC32_H_
#include <cstdint> #include <stdint.h>
namespace zucchini { namespace zucchini {
......
...@@ -4,7 +4,8 @@ ...@@ -4,7 +4,8 @@
#include "chrome/installer/zucchini/crc32.h" #include "chrome/installer/zucchini/crc32.h"
#include <cstdint> #include <stdint.h>
#include <iterator> #include <iterator>
#include "base/test/gtest_util.h" #include "base/test/gtest_util.h"
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#ifndef CHROME_INSTALLER_ZUCCHINI_IMAGE_UTILS_H_ #ifndef CHROME_INSTALLER_ZUCCHINI_IMAGE_UTILS_H_
#define 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" #include "chrome/installer/zucchini/typed_value.h"
......
...@@ -5,7 +5,8 @@ ...@@ -5,7 +5,8 @@
#ifndef CHROME_INSTALLER_ZUCCHINI_PATCH_UTILS_H_ #ifndef CHROME_INSTALLER_ZUCCHINI_PATCH_UTILS_H_
#define CHROME_INSTALLER_ZUCCHINI_PATCH_UTILS_H_ #define CHROME_INSTALLER_ZUCCHINI_PATCH_UTILS_H_
#include <cstdint> #include <stdint.h>
#include <type_traits> #include <type_traits>
#include "base/logging.h" #include "base/logging.h"
......
...@@ -4,7 +4,8 @@ ...@@ -4,7 +4,8 @@
#include "chrome/installer/zucchini/patch_utils.h" #include "chrome/installer/zucchini/patch_utils.h"
#include <cstdint> #include <stdint.h>
#include <iterator> #include <iterator>
#include <vector> #include <vector>
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#define CHROME_INSTALLER_ZUCCHINI_SUFFIX_ARRAY_H_ #define CHROME_INSTALLER_ZUCCHINI_SUFFIX_ARRAY_H_
#include <algorithm> #include <algorithm>
#include <cassert>
#include <iterator> #include <iterator>
#include <numeric> #include <numeric>
#include <vector> #include <vector>
......
...@@ -4,8 +4,9 @@ ...@@ -4,8 +4,9 @@
#include "chrome/installer/zucchini/suffix_array.h" #include "chrome/installer/zucchini/suffix_array.h"
#include <stddef.h>
#include <algorithm> #include <algorithm>
#include <cstddef>
#include <initializer_list> #include <initializer_list>
#include <string> #include <string>
#include <vector> #include <vector>
......
...@@ -5,8 +5,6 @@ ...@@ -5,8 +5,6 @@
#ifndef CHROME_INSTALLER_ZUCCHINI_TYPED_VALUE_H_ #ifndef CHROME_INSTALLER_ZUCCHINI_TYPED_VALUE_H_
#define CHROME_INSTALLER_ZUCCHINI_TYPED_VALUE_H_ #define CHROME_INSTALLER_ZUCCHINI_TYPED_VALUE_H_
#include <cstdint>
namespace zucchini { namespace zucchini {
// Strong typed values, with compare and convert functions for underlying data. // 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