#include "glyph_metrics_cache.h"
#include <array>
#include <cassert>
struct Font {};
int main() {
    using Cache=wearable::GlyphMetricsCache<Font>;
    std::array<Cache::Entry,Cache::slots> storage{};Font latin,cn;
    assert(!Cache::find(nullptr,65));Cache::put(nullptr,65,&latin,12,14,-1);
    assert(!Cache::find(storage.data(),65));
    Cache::put(storage.data(),65,&latin,12,14,-1);
    for(unsigned i=0;i<10000;++i) {
        const auto* glyph=Cache::find(storage.data(),65);
        assert(glyph && glyph->font==&latin && glyph->width==12 && glyph->advance==14 && glyph->offset==-1);
    }
    // Collision must invalidate the old code, never return a different glyph.
    Cache::put(storage.data(),65+Cache::slots,&cn,24,24,0);
    assert(!Cache::find(storage.data(),65));
    assert(Cache::find(storage.data(),65+Cache::slots)->font==&cn);
    // Missing-glyph results remain distinguishable from cache misses.
    Cache::put(storage.data(),33,nullptr,16,16,0);
    assert(Cache::find(storage.data(),33) && !Cache::find(storage.data(),33)->font);
    // Separate font roles cannot reuse each other's size/offsets.
    std::array<Cache::Entry,Cache::slots> large{};
    Cache::put(large.data(),65+Cache::slots,&cn,28,29,-2);
    assert(Cache::find(storage.data(),65+Cache::slots)->width==24);
    assert(Cache::find(large.data(),65+Cache::slots)->advance==29);
}
