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

wirenboard / wb-mqtt-serial / 964

28 Sep 2026 06:54AM UTC coverage: 83.234% (+6.4%) from 76.817%
964

push

github

web-flow
Add disable_fast_modbus option to ports and Modbus devices (#1270)

11435 of 13496 branches covered (84.73%)

150 of 152 new or added lines in 11 files covered. (98.68%)

1282 existing lines in 91 files now uncovered.

19376 of 23279 relevant lines covered (83.23%)

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

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

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

57
    return validStr;
2 ✔
UNCOV
58
}
×
59

60
int util::CompareVersionStrings(const std::string& v1, const std::string& v2)
169 ✔
61
{
62
    if (v1.empty() && v2.empty()) {
169 ✔
63
        return 0;
2 ✔
64
    }
65
    if (v1.empty()) {
167 ✔
66
        return -1;
6 ✔
67
    }
68
    if (v2.empty()) {
161 ✔
69
        return 1;
68 ✔
70
    }
71
    std::vector<int> l1 = ParseVersionString(v1);
93 ✔
72
    std::vector<int> l2 = ParseVersionString(v2);
93 ✔
73
    for (size_t i = 0; i < std::max(l1.size(), l2.size()); ++i) {
229 ✔
74
        int n1 = i < l1.size() ? l1[i] : 0;
217 ✔
75
        int n2 = i < l2.size() ? l2[i] : 0;
217 ✔
76
        if (n1 > n2) {
217 ✔
77
            return 1;
65 ✔
78
        }
79
        if (n1 < n2) {
152 ✔
80
            return -1;
16 ✔
81
        }
82
    }
83
    return 0;
12 ✔
84
}
93 ✔
85

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

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

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

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