Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef MEDIA_CDM_PPAPI_CDM_FILE_IO_TEST_H_ | |
| 6 #define MEDIA_CDM_PPAPI_CDM_FILE_IO_TEST_H_ | |
| 7 | |
| 8 #include <list> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/callback.h" | |
| 12 #include "base/compiler_specific.h" | |
| 13 #include "media/cdm/ppapi/api/content_decryption_module.h" | |
| 14 | |
| 15 namespace media { | |
| 16 | |
| 17 typedef base::Callback<void(bool success)> CompletionCB; | |
| 18 typedef base::Callback<cdm::FileIO*(cdm::FileIOClient* client)> CreateFileIOCB; | |
| 19 | |
| 20 class FileIOTest : public cdm::FileIOClient { | |
|
ddorwin
2013/12/14 20:44:04
Should you briefly describe how this worksat a hig
xhwang
2013/12/16 23:04:29
Done.
| |
| 21 public: | |
| 22 // Types of allowed test steps: | |
| 23 // - ACTION_* specifies the next step to test. | |
| 24 // - RESULT_* specifies the expected result of the previous step(s). | |
| 25 enum StepType { | |
| 26 ACTION_CREATE, | |
| 27 ACTION_OPEN, | |
| 28 RESULT_OPEN, | |
| 29 ACTION_READ, | |
| 30 RESULT_READ, | |
| 31 ACTION_WRITE, | |
| 32 RESULT_WRITE, | |
| 33 ACTION_CLOSE // If ACTION_CLOSE is not specified, FileIO::Close() will be | |
| 34 // automatically called at the end of the test. | |
| 35 }; | |
| 36 | |
| 37 FileIOTest(const CreateFileIOCB& create_file_io_cb, | |
| 38 const std::string& test_name); | |
| 39 ~FileIOTest(); | |
| 40 | |
| 41 // Adds a test step into this test case. | |
|
ddorwin
2013/12/14 20:44:04
nits:
s/into/to/?
"Test Case" in gtest means the c
xhwang
2013/12/16 23:04:29
Done.
| |
| 42 void AddTestStep( | |
| 43 StepType type, Status status, const uint8* data, uint32 data_size); | |
|
ddorwin
2013/12/14 20:44:04
It's not clear what |status| is. expected_status?
ddorwin
2013/12/14 20:44:04
Does this function take ownership of |data|?
xhwang
2013/12/16 23:04:29
Done.
xhwang
2013/12/16 23:04:29
Yeah, |expected_status| makes sense. But it's long
| |
| 44 | |
| 45 // Runs this test case and return the test result through |completion_cb|. | |
|
ddorwin
2013/12/14 20:44:04
return_s_
xhwang
2013/12/16 23:04:29
Done.
| |
| 46 void Run(const CompletionCB& completion_cb); | |
| 47 | |
| 48 // cdm::FileIOClient implementation. | |
|
ddorwin
2013/12/14 20:44:04
Can these be private?
xhwang
2013/12/16 23:04:29
Done.
| |
| 49 virtual void OnOpenComplete(Status status) OVERRIDE; | |
| 50 virtual void OnReadComplete(Status status, | |
| 51 const uint8_t* data, | |
| 52 uint32_t data_size) OVERRIDE; | |
| 53 virtual void OnWriteComplete(Status status) OVERRIDE; | |
| 54 | |
| 55 private: | |
| 56 struct TestStep { | |
| 57 TestStep(StepType type, Status status, const uint8* data, uint32 data_size) | |
|
ddorwin
2013/12/14 20:44:04
Does this object take ownership of |data|?
xhwang
2013/12/16 23:04:29
Done.
| |
| 58 : type(type), status(status), data(data), data_size(data_size) {} | |
| 59 | |
| 60 StepType type; | |
| 61 Status status; | |
| 62 const uint8* data; | |
| 63 uint32 data_size; | |
| 64 }; | |
| 65 | |
| 66 // Returns whether |test_step| is a RESULT_* step. | |
| 67 static bool IsResult(const TestStep& test_step); | |
| 68 | |
| 69 // Returns whether two results match. | |
| 70 static bool MatchesResult(const TestStep& a, const TestStep& b); | |
| 71 | |
| 72 // Runs the next step in this test case. | |
| 73 void RunNextStep(); | |
| 74 | |
| 75 void OnResult(const TestStep& result); | |
| 76 | |
| 77 // Checks whether the test result matches this step. This can only be called | |
| 78 // when this step is a RESULT_* step. | |
| 79 bool CheckResult(const TestStep& result); | |
| 80 | |
| 81 void OnTestComplete(bool success); | |
| 82 | |
| 83 CreateFileIOCB create_file_io_cb_; | |
| 84 std::string test_name_; | |
| 85 std::list<TestStep> test_steps_; | |
| 86 cdm::FileIO* file_io_; | |
| 87 cdm::FileIO* old_file_io_; | |
|
ddorwin
2013/12/14 20:44:04
What is old?
xhwang
2013/12/16 23:04:29
Added comments.
| |
| 88 CompletionCB completion_cb_; | |
|
ddorwin
2013/12/14 20:44:04
nit: Group CBs together?
xhwang
2013/12/16 23:04:29
Done.
| |
| 89 }; | |
| 90 | |
| 91 // Tests cdm::FileIO implementation. | |
| 92 class FileIOTestRunner { | |
| 93 public: | |
| 94 explicit FileIOTestRunner(const CreateFileIOCB& create_file_io_cb); | |
| 95 ~FileIOTestRunner(); | |
| 96 | |
| 97 void AddTests(); | |
| 98 | |
| 99 // Run all tests. When tests are completed, the result will be reported in the | |
| 100 // |completion_cb|. | |
| 101 void RunAllTests(const CompletionCB& completion_cb); | |
| 102 | |
| 103 private: | |
| 104 void OnTestComplete(bool success); | |
| 105 void RunNextTest(); | |
| 106 | |
| 107 CreateFileIOCB create_file_io_cb_; | |
| 108 CompletionCB completion_cb_; | |
| 109 std::list<FileIOTest> tests_; | |
|
ddorwin
2013/12/14 20:44:04
remaining_tests_?
xhwang
2013/12/16 23:04:29
Done.
| |
| 110 std::vector<uint8> large_data_; | |
| 111 size_t num_tests_; // Total number of tests. | |
|
ddorwin
2013/12/14 20:44:04
total_num_tests? or something that indicates it's
xhwang
2013/12/16 23:04:29
Done.
| |
| 112 size_t num_passed_tests_; // Number of passed tests. | |
| 113 | |
| 114 DISALLOW_COPY_AND_ASSIGN (FileIOTestRunner); | |
| 115 }; | |
| 116 | |
| 117 } // namespace media | |
| 118 | |
| 119 #endif // MEDIA_CDM_PPAPI_CDM_FILE_IO_TEST_H_ | |
| OLD | NEW |