Files
MapLibreParticleLab/test/algorithm/mock.hpp
Konstantin Käfer 78ea88d757 [core] make forcing cache/network only more explicit
Previously, we used the existence of a `prior*` field in the Resource object as an indication for whether we should consult the cache or not. However, this is prone to error, since a failed cache lookup won't set any prior fields. Therefore, we manually set `priorExpires` to 0. This in turn triggered another bug where generated wrong expiration timestamps when the server response we got was expired (or expired between sending and receiving).

This commit changes the flags so that we can now explicitly request CacheOnly/NetworkOnly (or All) loading methods, rather than the implicit Optional/Required naming scheme.
2017-10-12 17:58:03 +02:00

51 lines
1.1 KiB
C++

#pragma once
#include <cstdint>
#include <string>
#include <memory>
#include <set>
#include <map>
#include <mbgl/tile/tile_id.hpp>
#include <mbgl/util/range.hpp>
struct MockTileData;
struct MockSource {
mbgl::Range<uint8_t> zoomRange { 0, 16 };
std::map<mbgl::OverscaledTileID, std::unique_ptr<MockTileData>> dataTiles;
std::set<mbgl::UnwrappedTileID> idealTiles;
// Test API
inline MockTileData* createTileData(const mbgl::OverscaledTileID& tileID);
};
struct MockBucket {};
struct MockTileData {
MockTileData(const mbgl::OverscaledTileID& tileID_) : tileID(tileID_) {}
bool hasTriedCache() const {
return triedOptional;
}
bool isRenderable() const {
return renderable;
}
bool isLoaded() const {
return loaded;
}
bool renderable = false;
bool triedOptional = false;
bool loaded = false;
const mbgl::OverscaledTileID tileID;
};
MockTileData* MockSource::createTileData(const mbgl::OverscaledTileID& tileID) {
// Replace the existing MockTileData object, if any.
return (dataTiles[tileID] = std::make_unique<MockTileData>(tileID)).get();
}