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

wirenboard / wb-mqtt-serial / 1

20 Oct 2026 04:57AM UTC coverage: 86.817% (+14.0%) from 72.836%
1

Pull #1281

github

fab311
KraPete
Fix device model fallback in device/LoadConfig RPC

The short model register was never read because the extended register
error was converted to TRPCException. The RPC error now says that
the device model could not be read.
Pull Request #1281: Fix device model fallback in device/LoadConfig RPC

31180 of 80922 branches covered (38.53%)

74 of 76 new or added lines in 2 files covered. (97.37%)

1379 existing lines in 84 files now uncovered.

22464 of 25875 relevant lines covered (86.82%)

5205.91 hits per line

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

96.67
/src/common_utils.cpp
1
#include "common_utils.h"
2
#include <algorithm>
3
#include <regex>
4
#include <sstream>
5
#include <unordered_map>
6

7
namespace
8
{
9
    const std::unordered_map<char, std::string> ConvertToMqttStringMap =
10
        {{'\'', "|"}, {'"', "|"}, {'/', "|"}, {'+', "_plus_"}, {'$', "_"}, {'#', "_"}};
11

12
    static std::vector<int> ParseVersionString(const std::string& version)
380 ✔
13
    {
14
        std::string buffer;
380 ✔
15
        std::istringstream stream(version);
380 !
16
        std::vector<int> list;
380 ✔
17
        while (getline(stream, buffer, '.')) {
1,520 !
18
            if (std::regex_match(buffer, std::regex("^[0-9]+$"))) {
1,140 !
19
                list.push_back(std::stoi(buffer));
1,116 !
20
                continue;
1,116 ✔
21
            }
22
            if (std::regex_match(buffer, std::regex("^[0-9]+(-rc|\\+wb)[0-9]+$"))) {
24 !
23
                int index = buffer.find("-rc");
24 ✔
24
                int offset = -128;
24 ✔
25
                if (index < 0) {
24 ✔
26
                    index = buffer.find("+wb");
12 ✔
27
                    offset = 128;
12 ✔
28
                }
29
                list.push_back(std::stoi(buffer.substr(0, index)));
24 !
30
                list.push_back(std::stoi(buffer.substr(index + 3)) + offset);
24 !
31
                continue;
24 ✔
32
            }
24 ✔
UNCOV
33
            list.push_back(0);
×
34
        }
35
        return list;
380 ✔
36
    }
380 ✔
37
} // namespace
38

39
bool util::IsValidMqttTopicString(const std::string& src)
8 ✔
40
{
41
    return std::find_if(src.begin(), src.end(), [](auto ch) {
8 !
42
               return ConvertToMqttStringMap.find(ch) != ConvertToMqttStringMap.end();
68 !
43
           }) == src.end();
8 ✔
44
}
45

46
std::string util::ConvertToValidMqttTopicString(const std::string& src)
4 ✔
47
{
48
    std::string validStr;
4 ✔
49
    for (auto const& ch: src) {
102 ✔
50
        if (const auto it = ConvertToMqttStringMap.find(ch); it != ConvertToMqttStringMap.end()) {
98 !
51
            validStr += it->second;
16 !
52
        } else {
53
            validStr += ch;
82 !
54
        }
55
    }
56

57
    return validStr;
4 ✔
UNCOV
58
}
×
59

60
int util::CompareVersionStrings(const std::string& v1, const std::string& v2)
418 ✔
61
{
62
    if (v1.empty() && v2.empty()) {
418 ✔
63
        return 0;
78 ✔
64
    }
65
    if (v1.empty()) {
340 ✔
66
        return -1;
12 ✔
67
    }
68
    if (v2.empty()) {
328 ✔
69
        return 1;
138 ✔
70
    }
71
    std::vector<int> l1 = ParseVersionString(v1);
190 !
72
    std::vector<int> l2 = ParseVersionString(v2);
190 !
73
    for (size_t i = 0; i < std::max(l1.size(), l2.size()); ++i) {
462 ✔
74
        int n1 = i < l1.size() ? l1[i] : 0;
438 ✔
75
        int n2 = i < l2.size() ? l2[i] : 0;
438 ✔
76
        if (n1 > n2) {
438 ✔
77
            return 1;
130 ✔
78
        }
79
        if (n1 < n2) {
308 ✔
80
            return -1;
36 ✔
81
        }
82
    }
83
    return 0;
24 ✔
84
}
190 ✔
85

86
util::TSpentTimeMeter::TSpentTimeMeter(util::TGetNowFn nowFn): NowFn(nowFn)
606 ✔
87
{}
606 ✔
88

89
void util::TSpentTimeMeter::Start()
20,242 ✔
90
{
91
    StartTime = NowFn();
20,242 ✔
92
}
20,242 ✔
93

94
std::chrono::steady_clock::time_point util::TSpentTimeMeter::GetStartTime() const
69,952 ✔
95
{
96
    return StartTime;
69,952 ✔
97
}
98

99
std::chrono::microseconds util::TSpentTimeMeter::GetSpentTime() const
29,574 ✔
100
{
101
    return std::chrono::ceil<std::chrono::microseconds>(NowFn() - StartTime);
29,574 !
102
}
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