3 #include <boost/test/unit_test.hpp>
4 #include <test_common.h>
6 #include <ckm/ckm-raw-buffer.h>
12 const size_t LEN = 100;
16 Item(size_t a) : mA(a) {}
19 bool operator==(const size_t& other) const {
27 size_t buffer_erase_test()
29 typename T::value_type* data = NULL;
30 typename T::size_type i = 0;
34 buffer.push_back(typename T::value_type(i));
39 BOOST_CHECK(data[i] == i);
43 * operator delete of RawBuffer which is called after buffer memory is erased
44 * (see erase_on_dealloc::deallocate) sometimes leaves garbage in the beginning of that memory.
45 * Therefore the test will be marked as failing only if more than 1/10 of the data matches
50 cnt += (data[i] == i?1:0);
55 } // namespace anonymous
57 BOOST_AUTO_TEST_SUITE(SAFE_BUFFER_TEST)
59 // Tests for SafeBuffer. Checks if memory occupied by the buffer is wiped after it's deleted.
61 BOOST_AUTO_TEST_CASE(SafeBufferTest_uc_control_group) {
62 size_t cnt = buffer_erase_test<std::vector<unsigned char> >();
64 BOOST_REQUIRE_MESSAGE(cnt > LEN/2, "Less than 1/2 of data matches the original.");
67 BOOST_AUTO_TEST_CASE(SafeBufferTest_item_control_group) {
68 size_t cnt = buffer_erase_test<std::vector<Item> >();
70 BOOST_REQUIRE_MESSAGE(cnt > LEN/2, "Less than 1/2 of data matches the original.");
73 BOOST_AUTO_TEST_CASE(SafeBufferTest_uc) {
74 size_t cnt = buffer_erase_test<RawBuffer>();
76 BOOST_REQUIRE_MESSAGE(cnt <= LEN/10, "More than 1/10 of data matches the original.");
79 BOOST_AUTO_TEST_CASE(SafeBufferTest_item) {
80 size_t cnt = buffer_erase_test<SafeBuffer<Item>::Type>();
82 BOOST_REQUIRE_MESSAGE(cnt <= LEN/10, "More than 1/10 of data matches the original.");
85 BOOST_AUTO_TEST_SUITE_END()