diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
commit | 19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch) | |
tree | 42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/test/librbd/crypto/test_mock_CryptoContextPool.cc | |
parent | Initial commit. (diff) | |
download | ceph-upstream.tar.xz ceph-upstream.zip |
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/librbd/crypto/test_mock_CryptoContextPool.cc')
-rw-r--r-- | src/test/librbd/crypto/test_mock_CryptoContextPool.cc | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/test/librbd/crypto/test_mock_CryptoContextPool.cc b/src/test/librbd/crypto/test_mock_CryptoContextPool.cc new file mode 100644 index 000000000..6eb7877eb --- /dev/null +++ b/src/test/librbd/crypto/test_mock_CryptoContextPool.cc @@ -0,0 +1,54 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#include "gtest/gtest.h" +#include "librbd/crypto/CryptoContextPool.h" +#include "test/librbd/mock/crypto/MockDataCryptor.h" + +#include "librbd/crypto/CryptoContextPool.cc" +template class librbd::crypto::CryptoContextPool< + librbd::crypto::MockCryptoContext>; + +using ::testing::Return; + +namespace librbd { +namespace crypto { + +struct TestMockCryptoCryptoContextPool : public ::testing::Test { + MockDataCryptor cryptor; + + void expect_get_context(CipherMode mode) { + EXPECT_CALL(cryptor, get_context(mode)).WillOnce(Return( + new MockCryptoContext())); + } + + void expect_return_context(MockCryptoContext* ctx, CipherMode mode) { + delete ctx; + EXPECT_CALL(cryptor, return_context(ctx, mode)); + } +}; + +TEST_F(TestMockCryptoCryptoContextPool, Test) { + CryptoContextPool<MockCryptoContext> pool(&cryptor, 1); + + expect_get_context(CipherMode::CIPHER_MODE_ENC); + auto enc_ctx = pool.get_context(CipherMode::CIPHER_MODE_ENC); + + expect_get_context(CipherMode::CIPHER_MODE_DEC); + auto dec_ctx1 = pool.get_context(CipherMode::CIPHER_MODE_DEC); + expect_get_context(CipherMode::CIPHER_MODE_DEC); + auto dec_ctx2 = pool.get_context(CipherMode::CIPHER_MODE_DEC); + pool.return_context(dec_ctx1, CipherMode::CIPHER_MODE_DEC); + expect_return_context(dec_ctx2, CipherMode::CIPHER_MODE_DEC); + pool.return_context(dec_ctx2, CipherMode::CIPHER_MODE_DEC); + + pool.return_context(enc_ctx, CipherMode::CIPHER_MODE_ENC); + ASSERT_EQ(enc_ctx, pool.get_context(CipherMode::CIPHER_MODE_ENC)); + pool.return_context(enc_ctx, CipherMode::CIPHER_MODE_ENC); + + expect_return_context(enc_ctx, CipherMode::CIPHER_MODE_ENC); + expect_return_context(dec_ctx1, CipherMode::CIPHER_MODE_DEC); +} + +} // namespace crypto +} // namespace librbd |