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

Side by Side Diff: chrome/browser/extensions/api/image_writer_private/test_utils.cc

Issue 109793006: Adds ImageWriterPrivate.destroyPartitions operation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleanup Created 7 years 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 #include "chrome/browser/extensions/api/image_writer_private/test_utils.h" 5 #include "chrome/browser/extensions/api/image_writer_private/test_utils.h"
6 6
7 namespace extensions { 7 namespace extensions {
8 namespace image_writer { 8 namespace image_writer {
9 9
10 MockOperationManager::MockOperationManager() 10 MockOperationManager::MockOperationManager()
11 : OperationManager(NULL) { 11 : OperationManager(NULL) {
12 } 12 }
13 13
14 MockOperationManager::~MockOperationManager() { 14 MockOperationManager::~MockOperationManager() {
15 } 15 }
16 16
17 void ImageWriterUnitTestBase::SetUp() { 17 void ImageWriterUnitTestBase::SetUp() {
18 ASSERT_TRUE(base::CreateTemporaryFile(&test_image_)); 18 testing::Test::SetUp();
19 ASSERT_TRUE(base::CreateTemporaryFile(&test_device_)); 19 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
20 20
21 ASSERT_EQ(32, file_util::WriteFile(test_image_, kTestData, 32)); 21 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(),
22 &test_image_path_));
23 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(),
24 &test_device_path_));
25
26 ASSERT_TRUE(FillFile(test_image_path_, kImagePattern, kTestFileSize));
27 ASSERT_TRUE(FillFile(test_device_path_, kDevicePattern, kTestFileSize));
22 } 28 }
23 29
24 void ImageWriterUnitTestBase::TearDown() { 30 void ImageWriterUnitTestBase::TearDown() {
25 base::DeleteFile(test_image_, false); 31 }
26 base::DeleteFile(test_device_, false); 32
33 bool ImageWriterUnitTestBase::CompareImageAndDevice() {
34 char image_buffer[kTestFileSize];
35 char device_buffer[kTestFileSize];
36
37 while (true) {
38 int image_bytes_read = ReadFile(test_image_path_,
39 image_buffer,
40 kTestFileSize);
41 int device_bytes_read = ReadFile(test_device_path_,
42 device_buffer,
43 kTestFileSize);
44
45 if (image_bytes_read != device_bytes_read)
46 return false;
47
48 if (image_bytes_read == 0)
49 return true;
50
51 if (memcmp(image_buffer, device_buffer, image_bytes_read) != 0)
52 return false;
53 }
54
55 NOTREACHED();
56 }
57
58 bool ImageWriterUnitTestBase::FillFile(const base::FilePath& file,
59 const char pattern,
60 const int length) {
61 char buffer[length];
62 memset(buffer, pattern, length);
63
64 return file_util::WriteFile(file, buffer, length) == length;
27 } 65 }
28 66
29 } // namespace image_writer 67 } // namespace image_writer
30 } // namespace extensions 68 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698