/* * This file Copyright (C) 2013-2014 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. * */ #include "transmission.h" #include "error.h" #include "metainfo.h" #include "torrent.h" #include "utils.h" #include "test-fixtures.h" #include #include #include #include #define BEFORE_PATH \ "d10:created by25:Transmission/2.82 (14160)13:creation datei1402280218e8:encoding5:UTF-84:infod5:filesld6:lengthi2e4:pathl" #define AFTER_PATH \ "eed6:lengthi2e4:pathl5:b.txteee4:name3:foo12:piece lengthi32768e6:pieces20:ÞÉ`âM‘‹Šs¡Å;˺¬.åÂà7:privatei0eee" using namespace std::literals; namespace libtransmission { namespace test { using MetainfoTest = SessionTest; TEST_F(MetainfoTest, sanitize) { struct LocalTest { std::string_view input; std::string_view expected_output; }; auto const tests = std::array{ // skipped LocalTest{ ""sv, ""sv }, { "."sv, ""sv }, { ".."sv, ""sv }, { "....."sv, ""sv }, { " "sv, ""sv }, { " . "sv, ""sv }, { ". . ."sv, ""sv }, // replaced with '_' { "/"sv, "_"sv }, { "////"sv, "____"sv }, { "\\\\"sv, "__"sv }, { "/../"sv, "_.._"sv }, { "foocode); tr_error_clear(&error); } // now try saving _with_ metainfo EXPECT_TRUE(tr_ctorSetMetainfoFromFile(ctor, src_filename.c_str(), &error)); EXPECT_EQ(nullptr, error); EXPECT_TRUE(tr_ctorSaveContents(ctor, tgt_filename.c_str(), &error)); EXPECT_EQ(nullptr, error); // the saved contents should match the source file's contents auto src_contents = std::vector{}; EXPECT_TRUE(tr_loadFile(src_contents, src_filename.c_str(), &error)); auto tgt_contents = std::vector{}; EXPECT_TRUE(tr_loadFile(tgt_contents, tgt_filename.c_str(), &error)); EXPECT_EQ(src_contents, tgt_contents); // cleanup EXPECT_TRUE(tr_sys_path_remove(tgt_filename.c_str(), &error)); EXPECT_EQ(nullptr, error); tr_error_clear(&error); tr_ctorFree(ctor); } } // namespace test } // namespace libtransmission