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

GothenburgBitFactory / taskwarrior / 10152339701

29 Jul 2024 09:45PM UTC coverage: 84.437% (+0.07%) from 84.372%
10152339701

push

github

web-flow
Merge pull request #3566 from felixschurk/add-clang-format

Add clang-format to enforce style guide

12359 of 13760 new or added lines in 147 files covered. (89.82%)

123 existing lines in 42 files now uncovered.

19070 of 22585 relevant lines covered (84.44%)

19724.02 hits per line

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

82.09
/src/tc/Task.cpp
1
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Copyright 2022, Dustin J. Mitchell
4
//
5
// Permission is hereby granted, free of charge, to any person obtaining a copy
6
// of this software and associated documentation files (the "Software"), to deal
7
// in the Software without restriction, including without limitation the rights
8
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
// copies of the Software, and to permit persons to whom the Software is
10
// furnished to do so, subject to the following conditions:
11
//
12
// The above copyright notice and this permission notice shall be included
13
// in all copies or substantial portions of the Software.
14
//
15
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
// SOFTWARE.
22
//
23
// https://www.opensource.org/licenses/mit-license.php
24
//
25
////////////////////////////////////////////////////////////////////////////////
26

27
#include <cmake.h>
28
// cmake.h include header must come first
29

30
#include <assert.h>
31

32
#include "tc/Task.h"
33
#include "tc/util.h"
34

35
using namespace tc::ffi;
36

37
////////////////////////////////////////////////////////////////////////////////
38
tc::Task::Task(TCTask* tctask) {
763,459✔
39
  inner = unique_tctask_ptr(tctask, [](TCTask* task) { tc_task_free(task); });
766,395✔
40
}
763,459✔
41

42
////////////////////////////////////////////////////////////////////////////////
43
tc::Task::Task(Task&& other) noexcept {
787,613✔
44
  // move inner from other
45
  inner = unique_tctask_ptr(other.inner.release(), [](TCTask* task) { tc_task_free(task); });
1,548,135✔
46
}
787,613✔
47

48
////////////////////////////////////////////////////////////////////////////////
49
tc::Task& tc::Task::operator=(Task&& other) noexcept {
1✔
50
  if (this != &other) {
1✔
51
    // move inner from other
52
    inner = unique_tctask_ptr(other.inner.release(), [](TCTask* task) { tc_task_free(task); });
2✔
53
  }
54
  return *this;
1✔
55
}
56

57
////////////////////////////////////////////////////////////////////////////////
58
void tc::Task::to_mut(TCReplica* replica) { tc_task_to_mut(&*inner, replica); }
3,488✔
59

60
////////////////////////////////////////////////////////////////////////////////
61
void tc::Task::to_immut() { tc_task_to_immut(&*inner); }
3,488✔
62

63
////////////////////////////////////////////////////////////////////////////////
64
std::string tc::Task::get_uuid() const {
760,035✔
65
  auto uuid = tc_task_get_uuid(&*inner);
760,035✔
66
  return tc2uuid(uuid);
1,520,070✔
67
}
68

69
////////////////////////////////////////////////////////////////////////////////
70
tc::Status tc::Task::get_status() const {
2✔
71
  auto status = tc_task_get_status(&*inner);
2✔
72
  return tc::Status(status);
2✔
73
}
74

75
////////////////////////////////////////////////////////////////////////////////
76
std::map<std::string, std::string> tc::Task::get_taskmap() const {
26,916✔
77
  TCKVList kv = tc_task_get_taskmap(&*inner);
26,916✔
78
  if (!kv.items) {
26,916✔
NEW
79
    throw task_error();
×
80
  }
81

82
  std::map<std::string, std::string> taskmap;
26,916✔
83
  for (size_t i = 0; i < kv.len; i++) {
160,755✔
84
    auto k = tc2string_clone(kv.items[i].key);
133,839✔
85
    auto v = tc2string_clone(kv.items[i].value);
133,839✔
86
    taskmap[k] = v;
133,839✔
87
  }
133,839✔
88

89
  return taskmap;
53,832✔
90
}
91

92
////////////////////////////////////////////////////////////////////////////////
93
std::string tc::Task::get_description() const {
3✔
94
  auto desc = tc_task_get_description(&*inner);
3✔
95
  return tc2string(desc);
6✔
96
}
97

98
////////////////////////////////////////////////////////////////////////////////
99
std::optional<std::string> tc::Task::get_value(std::string property) const {
175✔
100
  auto maybe_desc = tc_task_get_value(&*inner, string2tc(property));
175✔
101
  if (maybe_desc.ptr == NULL) {
175✔
102
    return std::nullopt;
161✔
103
  }
104
  return std::make_optional(tc2string(maybe_desc));
14✔
105
}
106

107
bool tc::Task::is_waiting() const { return tc_task_is_waiting(&*inner); }
1✔
108

109
////////////////////////////////////////////////////////////////////////////////
110
bool tc::Task::is_active() const { return tc_task_is_active(&*inner); }
1✔
111

112
////////////////////////////////////////////////////////////////////////////////
113
bool tc::Task::is_blocked() const { return tc_task_is_blocked(&*inner); }
26,362✔
114

115
////////////////////////////////////////////////////////////////////////////////
116
bool tc::Task::is_blocking() const { return tc_task_is_blocking(&*inner); }
26,362✔
117

118
////////////////////////////////////////////////////////////////////////////////
119
void tc::Task::set_status(tc::Status status) {
2,935✔
120
  TCResult res = tc_task_set_status(&*inner, (TCStatus)status);
2,935✔
121
  if (res != TC_RESULT_OK) {
2,935✔
NEW
122
    throw task_error();
×
123
  }
124
}
2,935✔
125

126
////////////////////////////////////////////////////////////////////////////////
127
void tc::Task::set_value(std::string property, std::optional<std::string> value) {
8,714✔
128
  TCResult res;
129
  if (value.has_value()) {
8,714✔
130
    res = tc_task_set_value(&*inner, string2tc(property), string2tc(value.value()));
8,650✔
131
  } else {
132
    TCString nullstr;
133
    nullstr.ptr = NULL;
64✔
134
    res = tc_task_set_value(&*inner, string2tc(property), nullstr);
64✔
135
  }
136
  if (res != TC_RESULT_OK) {
8,714✔
NEW
137
    throw task_error();
×
138
  }
139
}
8,714✔
140

141
////////////////////////////////////////////////////////////////////////////////
142
void tc::Task::set_modified(time_t modified) {
2,935✔
143
  TCResult res = tc_task_set_modified(&*inner, modified);
2,935✔
144
  if (res != TC_RESULT_OK) {
2,935✔
NEW
145
    throw task_error();
×
146
  }
147
}
2,935✔
148

149
////////////////////////////////////////////////////////////////////////////////
NEW
150
std::string tc::Task::task_error() const {
×
NEW
151
  TCString error = tc_task_error(&*inner);
×
152
  std::string errmsg;
×
153
  if (!error.ptr) {
×
NEW
154
    errmsg = std::string("Unknown TaskChampion error");
×
155
  } else {
NEW
156
    errmsg = std::string(tc_string_content(&error));
×
157
  }
NEW
158
  tc_string_free(&error);
×
159
  return errmsg;
×
160
}
161

162
////////////////////////////////////////////////////////////////////////////////
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