| 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/openssl_util.h" |   9 #include "crypto/scoped_openssl_types.h" | 
|  10 #include "testing/gtest/include/gtest/gtest.h" |  10 #include "testing/gtest/include/gtest/gtest.h" | 
|  11  |  11  | 
 |  12 namespace crypto { | 
 |  13  | 
|  12 TEST(OpenSSLBIOString, TestWrite) { |  14 TEST(OpenSSLBIOString, TestWrite) { | 
|  13   std::string s; |  15   std::string s; | 
|  14   const std::string expected1("a one\nb 2\n"); |  16   const std::string expected1("a one\nb 2\n"); | 
|  15   const std::string expected2("c d e f"); |  17   const std::string expected2("c d e f"); | 
|  16   const std::string expected3("g h i"); |  18   const std::string expected3("g h i"); | 
|  17   { |  19   { | 
|  18     crypto::ScopedOpenSSL<BIO, BIO_free_all> bio(crypto::BIO_new_string(&s)); |  20     ScopedBIO bio(BIO_new_string(&s)); | 
|  19     ASSERT_TRUE(bio.get()); |  21     ASSERT_TRUE(bio.get()); | 
|  20  |  22  | 
|  21     EXPECT_EQ(static_cast<int>(expected1.size()), |  23     EXPECT_EQ(static_cast<int>(expected1.size()), | 
|  22               BIO_printf(bio.get(), "a %s\nb %i\n", "one", 2)); |  24               BIO_printf(bio.get(), "a %s\nb %i\n", "one", 2)); | 
|  23     EXPECT_EQ(expected1, s); |  25     EXPECT_EQ(expected1, s); | 
|  24     EXPECT_EQ(static_cast<int>(expected1.size()), BIO_tell(bio.get())); |  26     EXPECT_EQ(static_cast<int>(expected1.size()), BIO_tell(bio.get())); | 
|  25  |  27  | 
|  26     EXPECT_EQ(1, BIO_flush(bio.get())); |  28     EXPECT_EQ(1, BIO_flush(bio.get())); | 
|  27     EXPECT_EQ(-1, BIO_seek(bio.get(), 0)); |  29     EXPECT_EQ(-1, BIO_seek(bio.get(), 0)); | 
|  28     EXPECT_EQ(expected1, s); |  30     EXPECT_EQ(expected1, s); | 
| (...skipping 12 matching lines...) Expand all  Loading... | 
|  41               BIO_tell(bio.get())); |  43               BIO_tell(bio.get())); | 
|  42   } |  44   } | 
|  43   EXPECT_EQ(expected1 + expected2 + expected3, s); |  45   EXPECT_EQ(expected1 + expected2 + expected3, s); | 
|  44 } |  46 } | 
|  45  |  47  | 
|  46 TEST(OpenSSLBIOString, TestReset) { |  48 TEST(OpenSSLBIOString, TestReset) { | 
|  47   std::string s; |  49   std::string s; | 
|  48   const std::string expected1("a b c\n"); |  50   const std::string expected1("a b c\n"); | 
|  49   const std::string expected2("d e f g\n"); |  51   const std::string expected2("d e f g\n"); | 
|  50   { |  52   { | 
|  51     crypto::ScopedOpenSSL<BIO, BIO_free_all> bio(crypto::BIO_new_string(&s)); |  53     ScopedBIO bio(BIO_new_string(&s)); | 
|  52     ASSERT_TRUE(bio.get()); |  54     ASSERT_TRUE(bio.get()); | 
|  53  |  55  | 
|  54     EXPECT_EQ(static_cast<int>(expected1.size()), |  56     EXPECT_EQ(static_cast<int>(expected1.size()), | 
|  55               BIO_write(bio.get(), expected1.data(), expected1.size())); |  57               BIO_write(bio.get(), expected1.data(), expected1.size())); | 
|  56     EXPECT_EQ(expected1, s); |  58     EXPECT_EQ(expected1, s); | 
|  57  |  59  | 
|  58     EXPECT_EQ(1, BIO_reset(bio.get())); |  60     EXPECT_EQ(1, BIO_reset(bio.get())); | 
|  59     EXPECT_EQ(std::string(), s); |  61     EXPECT_EQ(std::string(), s); | 
|  60  |  62  | 
|  61     EXPECT_EQ(static_cast<int>(expected2.size()), |  63     EXPECT_EQ(static_cast<int>(expected2.size()), | 
|  62               BIO_write(bio.get(), expected2.data(), expected2.size())); |  64               BIO_write(bio.get(), expected2.data(), expected2.size())); | 
|  63     EXPECT_EQ(expected2, s); |  65     EXPECT_EQ(expected2, s); | 
|  64   } |  66   } | 
|  65   EXPECT_EQ(expected2, s); |  67   EXPECT_EQ(expected2, s); | 
|  66 } |  68 } | 
 |  69  | 
 |  70 }  // namespace crypto | 
| OLD | NEW |