Skip to content

Commit

Permalink
Fix some clang-tidy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
sjanel committed Sep 15, 2024
1 parent 01ad570 commit fbbae4e
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 23 deletions.
18 changes: 9 additions & 9 deletions src/api/common/test/ssl_sha_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ TEST(SSLTest, Sha256) {
static constexpr char kExpectedData[] = {-98, 74, -90, 56, -41, 61, -33, 98, -108, -110, -41,
-82, -110, -102, -80, 85, 127, -112, -55, -116, 38, 36,
10, -104, -37, 93, 105, 14, 73, 99, 98, 95};
EXPECT_TRUE(std::equal(sha256.begin(), sha256.end(), std::begin(kExpectedData), std::end(kExpectedData)));
EXPECT_TRUE(std::ranges::equal(sha256, kExpectedData));
}

TEST(SSLTest, ShaBin256) {
auto actual = Sha256Bin("data1234", "secret1234");
static constexpr char kExpectedData[] = {11, -51, -56, -21, -101, 61, 35, 28, 86, 97, -50,
-8, 47, -113, -13, -107, -100, -93, 27, 71, 101, -128,
-65, 101, -110, -123, 38, 73, 77, 73, -10, -39};
EXPECT_TRUE(std::equal(actual.begin(), actual.end(), std::begin(kExpectedData), std::end(kExpectedData)));
EXPECT_TRUE(std::ranges::equal(actual, kExpectedData));
}

TEST(SSLTest, ShaBin512) {
Expand All @@ -33,7 +33,7 @@ TEST(SSLTest, ShaBin512) {
87, 22, -61, 82, 89, 52, 105, 2, -89, -76, 63, 4, 95,
124, -24, 93, -46, -104, -87, -110, -80, -77, -66, -43, 26, 126,
114, 101, -68, -66, 75, -62, -93, -77, -124, 78, -121, -96};
EXPECT_TRUE(std::equal(actual.begin(), actual.end(), std::begin(kExpectedData), std::end(kExpectedData)));
EXPECT_TRUE(std::ranges::equal(actual, kExpectedData));
}

TEST(SSLTest, ShaHex256) {
Expand All @@ -42,7 +42,7 @@ TEST(SSLTest, ShaHex256) {
53, 54, 54, 49, 99, 101, 102, 56, 50, 102, 56, 102, 102, 51, 57, 53,
57, 99, 97, 51, 49, 98, 52, 55, 54, 53, 56, 48, 98, 102, 54, 53,
57, 50, 56, 53, 50, 54, 52, 57, 52, 100, 52, 57, 102, 54, 100, 57};
EXPECT_TRUE(std::equal(actual.begin(), actual.end(), std::begin(kExpectedData), std::end(kExpectedData)));
EXPECT_TRUE(std::ranges::equal(actual, kExpectedData));
}

TEST(SSLTest, ShaHex512) {
Expand All @@ -54,7 +54,7 @@ TEST(SSLTest, ShaHex512) {
48, 50, 97, 55, 98, 52, 51, 102, 48, 52, 53, 102, 55, 99, 101, 56, 53, 100, 100, 50, 57, 56,
97, 57, 57, 50, 98, 48, 98, 51, 98, 101, 100, 53, 49, 97, 55, 101, 55, 50, 54, 53, 98, 99,
98, 101, 52, 98, 99, 50, 97, 51, 98, 51, 56, 52, 52, 101, 56, 55, 97, 48};
EXPECT_TRUE(std::equal(actual.begin(), actual.end(), std::begin(kExpectedData), std::end(kExpectedData)));
EXPECT_TRUE(std::ranges::equal(actual, kExpectedData));
}

TEST(SSLTest, ShaDigest256) {
Expand All @@ -63,7 +63,7 @@ TEST(SSLTest, ShaDigest256) {
51, 50, 57, 55, 100, 50, 56, 97, 52, 55, 50, 57, 51, 102, 49, 50,
51, 97, 49, 51, 50, 54, 50, 57, 48, 101, 102, 51, 100, 55, 48, 49,
53, 57, 55, 101, 57, 51, 56, 102, 99, 53, 48, 102, 48, 57, 57, 57};
EXPECT_TRUE(std::equal(actual.begin(), actual.end(), std::begin(kExpectedData), std::end(kExpectedData)));
EXPECT_TRUE(std::ranges::equal(actual, kExpectedData));
}

TEST(SSLTest, ShaDigest512) {
Expand All @@ -75,7 +75,7 @@ TEST(SSLTest, ShaDigest512) {
50, 49, 99, 100, 100, 57, 54, 102, 50, 52, 48, 54, 48, 102, 101, 49, 56, 102, 52, 52, 50, 100,
54, 57, 100, 98, 54, 99, 56, 53, 56, 49, 53, 51, 52, 57, 102, 50, 52, 101, 99, 100, 99, 48,
100, 97, 51, 51, 51, 53, 48, 49, 56, 51, 53, 98, 53, 52, 51, 102, 54, 53};
EXPECT_TRUE(std::equal(actual.begin(), actual.end(), std::begin(kExpectedData), std::end(kExpectedData)));
EXPECT_TRUE(std::ranges::equal(actual, kExpectedData));
}

TEST(SSLTest, ShaDigest256Multiple) {
Expand All @@ -86,7 +86,7 @@ TEST(SSLTest, ShaDigest256Multiple) {
100, 57, 97, 52, 48, 99, 51, 52, 101, 97, 50, 99, 53, 98, 97, 51,
100, 54, 55, 50, 102, 100, 51, 102, 100, 98, 51, 54, 52, 100, 98, 50,
101, 49, 97, 56, 53, 54, 99, 48, 100, 53, 52, 98, 49, 101, 51, 50};
EXPECT_TRUE(std::equal(actual.begin(), actual.end(), std::begin(kExpectedData), std::end(kExpectedData)));
EXPECT_TRUE(std::ranges::equal(actual, kExpectedData));
}

TEST(SSLTest, ShaDigest512Multiple) {
Expand All @@ -100,6 +100,6 @@ TEST(SSLTest, ShaDigest512Multiple) {
48, 56, 54, 49, 100, 57, 49, 51, 98, 97, 57, 53, 56, 54, 54, 54, 52, 53, 53, 48, 57, 98,
100, 99, 102, 57, 54, 52, 55, 55, 49, 55, 48, 56, 97, 55, 50, 102, 52, 54, 52, 101, 56, 50,
51, 102, 57, 54, 98, 53, 50, 51, 52, 99, 98, 48, 51, 56, 100, 53, 55, 56};
EXPECT_TRUE(std::equal(actual.begin(), actual.end(), std::begin(kExpectedData), std::end(kExpectedData)));
EXPECT_TRUE(std::ranges::equal(actual, kExpectedData));
}
} // namespace cct::ssl
6 changes: 3 additions & 3 deletions src/api/exchanges/src/binanceprivateapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -794,9 +794,9 @@ ReceivedWithdrawInfo BinancePrivate::queryWithdrawDelivery(const InitiatedWithdr
_queryDelay, {{"coin", currencyCode.str()}});
const Wallet& wallet = initiatedWithdrawInfo.receivingWallet();

auto newEndIt = std::remove_if(depositStatus.begin(), depositStatus.end(), [&wallet](const json& el) {
return el["status"].get<int>() != 1 || el["address"].get<std::string_view>() != wallet.address();
});
auto newEndIt = std::ranges::remove_if(depositStatus, [&wallet](const json& el) {
return el["status"].get<int>() != 1 || el["address"].get<std::string_view>() != wallet.address();
}).begin();

depositStatus.erase(newEndIt, depositStatus.end());

Expand Down
4 changes: 2 additions & 2 deletions src/api/exchanges/src/bithumbprivateapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -745,8 +745,8 @@ json QueryUserTransactions(BithumbPrivate& exchangePrivate, CurlHandle& curlHand
continue;
}
} else if (userTransactionEnum == UserTransactionEnum::kClosedOrders) {
const auto searchGb = StringToIntegral<int>(trx["search"].get<std::string_view>());
if (searchGb != kSearchGbBuy && searchGb != kSearchGbSell) {
const auto searchValue = StringToIntegral<int>(trx["search"].get<std::string_view>());
if (searchValue != kSearchGbBuy && searchValue != kSearchGbSell) {
continue;
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/engine/include/queryresultprinter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ class QueryResultPrinter {

void printConversionPath(Market mk, const ConversionPathPerExchange &conversionPathsPerExchange) const;

void printWithdrawFees(const MonetaryAmountByCurrencySetPerExchange &withdrawFeesPerExchange, CurrencyCode cur) const;
void printWithdrawFees(const MonetaryAmountByCurrencySetPerExchange &withdrawFeesPerExchange,
CurrencyCode currencyCode) const;

void printLast24hTradedVolume(Market mk, const MonetaryAmountPerExchange &tradedVolumePerExchange) const;

Expand Down
4 changes: 2 additions & 2 deletions src/engine/src/queryresultprinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1352,8 +1352,8 @@ void QueryResultPrinter::printConversionPath(Market mk,
}

void QueryResultPrinter::printWithdrawFees(const MonetaryAmountByCurrencySetPerExchange &withdrawFeesPerExchange,
CurrencyCode cur) const {
json jsonData = WithdrawFeesJson(withdrawFeesPerExchange, cur);
CurrencyCode currencyCode) const {
json jsonData = WithdrawFeesJson(withdrawFeesPerExchange, currencyCode);
switch (_apiOutputType) {
case ApiOutputType::kFormattedTable: {
table::Row header("Withdraw fee currency");
Expand Down
1 change: 1 addition & 0 deletions src/http-request/src/curlhandle.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "curlhandle.hpp"

#include <curl/curl.h>
#include <curl/easy.h>

#include <algorithm>
#include <chrono>
Expand Down
12 changes: 8 additions & 4 deletions src/objects/include/currencycode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ class CurrencyCodeIterator {
using pointer = const char *;
using reference = const char &;

// Public default constructor needed for an iterator in C++20
CurrencyCodeIterator() noexcept = default;

constexpr std::strong_ordering operator<=>(const CurrencyCodeIterator &) const noexcept = default;

constexpr bool operator==(const CurrencyCodeIterator &) const noexcept = default;
Expand Down Expand Up @@ -103,11 +106,10 @@ class CurrencyCodeIterator {
private:
friend class CurrencyCode;

// Default constructor needed for an iterator in C++20
constexpr explicit CurrencyCodeIterator(uint64_t data = 0, uint64_t pos = 0) noexcept : _data(data), _pos(pos) {}
constexpr explicit CurrencyCodeIterator(uint64_t data, uint64_t pos = 0) noexcept : _data(data), _pos(pos) {}

uint64_t _data;
uint64_t _pos;
uint64_t _data{};
uint64_t _pos{};
};

/// Lightweight object representing a currency code with its acronym.
Expand Down Expand Up @@ -278,6 +280,8 @@ class CurrencyCode {
}
};

static_assert(std::ranges::bidirectional_range<CurrencyCode>);

} // namespace cct

#ifndef CCT_DISABLE_SPDLOG
Expand Down
2 changes: 1 addition & 1 deletion src/objects/test/currencycode_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ TEST(CurrencyCodeTest, UpperConversion) {

namespace {
constexpr bool HasZ(CurrencyCode cur) {
return std::any_of(cur.begin(), cur.end(), [](char ch) { return ch == 'Z'; });
return std::ranges::any_of(cur, [](char ch) { return ch == 'Z'; });
}
} // namespace

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include <initializer_list>

#include "amount-price.hpp"
#include "market.hpp"
#include "marketorderbook.hpp"
#include "monetaryamount.hpp"
Expand Down
1 change: 1 addition & 0 deletions src/tech/include/cct_log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#ifdef CCT_DISABLE_SPDLOG
#include <string_view>
#else
#include <spdlog/common.h> // IWYU pragma: export
#include <spdlog/spdlog.h> // IWYU pragma: export
#endif

Expand Down

0 comments on commit fbbae4e

Please sign in to comment.