Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Side by Side Diff: crypto/openssl_bio_string_unittest.cc

Issue 286263006: Add OpenSSL BIO method that writes to a std::string. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: unittest should check BIO_new_string result Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« crypto/openssl_bio_string.cc ('K') | « crypto/openssl_bio_string.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "crypto/openssl_bio_string.h"
6
7 #include <openssl/bio.h>
8
9 #include "crypto/openssl_util.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 TEST(OpenSSLBIOString, TestWrite) {
13 std::string s;
14 const std::string expected1("a one\nb 2\n");
15 const std::string expected2("c d e f");
16 {
17 crypto::ScopedOpenSSL<BIO, BIO_free_all> bio(crypto::BIO_new_string(&s));
18 ASSERT_TRUE(bio.get());
19
20 EXPECT_EQ(static_cast<int>(expected1.size()),
21 BIO_printf(bio.get(), "a %s\nb %i\n", "one", 2));
22 EXPECT_EQ(expected1, s);
23 EXPECT_EQ(static_cast<int>(expected1.size()), BIO_tell(bio.get()));
24
25 EXPECT_EQ(1, BIO_flush(bio.get()));
26 EXPECT_EQ(-1, BIO_seek(bio.get(), 0));
27 EXPECT_EQ(expected1, s);
28
29 EXPECT_EQ(static_cast<int>(expected2.size()),
30 BIO_write(bio.get(), expected2.data(), expected2.size()));
31 EXPECT_EQ(expected1 + expected2, s);
32 EXPECT_EQ(static_cast<int>(expected1.size() + expected2.size()),
33 BIO_tell(bio.get()));
34 }
35 EXPECT_EQ(expected1 + expected2, s);
36 }
37
38 TEST(OpenSSLBIOString, TestReset) {
39 std::string s;
40 const std::string expected1("a b c\n");
41 const std::string expected2("d e f g\n");
42 {
43 crypto::ScopedOpenSSL<BIO, BIO_free_all> bio(crypto::BIO_new_string(&s));
44 ASSERT_TRUE(bio.get());
45
46 EXPECT_EQ(static_cast<int>(expected1.size()),
47 BIO_write(bio.get(), expected1.data(), expected1.size()));
48 EXPECT_EQ(expected1, s);
49
50 EXPECT_EQ(1, BIO_reset(bio.get()));
51 EXPECT_EQ(std::string(), s);
52
53 EXPECT_EQ(static_cast<int>(expected2.size()),
54 BIO_write(bio.get(), expected2.data(), expected2.size()));
55 EXPECT_EQ(expected2, s);
56 }
57 EXPECT_EQ(expected2, s);
58 }
OLDNEW
« crypto/openssl_bio_string.cc ('K') | « crypto/openssl_bio_string.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698