|
3 | 3 |
|
4 | 4 | #include <gtest/gtest.h> |
5 | 5 |
|
6 | | -namespace |
| 6 | +namespace Misc::ResourceHelpers |
7 | 7 | { |
8 | | - using namespace Misc::ResourceHelpers; |
9 | | - TEST(CorrectSoundPath, wav_files_not_overridden_with_mp3_in_vfs_are_not_corrected) |
10 | | - { |
11 | | - constexpr VFS::Path::NormalizedView path("sound/bar.wav"); |
12 | | - std::unique_ptr<VFS::Manager> mVFS = TestingOpenMW::createTestVFS({ { path, nullptr } }); |
13 | | - EXPECT_EQ(correctSoundPath(path, *mVFS), "sound/bar.wav"); |
14 | | - } |
15 | | - |
16 | | - TEST(CorrectSoundPath, wav_files_overridden_with_mp3_in_vfs_are_corrected) |
| 8 | + namespace |
17 | 9 | { |
18 | | - constexpr VFS::Path::NormalizedView mp3("sound/foo.mp3"); |
19 | | - std::unique_ptr<VFS::Manager> mVFS = TestingOpenMW::createTestVFS({ { mp3, nullptr } }); |
20 | | - constexpr VFS::Path::NormalizedView wav("sound/foo.wav"); |
21 | | - EXPECT_EQ(correctSoundPath(wav, *mVFS), "sound/foo.mp3"); |
22 | | - } |
| 10 | + using namespace ::testing; |
23 | 11 |
|
24 | | - TEST(CorrectSoundPath, corrected_path_does_not_check_existence_in_vfs) |
25 | | - { |
26 | | - std::unique_ptr<VFS::Manager> mVFS = TestingOpenMW::createTestVFS({}); |
| 12 | + TEST(MiscResourceHelpersCorrectSoundPath, shouldKeepWavExtensionIfExistsInVfs) |
| 13 | + { |
| 14 | + constexpr VFS::Path::NormalizedView path("sound/foo.wav"); |
| 15 | + const std::unique_ptr<const VFS::Manager> vfs = TestingOpenMW::createTestVFS({ { path, nullptr } }); |
| 16 | + EXPECT_EQ(correctSoundPath(path, *vfs), "sound/foo.wav"); |
| 17 | + } |
27 | 18 |
|
| 19 | + TEST(MiscResourceHelpersCorrectSoundPath, shouldFallbackToMp3IfWavDoesNotExistInVfs) |
28 | 20 | { |
| 21 | + const std::unique_ptr<const VFS::Manager> vfs = TestingOpenMW::createTestVFS({}); |
29 | 22 | constexpr VFS::Path::NormalizedView path("sound/foo.wav"); |
30 | | - EXPECT_EQ(correctSoundPath(path, *mVFS), "sound/foo.mp3"); |
| 23 | + EXPECT_EQ(correctSoundPath(path, *vfs), "sound/foo.mp3"); |
31 | 24 | } |
32 | 25 |
|
33 | | - auto correctESM4SoundPath = [](auto path, auto* vfs) { |
34 | | - return Misc::ResourceHelpers::correctResourcePath({ { "sound" } }, path, vfs, ".mp3"); |
35 | | - }; |
| 26 | + TEST(MiscResourceHelpersCorrectSoundPath, shouldKeepWavExtensionIfBothExistsInVfs) |
| 27 | + { |
| 28 | + constexpr VFS::Path::NormalizedView wav("sound/foo.wav"); |
| 29 | + constexpr VFS::Path::NormalizedView mp3("sound/foo.mp3"); |
| 30 | + const std::unique_ptr<const VFS::Manager> vfs = TestingOpenMW::createTestVFS({ |
| 31 | + { wav, nullptr }, |
| 32 | + { mp3, nullptr }, |
| 33 | + }); |
| 34 | + EXPECT_EQ(correctSoundPath(wav, *vfs), "sound/foo.wav"); |
| 35 | + } |
36 | 36 |
|
37 | | - EXPECT_EQ(correctESM4SoundPath("foo.WAV", mVFS.get()), "sound\\foo.mp3"); |
38 | | - EXPECT_EQ(correctESM4SoundPath("SOUND/foo.WAV", mVFS.get()), "sound\\foo.mp3"); |
39 | | - EXPECT_EQ(correctESM4SoundPath("DATA\\SOUND\\foo.WAV", mVFS.get()), "sound\\foo.mp3"); |
40 | | - EXPECT_EQ(correctESM4SoundPath("\\Data/Sound\\foo.WAV", mVFS.get()), "sound\\foo.mp3"); |
41 | | - } |
| 37 | + TEST(MiscResourceHelpersCorrectResourcePath, shouldFallbackToGivenExtentionIfDoesNotExistInVfs) |
| 38 | + { |
| 39 | + const std::unique_ptr<const VFS::Manager> vfs = TestingOpenMW::createTestVFS({}); |
| 40 | + EXPECT_EQ(correctResourcePath({ { "sound" } }, "sound/foo.wav", vfs.get(), "mp3"), "sound/foo.mp3"); |
| 41 | + } |
42 | 42 |
|
43 | | - namespace |
44 | | - { |
45 | | - std::string checkChangeExtensionToDds(std::string path) |
| 43 | + TEST(MiscResourceHelpersCorrectResourcePath, shouldFallbackToGivenExtentionIfBothExistInVfs) |
46 | 44 | { |
47 | | - changeExtensionToDds(path); |
48 | | - return path; |
| 45 | + constexpr VFS::Path::NormalizedView wav("sound/foo.wav"); |
| 46 | + constexpr VFS::Path::NormalizedView mp3("sound/foo.mp3"); |
| 47 | + const std::unique_ptr<const VFS::Manager> vfs = TestingOpenMW::createTestVFS({ |
| 48 | + { wav, nullptr }, |
| 49 | + { mp3, nullptr }, |
| 50 | + }); |
| 51 | + EXPECT_EQ(correctResourcePath({ { "sound" } }, wav.value(), vfs.get(), "mp3"), "sound/foo.mp3"); |
49 | 52 | } |
50 | | - } |
51 | 53 |
|
52 | | - TEST(ChangeExtensionToDds, original_extension_with_same_size_as_dds) |
53 | | - { |
54 | | - EXPECT_EQ(checkChangeExtensionToDds("texture/bar.tga"), "texture/bar.dds"); |
55 | | - } |
| 54 | + TEST(MiscResourceHelpersCorrectResourcePath, shouldKeepExtentionIfExistInVfs) |
| 55 | + { |
| 56 | + constexpr VFS::Path::NormalizedView wav("sound/foo.wav"); |
| 57 | + const std::unique_ptr<const VFS::Manager> vfs = TestingOpenMW::createTestVFS({ |
| 58 | + { wav, nullptr }, |
| 59 | + }); |
| 60 | + EXPECT_EQ(correctResourcePath({ { "sound" } }, wav.value(), vfs.get(), "mp3"), "sound/foo.wav"); |
| 61 | + } |
56 | 62 |
|
57 | | - TEST(ChangeExtensionToDds, original_extension_greater_than_dds) |
58 | | - { |
59 | | - EXPECT_EQ(checkChangeExtensionToDds("texture/bar.jpeg"), "texture/bar.dds"); |
60 | | - } |
| 63 | + TEST(MiscResourceHelpersCorrectResourcePath, shouldPrefixWithGivenTopDirectory) |
| 64 | + { |
| 65 | + const std::unique_ptr<const VFS::Manager> vfs = TestingOpenMW::createTestVFS({}); |
| 66 | + EXPECT_EQ(correctResourcePath({ { "sound" } }, "foo.mp3", vfs.get(), "mp3"), "sound/foo.mp3"); |
| 67 | + } |
61 | 68 |
|
62 | | - TEST(ChangeExtensionToDds, original_extension_smaller_than_dds) |
63 | | - { |
64 | | - EXPECT_EQ(checkChangeExtensionToDds("texture/bar.xx"), "texture/bar.dds"); |
65 | | - } |
| 69 | + TEST(MiscResourceHelpersCorrectResourcePath, shouldChangeTopDirectoryAndKeepExtensionIfOriginalExistInVfs) |
| 70 | + { |
| 71 | + constexpr VFS::Path::NormalizedView a("textures/foo.a"); |
| 72 | + const std::unique_ptr<const VFS::Manager> vfs = TestingOpenMW::createTestVFS({ |
| 73 | + { a, nullptr }, |
| 74 | + }); |
| 75 | + EXPECT_EQ( |
| 76 | + correctResourcePath({ { "textures", "bookart" } }, "bookart/foo.a", vfs.get(), "b"), "textures/foo.a"); |
| 77 | + } |
66 | 78 |
|
67 | | - TEST(ChangeExtensionToDds, does_not_change_dds_extension) |
68 | | - { |
69 | | - std::string path = "texture/bar.dds"; |
70 | | - EXPECT_FALSE(changeExtensionToDds(path)); |
71 | | - } |
| 79 | + TEST(MiscResourceHelpersCorrectResourcePath, shouldChangeTopDirectoryAndChangeExtensionIfFallbackExistInVfs) |
| 80 | + { |
| 81 | + constexpr VFS::Path::NormalizedView b("textures/foo.b"); |
| 82 | + const std::unique_ptr<const VFS::Manager> vfs = TestingOpenMW::createTestVFS({ |
| 83 | + { b, nullptr }, |
| 84 | + }); |
| 85 | + EXPECT_EQ( |
| 86 | + correctResourcePath({ { "textures", "bookart" } }, "bookart/foo.a", vfs.get(), "b"), "textures/foo.b"); |
| 87 | + } |
72 | 88 |
|
73 | | - TEST(ChangeExtensionToDds, does_not_change_when_no_extension) |
74 | | - { |
75 | | - std::string path = "texture/bar"; |
76 | | - EXPECT_FALSE(changeExtensionToDds(path)); |
77 | | - } |
| 89 | + TEST(MiscResourceHelpersCorrectResourcePath, shouldLowerCase) |
| 90 | + { |
| 91 | + const std::unique_ptr<const VFS::Manager> vfs = TestingOpenMW::createTestVFS({}); |
| 92 | + EXPECT_EQ(correctResourcePath({ { "sound" } }, "SOUND\\Foo.MP3", vfs.get(), "mp3"), "sound/foo.mp3"); |
| 93 | + } |
78 | 94 |
|
79 | | - TEST(ChangeExtensionToDds, change_when_there_is_an_extension) |
80 | | - { |
81 | | - std::string path = "texture/bar.jpeg"; |
82 | | - EXPECT_TRUE(changeExtensionToDds(path)); |
| 95 | + TEST(MiscResourceHelpersCorrectResourcePath, shouldRemoveLeadingSlash) |
| 96 | + { |
| 97 | + const std::unique_ptr<const VFS::Manager> vfs = TestingOpenMW::createTestVFS({}); |
| 98 | + EXPECT_EQ(correctResourcePath({ { "sound" } }, "\\SOUND\\Foo.MP3", vfs.get(), "mp3"), "sound/foo.mp3"); |
| 99 | + } |
| 100 | + |
| 101 | + TEST(MiscResourceHelpersCorrectResourcePath, shouldRemoveDuplicateSlashes) |
| 102 | + { |
| 103 | + const std::unique_ptr<const VFS::Manager> vfs = TestingOpenMW::createTestVFS({}); |
| 104 | + EXPECT_EQ(correctResourcePath({ { "sound" } }, "\\\\SOUND\\\\Foo.MP3", vfs.get(), "mp3"), "sound/foo.mp3"); |
| 105 | + } |
| 106 | + |
| 107 | + TEST(MiscResourceHelpersCorrectResourcePath, shouldConvertToForwardSlash) |
| 108 | + { |
| 109 | + const std::unique_ptr<const VFS::Manager> vfs = TestingOpenMW::createTestVFS({}); |
| 110 | + EXPECT_EQ(correctResourcePath({ { "sound" } }, "SOUND/Foo.MP3", vfs.get(), "mp3"), "sound/foo.mp3"); |
| 111 | + } |
| 112 | + |
| 113 | + TEST(MiscResourceHelpersCorrectResourcePath, shouldHandlePathEqualToDirectory) |
| 114 | + { |
| 115 | + const std::unique_ptr<const VFS::Manager> vfs = TestingOpenMW::createTestVFS({}); |
| 116 | + EXPECT_EQ(correctResourcePath({ { "sound" } }, "sound", vfs.get(), "mp3"), "sound/sound"); |
| 117 | + } |
| 118 | + |
| 119 | + struct MiscResourceHelpersCorrectResourcePathShouldRemoveExtraPrefix : TestWithParam<std::string> |
| 120 | + { |
| 121 | + }; |
| 122 | + |
| 123 | + TEST_P(MiscResourceHelpersCorrectResourcePathShouldRemoveExtraPrefix, shouldMatchExpected) |
| 124 | + { |
| 125 | + const std::unique_ptr<const VFS::Manager> vfs = TestingOpenMW::createTestVFS({}); |
| 126 | + EXPECT_EQ(correctResourcePath({ { "sound" } }, GetParam(), vfs.get(), "mp3"), "sound/foo.mp3"); |
| 127 | + } |
| 128 | + |
| 129 | + const std::vector<std::string> pathsWithPrefix = { |
| 130 | + "data/sound/foo.mp3", |
| 131 | + "data/notsound/sound/foo.mp3", |
| 132 | + "data/soundnot/sound/foo.mp3", |
| 133 | + "data/notsoundnot/sound/foo.mp3", |
| 134 | + }; |
| 135 | + |
| 136 | + INSTANTIATE_TEST_SUITE_P( |
| 137 | + PathsWithPrefix, MiscResourceHelpersCorrectResourcePathShouldRemoveExtraPrefix, ValuesIn(pathsWithPrefix)); |
| 138 | + |
| 139 | + TEST(MiscResourceHelpersChangeExtensionToDds, original_extension_with_same_size_as_dds) |
| 140 | + { |
| 141 | + std::string path = "texture/bar.tga"; |
| 142 | + ASSERT_TRUE(changeExtensionToDds(path)); |
| 143 | + EXPECT_EQ(path, "texture/bar.dds"); |
| 144 | + } |
| 145 | + |
| 146 | + TEST(MiscResourceHelpersChangeExtensionToDds, original_extension_greater_than_dds) |
| 147 | + { |
| 148 | + std::string path = "texture/bar.jpeg"; |
| 149 | + ASSERT_TRUE(changeExtensionToDds(path)); |
| 150 | + EXPECT_EQ(path, "texture/bar.dds"); |
| 151 | + } |
| 152 | + |
| 153 | + TEST(MiscResourceHelpersChangeExtensionToDds, original_extension_smaller_than_dds) |
| 154 | + { |
| 155 | + std::string path = "texture/bar.xx"; |
| 156 | + ASSERT_TRUE(changeExtensionToDds(path)); |
| 157 | + EXPECT_EQ(path, "texture/bar.dds"); |
| 158 | + } |
| 159 | + |
| 160 | + TEST(MiscResourceHelpersChangeExtensionToDds, does_not_change_dds_extension) |
| 161 | + { |
| 162 | + std::string path = "texture/bar.dds"; |
| 163 | + EXPECT_FALSE(changeExtensionToDds(path)); |
| 164 | + EXPECT_EQ(path, "texture/bar.dds"); |
| 165 | + } |
| 166 | + |
| 167 | + TEST(MiscResourceHelpersChangeExtensionToDds, does_not_change_when_no_extension) |
| 168 | + { |
| 169 | + std::string path = "texture/bar"; |
| 170 | + EXPECT_FALSE(changeExtensionToDds(path)); |
| 171 | + EXPECT_EQ(path, "texture/bar"); |
| 172 | + } |
83 | 173 | } |
84 | 174 | } |
0 commit comments