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..d457684195d48af227206479a4c68bc4f4a8849b |
--- /dev/null |
+++ b/media/cdm/ppapi/cdm_file_io_test.cc |
@@ -0,0 +1,71 @@ |
+// Copyright 2013 The Chromium Authors. All rights reserved. |
ddorwin
2013/12/04 05:27:08
Ideally, we'd have more tests that close the file,
xhwang
2013/12/10 01:24:25
Yes, that's in the plan. Added TODO.
|
+// 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_ON_FAILURE(status, log) \ |
+ do { \ |
+ if ((status) != kSuccess) { \ |
+ LOG(ERROR) << log; \ |
ddorwin
2013/12/04 05:27:08
Since this comes from a CDM, we should probably ad
xhwang
2013/12/10 01:24:25
Done.
|
+ OnTestComplete(false); \ |
+ return; \ |
+ } \ |
+ } while (0) |
+ |
+const char kTestFileName[] = "cdm_file_io_test_file"; |
+const uint8_t kTestData[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
ddorwin
2013/12/04 05:27:08
We need really big test data to test the multiple
xhwang
2013/12/10 01:24:25
Added TODO.
|
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }; |
+ |
+CdmFileIOTest::CdmFileIOTest() |
+ : cdm_file_io_(NULL), |
+ test_data_(kTestData, kTestData + arraysize(kTestData)) {} |
+ |
+CdmFileIOTest::~CdmFileIOTest() {} |
+ |
+void CdmFileIOTest::OnOpenComplete(Status status) { |
+ LOG(ERROR) << __FUNCTION__; |
ddorwin
2013/12/04 05:27:08
debugging leftovers?
xhwang
2013/12/10 01:24:25
Removed.
|
+ RETURN_ON_FAILURE(status, "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) { |
+ LOG(ERROR) << __FUNCTION__; |
+ RETURN_ON_FAILURE(status, "Read failed."); |
+ |
+ std::vector<uint8_t> data_read(data, data + data_size); |
+ bool success = (test_data_ == data_read); |
+ OnTestComplete(success); |
ddorwin
2013/12/04 05:27:08
Here we don't get details about what failed. Shoul
xhwang
2013/12/10 01:24:25
Done.
|
+} |
+ |
+void CdmFileIOTest::OnWriteComplete(Status status) { |
+ LOG(ERROR) << __FUNCTION__; |
+ RETURN_ON_FAILURE(status, "Write failed."); |
+ |
+ cdm_file_io_->Read(); |
+} |
+ |
+void CdmFileIOTest::Run(cdm::CdmFileIO* cdm_file_io, |
+ CompletionCB completion_cb) { |
+ LOG(ERROR) << __FUNCTION__; |
+ |
+ 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(); |
+ cdm_file_io_ = NULL; |
+} |
+ |
+} // namespace media |