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

Unified 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 side-by-side diff with in-line comments
Download patch
« crypto/openssl_bio_string.cc ('K') | « crypto/openssl_bio_string.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: crypto/openssl_bio_string_unittest.cc
diff --git a/crypto/openssl_bio_string_unittest.cc b/crypto/openssl_bio_string_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..24ddaff54256521406c9b39fa80bb111d6f375da
--- /dev/null
+++ b/crypto/openssl_bio_string_unittest.cc
@@ -0,0 +1,58 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "crypto/openssl_bio_string.h"
+
+#include <openssl/bio.h>
+
+#include "crypto/openssl_util.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+TEST(OpenSSLBIOString, TestWrite) {
+ std::string s;
+ const std::string expected1("a one\nb 2\n");
+ const std::string expected2("c d e f");
+ {
+ crypto::ScopedOpenSSL<BIO, BIO_free_all> bio(crypto::BIO_new_string(&s));
+ ASSERT_TRUE(bio.get());
+
+ EXPECT_EQ(static_cast<int>(expected1.size()),
+ BIO_printf(bio.get(), "a %s\nb %i\n", "one", 2));
+ EXPECT_EQ(expected1, s);
+ EXPECT_EQ(static_cast<int>(expected1.size()), BIO_tell(bio.get()));
+
+ EXPECT_EQ(1, BIO_flush(bio.get()));
+ EXPECT_EQ(-1, BIO_seek(bio.get(), 0));
+ EXPECT_EQ(expected1, s);
+
+ EXPECT_EQ(static_cast<int>(expected2.size()),
+ BIO_write(bio.get(), expected2.data(), expected2.size()));
+ EXPECT_EQ(expected1 + expected2, s);
+ EXPECT_EQ(static_cast<int>(expected1.size() + expected2.size()),
+ BIO_tell(bio.get()));
+ }
+ EXPECT_EQ(expected1 + expected2, s);
+}
+
+TEST(OpenSSLBIOString, TestReset) {
+ std::string s;
+ const std::string expected1("a b c\n");
+ const std::string expected2("d e f g\n");
+ {
+ crypto::ScopedOpenSSL<BIO, BIO_free_all> bio(crypto::BIO_new_string(&s));
+ ASSERT_TRUE(bio.get());
+
+ EXPECT_EQ(static_cast<int>(expected1.size()),
+ BIO_write(bio.get(), expected1.data(), expected1.size()));
+ EXPECT_EQ(expected1, s);
+
+ EXPECT_EQ(1, BIO_reset(bio.get()));
+ EXPECT_EQ(std::string(), s);
+
+ EXPECT_EQ(static_cast<int>(expected2.size()),
+ BIO_write(bio.get(), expected2.data(), expected2.size()));
+ EXPECT_EQ(expected2, s);
+ }
+ EXPECT_EQ(expected2, s);
+}
« 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