diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:24:48 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:24:48 +0000 |
commit | cca66b9ec4e494c1d919bff0f71a820d8afab1fa (patch) | |
tree | 146f39ded1c938019e1ed42d30923c2ac9e86789 /testfiles/src/svg-extension-test.cpp | |
parent | Initial commit. (diff) | |
download | inkscape-cca66b9ec4e494c1d919bff0f71a820d8afab1fa.tar.xz inkscape-cca66b9ec4e494c1d919bff0f71a820d8afab1fa.zip |
Adding upstream version 1.2.2.upstream/1.2.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testfiles/src/svg-extension-test.cpp')
-rw-r--r-- | testfiles/src/svg-extension-test.cpp | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/testfiles/src/svg-extension-test.cpp b/testfiles/src/svg-extension-test.cpp new file mode 100644 index 0000000..e650d24 --- /dev/null +++ b/testfiles/src/svg-extension-test.cpp @@ -0,0 +1,80 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/** @file + * SVG Extension test + *//* + * Authors: see git history + * + * Copyright (C) 2020 Authors + * + * Released under GNU GPL version 2 or later, read the file 'COPYING' for more information + */ + +#include <gtest/gtest.h> + +#include <src/extension/db.h> +#include <src/extension/input.h> +#include <src/extension/internal/svg.h> +#include <src/inkscape.h> + +#include <glib/gstdio.h> + +using namespace Inkscape; +using namespace Inkscape::Extension; +using namespace Inkscape::Extension::Internal; + +class SvgExtensionTest : public ::testing::Test { + public: + static std::string create_file(const std::string &filename, const std::string &content) + { + std::stringstream path_builder; + path_builder << "SvgExtensionTest_" << _files.size() << "_" << filename; + std::string path = path_builder.str(); + GError *error = nullptr; + if (!g_file_set_contents(path.c_str(), content.c_str(), content.size(), &error)) { + std::stringstream msg; + msg << "SvgExtensionTest::create_file failed: GError(" << error->domain << ", " << error->code << ", " + << error->message << ")"; + g_error_free(error); + throw std::runtime_error(msg.str()); + } + _files.insert(path); + return path; + } + + static std::set<std::string> _files; + + protected: + void SetUp() override + { + // setup hidden dependency + Application::create(false); + } + + static void TearDownTestCase() + { + for (auto file : _files) { + if (g_remove(file.c_str())) { + std::cout << "SvgExtensionTest was unable to remove file: " << file << std::endl; + } + } + } +}; + +std::set<std::string> SvgExtensionTest::_files; + +TEST_F(SvgExtensionTest, openingAsLinkInImageASizelessSvgFileReturnsNull) +{ + std::string sizeless_svg_file = + create_file("sizeless.svg", + "<svg><path d=\"M 71.527648,186.14229 A 740.48715,740.48715 0 0 0 696.31258,625.8041 Z\"/></svg>"); + + Svg::init(); + Input *svg_input_extension(dynamic_cast<Input *>(db.get(SP_MODULE_KEY_INPUT_SVG))); + + Preferences *prefs = Preferences::get(); + prefs->setBool("/options/onimport", true); + prefs->setBool("/dialogs/import/ask_svg", false); + prefs->setString("/dialogs/import/import_mode_svg", "link"); + + ASSERT_EQ(svg_input_extension->open(sizeless_svg_file.c_str()), nullptr); +}
\ No newline at end of file |