diff options
author | Max Kellermann <max@musicpd.org> | 2018-10-16 19:01:13 +0200 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2018-10-16 21:26:04 +0200 |
commit | 01b6e1cbf28f54793e22cc40affac7fb03511180 (patch) | |
tree | 5ac27527b2c5f36384f2c42d3907f12fa96067af /test/test_translate_song.cxx | |
parent | eefc0f5d80fbcb485db230c3df090b69994a75ce (diff) |
test: use GTest instead of cppunit
Diffstat (limited to 'test/test_translate_song.cxx')
-rw-r--r-- | test/test_translate_song.cxx | 198 |
1 files changed, 95 insertions, 103 deletions
diff --git a/test/test_translate_song.cxx b/test/test_translate_song.cxx index 10c1acc61..7784a2e24 100644 --- a/test/test_translate_song.cxx +++ b/test/test_translate_song.cxx @@ -19,10 +19,7 @@ #include "Mapper.hxx" #include "util/ChronoUtil.hxx" -#include <cppunit/TestFixture.h> -#include <cppunit/extensions/TestFactoryRegistry.h> -#include <cppunit/ui/text/TestRunner.h> -#include <cppunit/extensions/HelperMacros.h> +#include <gtest/gtest.h> #include <string.h> #include <stdio.h> @@ -196,113 +193,108 @@ ToString(const DetachedSong &song) return result; } -class TranslateSongTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(TranslateSongTest); - CPPUNIT_TEST(TestAbsoluteURI); - CPPUNIT_TEST(TestInsecure); - CPPUNIT_TEST(TestSecure); - CPPUNIT_TEST(TestInDatabase); - CPPUNIT_TEST(TestRelative); - CPPUNIT_TEST_SUITE_END(); - - void TestAbsoluteURI() { - DetachedSong song1("http://example.com/foo.ogg"); - auto se = ToString(song1); - const SongLoader loader(nullptr, nullptr); - CPPUNIT_ASSERT(playlist_check_translate_song(song1, "/ignored", - loader)); - CPPUNIT_ASSERT_EQUAL(se, ToString(song1)); - } +class TranslateSongTest : public ::testing::Test { + std::unique_ptr<Storage> _storage; - void TestInsecure() { - /* illegal because secure=false */ - DetachedSong song1 (uri1); - const SongLoader loader(*reinterpret_cast<const Client *>(1)); - CPPUNIT_ASSERT(!playlist_check_translate_song(song1, nullptr, - loader)); +protected: + void SetUp() override { + _storage = CreateLocalStorage(Path::FromFS(music_directory)); + storage = _storage.get(); } - void TestSecure() { - DetachedSong song1(uri1, MakeTag1b()); - auto s1 = ToString(song1); - auto se = ToString(DetachedSong(uri1, MakeTag1c())); - - const SongLoader loader(nullptr, nullptr); - CPPUNIT_ASSERT(playlist_check_translate_song(song1, "/ignored", - loader)); - CPPUNIT_ASSERT_EQUAL(se, ToString(song1)); + void TearDown() override { + _storage.reset(); } +}; - void TestInDatabase() { - const SongLoader loader(reinterpret_cast<const Database *>(1), - storage); - - DetachedSong song1("doesntexist"); - CPPUNIT_ASSERT(!playlist_check_translate_song(song1, nullptr, - loader)); - - DetachedSong song2(uri2, MakeTag2b()); - auto s1 = ToString(song2); - auto se = ToString(DetachedSong(uri2, MakeTag2c())); - CPPUNIT_ASSERT(playlist_check_translate_song(song2, nullptr, - loader)); - CPPUNIT_ASSERT_EQUAL(se, ToString(song2)); - - DetachedSong song3("/music/foo/bar.ogg", MakeTag2b()); - s1 = ToString(song3); - se = ToString(DetachedSong(uri2, MakeTag2c())); - CPPUNIT_ASSERT(playlist_check_translate_song(song3, nullptr, - loader)); - CPPUNIT_ASSERT_EQUAL(se, ToString(song3)); - } +TEST_F(TranslateSongTest, AbsoluteURI) +{ + DetachedSong song1("http://example.com/foo.ogg"); + auto se = ToString(song1); + const SongLoader loader(nullptr, nullptr); + EXPECT_TRUE(playlist_check_translate_song(song1, "/ignored", + loader)); + EXPECT_EQ(se, ToString(song1)); +} - void TestRelative() { - const Database &db = *reinterpret_cast<const Database *>(1); - const SongLoader secure_loader(&db, storage); - const SongLoader insecure_loader(*reinterpret_cast<const Client *>(1), - &db, storage); - - /* map to music_directory */ - DetachedSong song1("bar.ogg", MakeTag2b()); - auto s1 = ToString(song1); - auto se = ToString(DetachedSong(uri2, MakeTag2c())); - CPPUNIT_ASSERT(playlist_check_translate_song(song1, "/music/foo", - insecure_loader)); - CPPUNIT_ASSERT_EQUAL(se, ToString(song1)); - - /* illegal because secure=false */ - DetachedSong song2("bar.ogg", MakeTag2b()); - CPPUNIT_ASSERT(!playlist_check_translate_song(song1, "/foo", - insecure_loader)); - - /* legal because secure=true */ - DetachedSong song3("bar.ogg", MakeTag1b()); - s1 = ToString(song3); - se = ToString(DetachedSong(uri1, MakeTag1c())); - CPPUNIT_ASSERT(playlist_check_translate_song(song3, "/foo", - secure_loader)); - CPPUNIT_ASSERT_EQUAL(se, ToString(song3)); - - /* relative to http:// */ - DetachedSong song4("bar.ogg", MakeTag2a()); - s1 = ToString(song4); - se = ToString(DetachedSong("http://example.com/foo/bar.ogg", MakeTag2a())); - CPPUNIT_ASSERT(playlist_check_translate_song(song4, "http://example.com/foo", - insecure_loader)); - CPPUNIT_ASSERT_EQUAL(se, ToString(song4)); - } -}; +TEST_F(TranslateSongTest, Insecure) +{ + /* illegal because secure=false */ + DetachedSong song1 (uri1); + const SongLoader loader(*reinterpret_cast<const Client *>(1)); + EXPECT_FALSE(playlist_check_translate_song(song1, nullptr, + loader)); +} -CPPUNIT_TEST_SUITE_REGISTRATION(TranslateSongTest); +TEST_F(TranslateSongTest, Secure) +{ + DetachedSong song1(uri1, MakeTag1b()); + auto s1 = ToString(song1); + auto se = ToString(DetachedSong(uri1, MakeTag1c())); + + const SongLoader loader(nullptr, nullptr); + EXPECT_TRUE(playlist_check_translate_song(song1, "/ignored", + loader)); + EXPECT_EQ(se, ToString(song1)); +} -int -main(gcc_unused int argc, gcc_unused char **argv) +TEST_F(TranslateSongTest, InDatabase) { - auto _storage = CreateLocalStorage(Path::FromFS(music_directory)); - storage = _storage.get(); + const SongLoader loader(reinterpret_cast<const Database *>(1), + storage); + + DetachedSong song1("doesntexist"); + EXPECT_FALSE(playlist_check_translate_song(song1, nullptr, + loader)); + + DetachedSong song2(uri2, MakeTag2b()); + auto s1 = ToString(song2); + auto se = ToString(DetachedSong(uri2, MakeTag2c())); + EXPECT_TRUE(playlist_check_translate_song(song2, nullptr, + loader)); + EXPECT_EQ(se, ToString(song2)); + + DetachedSong song3("/music/foo/bar.ogg", MakeTag2b()); + s1 = ToString(song3); + se = ToString(DetachedSong(uri2, MakeTag2c())); + EXPECT_TRUE(playlist_check_translate_song(song3, nullptr, + loader)); + EXPECT_EQ(se, ToString(song3)); +} - CppUnit::TextUi::TestRunner runner; - auto ®istry = CppUnit::TestFactoryRegistry::getRegistry(); - runner.addTest(registry.makeTest()); - return runner.run() ? EXIT_SUCCESS : EXIT_FAILURE; +TEST_F(TranslateSongTest, Relative) +{ + const Database &db = *reinterpret_cast<const Database *>(1); + const SongLoader secure_loader(&db, storage); + const SongLoader insecure_loader(*reinterpret_cast<const Client *>(1), + &db, storage); + + /* map to music_directory */ + DetachedSong song1("bar.ogg", MakeTag2b()); + auto s1 = ToString(song1); + auto se = ToString(DetachedSong(uri2, MakeTag2c())); + EXPECT_TRUE(playlist_check_translate_song(song1, "/music/foo", + insecure_loader)); + EXPECT_EQ(se, ToString(song1)); + + /* illegal because secure=false */ + DetachedSong song2("bar.ogg", MakeTag2b()); + EXPECT_FALSE(playlist_check_translate_song(song1, "/foo", + insecure_loader)); + + /* legal because secure=true */ + DetachedSong song3("bar.ogg", MakeTag1b()); + s1 = ToString(song3); + se = ToString(DetachedSong(uri1, MakeTag1c())); + EXPECT_TRUE(playlist_check_translate_song(song3, "/foo", + secure_loader)); + EXPECT_EQ(se, ToString(song3)); + + /* relative to http:// */ + DetachedSong song4("bar.ogg", MakeTag2a()); + s1 = ToString(song4); + se = ToString(DetachedSong("http://example.com/foo/bar.ogg", MakeTag2a())); + EXPECT_TRUE(playlist_check_translate_song(song4, "http://example.com/foo", + insecure_loader)); + EXPECT_EQ(se, ToString(song4)); } |