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

Side by Side Diff: media/cdm/ppapi/cdm_file_io_test.h

Issue 93243003: Add CDM FileIO tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comments addressed 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 | Annotate | Revision Log
OLDNEW
(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 // A customizable test class that tests cdm::FileIO implementation.
ddorwin 2013/12/17 00:17:04 Nice! Thanks. :)
xhwang 2013/12/17 18:25:03 Done.
21 // - To create a test, call AddTestStep() to add a test step. A test step can be
22 // either an action to make (use ACTION_* types), or a result to verify (use
23 // RESULT_* types).
24 // - To run the test, simply call Run() with a completion callback. The result
25 // will be reported in the completion callback when the test is finished.
26 //
27 // The following rules apply to the test steps:
28 // - Test steps are ordered (with the exception that results in a result group
29 // is not ordered).
30 // - Consecutive action steps form an "action group". Consecutively result
31 // steps form a "result group". An action group is followed by a result
32 // group and vice versa.
33 // - A test must start with an action group.
34 // - To process an action group, the test runner runs (and clears) all steps
35 // in the group in the order they were added. Then it waits for test
36 // results.
37 // - When a cdm::FileIOClient method is called, the test runner compares the
38 // result with all results in the current result group. If no result in that
39 // group matches the test result, the test fails. Otherwise, the matching
40 // result is cleared from the group. If the group is empty, the test runner
41 // starts to process the next action group. Otherwise, the test runner keeps
42 // waiting for the next test result.
43 // - After all steps are cleared, the test passes.
44 class FileIOTest : public cdm::FileIOClient {
45 public:
46 // Types of allowed test steps:
47 // - ACTION_* specifies the next step to test.
48 // - RESULT_* specifies the expected result of the previous step(s).
49 enum StepType {
50 ACTION_CREATE,
51 ACTION_OPEN, // |test_name_| will be used used as the file name to open.
52 RESULT_OPEN,
53 ACTION_READ,
54 RESULT_READ,
55 ACTION_WRITE,
56 RESULT_WRITE,
57 ACTION_CLOSE // If ACTION_CLOSE is not specified, FileIO::Close() will be
58 // automatically called at the end of the test.
59 };
60
61 FileIOTest(const CreateFileIOCB& create_file_io_cb,
62 const std::string& test_name);
63 ~FileIOTest();
64
65 // Adds a test step in this test. |this| object doesn't take the ownership of
66 // |data|, which should be valid throughout the lifetime of |this| object.
67 void AddTestStep(
68 StepType type, Status status, const uint8* data, uint32 data_size);
69
70 // Runs this test case and returns the test result through |completion_cb|.
71 void Run(const CompletionCB& completion_cb);
72
73 private:
74 struct TestStep {
75 // |this| object doesn't take the ownership of |data|, which should be valid
76 // throughout the lifetime of |this| object.
77 TestStep(StepType type, Status status, const uint8* data, uint32 data_size)
78 : type(type), status(status), data(data), data_size(data_size) {}
79
80 StepType type;
81
82 // Expected status for RESULT* steps.
83 Status status;
84
85 // Data to write in ACTION_WRITE, or read data in RESULT_READ.
86 const uint8* data;
87 uint32 data_size;
88 };
89
90 // Returns whether |test_step| is a RESULT_* step.
91 static bool IsResult(const TestStep& test_step);
92
93 // Returns whether two results match.
94 static bool MatchesResult(const TestStep& a, const TestStep& b);
95
96 // cdm::FileIOClient implementation.
97 virtual void OnOpenComplete(Status status) OVERRIDE;
98 virtual void OnReadComplete(Status status,
99 const uint8_t* data,
100 uint32_t data_size) OVERRIDE;
101 virtual void OnWriteComplete(Status status) OVERRIDE;
102
103 // Runs the next step in this test case.
104 void RunNextStep();
105
106 void OnResult(const TestStep& result);
107
108 // Checks whether the test result matches this step. This can only be called
109 // when this step is a RESULT_* step.
110 bool CheckResult(const TestStep& result);
111
112 void OnTestComplete(bool success);
113
114 CreateFileIOCB create_file_io_cb_;
115 CompletionCB completion_cb_;
116
117 std::string test_name_;
118 std::list<TestStep> test_steps_;
119
120 // The currently opened cdm::FileIO object.
121 cdm::FileIO* file_io_;
122
123 // The previously opened cdm::FileIO object. We keep at most two cdm::FileIO
124 // objects open at the same time so that we can test two cdm::FileIO objects
125 // accessing the same file.
ddorwin 2013/12/17 00:17:04 Would things be easier if it was a vector? Even if
xhwang 2013/12/17 18:25:03 Done.
126 cdm::FileIO* old_file_io_;
127 };
128
129 // Tests cdm::FileIO implementation.
130 class FileIOTestRunner {
131 public:
132 explicit FileIOTestRunner(const CreateFileIOCB& create_file_io_cb);
133 ~FileIOTestRunner();
134
135 void AddTests();
136
137 // Run all tests. When tests are completed, the result will be reported in the
138 // |completion_cb|.
139 void RunAllTests(const CompletionCB& completion_cb);
140
141 private:
142 void OnTestComplete(bool success);
143 void RunNextTest();
144
145 CreateFileIOCB create_file_io_cb_;
146 CompletionCB completion_cb_;
147 std::list<FileIOTest> remaining_tests_;
148 std::vector<uint8> large_data_;
149 size_t num_tests_; // Total number of tests.
ddorwin 2013/12/17 00:17:04 This wasn't renamed.
xhwang 2013/12/17 18:25:03 Done.
150 size_t num_passed_tests_; // Number of passed tests.
151
152 DISALLOW_COPY_AND_ASSIGN (FileIOTestRunner);
153 };
154
155 } // namespace media
156
157 #endif // MEDIA_CDM_PPAPI_CDM_FILE_IO_TEST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698