#include "fiko/cekirdek/gecici.hpp" #include #include "fiko_test.hpp" namespace fs = std::filesystem; using namespace fiko; // Testler gerçek dosya sistemine dokunur → kök sistem temp altına alınır // (kurulum dizini kirlenmesin). kokAta zaten ayar yolunun aynısı. static fs::path testKokKur(const char* ad) { const fs::path k = fs::temp_directory_path() / ad; fs::remove_all(k); gecici::kokAta(k); return k; } static void dosyaYaz(const fs::path& p, size_t bayt) { std::ofstream o(p, std::ios::binary | std::ios::trunc); o << std::string(bayt, 'x'); } FIKO_TEST(gecici_kok_ve_alt_dizin) { const fs::path k = testKokKur("fiko_test_gecici1"); FIKO_KONTROL(gecici::kok() == k); FIKO_KONTROL(fs::is_directory(k)); const fs::path onb = gecici::altDizin("onbellek"); FIKO_KONTROL(onb == k / "onbellek"); FIKO_KONTROL(fs::is_directory(onb)); // Ayraç içeren ad kabul edilmez (kök dışına kaçış yok). FIKO_KONTROL(gecici::altDizin("../disari") == k); gecici::kokAta({}); // varsayılana dön (diğer testleri etkilemesin) } FIKO_TEST(gecici_onbellek_yolu_kaynak_yaninda_degil) { const fs::path k = testKokKur("fiko_test_gecici2"); const fs::path c = gecici::onbellekDosyasi("D:/veri/parca.stp", "fkcache"); FIKO_KONTROL(c.parent_path() == k / "onbellek"); // kaynağın YANINDA değil FIKO_KONTROL(c.extension() == ".fkcache"); FIKO_KONTROL(c.filename().string().rfind("parca.stp-", 0) == 0); // okunabilir ad korunur // Aynı adlı farklı yollar çakışmaz; yol normalizasyonu (ayraç/harf) aynı sonucu verir. FIKO_KONTROL(gecici::onbellekDosyasi("D:/baska/parca.stp", "fkcache") != c); FIKO_KONTROL(gecici::onbellekDosyasi("d:\\VERI\\parca.stp", "fkcache") == c); gecici::kokAta({}); } FIKO_TEST(gecici_kok_icinde_mi) { const fs::path k = testKokKur("fiko_test_gecici5"); FIKO_KONTROL(gecici::kokIcindeMi((k / "onbellek" / "a.fkcache").string())); FIKO_KONTROL(gecici::kokIcindeMi(k.string())); FIKO_KONTROL(!gecici::kokIcindeMi("D:/veri/parca.stp")); // kullanıcı dosyası → MRU'ya girer FIKO_KONTROL(!gecici::kokIcindeMi("")); gecici::kokAta({}); } FIKO_TEST(gecici_buda_boyut_tavani) { const fs::path k = testKokKur("fiko_test_gecici3"); const fs::path onb = gecici::altDizin("onbellek"); for (int i = 0; i < 4; ++i) dosyaYaz(onb / ("d" + std::to_string(i) + ".bin"), 300 * 1024); FIKO_KONTROL(gecici::toplamBoyut() >= 1200u * 1024u); gecici::buda({.maksGun = 0, .maksMb = 1}); // 1 MB tavan → en eskiler silinir FIKO_KONTROL(gecici::toplamBoyut() <= 1024u * 1024u); FIKO_KONTROL(gecici::temizle() > 0); FIKO_KONTROL(gecici::toplamBoyut() == 0); gecici::kokAta({}); } FIKO_TEST(gecici_eski_yan_dosya_goc) { const fs::path k = testKokKur("fiko_test_gecici4"); const fs::path veri = fs::temp_directory_path() / "fiko_test_gecici4_veri"; fs::create_directories(veri); const fs::path kaynak = veri / "eski.stp"; dosyaYaz(kaynak, 16); dosyaYaz(veri / "eski.stp.fkcache", 32); // eski sürümün yan-dosyası FIKO_KONTROL(gecici::eskiYanDosyaGoc(kaynak.string(), "fkcache")); FIKO_KONTROL(!fs::exists(veri / "eski.stp.fkcache")); // kullanıcı dizini temizlendi FIKO_KONTROL(fs::exists(gecici::onbellekDosyasi(kaynak.string(), "fkcache"))); fs::remove_all(veri); gecici::kokAta({}); } FIKO_TEST(gecici_dosya_benzersiz_ve_kok_icinde) { const fs::path k = testKokKur("fiko_test_gecici6"); const fs::path a = gecici::geciciDosya("olcum", "txt"); const fs::path b = gecici::geciciDosya("olcum", "txt"); FIKO_KONTROL(a != b); // sayaç benzersizliği FIKO_KONTROL(a.parent_path() == k); // kök içinde FIKO_KONTROL(a.extension() == ".txt"); FIKO_KONTROL(a.filename().string().rfind("olcum-", 0) == 0); FIKO_KONTROL(gecici::kokIcindeMi(a.string())); // Dosya OLUŞTURULMAZ (sözleşme) — silme çağıranın işi. FIKO_KONTROL(!fs::exists(a)); // Öneksiz/uzantısız çağrı da geçerli yol üretir. const fs::path c = gecici::geciciDosya("", ""); FIKO_KONTROL(c.parent_path() == k); gecici::kokAta({}); }