forked from Brill-Power/thingsetplusplus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestRecordMembers.cpp
More file actions
68 lines (59 loc) · 1.83 KB
/
TestRecordMembers.cpp
File metadata and controls
68 lines (59 loc) · 1.83 KB
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
/*
* Copyright (c) 2025 Brill Power.
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "gtest/gtest.h"
#include <thingset++/ThingSet.hpp>
using namespace ThingSet;
struct Child
{
ThingSetReadOnlyRecordMember<0x511, 0x510, "voltage", float> voltage;
};
struct Record
{
ThingSetReadOnlyRecordMember<0x501, 0x500, "voltage", float> voltage;
ThingSetReadOnlyRecordMember<0x502, 0x500, "current", float> current;
ThingSetReadOnlyRecordMember<0x503, 0x500, "error", uint64_t> error;
ThingSetReadOnlyRecordMember<0x510, 0x500, "cells", std::array<Child, 4>> cells;
};
ThingSetReadOnlyProperty<std::array<Record, 2>> records { 0x500, 0x0, "records" };
TEST(RecordMembers, FindRecordById)
{
ThingSetNode *node;
ASSERT_TRUE(ThingSetRegistry::findById(0x500, &node));
ASSERT_EQ("records", node->getName());
}
TEST(RecordMembers, FindRecordByName)
{
ThingSetNode *node;
ASSERT_TRUE(ThingSetRegistry::findByName("records", &node));
ASSERT_EQ(0x500, node->getId());
}
TEST(RecordMembers, FindValueRecordMemberById)
{
ThingSetNode *node;
ASSERT_TRUE(ThingSetRegistry::findById(0x501, 0x500, &node));
ASSERT_EQ("voltage", node->getName());
}
TEST(RecordMembers, FindArrayRecordMemberById)
{
ThingSetNode *node;
ASSERT_TRUE(ThingSetRegistry::findById(0x510, 0x500, &node));
ASSERT_EQ("cells", node->getName());
}
TEST(RecordMembers, ArrayRecordMemberHasChildren)
{
ThingSetNode *node;
ASSERT_TRUE(ThingSetRegistry::findById(0x510, 0x500, &node));
void *target;
ASSERT_TRUE(node->tryCastTo(ThingSetNodeType::hasChildren, &target));
ThingSetParentNode &parent = *reinterpret_cast<ThingSetParentNode *>(target);
size_t count = 0;
for (auto n : parent) {
ASSERT_EQ("voltage", n->getName());
ASSERT_EQ(0x511, n->getId());
count++;
}
ASSERT_EQ(1, count);
}