IPC unit tests and testing framework improvements
[platform/core/security/vasum.git] / tests / unit_tests / ipc / ut-unique-id.cpp
1 /*
2  *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *  Contact: Lukasz Kostyra <l.kostyra@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
19
20 /**
21  * @file
22  * @author  Lukasz Kostyra (l.kostyra@samsung.com)
23  * @brief   Unit tests of UID
24  */
25
26 #include "config.hpp"
27 #include "ut.hpp"
28
29 #include "ipc/unique-id.hpp"
30
31 #include <string>
32 #include <sstream>
33 #include <uuid/uuid.h>
34
35 namespace {
36
37 const std::string EMPTY_UUID = "00000000-0000-0000-0000-000000000000";
38
39 } // namespace
40
41 BOOST_AUTO_TEST_SUITE(UniqueIDSuite)
42
43 // constructor should provide empty timestamp and UUID
44 BOOST_AUTO_TEST_CASE(Constructor)
45 {
46     ipc::UniqueID uid;
47
48     BOOST_CHECK_EQUAL(static_cast<std::int64_t>(uid.mTime.tv_sec), 0);
49     BOOST_CHECK_EQUAL(uid.mTime.tv_nsec, 0);
50     char uuid[37]; // 36 chars + terminating zero
51     ::uuid_unparse(uid.mUUID, uuid);
52     BOOST_CHECK(EMPTY_UUID.compare(uuid) == 0);
53 }
54
55 // generate one UID and compare with empty
56 BOOST_AUTO_TEST_CASE(Generate)
57 {
58     ipc::UniqueID uid, emptyuid;
59     uid.generate();
60
61     BOOST_CHECK_NE(uid, emptyuid);
62 }
63
64 // generate two UIDs and compare them
65 BOOST_AUTO_TEST_CASE(DoubleGenerate)
66 {
67     ipc::UniqueID uid1, uid2;
68
69     uid1.generate();
70     uid2.generate();
71     BOOST_CHECK_NE(uid1, uid2);
72 }
73
74 // compare two empty UIDs
75 BOOST_AUTO_TEST_CASE(EmptyCompare)
76 {
77     ipc::UniqueID uid1, uid2;
78
79     BOOST_CHECK_EQUAL(uid1, uid2);
80 }
81
82 // pass empty UID to a stream
83 BOOST_AUTO_TEST_CASE(StreamOperator)
84 {
85     ipc::UniqueID uid;
86     std::stringstream ss;
87
88     ss << uid;
89     BOOST_CHECK_EQUAL(ss.str(), "0.0:" + EMPTY_UUID);
90 }
91
92 BOOST_AUTO_TEST_SUITE_END()