Skip to content

Commit

Permalink
2041: add QString pretty printer for gtest.
Browse files Browse the repository at this point in the history
Stop using GLOB_RECURSE for .cpp/.h files
Maybe fix PreferencesTest.serializeV1Path on non-Windows
  • Loading branch information
ericwa committed Aug 5, 2019
1 parent 5eebcc2 commit 2129841
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 10 deletions.
3 changes: 1 addition & 2 deletions cmake/TrenchBroomApp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ INCLUDE(cmake/GenerateManual.cmake)
SET(APP_DIR "${CMAKE_SOURCE_DIR}/app")
SET(APP_SOURCE_DIR "${APP_DIR}/src")

# Collect the source files for compilation.
FILE(GLOB_RECURSE APP_SOURCE
SET(APP_SOURCE
"${APP_SOURCE_DIR}/Main.cpp"
)

Expand Down
115 changes: 109 additions & 6 deletions cmake/TrenchBroomTest.cmake
Original file line number Diff line number Diff line change
@@ -1,13 +1,116 @@
SET(TEST_SOURCE_DIR "${CMAKE_SOURCE_DIR}/test/src")
SET(BENCHMARK_SOURCE_DIR "${CMAKE_SOURCE_DIR}/benchmark/src")

FILE(GLOB_RECURSE TEST_SOURCE
"${TEST_SOURCE_DIR}/*.h"
"${TEST_SOURCE_DIR}/*.cpp"
SET(TEST_SOURCE
"${TEST_SOURCE_DIR}/Assets/EntityDefinitionTestUtils.h"
"${TEST_SOURCE_DIR}/IO/TestEnvironment.h"
"${TEST_SOURCE_DIR}/IO/TestParserStatus.h"
"${TEST_SOURCE_DIR}/MockObserver.h"
"${TEST_SOURCE_DIR}/Model/TestGame.h"
"${TEST_SOURCE_DIR}/QtPrettyPrinters.h"
"${TEST_SOURCE_DIR}/TestUtils.h"
"${TEST_SOURCE_DIR}/View/MapDocumentTest.h"
"${TEST_SOURCE_DIR}/AABBTreeStressTest.cpp"
"${TEST_SOURCE_DIR}/AABBTreeTest.cpp"
"${TEST_SOURCE_DIR}/Assets/EntityDefinitionTestUtils.cpp"
"${TEST_SOURCE_DIR}/bbox_test.cpp"
"${TEST_SOURCE_DIR}/CollectionUtilsTest.cpp"
"${TEST_SOURCE_DIR}/convex_hull_test.cpp"
"${TEST_SOURCE_DIR}/distance_test.cpp"
"${TEST_SOURCE_DIR}/DoublyLinkedListTest.cpp"
"${TEST_SOURCE_DIR}/EL/ELTest.cpp"
"${TEST_SOURCE_DIR}/EL/ExpressionTest.cpp"
"${TEST_SOURCE_DIR}/EL/InterpolatorTest.cpp"
"${TEST_SOURCE_DIR}/EnsureTest.cpp"
"${TEST_SOURCE_DIR}/intersection_test.cpp"
"${TEST_SOURCE_DIR}/IO/AseParserTest.cpp"
"${TEST_SOURCE_DIR}/IO/CompilationConfigParserTest.cpp"
"${TEST_SOURCE_DIR}/IO/DefParserTest.cpp"
"${TEST_SOURCE_DIR}/IO/DiskFileSystemTest.cpp"
"${TEST_SOURCE_DIR}/IO/DkPakFileSystemTest.cpp"
"${TEST_SOURCE_DIR}/IO/ELParserTest.cpp"
"${TEST_SOURCE_DIR}/IO/EntParserTest.cpp"
"${TEST_SOURCE_DIR}/IO/FgdParserTest.cpp"
"${TEST_SOURCE_DIR}/IO/FreeImageTextureReaderTest.cpp"
"${TEST_SOURCE_DIR}/IO/GameConfigParserTest.cpp"
"${TEST_SOURCE_DIR}/IO/IdMipTextureReaderTest.cpp"
"${TEST_SOURCE_DIR}/IO/IdPakFileSystemTest.cpp"
"${TEST_SOURCE_DIR}/IO/Md3ParserTest.cpp"
"${TEST_SOURCE_DIR}/IO/MdlParserTest.cpp"
"${TEST_SOURCE_DIR}/IO/NodeWriterTest.cpp"
"${TEST_SOURCE_DIR}/IO/PathTest.cpp"
"${TEST_SOURCE_DIR}/IO/Quake3ShaderFileSystemTest.cpp"
"${TEST_SOURCE_DIR}/IO/Quake3ShaderParserTest.cpp"
"${TEST_SOURCE_DIR}/IO/ReaderTest.cpp"
"${TEST_SOURCE_DIR}/IO/TestEnvironment.cpp"
"${TEST_SOURCE_DIR}/IO/TestParserStatus.cpp"
"${TEST_SOURCE_DIR}/IO/TokenizerTest.cpp"
"${TEST_SOURCE_DIR}/IO/WadFileSystemTest.cpp"
"${TEST_SOURCE_DIR}/IO/WalTextureReaderTest.cpp"
"${TEST_SOURCE_DIR}/IO/WorldReaderTest.cpp"
"${TEST_SOURCE_DIR}/IO/ZipFileSystemTest.cpp"
"${TEST_SOURCE_DIR}/line_test.cpp"
"${TEST_SOURCE_DIR}/mat_ext_test.cpp"
"${TEST_SOURCE_DIR}/mat_test.cpp"
"${TEST_SOURCE_DIR}/Model/AttributableIndexTest.cpp"
"${TEST_SOURCE_DIR}/Model/AttributableLinkTest.cpp"
"${TEST_SOURCE_DIR}/Model/BrushBuilderTest.cpp"
"${TEST_SOURCE_DIR}/Model/BrushFaceTest.cpp"
"${TEST_SOURCE_DIR}/Model/BrushTest.cpp"
"${TEST_SOURCE_DIR}/Model/EditorContextTest.cpp"
"${TEST_SOURCE_DIR}/Model/EntityTest.cpp"
"${TEST_SOURCE_DIR}/Model/GameTest.cpp"
"${TEST_SOURCE_DIR}/Model/NodeTest.cpp"
"${TEST_SOURCE_DIR}/Model/PlanePointFinderTest.cpp"
"${TEST_SOURCE_DIR}/Model/PortalFileTest.cpp"
"${TEST_SOURCE_DIR}/Model/TaggingTest.cpp"
"${TEST_SOURCE_DIR}/Model/TestGame.cpp"
"${TEST_SOURCE_DIR}/Model/TexCoordSystemTest.cpp"
"${TEST_SOURCE_DIR}/NotifierTest.cpp"
"${TEST_SOURCE_DIR}/plane_test.cpp"
"${TEST_SOURCE_DIR}/polygon_test.cpp"
"${TEST_SOURCE_DIR}/PolyhedronTest.cpp"
"${TEST_SOURCE_DIR}/PreferencesTest.cpp"
"${TEST_SOURCE_DIR}/quat_test.cpp"
"${TEST_SOURCE_DIR}/ray_test.cpp"
"${TEST_SOURCE_DIR}/relation_test.cpp"
"${TEST_SOURCE_DIR}/Renderer/AllocationTrackerTest.cpp"
"${TEST_SOURCE_DIR}/Renderer/CameraTest.cpp"
"${TEST_SOURCE_DIR}/Renderer/VertexTest.cpp"
"${TEST_SOURCE_DIR}/RunAllTests.cpp"
"${TEST_SOURCE_DIR}/scalar_test.cpp"
"${TEST_SOURCE_DIR}/segment_test.cpp"
"${TEST_SOURCE_DIR}/StackWalkerTest.cpp"
"${TEST_SOURCE_DIR}/StepIteratorTest.cpp"
"${TEST_SOURCE_DIR}/StringMapTest.cpp"
"${TEST_SOURCE_DIR}/StringUtilsTest.cpp"
"${TEST_SOURCE_DIR}/TestUtils.cpp"
"${TEST_SOURCE_DIR}/vec_test.cpp"
"${TEST_SOURCE_DIR}/View/AutosaverTest.cpp"
"${TEST_SOURCE_DIR}/View/ChangeBrushFaceAttributesTest.cpp"
"${TEST_SOURCE_DIR}/View/ClipToolControllerTest.cpp"
"${TEST_SOURCE_DIR}/View/GridTest.cpp"
"${TEST_SOURCE_DIR}/View/GroupNodesTest.cpp"
"${TEST_SOURCE_DIR}/View/KeyboardShortcutTest.cpp"
"${TEST_SOURCE_DIR}/View/MapDocumentTest.cpp"
"${TEST_SOURCE_DIR}/View/MoveToolControllerTest.cpp"
"${TEST_SOURCE_DIR}/View/RemoveNodesTest.cpp"
"${TEST_SOURCE_DIR}/View/ReparentNodesTest.cpp"
"${TEST_SOURCE_DIR}/View/ScaleObjectsToolTest.cpp"
"${TEST_SOURCE_DIR}/View/SelectionCommandTest.cpp"
"${TEST_SOURCE_DIR}/View/SelectionTest.cpp"
"${TEST_SOURCE_DIR}/View/SnapBrushVerticesTest.cpp"
"${TEST_SOURCE_DIR}/View/SnapshotTest.cpp"
"${TEST_SOURCE_DIR}/View/TagManagementTest.cpp"
)
FILE(GLOB_RECURSE BENCHMARK_SOURCE
"${BENCHMARK_SOURCE_DIR}/*.h"
"${BENCHMARK_SOURCE_DIR}/*.cpp"

SET(BENCHMARK_SOURCE
"${BENCHMARK_SOURCE_DIR}/BenchmarkUtils.h"
"${BENCHMARK_SOURCE_DIR}/IO/TestParserStatus.h"
"${BENCHMARK_SOURCE_DIR}/AABBTreeBenchmark.cpp"
"${BENCHMARK_SOURCE_DIR}/IO/TestParserStatus.cpp"
"${BENCHMARK_SOURCE_DIR}/Main.cpp"
"${BENCHMARK_SOURCE_DIR}/Renderer/BrushRendererBenchmark.cpp"
)

get_target_property(common_TYPE common TYPE)
Expand Down
13 changes: 11 additions & 2 deletions test/src/PreferencesTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <optional-lite/optional.hpp>

#include "PreferenceManager.h"
#include "QtPrettyPrinters.h"

namespace TrenchBroom {
static QString getValue(const std::map<QString, std::map<QString, QString>>& map,
Expand Down Expand Up @@ -77,8 +78,6 @@ namespace TrenchBroom {
static void testSerializedDeserializedPair(const QString& str, const PrimitiveType& value) {
const PrimitiveType testDeserialize = maybeDeserialize<PreferenceSerializerV1, PrimitiveType>(str).value();
const QString testSerialize = serialize<Serializer, PrimitiveType>(value);

qDebug() << testSerialize;

EXPECT_EQ(value, testDeserialize);
EXPECT_EQ(str, testSerialize);
Expand Down Expand Up @@ -111,7 +110,17 @@ namespace TrenchBroom {
}

TEST(PreferencesTest, serializeV1Path) {
#ifdef _WIN32
testSerializedDeserializedPair<PreferenceSerializerV1, IO::Path>(QStringLiteral("c:\\foo\\bar"), IO::Path("c:\\foo\\bar"));
testSerializedDeserializedPair<PreferenceSerializerV1, IO::Path>(QStringLiteral("c:\\foo\\bar"), IO::Path("c:/foo/bar"));
testSerializedDeserializedPair<PreferenceSerializerV1, IO::Path>(QStringLiteral("\\home\\foo\\bar"), IO::Path("/home/foo/bar"));
testSerializedDeserializedPair<PreferenceSerializerV1, IO::Path>(QStringLiteral("\\home\\foo\\bar"), IO::Path("\\home\\foo\\bar"));
#else
testSerializedDeserializedPair<PreferenceSerializerV1, IO::Path>(QStringLiteral("c:/foo/bar"), IO::Path("c:\\foo\\bar"));
testSerializedDeserializedPair<PreferenceSerializerV1, IO::Path>(QStringLiteral("c:/foo/bar"), IO::Path("c:/foo/bar"));
testSerializedDeserializedPair<PreferenceSerializerV1, IO::Path>(QStringLiteral("/home/foo/bar"), IO::Path("/home/foo/bar"));
testSerializedDeserializedPair<PreferenceSerializerV1, IO::Path>(QStringLiteral("/home/foo/bar"), IO::Path("\\home\\foo\\bar"));
#endif
testSerializedDeserializedPair<PreferenceSerializerV1, IO::Path>(QStringLiteral(""), IO::Path());
}

Expand Down
33 changes: 33 additions & 0 deletions test/src/QtPrettyPrinters.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
Copyright (C) 2010-2017 Kristian Duske
This file is part of TrenchBroom.
TrenchBroom 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.
TrenchBroom 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.
You should have received a copy of the GNU General Public License
along with TrenchBroom. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef TrenchBroom_QtPrettyPrinters_h
#define TrenchBroom_QtPrettyPrinters_h

#include <QString>

#include <ostream>

// These are so Google Test can print Qt types

inline void PrintTo(const QString& string, std::ostream* ostream) {
*ostream << qUtf8Printable(string);
}

#endif

0 comments on commit 2129841

Please sign in to comment.