• 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

30.77
/src/tc/Server.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 <format.h>
31

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

35
using namespace tc::ffi;
36

37
////////////////////////////////////////////////////////////////////////////////
38
tc::Server tc::Server::new_local(const std::string &server_dir) {
2✔
39
  TCString tc_server_dir = tc_string_borrow(server_dir.c_str());
2✔
40
  TCString error;
41
  auto tcserver = tc_server_new_local(tc_server_dir, &error);
2✔
42
  if (!tcserver) {
2✔
43
    std::string errmsg = format("Could not configure local server at {1}: {2}", server_dir,
NEW
44
                                tc_string_content(&error));
×
NEW
45
    tc_string_free(&error);
×
UNCOV
46
    throw errmsg;
×
47
  }
48
  return Server(unique_tcserver_ptr(tcserver, [](TCServer *rep) { tc_server_free(rep); }));
2✔
49
}
50

51
////////////////////////////////////////////////////////////////////////////////
NEW
52
tc::Server tc::Server::new_sync(const std::string &url, const std::string &client_id,
×
53
                                const std::string &encryption_secret) {
NEW
54
  TCString tc_url = tc_string_borrow(url.c_str());
×
NEW
55
  TCString tc_client_id = tc_string_borrow(client_id.c_str());
×
NEW
56
  TCString tc_encryption_secret = tc_string_borrow(encryption_secret.c_str());
×
57

58
  TCUuid tc_client_uuid;
59
  if (tc_uuid_from_str(tc_client_id, &tc_client_uuid) != TC_RESULT_OK) {
×
60
    tc_string_free(&tc_url);
×
61
    tc_string_free(&tc_encryption_secret);
×
NEW
62
    throw format("client_id '{1}' is not a valid UUID", client_id);
×
63
  }
64

65
  TCString error;
NEW
66
  auto tcserver = tc_server_new_sync(tc_url, tc_client_uuid, tc_encryption_secret, &error);
×
67
  if (!tcserver) {
×
68
    std::string errmsg = format("Could not configure connection to server at {1}: {2}", url,
NEW
69
                                tc_string_content(&error));
×
NEW
70
    tc_string_free(&error);
×
UNCOV
71
    throw errmsg;
×
72
  }
NEW
73
  return Server(unique_tcserver_ptr(tcserver, [](TCServer *rep) { tc_server_free(rep); }));
×
74
}
75

76
////////////////////////////////////////////////////////////////////////////////
NEW
77
tc::Server tc::Server::new_gcp(const std::string &bucket, const std::string &credential_path,
×
78
                               const std::string &encryption_secret) {
NEW
79
  TCString tc_bucket = tc_string_borrow(bucket.c_str());
×
NEW
80
  TCString tc_encryption_secret = tc_string_borrow(encryption_secret.c_str());
×
NEW
81
  TCString tc_credential_path = tc_string_borrow(credential_path.c_str());
×
82

83
  TCString error;
NEW
84
  auto tcserver = tc_server_new_gcp(tc_bucket, tc_credential_path, tc_encryption_secret, &error);
×
85
  if (!tcserver) {
×
86
    std::string errmsg = format("Could not configure connection to GCP bucket {1}: {2}", bucket,
NEW
87
                                tc_string_content(&error));
×
NEW
88
    tc_string_free(&error);
×
UNCOV
89
    throw errmsg;
×
90
  }
NEW
91
  return Server(unique_tcserver_ptr(tcserver, [](TCServer *rep) { tc_server_free(rep); }));
×
92
}
93

94
////////////////////////////////////////////////////////////////////////////////
95
tc::Server::Server(tc::Server &&other) noexcept {
4✔
96
  // move inner from other
97
  inner = unique_tcserver_ptr(other.inner.release(), [](TCServer *rep) { tc_server_free(rep); });
6✔
98
}
4✔
99

100
////////////////////////////////////////////////////////////////////////////////
101
tc::Server &tc::Server::operator=(tc::Server &&other) noexcept {
2✔
102
  if (this != &other) {
2✔
103
    // move inner from other
104
    inner = unique_tcserver_ptr(other.inner.release(), [](TCServer *rep) { tc_server_free(rep); });
2✔
105
  }
106
  return *this;
2✔
107
}
108

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