OLD | NEW |
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 "media/cdm/ppapi/cdm_file_io_test.h" | 5 #include "media/cdm/ppapi/cdm_file_io_test.h" |
6 | 6 |
| 7 #include <limits> |
| 8 |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
9 #include "base/logging.h" | 11 #include "base/logging.h" |
10 | 12 |
11 namespace media { | 13 namespace media { |
12 | 14 |
13 #define FILE_IO_DVLOG(level) DVLOG(level) << "File IO Test: " | 15 #define FILE_IO_DVLOG(level) DVLOG(level) << "File IO Test: " |
14 | 16 |
15 const uint8 kData[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | 17 const uint8_t kData[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
16 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }; | 18 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}; |
17 const uint32 kDataSize = arraysize(kData); | 19 const uint32_t kDataSize = arraysize(kData); |
18 | 20 |
19 const uint8 kBigData[] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, | 21 const uint8_t kBigData[] = { |
20 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, | 22 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, |
21 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, | 23 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, |
22 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, | 24 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x00}; |
23 0x00 }; | 25 const uint32_t kBigDataSize = arraysize(kBigData); |
24 const uint32 kBigDataSize = arraysize(kBigData); | |
25 | 26 |
26 // Must be > kReadSize in cdm_file_io_impl.cc. | 27 // Must be > kReadSize in cdm_file_io_impl.cc. |
27 const uint32 kLargeDataSize = 20 * 1024 + 7; | 28 const uint32_t kLargeDataSize = 20 * 1024 + 7; |
28 | 29 |
29 // Macros to help add test cases/steps. | 30 // Macros to help add test cases/steps. |
30 | 31 |
31 // |test_name| is also used as the file name. File name validity tests relies | 32 // |test_name| is also used as the file name. File name validity tests relies |
32 // on this to work. | 33 // on this to work. |
33 #define START_TEST_CASE(test_name) \ | 34 #define START_TEST_CASE(test_name) \ |
34 do { \ | 35 do { \ |
35 FileIOTest test_case(create_file_io_cb_, test_name); \ | 36 FileIOTest test_case(create_file_io_cb_, test_name); \ |
36 CREATE_FILE_IO // Create FileIO for each test case. | 37 CREATE_FILE_IO // Create FileIO for each test case. |
37 | 38 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 | 70 |
70 // FileIOTestRunner implementation. | 71 // FileIOTestRunner implementation. |
71 | 72 |
72 FileIOTestRunner::FileIOTestRunner(const CreateFileIOCB& create_file_io_cb) | 73 FileIOTestRunner::FileIOTestRunner(const CreateFileIOCB& create_file_io_cb) |
73 : create_file_io_cb_(create_file_io_cb), | 74 : create_file_io_cb_(create_file_io_cb), |
74 total_num_tests_(0), | 75 total_num_tests_(0), |
75 num_passed_tests_(0) { | 76 num_passed_tests_(0) { |
76 // Generate |large_data_|. | 77 // Generate |large_data_|. |
77 large_data_.resize(kLargeDataSize); | 78 large_data_.resize(kLargeDataSize); |
78 for (size_t i = 0; i < kLargeDataSize; ++i) | 79 for (size_t i = 0; i < kLargeDataSize; ++i) |
79 large_data_[i] = i % kuint8max; | 80 large_data_[i] = i % std::numeric_limits<uint8_t>::max(); |
80 | 81 |
81 AddTests(); | 82 AddTests(); |
82 } | 83 } |
83 | 84 |
84 FileIOTestRunner::~FileIOTestRunner() { | 85 FileIOTestRunner::~FileIOTestRunner() { |
85 if (remaining_tests_.empty()) | 86 if (remaining_tests_.empty()) |
86 return; | 87 return; |
87 | 88 |
88 DCHECK_LT(num_passed_tests_, total_num_tests_); | 89 DCHECK_LT(num_passed_tests_, total_num_tests_); |
89 FILE_IO_DVLOG(1) << "Not Finished (probably due to timeout). " | 90 FILE_IO_DVLOG(1) << "Not Finished (probably due to timeout). " |
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 | 466 |
466 // FileIOTest implementation. | 467 // FileIOTest implementation. |
467 | 468 |
468 FileIOTest::FileIOTest(const CreateFileIOCB& create_file_io_cb, | 469 FileIOTest::FileIOTest(const CreateFileIOCB& create_file_io_cb, |
469 const std::string& test_name) | 470 const std::string& test_name) |
470 : create_file_io_cb_(create_file_io_cb), | 471 : create_file_io_cb_(create_file_io_cb), |
471 test_name_(test_name) {} | 472 test_name_(test_name) {} |
472 | 473 |
473 FileIOTest::~FileIOTest() {} | 474 FileIOTest::~FileIOTest() {} |
474 | 475 |
475 void FileIOTest::AddTestStep( | 476 void FileIOTest::AddTestStep(StepType type, |
476 StepType type, Status status, const uint8* data, uint32 data_size) { | 477 Status status, |
| 478 const uint8_t* data, |
| 479 uint32_t data_size) { |
477 test_steps_.push_back(TestStep(type, status, data, data_size)); | 480 test_steps_.push_back(TestStep(type, status, data, data_size)); |
478 } | 481 } |
479 | 482 |
480 void FileIOTest::Run(const CompletionCB& completion_cb) { | 483 void FileIOTest::Run(const CompletionCB& completion_cb) { |
481 FILE_IO_DVLOG(3) << "Run " << test_name_; | 484 FILE_IO_DVLOG(3) << "Run " << test_name_; |
482 completion_cb_ = completion_cb; | 485 completion_cb_ = completion_cb; |
483 DCHECK(!test_steps_.empty() && !IsResult(test_steps_.front())); | 486 DCHECK(!test_steps_.empty() && !IsResult(test_steps_.front())); |
484 RunNextStep(); | 487 RunNextStep(); |
485 } | 488 } |
486 | 489 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 void FileIOTest::OnTestComplete(bool success) { | 607 void FileIOTest::OnTestComplete(bool success) { |
605 while (!file_io_stack_.empty()) { | 608 while (!file_io_stack_.empty()) { |
606 file_io_stack_.top()->Close(); | 609 file_io_stack_.top()->Close(); |
607 file_io_stack_.pop(); | 610 file_io_stack_.pop(); |
608 } | 611 } |
609 FILE_IO_DVLOG(3) << test_name_ << (success ? " PASSED" : " FAILED"); | 612 FILE_IO_DVLOG(3) << test_name_ << (success ? " PASSED" : " FAILED"); |
610 base::ResetAndReturn(&completion_cb_).Run(success); | 613 base::ResetAndReturn(&completion_cb_).Run(success); |
611 } | 614 } |
612 | 615 |
613 } // namespace media | 616 } // namespace media |
OLD | NEW |