Chromium Code Reviews| Index: media/cdm/ppapi/cdm_file_io_test.cc |
| diff --git a/media/cdm/ppapi/cdm_file_io_test.cc b/media/cdm/ppapi/cdm_file_io_test.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..cadaf9c0b55d24c5df61fc1d9fcaef7c0bd20497 |
| --- /dev/null |
| +++ b/media/cdm/ppapi/cdm_file_io_test.cc |
| @@ -0,0 +1,71 @@ |
| +// 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. |
| + |
| +#include "media/cdm/ppapi/cdm_file_io_test.h" |
| + |
| +#include "base/callback_helpers.h" |
| +#include "media/base/bind_to_loop.h" |
| + |
| +namespace media { |
| + |
| +#define RETURN_IF_FAILURE(success, log) \ |
|
ddorwin
2013/12/11 21:16:17
It's really "return if false" now or "log failure
ddorwin
2013/12/11 21:16:17
Not in this CL, but bonus points if you can figure
xhwang
2013/12/13 02:51:47
This Macro is Removed.
xhwang
2013/12/13 02:51:47
This Macro is Removed.
|
| + do { \ |
| + if (!(success)) { \ |
| + DVLOG(1) << "CDM File IO Test failure: " << log; \ |
|
ddorwin
2013/12/11 21:16:17
DLOG
xhwang
2013/12/13 02:51:47
This Macro is Removed.
|
| + OnTestComplete(false); \ |
| + return; \ |
| + } \ |
| + } while (0) |
| + |
| +const char kTestFileName[] = "cdm_file_io_test_file"; |
| + |
| +// TODO(xhwang): Add tests that test multiple reads (needs large data to read). |
|
ddorwin
2013/12/11 21:16:17
Just a thought for future tests:
Is there a thresh
xhwang
2013/12/13 02:51:47
There WAS no limit. I filed a bug and now (as of t
xhwang
2013/12/13 05:03:06
FYI: I tested writing and reading ~33M data and I
|
| +const uint8_t kTestData[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }; |
| + |
| +// TODO(xhwang): Add more test cases. |
| + |
| +CdmFileIOTest::CdmFileIOTest(ClearKeyCdmHost* cdm_host) |
| + : cdm_host_(cdm_host), |
| + cdm_file_io_(NULL), |
| + test_data_(kTestData, kTestData + arraysize(kTestData)) {} |
| + |
| +CdmFileIOTest::~CdmFileIOTest() {} |
| + |
| +void CdmFileIOTest::OnOpenComplete(Status status) { |
| + RETURN_IF_FAILURE(status == kSuccess, "Open failed."); |
| + cdm_file_io_->Write(&test_data_[0], test_data_.size()); |
| +} |
| + |
| +void CdmFileIOTest::OnReadComplete(Status status, |
| + const uint8_t* data, uint32_t data_size) { |
| + RETURN_IF_FAILURE(status == kSuccess, "Read failed."); |
| + |
| + std::vector<uint8_t> data_read(data, data + data_size); |
| + RETURN_IF_FAILURE(test_data_ == data_read, "Read data mismatch."); |
| + |
| + OnTestComplete(true); |
| +} |
| + |
| +void CdmFileIOTest::OnWriteComplete(Status status) { |
| + RETURN_IF_FAILURE(status == kSuccess, "Write failed."); |
| + cdm_file_io_->Read(); |
| +} |
| + |
| +void CdmFileIOTest::Run(CompletionCB completion_cb) { |
| + cdm::FileIO* cdm_file_io = cdm_host_->CreateFileIO(this); |
|
ddorwin
2013/12/11 21:16:17
We could separate this class from CK by passing in
xhwang
2013/12/13 02:51:47
Done.
|
| + RETURN_IF_FAILURE(cdm_file_io, "Cannot get CDM File IO interface."); |
| + |
| + cdm_file_io_ = cdm_file_io; |
| + completion_cb_ = BindToCurrentLoop(completion_cb); |
| + cdm_file_io_->Open(kTestFileName, arraysize(kTestFileName)); |
| +} |
| + |
| +void CdmFileIOTest::OnTestComplete(bool success) { |
| + base::ResetAndReturn(&completion_cb_).Run(success); |
| + cdm_file_io_->Close(); |
|
ddorwin
2013/12/11 21:16:17
Delete the file to clean up after the test.
xhwang
2013/12/13 02:51:47
There's no "delete" in FileIO. The closest thing i
|
| + cdm_file_io_ = NULL; |
| +} |
| + |
| +} // namespace media |