File: main.cpp

package info (click to toggle)
tomlplusplus 3.3.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,184 kB
  • sloc: cpp: 35,145; ansic: 2,220; python: 983; makefile: 25; sh: 17
file content (98 lines) | stat: -rw-r--r-- 2,264 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// This file is a part of toml++ and is subject to the the terms of the MIT license.
// Copyright (c) Mark Gillard <mark.gillard@outlook.com.au>
// See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text.
// SPDX-License-Identifier: MIT

#ifdef _MSC_VER
#pragma warning(disable : 4619)
#pragma warning(disable : 5262)
#pragma warning(disable : 5264)
#endif

#define CATCH_CONFIG_RUNNER
#include "lib_catch2.h"
#include <clocale>

#if LEAK_TESTS

#include <iostream>
#include <iomanip>
#include <atomic>
#include "leakproof.h"
using namespace std::string_view_literals;

namespace leakproof
{
	static std::atomic_llong total_created_ = 0LL;
	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_++;
	}

	void table_destroyed() noexcept
	{
		tables_--;
	}

	void array_created() noexcept
	{
		arrays_++;
		total_created_++;
	}

	void array_destroyed() noexcept
	{
		arrays_--;
	}

	void value_created() noexcept
	{
		values_++;
		total_created_++;
	}

	void value_destroyed() noexcept
	{
		values_--;
	}
}

#endif // LEAK_TESTS

int main(int argc, char* argv[])
{
#ifdef _WIN32
	SetConsoleOutputCP(65001);
#endif
	std::setlocale(LC_ALL, "");
	std::locale::global(std::locale(""));
	if (auto result = Catch::Session().run(argc, argv))
		return result;

#if LEAK_TESTS
	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;
	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;
	std::cout << "\n(total objects created: "sv << leakproof::total_created_.load() << ")"sv;
	std::cout << "\n---------------------------------------"sv;
	return ok ? 0 : -1;
#else
	return 0;
#endif
}