test_crypto.cc 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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
  3. // found in the LICENSE file.
  4. #include "ppapi/tests/test_crypto.h"
  5. #include "ppapi/c/dev/ppb_crypto_dev.h"
  6. #include "ppapi/cpp/module.h"
  7. #include "ppapi/tests/testing_instance.h"
  8. REGISTER_TEST_CASE(Crypto);
  9. TestCrypto::TestCrypto(TestingInstance* instance)
  10. : TestCase(instance),
  11. crypto_interface_(NULL) {
  12. }
  13. bool TestCrypto::Init() {
  14. crypto_interface_ = static_cast<const PPB_Crypto_Dev*>(
  15. pp::Module::Get()->GetBrowserInterface(PPB_CRYPTO_DEV_INTERFACE));
  16. return !!crypto_interface_;
  17. }
  18. void TestCrypto::RunTests(const std::string& filter) {
  19. RUN_TEST(GetRandomBytes, filter);
  20. }
  21. std::string TestCrypto::TestGetRandomBytes() {
  22. const int kBufSize = 16;
  23. char buf[kBufSize] = {0};
  24. crypto_interface_->GetRandomBytes(buf, kBufSize);
  25. // Verify that the interface wrote "something" to the buffer.
  26. bool found_nonzero = false;
  27. for (int i = 0; i < kBufSize; i++) {
  28. if (buf[i]) {
  29. found_nonzero = true;
  30. break;
  31. }
  32. }
  33. ASSERT_TRUE(found_nonzero);
  34. PASS();
  35. }