summaryrefslogtreecommitdiffstats
path: root/test/message/native_types.cpp
blob: 3c9d20a77d3ba0f1baa34ec367d17c458c89f44b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <map>
#include <sdbusplus/message.hpp>
#include <string>
#include <unordered_map>
#include <vector>

#include <gtest/gtest.h>

using namespace std::string_literals;

/* Suite tests that object_path and signature can be cleanly converted to
 * and from strings and used as container parameters.
 */

TEST(MessageNativeTypeConversions, ObjectPath)
{
    std::string s1 = sdbusplus::message::object_path("/asdf/");
    sdbusplus::message::object_path p = std::move(s1);

    ASSERT_EQ("/asdf/", p);
    ASSERT_EQ(p, "/asdf/");
}

TEST(MessageNativeTypeConversions, Signature)
{
    std::string s2 = sdbusplus::message::signature("iii");
    sdbusplus::message::signature sig = s2;

    ASSERT_EQ(sig, s2);
    ASSERT_EQ(s2, sig);
}

TEST(MessageNativeTypeConversions, SignatureInVector)
{
    std::vector<sdbusplus::message::signature> v = {
        sdbusplus::message::signature("iii")};

    ASSERT_EQ(v.front(), "iii");
}

TEST(MessageNativeTypeConversions, SignatureInMap)
{
    std::map<sdbusplus::message::signature, int> m = {
        {sdbusplus::message::signature("iii"), 1}};

    ASSERT_EQ(m[sdbusplus::message::signature("iii")], 1);
}

TEST(MessageNativeTypeConversions, SignatureInUnorderedMap)
{
    std::unordered_map<sdbusplus::message::signature, int> u = {
        {sdbusplus::message::signature("iii"), 2}};

    ASSERT_EQ(u[sdbusplus::message::signature("iii")], 2);
}

TEST(MessageNativeTypeConversions, WrapperReference)
{
    auto orig = "str"s;
    sdbusplus::message::object_path obj = orig;
    auto out = static_cast<std::string>(obj);
    EXPECT_EQ(orig, out);
}

TEST(MessageNativeTypeConversions, WrapperMove)
{
    auto orig = "str"s;
    sdbusplus::message::object_path obj = orig;
    auto out = static_cast<std::string>(std::move(obj));
    EXPECT_EQ(orig, out);
}
OpenPOWER on IntegriCloud