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

mendersoftware / mender / 1006302423

15 Sep 2023 12:56PM UTC coverage: 78.737% (+0.3%) from 78.482%
1006302423

push

gitlab-ci

oleorhagen
feat(daemon): Add state script support

Ticket: MEN-6637
Changelog: None

Signed-off-by: Ole Petter <ole.orhagen@northern.tech>

194 of 194 new or added lines in 4 files covered. (100.0%)

5984 of 7600 relevant lines covered (78.74%)

1109.89 hits per line

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

78.79
/common/common.cpp
1
// Copyright 2023 Northern.tech AS
2
//
3
//    Licensed under the Apache License, Version 2.0 (the "License");
4
//    you may not use this file except in compliance with the License.
5
//    You may obtain a copy of the License at
6
//
7
//        http://www.apache.org/licenses/LICENSE-2.0
8
//
9
//    Unless required by applicable law or agreed to in writing, software
10
//    distributed under the License is distributed on an "AS IS" BASIS,
11
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
//    See the License for the specific language governing permissions and
13
//    limitations under the License.
14

15
#include <common/common.hpp>
16
#include <common/error.hpp>
17

18
#include <cerrno>
19
#include <cstdlib>
20

21
namespace mender {
22
namespace common {
23

24
mender::common::expected::ExpectedLongLong StringToLongLong(const string &str, int base) {
418✔
25
        char *end;
26
        errno = 0;
418✔
27
        long long num = strtoll(str.c_str(), &end, base);
418✔
28
        if (errno != 0) {
418✔
29
                int int_error = errno;
×
30
                return expected::unexpected(mender::common::error::Error(
×
31
                        std::generic_category().default_error_condition(int_error), ""));
×
32
        }
33
        if (end != &*str.end()) {
418✔
34
                return expected::unexpected(mender::common::error::Error(
×
35
                        std::make_error_condition(errc::invalid_argument),
×
36
                        str + " had trailing non-numeric data"));
×
37
        }
38

39
        return num;
418✔
40
}
41

42
vector<string> SplitString(const string &str, const string &delim) {
822✔
43
        vector<string> ret;
822✔
44
        for (size_t begin = 0, end = str.find(delim);;) {
822✔
45
                if (end == string::npos) {
965✔
46
                        ret.push_back(string(str.begin() + begin, str.end()));
822✔
47
                        break;
822✔
48
                } else {
49
                        ret.push_back(string(str.begin() + begin, str.begin() + end));
143✔
50
                        begin = end + 1;
143✔
51
                        end = str.find(delim, begin);
143✔
52
                }
53
        }
54
        return ret;
822✔
55
}
56

57
string JoinStrings(const vector<string> &str, const string &delim) {
168✔
58
        string ret;
168✔
59
        auto s = str.begin();
168✔
60
        if (s == str.end()) {
168✔
61
                return ret;
×
62
        }
63
        ret += *s;
168✔
64
        s++;
168✔
65
        for (; s != str.end(); s++) {
1,663✔
66
                ret += delim;
1,495✔
67
                ret += *s;
1,495✔
68
        }
69
        return ret;
168✔
70
}
71

72
} // namespace common
73
} // namespace mender
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc