2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Contact: Kyungwook Tak <k.tak@samsung.com>
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License
18 * @file test_safe-buffer.cpp
19 * @author Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
25 #include <boost/test/unit_test.hpp>
26 #include <test_common.h>
28 #include <ckm/ckm-raw-buffer.h>
34 const size_t LEN = 100;
38 Item(size_t a) : mA(a) {}
41 bool operator==(const size_t& other) const {
49 size_t buffer_erase_test()
51 typename T::value_type* data = NULL;
52 typename T::size_type i = 0;
56 buffer.push_back(typename T::value_type(i));
61 BOOST_CHECK(data[i] == i);
65 * operator delete of RawBuffer which is called after buffer memory is erased
66 * (see erase_on_dealloc::deallocate) sometimes leaves garbage in the beginning of that memory.
67 * Therefore the test will be marked as failing only if more than 1/10 of the data matches
72 cnt += (data[i] == i?1:0);
77 } // namespace anonymous
79 BOOST_AUTO_TEST_SUITE(SAFE_BUFFER_TEST)
81 // Tests for SafeBuffer. Checks if memory occupied by the buffer is wiped after it's deleted.
83 BOOST_AUTO_TEST_CASE(SafeBufferTest_uc_control_group) {
84 size_t cnt = buffer_erase_test<std::vector<unsigned char> >();
86 BOOST_REQUIRE_MESSAGE(cnt > LEN/2, "Less than 1/2 of data matches the original.");
89 BOOST_AUTO_TEST_CASE(SafeBufferTest_item_control_group) {
90 size_t cnt = buffer_erase_test<std::vector<Item> >();
92 BOOST_REQUIRE_MESSAGE(cnt > LEN/2, "Less than 1/2 of data matches the original.");
95 BOOST_AUTO_TEST_CASE(SafeBufferTest_uc) {
96 size_t cnt = buffer_erase_test<RawBuffer>();
98 BOOST_REQUIRE_MESSAGE(cnt <= LEN/10, "More than 1/10 of data matches the original.");
101 BOOST_AUTO_TEST_CASE(SafeBufferTest_item) {
102 size_t cnt = buffer_erase_test<SafeBuffer<Item>::Type>();
104 BOOST_REQUIRE_MESSAGE(cnt <= LEN/10, "More than 1/10 of data matches the original.");
107 BOOST_AUTO_TEST_SUITE_END()