| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ppapi/tests/test_crypto.h" | 5 #include "ppapi/tests/test_crypto.h" |
| 6 | 6 |
| 7 #include "ppapi/c/dev/ppb_crypto_dev.h" | 7 #include "ppapi/c/dev/ppb_crypto_dev.h" |
| 8 #include "ppapi/cpp/module.h" | 8 #include "ppapi/cpp/module.h" |
| 9 #include "ppapi/tests/testing_instance.h" | 9 #include "ppapi/tests/testing_instance.h" |
| 10 | 10 |
| 11 REGISTER_TEST_CASE(Crypto); | 11 REGISTER_TEST_CASE(Crypto); |
| 12 | 12 |
| 13 TestCrypto::TestCrypto(TestingInstance* instance) | 13 TestCrypto::TestCrypto(TestingInstance* instance) |
| 14 : TestCase(instance), | 14 : TestCase(instance), |
| 15 crypto_interface_(NULL) { | 15 crypto_interface_(NULL) { |
| 16 } | 16 } |
| 17 | 17 |
| 18 bool TestCrypto::Init() { | 18 bool TestCrypto::Init() { |
| 19 crypto_interface_ = static_cast<PPB_Crypto_Dev const*>( | 19 crypto_interface_ = static_cast<const PPB_Crypto_Dev*>( |
| 20 pp::Module::Get()->GetBrowserInterface(PPB_CRYPTO_DEV_INTERFACE)); | 20 pp::Module::Get()->GetBrowserInterface(PPB_CRYPTO_DEV_INTERFACE)); |
| 21 return !!crypto_interface_; | 21 return !!crypto_interface_; |
| 22 } | 22 } |
| 23 | 23 |
| 24 void TestCrypto::RunTests(const std::string& filter) { | 24 void TestCrypto::RunTests(const std::string& filter) { |
| 25 RUN_TEST(GetRandomBytes, filter); | 25 RUN_TEST(GetRandomBytes, filter); |
| 26 } | 26 } |
| 27 | 27 |
| 28 std::string TestCrypto::TestGetRandomBytes() { | 28 std::string TestCrypto::TestGetRandomBytes() { |
| 29 const int kBufSize = 16; | 29 const int kBufSize = 16; |
| 30 char buf[kBufSize] = {0}; | 30 char buf[kBufSize] = {0}; |
| 31 | 31 |
| 32 crypto_interface_->GetRandomBytes(buf, kBufSize); | 32 crypto_interface_->GetRandomBytes(buf, kBufSize); |
| 33 | 33 |
| 34 // Verify that the interface wrote "something" to the buffer. | 34 // Verify that the interface wrote "something" to the buffer. |
| 35 bool found_nonzero = false; | 35 bool found_nonzero = false; |
| 36 for (int i = 0; i < kBufSize; i++) { | 36 for (int i = 0; i < kBufSize; i++) { |
| 37 if (buf[i]) { | 37 if (buf[i]) { |
| 38 found_nonzero = true; | 38 found_nonzero = true; |
| 39 break; | 39 break; |
| 40 } | 40 } |
| 41 } | 41 } |
| 42 ASSERT_TRUE(found_nonzero); | 42 ASSERT_TRUE(found_nonzero); |
| 43 | 43 |
| 44 PASS(); | 44 PASS(); |
| 45 } | 45 } |
| OLD | NEW |