blob: cfeb5a80bab09fd870b8ff29814ab9009bba29ea [file] [log] [blame]
[email protected]8d770e492011-10-11 04:54:311// 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
5#include "ppapi/tests/test_crypto.h"
6
7#include "ppapi/c/dev/ppb_crypto_dev.h"
8#include "ppapi/cpp/module.h"
9#include "ppapi/tests/testing_instance.h"
10
11REGISTER_TEST_CASE(Crypto);
12
13TestCrypto::TestCrypto(TestingInstance* instance)
14 : TestCase(instance),
15 crypto_interface_(NULL) {
16}
17
18bool TestCrypto::Init() {
[email protected]4d529232011-12-08 22:31:2119 crypto_interface_ = static_cast<const PPB_Crypto_Dev*>(
[email protected]8d770e492011-10-11 04:54:3120 pp::Module::Get()->GetBrowserInterface(PPB_CRYPTO_DEV_INTERFACE));
21 return !!crypto_interface_;
22}
23
[email protected]2622d6b2011-11-16 04:28:0224void TestCrypto::RunTests(const std::string& filter) {
25 RUN_TEST(GetRandomBytes, filter);
[email protected]8d770e492011-10-11 04:54:3126}
27
28std::string TestCrypto::TestGetRandomBytes() {
29 const int kBufSize = 16;
30 char buf[kBufSize] = {0};
31
32 crypto_interface_->GetRandomBytes(buf, kBufSize);
33
34 // Verify that the interface wrote "something" to the buffer.
35 bool found_nonzero = false;
36 for (int i = 0; i < kBufSize; i++) {
37 if (buf[i]) {
38 found_nonzero = true;
39 break;
40 }
41 }
42 ASSERT_TRUE(found_nonzero);
43
44 PASS();
45}