| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "crypto/openssl_bio_string.h" | 5 #include "crypto/openssl_bio_string.h" |
| 6 | 6 |
| 7 #include <openssl/bio.h> | 7 #include <openssl/bio.h> |
| 8 | 8 |
| 9 #include "crypto/scoped_openssl_types.h" | |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 10 |
| 12 namespace crypto { | 11 namespace crypto { |
| 13 | 12 |
| 14 TEST(OpenSSLBIOString, TestWrite) { | 13 TEST(OpenSSLBIOString, TestWrite) { |
| 15 std::string s; | 14 std::string s; |
| 16 const std::string expected1("a one\nb 2\n"); | 15 const std::string expected1("a one\nb 2\n"); |
| 17 const std::string expected2("c d e f"); | 16 const std::string expected2("c d e f"); |
| 18 const std::string expected3("g h i"); | 17 const std::string expected3("g h i"); |
| 19 { | 18 { |
| 20 ScopedBIO bio(BIO_new_string(&s)); | 19 bssl::UniquePtr<BIO> bio(BIO_new_string(&s)); |
| 21 ASSERT_TRUE(bio.get()); | 20 ASSERT_TRUE(bio.get()); |
| 22 | 21 |
| 23 EXPECT_EQ(static_cast<int>(expected1.size()), | 22 EXPECT_EQ(static_cast<int>(expected1.size()), |
| 24 BIO_printf(bio.get(), "a %s\nb %i\n", "one", 2)); | 23 BIO_printf(bio.get(), "a %s\nb %i\n", "one", 2)); |
| 25 EXPECT_EQ(expected1, s); | 24 EXPECT_EQ(expected1, s); |
| 26 | 25 |
| 27 EXPECT_EQ(1, BIO_flush(bio.get())); | 26 EXPECT_EQ(1, BIO_flush(bio.get())); |
| 28 EXPECT_EQ(expected1, s); | 27 EXPECT_EQ(expected1, s); |
| 29 | 28 |
| 30 EXPECT_EQ(static_cast<int>(expected2.size()), | 29 EXPECT_EQ(static_cast<int>(expected2.size()), |
| 31 BIO_write(bio.get(), expected2.data(), expected2.size())); | 30 BIO_write(bio.get(), expected2.data(), expected2.size())); |
| 32 EXPECT_EQ(expected1 + expected2, s); | 31 EXPECT_EQ(expected1 + expected2, s); |
| 33 | 32 |
| 34 EXPECT_EQ(static_cast<int>(expected3.size()), | 33 EXPECT_EQ(static_cast<int>(expected3.size()), |
| 35 BIO_puts(bio.get(), expected3.c_str())); | 34 BIO_puts(bio.get(), expected3.c_str())); |
| 36 EXPECT_EQ(expected1 + expected2 + expected3, s); | 35 EXPECT_EQ(expected1 + expected2 + expected3, s); |
| 37 } | 36 } |
| 38 EXPECT_EQ(expected1 + expected2 + expected3, s); | 37 EXPECT_EQ(expected1 + expected2 + expected3, s); |
| 39 } | 38 } |
| 40 | 39 |
| 41 TEST(OpenSSLBIOString, TestReset) { | 40 TEST(OpenSSLBIOString, TestReset) { |
| 42 std::string s; | 41 std::string s; |
| 43 const std::string expected1("a b c\n"); | 42 const std::string expected1("a b c\n"); |
| 44 const std::string expected2("d e f g\n"); | 43 const std::string expected2("d e f g\n"); |
| 45 { | 44 { |
| 46 ScopedBIO bio(BIO_new_string(&s)); | 45 bssl::UniquePtr<BIO> bio(BIO_new_string(&s)); |
| 47 ASSERT_TRUE(bio.get()); | 46 ASSERT_TRUE(bio.get()); |
| 48 | 47 |
| 49 EXPECT_EQ(static_cast<int>(expected1.size()), | 48 EXPECT_EQ(static_cast<int>(expected1.size()), |
| 50 BIO_write(bio.get(), expected1.data(), expected1.size())); | 49 BIO_write(bio.get(), expected1.data(), expected1.size())); |
| 51 EXPECT_EQ(expected1, s); | 50 EXPECT_EQ(expected1, s); |
| 52 | 51 |
| 53 EXPECT_EQ(1, BIO_reset(bio.get())); | 52 EXPECT_EQ(1, BIO_reset(bio.get())); |
| 54 EXPECT_EQ(std::string(), s); | 53 EXPECT_EQ(std::string(), s); |
| 55 | 54 |
| 56 EXPECT_EQ(static_cast<int>(expected2.size()), | 55 EXPECT_EQ(static_cast<int>(expected2.size()), |
| 57 BIO_write(bio.get(), expected2.data(), expected2.size())); | 56 BIO_write(bio.get(), expected2.data(), expected2.size())); |
| 58 EXPECT_EQ(expected2, s); | 57 EXPECT_EQ(expected2, s); |
| 59 } | 58 } |
| 60 EXPECT_EQ(expected2, s); | 59 EXPECT_EQ(expected2, s); |
| 61 } | 60 } |
| 62 | 61 |
| 63 } // namespace crypto | 62 } // namespace crypto |
| OLD | NEW |