Remove restrict mechanism.
[platform/core/security/key-manager.git] / tests / test_safe-buffer.cpp
1 #include <boost/test/unit_test.hpp>
2
3 #include <test_common.h>
4
5 #include <ckm/ckm-raw-buffer.h>
6
7 BOOST_GLOBAL_FIXTURE(TestConfig)
8
9 using namespace CKM;
10
11 namespace {
12     const RawBuffer::size_type LEN = 10;
13
14     struct Item
15     {
16         Item(size_t a) : mA(a) {}
17         ~Item() {}
18
19         size_t mA;
20     };
21 } // namespace anonymous
22
23 BOOST_AUTO_TEST_SUITE(SAFE_BUFFER_TEST)
24
25 /*
26  * Test for SafeBuffer. Checks if memory occupied by the buffer is wiped after
27  * it's deleted
28  */
29 BOOST_AUTO_TEST_CASE(SafeBufferTest_uc) {
30     const unsigned char* data = NULL;
31     RawBuffer::size_type i = 0;
32     {
33         RawBuffer buffer;
34         for (i=0;i<LEN;++i)
35             buffer.push_back(i);
36
37         data = buffer.data();
38
39         for (i=0;i<LEN;++i)
40             BOOST_CHECK(data[i] == i);
41     }
42     for (i=0;i<LEN;++i)
43         BOOST_CHECK(data[i] == 0);
44 }
45
46 BOOST_AUTO_TEST_CASE(SafeBufferTest_item) {
47     const unsigned char* data = NULL;
48     RawBuffer::size_type i = 0;
49     {
50         SafeBuffer<Item>::Type buffer;
51         for (i=0;i<LEN;++i)
52             buffer.push_back(i);
53
54         for (i=0;i<LEN;++i) {
55             BOOST_CHECK(buffer[i].mA == i);
56         }
57
58         data = reinterpret_cast<unsigned char*>(buffer.data());
59     }
60     for (i=0;i<LEN*sizeof(Item);++i)
61         BOOST_CHECK(data[i] == 0);
62 }
63
64 BOOST_AUTO_TEST_SUITE_END()