Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(221)

Side by Side Diff: chrome/common/partial_circular_buffer_unittest.cc

Issue 1880143002: Convert chrome/common to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // The test buffer data is 52 bytes, wrap position is set to 20 (this is 5 // The test buffer data is 52 bytes, wrap position is set to 20 (this is
6 // arbitrarily chosen). The total buffer size is allocated dynamically based on 6 // arbitrarily chosen). The total buffer size is allocated dynamically based on
7 // the actual header size. This gives: 7 // the actual header size. This gives:
8 // Header of some size, non-wrapping part 20 bytes, wrapping part 32 bytes. 8 // Header of some size, non-wrapping part 20 bytes, wrapping part 32 bytes.
9 // As input data, a 14 byte array is used and repeatedly written. It's chosen 9 // As input data, a 14 byte array is used and repeatedly written. It's chosen
10 // not to be an integer factor smaller than the wrapping part. This ensures that 10 // not to be an integer factor smaller than the wrapping part. This ensures that
11 // the wrapped data isn't repeated at the same position. 11 // the wrapped data isn't repeated at the same position.
12 // Note that desipte the number of wraps (if one or more), the reference output 12 // Note that desipte the number of wraps (if one or more), the reference output
13 // data is the same since the offset at each wrap is always the same. 13 // data is the same since the offset at each wrap is always the same.
14 14
15 #include "chrome/common/partial_circular_buffer.h"
16
15 #include <stddef.h> 17 #include <stddef.h>
16 #include <stdint.h> 18 #include <stdint.h>
17 19
20 #include <memory>
21
18 #include "base/macros.h" 22 #include "base/macros.h"
19 #include "base/memory/scoped_ptr.h"
20 #include "chrome/common/partial_circular_buffer.h"
21 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
22 24
23 const uint32_t kWrapPosition = 20; 25 const uint32_t kWrapPosition = 20;
24 const uint8_t kInputData[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}; 26 const uint8_t kInputData[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
25 const uint8_t kOutputRefDataWrap[] = 27 const uint8_t kOutputRefDataWrap[] =
26 // The 20 bytes in the non-wrapping part. 28 // The 20 bytes in the non-wrapping part.
27 {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 1, 2, 3, 4, 5, 6, 29 {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 1, 2, 3, 4, 5, 6,
28 // The 32 bytes in wrapping part. 30 // The 32 bytes in wrapping part.
29 11, 12, 13, 14, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 1, 2, 3, 4, 31 11, 12, 13, 14, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 1, 2, 3, 4,
30 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}; 32 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
(...skipping 21 matching lines...) Expand all
52 for (int i = 0; i < num; ++i) 54 for (int i = 0; i < num; ++i)
53 pcb_write_->Write(kInputData, sizeof(kInputData)); 55 pcb_write_->Write(kInputData, sizeof(kInputData));
54 } 56 }
55 57
56 void InitReadBuffer() { 58 void InitReadBuffer() {
57 pcb_read_.reset(new PartialCircularBuffer( 59 pcb_read_.reset(new PartialCircularBuffer(
58 buffer_.get(), buffer_header_size_ + sizeof(kOutputRefDataWrap))); 60 buffer_.get(), buffer_header_size_ + sizeof(kOutputRefDataWrap)));
59 } 61 }
60 62
61 protected: 63 protected:
62 scoped_ptr<PartialCircularBuffer> pcb_write_; 64 std::unique_ptr<PartialCircularBuffer> pcb_write_;
63 scoped_ptr<PartialCircularBuffer> pcb_read_; 65 std::unique_ptr<PartialCircularBuffer> pcb_read_;
64 scoped_ptr<uint8_t[]> buffer_; 66 std::unique_ptr<uint8_t[]> buffer_;
65 uint32_t buffer_header_size_; 67 uint32_t buffer_header_size_;
66 68
67 DISALLOW_COPY_AND_ASSIGN(PartialCircularBufferTest); 69 DISALLOW_COPY_AND_ASSIGN(PartialCircularBufferTest);
68 }; 70 };
69 71
70 TEST_F(PartialCircularBufferTest, NoWrapBeginningPartOnly) { 72 TEST_F(PartialCircularBufferTest, NoWrapBeginningPartOnly) {
71 InitWriteBuffer(false); 73 InitWriteBuffer(false);
72 WriteToBuffer(1); 74 WriteToBuffer(1);
73 InitReadBuffer(); 75 InitReadBuffer();
74 76
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 209
208 uint8_t output_data[sizeof(kOutputRefDataWrap)] = {0}; 210 uint8_t output_data[sizeof(kOutputRefDataWrap)] = {0};
209 EXPECT_EQ(sizeof(output_data), 211 EXPECT_EQ(sizeof(output_data),
210 pcb_read_->Read(output_data, sizeof(output_data))); 212 pcb_read_->Read(output_data, sizeof(output_data)));
211 213
212 EXPECT_EQ(0, memcmp(kOutputRefDataWrap, output_data, sizeof(output_data))); 214 EXPECT_EQ(0, memcmp(kOutputRefDataWrap, output_data, sizeof(output_data)));
213 215
214 EXPECT_EQ(0u, pcb_read_->Read(output_data, sizeof(output_data))); 216 EXPECT_EQ(0u, pcb_read_->Read(output_data, sizeof(output_data)));
215 } 217 }
216 218
OLDNEW
« no previous file with comments | « chrome/common/net/x509_certificate_model_openssl.cc ('k') | chrome/common/pepper_permission_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698