2020-06-26 18:01:27 +00:00
|
|
|
// This file is a part of toml++ and is subject to the the terms of the MIT license.
|
2021-01-02 15:48:47 +00:00
|
|
|
// Copyright (c) Mark Gillard <mark.gillard@outlook.com.au>
|
2020-06-26 18:01:27 +00:00
|
|
|
// See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text.
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
2020-04-02 21:39:21 +00:00
|
|
|
#define CATCH_CONFIG_RUNNER
|
2021-10-26 13:49:23 +00:00
|
|
|
#include "lib_catch2.h"
|
2020-04-06 12:57:49 +00:00
|
|
|
#include <clocale>
|
2020-04-02 21:39:21 +00:00
|
|
|
|
2020-10-09 05:50:15 +00:00
|
|
|
#if LEAK_TESTS
|
2021-10-26 13:49:23 +00:00
|
|
|
|
2020-10-09 05:50:15 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <iomanip>
|
|
|
|
#include <atomic>
|
|
|
|
#include "leakproof.h"
|
|
|
|
using namespace std::string_view_literals;
|
2021-10-26 13:49:23 +00:00
|
|
|
|
2020-10-09 05:50:15 +00:00
|
|
|
namespace leakproof
|
|
|
|
{
|
|
|
|
static std::atomic_llong total_created_ = 0LL;
|
2021-10-26 13:49:23 +00:00
|
|
|
static std::atomic_llong tables_ = 0LL;
|
|
|
|
static std::atomic_llong arrays_ = 0LL;
|
|
|
|
static std::atomic_llong values_ = 0LL;
|
|
|
|
|
|
|
|
void table_created() noexcept
|
|
|
|
{
|
|
|
|
tables_++;
|
|
|
|
total_created_++;
|
|
|
|
}
|
|
|
|
|
2022-01-02 11:30:32 +00:00
|
|
|
void table_destroyed() noexcept
|
2021-10-26 13:49:23 +00:00
|
|
|
{
|
2022-01-02 11:30:32 +00:00
|
|
|
tables_--;
|
2021-10-26 13:49:23 +00:00
|
|
|
}
|
|
|
|
|
2022-01-02 11:30:32 +00:00
|
|
|
void array_created() noexcept
|
2021-10-26 13:49:23 +00:00
|
|
|
{
|
2022-01-02 11:30:32 +00:00
|
|
|
arrays_++;
|
2021-10-26 13:49:23 +00:00
|
|
|
total_created_++;
|
|
|
|
}
|
|
|
|
|
2022-01-02 11:30:32 +00:00
|
|
|
void array_destroyed() noexcept
|
2021-10-26 13:49:23 +00:00
|
|
|
{
|
2022-01-02 11:30:32 +00:00
|
|
|
arrays_--;
|
2021-10-26 13:49:23 +00:00
|
|
|
}
|
|
|
|
|
2022-01-02 11:30:32 +00:00
|
|
|
void value_created() noexcept
|
2021-10-26 13:49:23 +00:00
|
|
|
{
|
2022-01-02 11:30:32 +00:00
|
|
|
values_++;
|
|
|
|
total_created_++;
|
2021-10-26 13:49:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void value_destroyed() noexcept
|
|
|
|
{
|
|
|
|
values_--;
|
|
|
|
}
|
2020-10-09 05:50:15 +00:00
|
|
|
}
|
2021-10-26 13:49:23 +00:00
|
|
|
|
|
|
|
#endif // LEAK_TESTS
|
2020-10-09 05:50:15 +00:00
|
|
|
|
2020-04-02 21:39:21 +00:00
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
2021-10-26 13:49:23 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
SetConsoleOutputCP(65001);
|
|
|
|
#endif
|
2020-04-06 12:57:49 +00:00
|
|
|
std::setlocale(LC_ALL, "");
|
|
|
|
std::locale::global(std::locale(""));
|
2020-10-09 05:50:15 +00:00
|
|
|
if (auto result = Catch::Session().run(argc, argv))
|
|
|
|
return result;
|
|
|
|
|
2021-10-26 13:49:23 +00:00
|
|
|
#if LEAK_TESTS
|
2020-10-09 05:50:15 +00:00
|
|
|
constexpr auto handle_leak_result = [](std::string_view name, long long count) noexcept
|
|
|
|
{
|
|
|
|
std::cout << "\n"sv << name << ": "sv << std::right << std::setw(6) << count;
|
|
|
|
if (count > 0LL)
|
|
|
|
std::cout << " *** LEAK DETECTED ***"sv;
|
|
|
|
if (count < 0LL)
|
|
|
|
std::cout << " *** UNBALANCED LIFETIME CALLS ***"sv;
|
|
|
|
return count == 0LL;
|
|
|
|
};
|
|
|
|
std::cout << "\n---------- leak test results ----------"sv;
|
|
|
|
bool ok = true;
|
2021-10-26 13:49:23 +00:00
|
|
|
ok = handle_leak_result("tables"sv, leakproof::tables_.load()) && ok;
|
|
|
|
ok = handle_leak_result("arrays"sv, leakproof::arrays_.load()) && ok;
|
|
|
|
ok = handle_leak_result("values"sv, leakproof::values_.load()) && ok;
|
2020-10-09 05:50:15 +00:00
|
|
|
std::cout << "\n(total objects created: "sv << leakproof::total_created_.load() << ")"sv;
|
|
|
|
std::cout << "\n---------------------------------------"sv;
|
|
|
|
return ok ? 0 : -1;
|
2021-10-26 13:49:23 +00:00
|
|
|
#else
|
2020-10-09 05:50:15 +00:00
|
|
|
return 0;
|
2021-10-26 13:49:23 +00:00
|
|
|
#endif
|
2020-04-02 21:39:21 +00:00
|
|
|
}
|