You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

59 lines
2.0 KiB

  1. /* Copyright (c) 2016, Google Inc.
  2. *
  3. * Permission to use, copy, modify, and/or distribute this software for any
  4. * purpose with or without fee is hereby granted, provided that the above
  5. * copyright notice and this permission notice appear in all copies.
  6. *
  7. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  8. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  9. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  10. * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  11. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  12. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  13. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
  14. #include <gtest/gtest.h>
  15. #include <openssl/pool.h>
  16. #include "../test/test_util.h"
  17. TEST(PoolTest, Unpooled) {
  18. static const uint8_t kData[4] = {1, 2, 3, 4};
  19. bssl::UniquePtr<CRYPTO_BUFFER> buf(
  20. CRYPTO_BUFFER_new(kData, sizeof(kData), nullptr));
  21. ASSERT_TRUE(buf);
  22. EXPECT_EQ(Bytes(kData),
  23. Bytes(CRYPTO_BUFFER_data(buf.get()), CRYPTO_BUFFER_len(buf.get())));
  24. // Test that reference-counting works properly.
  25. CRYPTO_BUFFER_up_ref(buf.get());
  26. bssl::UniquePtr<CRYPTO_BUFFER> buf2(buf.get());
  27. }
  28. TEST(PoolTest, Empty) {
  29. bssl::UniquePtr<CRYPTO_BUFFER> buf(CRYPTO_BUFFER_new(nullptr, 0, nullptr));
  30. ASSERT_TRUE(buf);
  31. EXPECT_EQ(Bytes(""),
  32. Bytes(CRYPTO_BUFFER_data(buf.get()), CRYPTO_BUFFER_len(buf.get())));
  33. }
  34. TEST(PoolTest, Pooled) {
  35. bssl::UniquePtr<CRYPTO_BUFFER_POOL> pool(CRYPTO_BUFFER_POOL_new());
  36. ASSERT_TRUE(pool);
  37. static const uint8_t kData[4] = {1, 2, 3, 4};
  38. bssl::UniquePtr<CRYPTO_BUFFER> buf(
  39. CRYPTO_BUFFER_new(kData, sizeof(kData), pool.get()));
  40. ASSERT_TRUE(buf);
  41. bssl::UniquePtr<CRYPTO_BUFFER> buf2(
  42. CRYPTO_BUFFER_new(kData, sizeof(kData), pool.get()));
  43. ASSERT_TRUE(buf2);
  44. EXPECT_EQ(buf.get(), buf2.get()) << "CRYPTO_BUFFER_POOL did not dedup data.";
  45. }