Refactor build system and add internal test
[platform/core/security/libcryptsvc.git] / test / cs_test.cc
1 /*
2  *  Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *  Contact: Kyungwook Tak <k.tak@samsung.com>
5  *
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
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
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
17  *
18  * @file        cs_test.cc
19  * @author      Kyungwook Tak (k.tak@samsung.com)
20  * @version
21  * @brief
22  */
23 #include <iostream>
24
25 #include <boost/test/unit_test.hpp>
26
27 #include <SecCryptoSvc.h>
28
29 BOOST_AUTO_TEST_SUITE(CRYPTO_SERVICE_TEST)
30
31 BOOST_AUTO_TEST_CASE(PLATFORM_UNIQUE_KEY)
32 {
33     constexpr unsigned int KeyLen = 16;
34     unsigned char cek[KeyLen] = {0};
35     char *encoded_cek = nullptr;
36
37     BOOST_REQUIRE_MESSAGE(SecFrameGeneratePlatformUniqueKey(KeyLen, cek),
38         "Failed to SecFrameGeneratePlatformUniqueKey.");
39
40     encoded_cek = Base64Encoding(
41             reinterpret_cast<char *>(cek),
42             static_cast<int>(KeyLen));
43     BOOST_REQUIRE_MESSAGE(encoded_cek != nullptr, "Failed to base64 encoding.");
44
45     std::cout << "base64 encoded platform unique key(with len 16): "
46         << encoded_cek << std::endl;
47 }
48
49 BOOST_AUTO_TEST_CASE(GETDUID_16)
50 {
51     char *duid = GetDuid(16);
52     BOOST_REQUIRE_MESSAGE(duid != nullptr, "returned duid shouldn't be null");
53     std::cout << "duid: " << duid << std::endl;
54 }
55
56 BOOST_AUTO_TEST_CASE(GETDUID_20)
57 {
58     char *duid = GetDuid(20);
59     BOOST_REQUIRE_MESSAGE(duid != nullptr, "returned duid shouldn't be null");
60     std::cout << "duid: " << duid << std::endl;
61 }
62
63
64 BOOST_AUTO_TEST_SUITE_END()