Index: media/cdm/ppapi/cdm_file_io_test.h |
diff --git a/media/cdm/ppapi/cdm_file_io_test.h b/media/cdm/ppapi/cdm_file_io_test.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..be0d01a9198ca7bd13791d4838a0a661f304a5ca |
--- /dev/null |
+++ b/media/cdm/ppapi/cdm_file_io_test.h |
@@ -0,0 +1,119 @@ |
+// Copyright 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef MEDIA_CDM_PPAPI_CDM_FILE_IO_TEST_H_ |
+#define MEDIA_CDM_PPAPI_CDM_FILE_IO_TEST_H_ |
+ |
+#include <list> |
+#include <vector> |
+ |
+#include "base/callback.h" |
+#include "base/compiler_specific.h" |
+#include "media/cdm/ppapi/api/content_decryption_module.h" |
+ |
+namespace media { |
+ |
+typedef base::Callback<void(bool success)> CompletionCB; |
+typedef base::Callback<cdm::FileIO*(cdm::FileIOClient* client)> CreateFileIOCB; |
+ |
+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.
|
+ public: |
+ // Types of allowed test steps: |
+ // - ACTION_* specifies the next step to test. |
+ // - RESULT_* specifies the expected result of the previous step(s). |
+ enum StepType { |
+ ACTION_CREATE, |
+ ACTION_OPEN, |
+ RESULT_OPEN, |
+ ACTION_READ, |
+ RESULT_READ, |
+ ACTION_WRITE, |
+ RESULT_WRITE, |
+ ACTION_CLOSE // If ACTION_CLOSE is not specified, FileIO::Close() will be |
+ // automatically called at the end of the test. |
+ }; |
+ |
+ FileIOTest(const CreateFileIOCB& create_file_io_cb, |
+ const std::string& test_name); |
+ ~FileIOTest(); |
+ |
+ // 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.
|
+ void AddTestStep( |
+ 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
|
+ |
+ // 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.
|
+ void Run(const CompletionCB& completion_cb); |
+ |
+ // cdm::FileIOClient implementation. |
ddorwin
2013/12/14 20:44:04
Can these be private?
xhwang
2013/12/16 23:04:29
Done.
|
+ virtual void OnOpenComplete(Status status) OVERRIDE; |
+ virtual void OnReadComplete(Status status, |
+ const uint8_t* data, |
+ uint32_t data_size) OVERRIDE; |
+ virtual void OnWriteComplete(Status status) OVERRIDE; |
+ |
+ private: |
+ struct TestStep { |
+ 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.
|
+ : type(type), status(status), data(data), data_size(data_size) {} |
+ |
+ StepType type; |
+ Status status; |
+ const uint8* data; |
+ uint32 data_size; |
+ }; |
+ |
+ // Returns whether |test_step| is a RESULT_* step. |
+ static bool IsResult(const TestStep& test_step); |
+ |
+ // Returns whether two results match. |
+ static bool MatchesResult(const TestStep& a, const TestStep& b); |
+ |
+ // Runs the next step in this test case. |
+ void RunNextStep(); |
+ |
+ void OnResult(const TestStep& result); |
+ |
+ // Checks whether the test result matches this step. This can only be called |
+ // when this step is a RESULT_* step. |
+ bool CheckResult(const TestStep& result); |
+ |
+ void OnTestComplete(bool success); |
+ |
+ CreateFileIOCB create_file_io_cb_; |
+ std::string test_name_; |
+ std::list<TestStep> test_steps_; |
+ cdm::FileIO* file_io_; |
+ cdm::FileIO* old_file_io_; |
ddorwin
2013/12/14 20:44:04
What is old?
xhwang
2013/12/16 23:04:29
Added comments.
|
+ CompletionCB completion_cb_; |
ddorwin
2013/12/14 20:44:04
nit: Group CBs together?
xhwang
2013/12/16 23:04:29
Done.
|
+}; |
+ |
+// Tests cdm::FileIO implementation. |
+class FileIOTestRunner { |
+ public: |
+ explicit FileIOTestRunner(const CreateFileIOCB& create_file_io_cb); |
+ ~FileIOTestRunner(); |
+ |
+ void AddTests(); |
+ |
+ // Run all tests. When tests are completed, the result will be reported in the |
+ // |completion_cb|. |
+ void RunAllTests(const CompletionCB& completion_cb); |
+ |
+ private: |
+ void OnTestComplete(bool success); |
+ void RunNextTest(); |
+ |
+ CreateFileIOCB create_file_io_cb_; |
+ CompletionCB completion_cb_; |
+ std::list<FileIOTest> tests_; |
ddorwin
2013/12/14 20:44:04
remaining_tests_?
xhwang
2013/12/16 23:04:29
Done.
|
+ std::vector<uint8> large_data_; |
+ 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.
|
+ size_t num_passed_tests_; // Number of passed tests. |
+ |
+ DISALLOW_COPY_AND_ASSIGN (FileIOTestRunner); |
+}; |
+ |
+} // namespace media |
+ |
+#endif // MEDIA_CDM_PPAPI_CDM_FILE_IO_TEST_H_ |