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

wirenboard / wb-mqtt-serial / 2

20 Oct 2026 05:26AM UTC coverage: 86.772% (+13.9%) from 72.836%
2

Pull #1283

github

e3f11f
KraPete
Remove comment from service unit

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Pull Request #1283: Order service after mosquitto and restart it without limit

31090 of 80727 branches covered (38.51%)

22401 of 25816 relevant lines covered (86.77%)

2589.67 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)
190 ✔
13
    {
14
        std::string buffer;
190 ✔
15
        std::istringstream stream(version);
190 !
16
        std::vector<int> list;
190 ✔
17
        while (getline(stream, buffer, '.')) {
760 !
18
            if (std::regex_match(buffer, std::regex("^[0-9]+$"))) {
570 !
19
                list.push_back(std::stoi(buffer));
558 !
20
                continue;
558 ✔
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 ✔
33
            list.push_back(0);
×
34
        }
35
        return list;
190 ✔
36
    }
190 ✔
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 ✔
58
}
×
59

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

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

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

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

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