• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wirenboard / wb-mqtt-iec104 / 38

31 Jul 2026 10:43AM UTC coverage: 52.549% (-0.2%) from 52.705%
38

push

github

web-flow
Use exported vars instead of MAKEFLAGS for coverage options (#30)

236 of 389 branches covered (60.67%)

402 of 765 relevant lines covered (52.55%)

3.58 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.33
/test/gateway.test.cpp
1
#include "gateway.h"
2
#include "config_parser.h"
3

4
#include <gtest/gtest.h>
5
#include <vector>
6

7
#include <wblib/json_utils.h>
8
#include <wblib/testing/fake_driver.h>
9
#include <wblib/testing/fake_mqtt.h>
10
#include <wblib/testing/testlog.h>
11

12
using namespace WBMQTT;
13

14
namespace
15
{
16
    void Dump(Testing::TLoggedFixture& fixture, const IEC104::TInformationObjects& obj)
13✔
17
    {
18
        for (auto v: obj.SinglePoint) {
16✔
19
            fixture.Emit() << "SP: " << v.Address << " = " << v.Value;
3✔
20
        }
21
        for (auto v: obj.MeasuredValueShort) {
16✔
22
            fixture.Emit() << "MShort: " << v.Address << " = " << v.Value;
3✔
23
        }
24
        for (auto v: obj.MeasuredValueScaled) {
16✔
25
            fixture.Emit() << "MScaled: " << v.Address << " = " << v.Value;
3✔
26
        }
27
        for (auto v: obj.SinglePointWithTimestamp) {
16✔
28
            fixture.Emit() << "SP: " << v.Address << " = " << v.Value << ", with timestamp";
3✔
29
        }
30
        for (auto v: obj.MeasuredValueShortWithTimestamp) {
16✔
31
            fixture.Emit() << "MShort: " << v.Address << " = " << v.Value << ", with timestamp";
3✔
32
        }
33
        for (auto v: obj.MeasuredValueScaledWithTimestamp) {
16✔
34
            fixture.Emit() << "MScaled: " << v.Address << " = " << v.Value << ", with timestamp";
3✔
35
        }
36
    }
13✔
37
}
38

39
class TGatewayTest: public Testing::TLoggedFixture
40
{
41
protected:
42
    std::string TestRootDir;
43
    std::string SchemaFile;
44
    PDeviceDriver Driver;
45
    TDeviceConfig Config;
46
    PControl Control1;
47
    PControl Control2;
48
    PControl Control3;
49
    PControl Control4;
50
    PControl Control5;
51
    PControl Control6;
52
    PControl ControlNotInConfig;
53

54
    void SetUp()
3✔
55
    {
56
        TestRootDir = GetDataFilePath("gateway_test_data");
3✔
57
        SchemaFile = TestRootDir + "/../../wb-mqtt-iec104.schema.json";
3✔
58

59
        auto mqttBroker = Testing::NewFakeMqttBroker(*this);
3✔
60
        auto mqttClient = mqttBroker->MakeClient("test");
6✔
61
        auto backend = NewDriverBackend(mqttClient);
3✔
62
        Driver = NewDriver(TDriverArgs{}.SetId("test").SetBackend(backend));
9✔
63

64
        Driver->StartLoop();
3✔
65
        Driver->WaitForReady();
3✔
66

67
        Config = LoadConfig(TestRootDir + "/config.conf", SchemaFile).Devices;
3✔
68

69
        auto tx = Driver->BeginTx();
3✔
70
        auto device = tx->CreateDevice(TLocalDeviceArgs{}.SetId("test")).GetValue();
9✔
71

72
        Control1 = device->CreateControl(tx, TControlArgs{}.SetId("test1").SetType("value").SetValue(1.23)).GetValue();
15✔
73

74
        Control2 =
75
            device->CreateControl(tx, TControlArgs{}.SetId("test2").SetType("switch").SetValue(false)).GetValue();
15✔
76

77
        Control3 = device->CreateControl(tx, TControlArgs{}.SetId("test3").SetType("value").SetValue(123)).GetValue();
15✔
78

79
        Control4 = device->CreateControl(tx, TControlArgs{}.SetId("test4").SetType("value").SetValue(3.21)).GetValue();
15✔
80

81
        Control5 = device->CreateControl(tx, TControlArgs{}.SetId("test5").SetType("switch").SetValue(true)).GetValue();
15✔
82

83
        Control6 = device->CreateControl(tx, TControlArgs{}.SetId("test6").SetType("value").SetValue(321)).GetValue();
15✔
84

85
        ControlNotInConfig =
86
            device->CreateControl(tx, TControlArgs{}.SetId("ControlNotInConfig").SetType("value").SetValue(1.23))
18✔
87
                .GetValue();
3✔
88
        tx->End();
3✔
89
    }
3✔
90
};
91

92
class TFakeIecServer: public IEC104::IServer
93
{
94
    Testing::TLoggedFixture& Fixture;
95

96
public:
97
    TFakeIecServer(Testing::TLoggedFixture& fixture): Fixture(fixture)
3✔
98
    {}
3✔
99

100
    void Stop()
×
101
    {}
×
102

103
    void SendSpontaneous(const IEC104::TInformationObjects& obj)
12✔
104
    {
105
        Fixture.Emit() << "IEC104::IServer::SendSpontaneous";
12✔
106
        Dump(Fixture, obj);
12✔
107
    }
12✔
108

109
    void SetHandler(IEC104::IHandler* handler)
3✔
110
    {}
3✔
111
};
112

113
TEST_F(TGatewayTest, SetParameter)
8✔
114
{
115
    TFakeIecServer iecServer(*this);
2✔
116
    TGateway gw(Driver, &iecServer, Config);
2✔
117

118
    // Valid params
119
    ASSERT_TRUE(gw.SetParameter(1, "10.21"));
4✔
120
    ASSERT_TRUE(gw.SetParameter(2, "1"));
4✔
121
    ASSERT_TRUE(gw.SetParameter(3, "-1"));
4✔
122
    ASSERT_TRUE(gw.SetParameter(4, "9.87"));
4✔
123
    ASSERT_TRUE(gw.SetParameter(5, "0"));
4✔
124
    ASSERT_TRUE(gw.SetParameter(6, "-15"));
4✔
125

126
    // Unknown ioa
127
    ASSERT_FALSE(gw.SetParameter(7, "7"));
4✔
128
}
2✔
129

130
TEST_F(TGatewayTest, GetInformationObjectsValues)
8✔
131
{
132
    TFakeIecServer iecServer(*this);
2✔
133
    TGateway gw(Driver, &iecServer, Config);
2✔
134
    Dump(*this, gw.GetInformationObjectsValues());
2✔
135
}
2✔
136

137
TEST_F(TGatewayTest, OnValueChanged)
8✔
138
{
139
    TFakeIecServer iecServer(*this);
2✔
140
    TGateway gw(Driver, &iecServer, Config);
2✔
141
    auto tx = Driver->BeginTx();
2✔
142
    ControlNotInConfig->SetValue(tx, 123.123).Sync();
2✔
143
    Control1->SetValue(tx, 2.34).Sync();
2✔
144
    Control2->SetValue(tx, true).Sync();
2✔
145
    Control3->SetRawValue(tx, "200").Sync();
4✔
146
    Control4->SetValue(tx, 5.67).Sync();
2✔
147
    Control5->SetValue(tx, false).Sync();
2✔
148
    Control6->SetRawValue(tx, "768").Sync();
4✔
149
    tx->End();
2✔
150
}
2✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc