#include "fiko_test.hpp" #include "surec_kopru.hpp" // saf çerçeve protokolü (Win32'siz, inline serialize/deserialize) #include #include using namespace fiko; using namespace fiko::surecproto; // ── Çerçeve round-trip: serialize → deserialize tüm alanları korur. ───────── FIKO_TEST(cerceve_roundtrip_tum_alanlar) { SurecCerceve c; c.tip = SurecMesajTip::Parametre; c.kaynakPid = 1234; c.hedefPid = 5678; c.korelasyon = 0xDEADBEEFCAFEull; c.govde = "gövde\tiçinde\ntab ve newline var"; // binary-güvenli olmalı const std::string wire = cerceveSerialize(c); SurecCerceve d; FIKO_KONTROL(cerceveDeserialize(wire.data(), wire.size(), d)); FIKO_KONTROL(d.tip == SurecMesajTip::Parametre); FIKO_KONTROL(d.kaynakPid == 1234); FIKO_KONTROL(d.hedefPid == 5678); FIKO_KONTROL(d.korelasyon == 0xDEADBEEFCAFEull); FIKO_KONTROL(d.govde == c.govde); } // ── Boş gövde + farklı tipler round-trip. ────────────────────────────────── FIKO_TEST(cerceve_bos_govde_ve_tipler) { for (uint16_t t = 1; t <= 10; ++t) { SurecCerceve c; c.tip = (SurecMesajTip)t; c.kaynakPid = t * 7; const std::string wire = cerceveSerialize(c); SurecCerceve d; FIKO_KONTROL(cerceveDeserialize(wire.data(), wire.size(), d)); FIKO_KONTROL((uint16_t)d.tip == t); FIKO_KONTROL(d.kaynakPid == (uint32_t)(t * 7)); FIKO_KONTROL(d.govde.empty()); } } // ── Geri-uyum: eski "komut\t" metni → Komut çerçevesi. ────────────────── FIKO_TEST(cerceve_geri_uyum_eski_metin) { const std::string eski = "komut\tYeni Belge"; SurecCerceve d; FIKO_KONTROL(cerceveDeserialize(eski.data(), eski.size(), d)); FIKO_KONTROL(d.tip == SurecMesajTip::Komut); FIKO_KONTROL(d.govde == "Yeni Belge"); FIKO_KONTROL(d.kaynakPid == 0); // Tab'sız düz ad da Komut sayılır. const std::string duz = "Kutu"; SurecCerceve d2; FIKO_KONTROL(cerceveDeserialize(duz.data(), duz.size(), d2)); FIKO_KONTROL(d2.tip == SurecMesajTip::Komut); FIKO_KONTROL(d2.govde == "Kutu"); } // ── Bozuk (sihirli ama kısa) çerçeve reddedilir. ─────────────────────────── FIKO_TEST(cerceve_bozuk_sihir_reddedilir) { std::string s; yazU32(s, SIHIR); // yalnız sihir; başlık eksik SurecCerceve d; FIKO_KONTROL(!cerceveDeserialize(s.data(), s.size(), d)); } // ── Parametre gövdesi: komut adı + key=val round-trip. ───────────────────── FIKO_TEST(param_serialize_coz_roundtrip) { std::vector> p = { {"yol", "C:\\parca.fikocad"}, {"kip", "hizli"}, {"bos", ""}}; const std::string govde = paramSerialize("Belge Aç", p); std::string ad; std::vector> cikan; FIKO_KONTROL(paramCoz(govde, ad, cikan)); FIKO_KONTROL(ad == "Belge Aç"); FIKO_KONTROL(cikan.size() == 3); FIKO_KONTROL(cikan[0].first == "yol" && cikan[0].second == "C:\\parca.fikocad"); FIKO_KONTROL(cikan[1].first == "kip" && cikan[1].second == "hizli"); FIKO_KONTROL(cikan[2].first == "bos" && cikan[2].second.empty()); } // ── Parametresiz komut gövdesi de çözülür (adet = 0). ────────────────────── FIKO_TEST(param_parametresiz) { const std::string govde = paramSerialize("Kaydet", {}); std::string ad; std::vector> cikan; FIKO_KONTROL(paramCoz(govde, ad, cikan)); FIKO_KONTROL(ad == "Kaydet"); FIKO_KONTROL(cikan.empty()); } // ── Parametre çerçevesini uçtan uca: cerceve(govde=param) → deser → paramCoz. ── FIKO_TEST(param_cerceve_uctan_uca) { std::vector> p = {{"a", "1"}, {"b", "2"}}; SurecCerceve c; c.tip = SurecMesajTip::Parametre; c.kaynakPid = 42; c.govde = paramSerialize("Komut", p); const std::string wire = cerceveSerialize(c); SurecCerceve d; FIKO_KONTROL(cerceveDeserialize(wire.data(), wire.size(), d)); FIKO_KONTROL(d.tip == SurecMesajTip::Parametre); std::string ad; std::vector> cikan; FIKO_KONTROL(paramCoz(d.govde, ad, cikan)); FIKO_KONTROL(ad == "Komut"); FIKO_KONTROL(cikan.size() == 2); FIKO_KONTROL(cikan[0].first == "a" && cikan[1].second == "2"); }