|
3 | 3 |
|
4 | 4 | using namespace rime;
|
5 | 5 |
|
| 6 | +static const ResourceType kMineralsType = ResourceType{ |
| 7 | + "minerals", |
| 8 | + "not_", |
| 9 | + ".minerals", |
| 10 | +}; |
| 11 | + |
6 | 12 | TEST(RimeResourceResolverTest, ResolvePath) {
|
7 |
| - const auto type = ResourceType{ |
8 |
| - "minerals", |
9 |
| - "not_", |
10 |
| - ".minerals", |
11 |
| - }; |
12 |
| - the<ResourceResolver> rr(new ResourceResolver(type)); |
13 |
| - rr->set_root_path("/starcraft"); |
14 |
| - auto actual = rr->ResolvePath("enough"); |
| 13 | + ResourceResolver rr(kMineralsType); |
| 14 | + rr.set_root_path("/starcraft"); |
| 15 | + auto actual = rr.ResolvePath("enough"); |
15 | 16 | boost::filesystem::path expected = "/starcraft/not_enough.minerals";
|
| 17 | + EXPECT_TRUE(actual.is_absolute()); |
16 | 18 | EXPECT_TRUE(expected == actual);
|
17 | 19 | }
|
| 20 | + |
| 21 | +TEST(RimeResourceResolverTest, FallbackRootPath) { |
| 22 | + FallbackResourceResolver rr(kMineralsType); |
| 23 | + rr.set_fallback_root_path("fallback"); |
| 24 | + boost::filesystem::create_directory("fallback"); |
| 25 | + { |
| 26 | + boost::filesystem::path nonexistent_default = "not_present.minerals"; |
| 27 | + boost::filesystem::remove(nonexistent_default); |
| 28 | + auto fallback = boost::filesystem::absolute("fallback/not_present.minerals"); |
| 29 | + boost::filesystem::ofstream(fallback).close(); |
| 30 | + auto actual = rr.ResolvePath("present"); |
| 31 | + EXPECT_TRUE(fallback == actual); |
| 32 | + boost::filesystem::remove(fallback); |
| 33 | + } |
| 34 | + { |
| 35 | + auto existent_default = boost::filesystem::absolute("not_falling_back.minerals"); |
| 36 | + boost::filesystem::ofstream(existent_default).close(); |
| 37 | + auto actual = rr.ResolvePath("falling_back"); |
| 38 | + EXPECT_TRUE(existent_default == actual); |
| 39 | + boost::filesystem::remove(existent_default); |
| 40 | + } |
| 41 | + { |
| 42 | + auto nonexistent_default = boost::filesystem::absolute("not_any.minerals"); |
| 43 | + boost::filesystem::remove(nonexistent_default); |
| 44 | + auto nonexistent_fallback = boost::filesystem::absolute("fallback/not_any.minerals"); |
| 45 | + boost::filesystem::remove(nonexistent_fallback); |
| 46 | + auto actual = rr.ResolvePath("any"); |
| 47 | + EXPECT_TRUE(nonexistent_default == actual); |
| 48 | + } |
| 49 | + boost::filesystem::remove_all("fallback"); |
| 50 | +} |
0 commit comments