3 #include <boost/test/unit_test.hpp>
4 #include <test_common.h>
6 #include <ckm/ckm-raw-buffer.h>
8 BOOST_GLOBAL_FIXTURE(TestConfig)
14 const size_t LEN = 100;
18 Item(size_t a) : mA(a) {}
21 bool operator==(const size_t& other) const {
29 size_t buffer_erase_test()
31 typename T::value_type* data = NULL;
32 typename T::size_type i = 0;
36 buffer.push_back(typename T::value_type(i));
41 BOOST_CHECK(data[i] == i);
45 * operator delete of RawBuffer which is called after buffer memory is erased
46 * (see erase_on_dealloc::deallocate) sometimes leaves garbage in the beginning of that memory.
47 * Therefore the test will be marked as failing only if more than 1/10 of the data matches
52 cnt += (data[i] == i?1:0);
57 } // namespace anonymous
59 BOOST_AUTO_TEST_SUITE(SAFE_BUFFER_TEST)
61 // Tests for SafeBuffer. Checks if memory occupied by the buffer is wiped after it's deleted.
63 BOOST_AUTO_TEST_CASE(SafeBufferTest_uc_control_group) {
64 size_t cnt = buffer_erase_test<std::vector<unsigned char> >();
66 BOOST_REQUIRE_MESSAGE(cnt > LEN/2, "Less than 1/2 of data matches the original.");
69 BOOST_AUTO_TEST_CASE(SafeBufferTest_item_control_group) {
70 size_t cnt = buffer_erase_test<std::vector<Item> >();
72 BOOST_REQUIRE_MESSAGE(cnt > LEN/2, "Less than 1/2 of data matches the original.");
75 BOOST_AUTO_TEST_CASE(SafeBufferTest_uc) {
76 size_t cnt = buffer_erase_test<RawBuffer>();
78 BOOST_REQUIRE_MESSAGE(cnt <= LEN/10, "More than 1/10 of data matches the original.");
81 BOOST_AUTO_TEST_CASE(SafeBufferTest_item) {
82 size_t cnt = buffer_erase_test<SafeBuffer<Item>::Type>();
84 BOOST_REQUIRE_MESSAGE(cnt <= LEN/10, "More than 1/10 of data matches the original.");
87 BOOST_AUTO_TEST_SUITE_END()