-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Catch unittest framework and some tests.
- Loading branch information
1 parent
48e2a54
commit 5faca8d
Showing
17 changed files
with
453 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
This file is part of Telegram Desktop, | ||
the official desktop version of Telegram messaging app, see https://telegram.org | ||
Telegram Desktop is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
It is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
In addition, as a special exception, the copyright holders give permission | ||
to link the code of portions of this program with the OpenSSL library. | ||
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE | ||
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org | ||
*/ | ||
#include "catch.hpp" | ||
|
||
#include "base/flat_map.h" | ||
#include <string> | ||
|
||
using namespace std; | ||
|
||
TEST_CASE("flat_maps should keep items sorted by key", "[flat_map]") { | ||
base::flat_map<int, string> v; | ||
v.emplace(0, "a"); | ||
v.emplace(5, "b"); | ||
v.emplace(4, "d"); | ||
v.emplace(2, "e"); | ||
|
||
auto checkSorted = [&] { | ||
auto prev = v.begin(); | ||
REQUIRE(prev != v.end()); | ||
for (auto i = prev + 1; i != v.end(); prev = i, ++i) { | ||
REQUIRE(prev->first < i->first); | ||
} | ||
}; | ||
REQUIRE(v.size() == 4); | ||
checkSorted(); | ||
|
||
SECTION("adding item puts it in the right position") { | ||
v.emplace(3, "c"); | ||
REQUIRE(v.size() == 5); | ||
REQUIRE(v.find(3) != v.end()); | ||
checkSorted(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
This file is part of Telegram Desktop, | ||
the official desktop version of Telegram messaging app, see https://telegram.org | ||
Telegram Desktop is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
It is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
In addition, as a special exception, the copyright holders give permission | ||
to link the code of portions of this program with the OpenSSL library. | ||
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE | ||
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org | ||
*/ | ||
#include "catch.hpp" | ||
|
||
#include "base/flat_set.h" | ||
|
||
TEST_CASE("flat_sets should keep items sorted", "[flat_set]") { | ||
base::flat_set<int> v; | ||
v.insert(0); | ||
v.insert(5); | ||
v.insert(4); | ||
v.insert(2); | ||
|
||
auto checkSorted = [&] { | ||
auto prev = v.begin(); | ||
REQUIRE(prev != v.end()); | ||
for (auto i = prev + 1; i != v.end(); prev = i, ++i) { | ||
REQUIRE(*prev < *i); | ||
} | ||
}; | ||
REQUIRE(v.size() == 4); | ||
checkSorted(); | ||
|
||
SECTION("adding item puts it in the right position") { | ||
v.insert(3); | ||
REQUIRE(v.size() == 5); | ||
REQUIRE(v.find(3) != v.end()); | ||
checkSorted(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
This file is part of Telegram Desktop, | ||
the official desktop version of Telegram messaging app, see https://telegram.org | ||
Telegram Desktop is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
It is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
In addition, as a special exception, the copyright holders give permission | ||
to link the code of portions of this program with the OpenSSL library. | ||
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE | ||
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org | ||
*/ | ||
#define CATCH_CONFIG_RUNNER | ||
#include "catch.hpp" | ||
#include "reporters/catch_reporter_compact.hpp" | ||
#include <QFile> | ||
|
||
namespace Catch { | ||
|
||
struct MinimalReporter : CompactReporter { | ||
MinimalReporter( ReporterConfig const& _config ) | ||
: CompactReporter( _config ) | ||
{} | ||
|
||
virtual void testRunEnded( TestRunStats const& _testRunStats ) { | ||
printTotals( _testRunStats.totals ); | ||
} | ||
|
||
private: | ||
// Colour, message variants: | ||
// - white: No tests ran. | ||
// - red: Failed [both/all] N test cases, failed [both/all] M assertions. | ||
// - white: Passed [both/all] N test cases (no assertions). | ||
// - red: Failed N tests cases, failed M assertions. | ||
// - green: Passed [both/all] N tests cases with M assertions. | ||
|
||
std::string bothOrAll( std::size_t count ) const { | ||
return count == 1 ? std::string() : count == 2 ? "both " : "all " ; | ||
} | ||
|
||
void printTotals( const Totals& totals ) const { | ||
if( totals.testCases.total() == 0 ) { | ||
} | ||
else if( totals.testCases.failed == totals.testCases.total() ) { | ||
Colour colour( Colour::ResultError ); | ||
const std::string qualify_assertions_failed = | ||
totals.assertions.failed == totals.assertions.total() ? | ||
bothOrAll( totals.assertions.failed ) : std::string(); | ||
stream << | ||
"Failed " << bothOrAll( totals.testCases.failed ) | ||
<< pluralise( totals.testCases.failed, "test case" ) << ", " | ||
"failed " << qualify_assertions_failed << | ||
pluralise( totals.assertions.failed, "assertion" ) << '.'; | ||
} | ||
else if( totals.assertions.total() == 0 ) { | ||
stream << | ||
"Passed " << bothOrAll( totals.testCases.total() ) | ||
<< pluralise( totals.testCases.total(), "test case" ) | ||
<< " (no assertions)."; | ||
} | ||
else if( totals.assertions.failed ) { | ||
Colour colour( Colour::ResultError ); | ||
stream << | ||
"Failed " << pluralise( totals.testCases.failed, "test case" ) << ", " | ||
"failed " << pluralise( totals.assertions.failed, "assertion" ) << '.'; | ||
} | ||
else { | ||
} | ||
} | ||
}; | ||
|
||
INTERNAL_CATCH_REGISTER_REPORTER( "minimal", MinimalReporter ) | ||
|
||
} // end namespace Catch | ||
|
||
int main(int argc, const char *argv[]) { | ||
const char *catch_argv[] = { argv[0], "-r", "minimal" }; | ||
constexpr auto catch_argc = sizeof(catch_argv) / sizeof(catch_argv[0]); | ||
auto result = Catch::Session().run(catch_argc, catch_argv); | ||
if (result == 0) { | ||
for (auto i = 0; i != argc; ++i) { | ||
if (argv[i] == QString("--touch") && i + 1 != argc) { | ||
QFile(QFile::decodeName(argv[++i])).open(QIODevice::WriteOnly); | ||
} | ||
} | ||
} | ||
return (result < 0xff ? result : 0xff); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.