Pepper: Access PepperMediaDeviceManager through a WeakPtr
[chromium-blink-merge.git] / third_party / boringssl / boringssl_unittest.cc
blobb0289215daba46117e9b025fe8db1492386e183e
1 // Copyright 2014 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.
5 #include <stdarg.h>
7 #include <string>
9 #include "base/base_paths.h"
10 #include "base/command_line.h"
11 #include "base/files/file_path.h"
12 #include "base/logging.h"
13 #include "base/path_service.h"
14 #include "base/process/launch.h"
15 #include "base/strings/string_util.h"
16 #include "testing/gtest/include/gtest/gtest.h"
18 namespace {
20 void TestProcess(const std::string& name,
21 const std::vector<base::CommandLine::StringType>& args) {
22 base::FilePath exe_dir;
23 ASSERT_TRUE(PathService::Get(base::DIR_EXE, &exe_dir));
24 base::FilePath test_binary =
25 exe_dir.AppendASCII("boringssl_" + name);
26 base::CommandLine cmd(test_binary);
28 for (size_t i = 0; i < args.size(); ++i) {
29 cmd.AppendArgNative(args[i]);
32 std::string output;
33 EXPECT_TRUE(base::GetAppOutput(cmd, &output));
34 // Account for Windows line endings.
35 ReplaceSubstringsAfterOffset(&output, 0, "\r\n", "\n");
37 const bool ok = output.size() >= 5 &&
38 memcmp("PASS\n", &output[output.size() - 5], 5) == 0 &&
39 (output.size() == 5 || output[output.size() - 6] == '\n');
41 EXPECT_TRUE(ok) << output;
44 void TestSimple(const std::string& name) {
45 std::vector<base::CommandLine::StringType> empty;
46 TestProcess(name, empty);
49 bool BoringSSLPath(base::FilePath* result) {
50 if (!PathService::Get(base::DIR_SOURCE_ROOT, result))
51 return false;
53 *result = result->Append(FILE_PATH_LITERAL("third_party"));
54 *result = result->Append(FILE_PATH_LITERAL("boringssl"));
55 *result = result->Append(FILE_PATH_LITERAL("src"));
56 return true;
59 bool CryptoCipherPath(base::FilePath *result) {
60 if (!BoringSSLPath(result))
61 return false;
63 *result = result->Append(FILE_PATH_LITERAL("crypto"));
64 *result = result->Append(FILE_PATH_LITERAL("cipher"));
65 return true;
68 } // anonymous namespace
70 TEST(BoringSSL, AES128GCM) {
71 base::FilePath data_file;
72 ASSERT_TRUE(CryptoCipherPath(&data_file));
73 data_file = data_file.Append(FILE_PATH_LITERAL("aes_128_gcm_tests.txt"));
75 std::vector<base::CommandLine::StringType> args;
76 args.push_back(FILE_PATH_LITERAL("aes-128-gcm"));
77 args.push_back(data_file.value());
79 TestProcess("aead_test", args);
82 TEST(BoringSSL, AES256GCM) {
83 base::FilePath data_file;
84 ASSERT_TRUE(CryptoCipherPath(&data_file));
85 data_file = data_file.Append(FILE_PATH_LITERAL("aes_256_gcm_tests.txt"));
87 std::vector<base::CommandLine::StringType> args;
88 args.push_back(FILE_PATH_LITERAL("aes-256-gcm"));
89 args.push_back(data_file.value());
91 TestProcess("aead_test", args);
94 TEST(BoringSSL, ChaCha20Poly1305) {
95 base::FilePath data_file;
96 ASSERT_TRUE(CryptoCipherPath(&data_file));
97 data_file =
98 data_file.Append(FILE_PATH_LITERAL("chacha20_poly1305_tests.txt"));
100 std::vector<base::CommandLine::StringType> args;
101 args.push_back(FILE_PATH_LITERAL("chacha20-poly1305"));
102 args.push_back(data_file.value());
104 TestProcess("aead_test", args);
107 TEST(BoringSSL, RC4MD5) {
108 base::FilePath data_file;
109 ASSERT_TRUE(CryptoCipherPath(&data_file));
110 data_file = data_file.Append(FILE_PATH_LITERAL("rc4_md5_tests.txt"));
112 std::vector<base::CommandLine::StringType> args;
113 args.push_back(FILE_PATH_LITERAL("rc4-md5"));
114 args.push_back(data_file.value());
116 TestProcess("aead_test", args);
119 TEST(BoringSSL, AESKW128) {
120 base::FilePath data_file;
121 ASSERT_TRUE(CryptoCipherPath(&data_file));
122 data_file = data_file.Append(FILE_PATH_LITERAL("aes_128_key_wrap_tests.txt"));
124 std::vector<base::CommandLine::StringType> args;
125 args.push_back(FILE_PATH_LITERAL("aes-128-key-wrap"));
126 args.push_back(data_file.value());
128 TestProcess("aead_test", args);
131 TEST(BoringSSL, AESKW256) {
132 base::FilePath data_file;
133 ASSERT_TRUE(CryptoCipherPath(&data_file));
134 data_file = data_file.Append(FILE_PATH_LITERAL("aes_256_key_wrap_tests.txt"));
136 std::vector<base::CommandLine::StringType> args;
137 args.push_back(FILE_PATH_LITERAL("aes-256-key-wrap"));
138 args.push_back(data_file.value());
140 TestProcess("aead_test", args);
143 TEST(BoringSSL, Base64) {
144 TestSimple("base64_test");
147 TEST(BoringSSL, BIO) {
148 TestSimple("bio_test");
151 TEST(BoringSSL, BN) {
152 TestSimple("bn_test");
155 TEST(BoringSSL, ByteString) {
156 TestSimple("bytestring_test");
159 TEST(BoringSSL, Cipher) {
160 base::FilePath data_file;
161 ASSERT_TRUE(CryptoCipherPath(&data_file));
162 data_file = data_file.Append(FILE_PATH_LITERAL("cipher_test.txt"));
164 std::vector<base::CommandLine::StringType> args;
165 args.push_back(data_file.value());
167 TestProcess("cipher_test", args);
170 TEST(BoringSSL, DH) {
171 TestSimple("dh_test");
174 TEST(BoringSSL, DSA) {
175 TestSimple("dsa_test");
178 TEST(BoringSSL, ECDSA) {
179 TestSimple("ecdsa_test");
182 TEST(BoringSSL, ERR) {
183 TestSimple("err_test");
186 TEST(BoringSSL, GCM) {
187 TestSimple("gcm_test");
190 TEST(BoringSSL, HMAC) {
191 TestSimple("hmac_test");
194 TEST(BoringSSL, LH) {
195 TestSimple("lhash_test");
198 TEST(BoringSSL, MD5) {
199 TestSimple("md5_test");
202 TEST(BoringSSL, RSA) {
203 TestSimple("rsa_test");
206 TEST(BoringSSL, SHA1) {
207 TestSimple("sha1_test");
210 TEST(BoringSSL, PKCS7) {
211 TestSimple("pkcs7_test");
214 TEST(BoringSSL, PKCS12) {
215 TestSimple("pkcs12_test");
218 TEST(BoringSSL, ExampleMul) {
219 TestSimple("example_mul");
222 TEST(BoringSSL, ExampleSign) {
223 TestSimple("example_sign");
226 TEST(BoringSSL, SSL) {
227 TestSimple("ssl_test");
230 TEST(BoringSSL, PQueue) {
231 TestSimple("pqueue_test");