From 03d43c28f6b8d2ecc0470a9dba0e1bbe303a6e5a Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Wed, 15 Jul 2015 10:16:29 +0100 Subject: [PATCH] Add Google Test value printers. For easier debugging test failures. --- CMakeLists.txt | 1 + src/tests/fixtures.h | 1 + src/tests/printers.h | 113 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 115 insertions(+) create mode 100644 src/tests/printers.h diff --git a/CMakeLists.txt b/CMakeLists.txt index e43334c7..f4c107e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -156,6 +156,7 @@ set (LOOT_API_HEADERS ${LOOT_HEADERS} set (LOOT_TESTS_SRC "${CMAKE_SOURCE_DIR}/src/tests/main.cpp") set (LOOT_TESTS_HEADERS "${CMAKE_SOURCE_DIR}/src/tests/fixtures.h" + "${CMAKE_SOURCE_DIR}/src/tests/printers.h" "${CMAKE_SOURCE_DIR}/src/tests/api/test_api.h" "${CMAKE_SOURCE_DIR}/src/tests/backend/game/test_game.h" "${CMAKE_SOURCE_DIR}/src/tests/backend/game/test_game_settings.h" diff --git a/src/tests/fixtures.h b/src/tests/fixtures.h index 89770fb4..1213e191 100644 --- a/src/tests/fixtures.h +++ b/src/tests/fixtures.h @@ -26,6 +26,7 @@ along with LOOT. If not, see #define LOOT_TEST_FIXTURES #include "backend/helpers/streams.h" +#include "printers.h" #include diff --git a/src/tests/printers.h b/src/tests/printers.h new file mode 100644 index 00000000..1733c581 --- /dev/null +++ b/src/tests/printers.h @@ -0,0 +1,113 @@ +/* LOOT + +A load order optimisation tool for Oblivion, Skyrim, Fallout 3 and +Fallout: New Vegas. + +Copyright (C) 2013-2015 WrinklyNinja + +This file is part of LOOT. + +LOOT 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. + +LOOT 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 LOOT. If not, see +. +*/ + +#ifndef LOOT_TEST_PRINTERS +#define LOOT_TEST_PRINTERS + +#include + +#include + +#include "backend/metadata/file.h" +#include "backend/metadata/formid.h" +#include "backend/metadata/location.h" +#include "backend/metadata/message.h" +#include "backend/metadata/message_content.h" +#include "backend/metadata/plugin_dirty_info.h" +#include "backend/metadata/plugin_metadata.h" +#include "backend/metadata/tag.h" +#include "backend/plugin/plugin.h" + +namespace loot { + void PrintTo(const File& value, ::std::ostream* os) { + *os << "loot::File(\"" << value.Name() << "\", " + << "\"" << value.DisplayName() << "\", " + << "\"" << value.Condition() << "\"" + << ")"; + } + + void PrintTo(const FormID& value, ::std::ostream* os) { + *os << "loot::FormID(\"" << value.Plugin() << "\", 0x" + << std::hex << std::uppercase + << value.Id() + << std::nouppercase << std::dec + << ")"; + } + + void PrintTo(const Location& value, ::std::ostream* os) { + *os << "loot::Location(\"" << value.URL() << "\", " + << ::testing::PrintToString(value.Versions()) + << ")"; + } + + void PrintTo(const Message& value, ::std::ostream* os) { + std::string type; + if (value.Type() == Message::warn) + type = "warn"; + else if (value.Type() == Message::error) + type = "error"; + else + type = "say"; + + *os << "loot::Message(\"" << type << "\", " + << ::testing::PrintToString(value.Content()) << ", " + << "\"" << value.Condition() << "\"" + << ")"; + } + + void PrintTo(const MessageContent& value, ::std::ostream* os) { + *os << "loot::MessageContent(\"" << value.Str() << "\", " + << "\"" << Language(value.Language()).Name() << "\"" + << ")"; + } + + void PrintTo(const PluginDirtyInfo& value, ::std::ostream* os) { + *os << "loot::PluginDirtyInfo(0x" + << std::hex << std::uppercase + << value.CRC() + << std::nouppercase << std::dec << ", " + << value.ITMs() << ", " + << value.DeletedRefs() << ", " + << value.DeletedNavmeshes() << ", " + << "\"" << value.CleaningUtility() << "\"" + << ")"; + } + + void PrintTo(const PluginMetadata& value, ::std::ostream* os) { + *os << "loot::PluginMetadata(\"" << value.Name() << "\")"; + } + + void PrintTo(const Tag& value, ::std::ostream* os) { + *os << "loot::Tag(\"" << value.Name() << "\", " + << value.IsAddition() << ", " + << "\"" << value.Condition() << "\"" + << ")"; + } + + void PrintTo(const Plugin& value, ::std::ostream* os) { + *os << "loot::Plugin(\"" << value.Name() << "\")"; + } +} + +#endif