#include #include #include #include #include "fiko/io/web_io.hpp" #include "fiko_test.hpp" #include "miniz.h" using namespace fiko; using namespace fiko::io; namespace { std::string veriYolu(const char* ad) { return std::string(FIKO_IO_VERI) + "/" + ad; } } // namespace // ---- (a) VRML fixture: 1 kup (12 ucgen) + 1 cizgi (2 segment) -------------- FIKO_TEST(wrl_mini) { WrlSonuc s = wrlOku(veriYolu("mini.wrl")); FIKO_KONTROL(s.basarili); FIKO_KONTROL(s.yuzMeshSayisi == 1); FIKO_KONTROL(s.cizgiSetSayisi == 1); FIKO_KONTROL(s.parcalar.size() == 2); // Kup: 6 quad → fan → 12 ucgen → 36 vertex, 36 indeks const HazirCizim* mesh = nullptr; const HazirCizim* cizgi = nullptr; for (const auto& c : s.parcalar) { if (!c.yuzey.vertexler.empty()) mesh = &c; if (!c.kenar.vertexler.empty()) cizgi = &c; } FIKO_KONTROL(mesh != nullptr); FIKO_KONTROL(cizgi != nullptr); if (mesh) { FIKO_KONTROL(mesh->yuzey.vertexler.size() == 36); FIKO_KONTROL(mesh->yuzey.indeksler.size() == 36); // diffuseColor 0.8 0.2 0.2 FIKO_YAKIN(mesh->renk.x, 0.8f, 1e-3); FIKO_YAKIN(mesh->renk.y, 0.2f, 1e-3); } if (cizgi) { // coordIndex 0 1 2 -1 → 2 segment → 4 KenarVertex FIKO_KONTROL(cizgi->kenar.vertexler.size() == 4); FIKO_KONTROL(cizgi->kenar.kenarSayi == 2); FIKO_YAKIN(cizgi->renk.y, 0.8f, 1e-3); // yesil } } // ---- (b) FikoOp fixture: gzip + JSON + INT olcek + delta decode ------------ FIKO_TEST(fikoop_mini) { FikoOpSonuc s = fikoOpOku(veriYolu("mini.FikoOp")); FIKO_KONTROL(s.basarili); FIKO_KONTROL(s.hata.empty()); // Eksen merkez (5,6,7) FIKO_YAKIN(s.eksenMerkez.x, 5.0, 1e-6); FIKO_YAKIN(s.eksenMerkez.y, 6.0, 1e-6); FIKO_YAKIN(s.eksenMerkez.z, 7.0, 1e-6); // Mesh: 6 vertex (2 ucgen), sinir kenar 4 vertex FIKO_KONTROL(s.cizimler.size() == 1); if (!s.cizimler.empty()) { const auto& c = s.cizimler[0]; FIKO_KONTROL(c.yuzey.vertexler.size() == 6); FIKO_KONTROL(c.yuzey.indeksler.size() == 6); FIKO_KONTROL(c.kenar.vertexler.size() == 4); FIKO_KONTROL(c.ad == "MiniParca"); } // Program + noktalar FIKO_KONTROL(s.programlar.size() == 1); FIKO_KONTROL(s.toplamNokta == 3); if (!s.programlar.empty()) { const auto& p = s.programlar[0]; FIKO_KONTROL(p.noktalar.size() == 3); FIKO_KONTROL(p.ad == "MiniProg"); // eksenKoord.o = [100, 0, 0] FIKO_YAKIN(p.cerceveOrigin.x, 100.0, 1e-6); if (p.noktalar.size() == 3) { const auto& n0 = p.noktalar[0]; const auto& n1 = p.noktalar[1]; const auto& n2 = p.noktalar[2]; // INT olcek: 4109548 / 100000 = 41.09548 FIKO_YAKIN(n0.konum.x, 41.09548, 1e-4); FIKO_YAKIN(n0.konum.z, -21.14726, 1e-4); FIKO_KONTROL(n0.tip == "linear"); FIKO_YAKIN(n0.hiz, 25000.0, 1e-3); // takim yonu ty [0,0,-100000] / 100000 = (0,0,-1) FIKO_YAKIN(n0.takimYonu.z, -1.0, 1e-6); // renk kirmizi #ff0000 FIKO_YAKIN(n0.renk.x, 1.0f, 1e-2); FIKO_YAKIN(n0.renk.y, 0.0f, 1e-2); // DELTA: n1 sadece x/y/z/r/guncelSure verir → tip/hiz MIRAS FIKO_KONTROL(n1.tip == "linear"); // miras FIKO_YAKIN(n1.hiz, 25000.0, 1e-3); // miras FIKO_YAKIN(n1.konum.z, -17.15726, 1e-4); FIKO_YAKIN(n1.renk.x, 1.0f, 1e-2); // sari #ffff00 FIKO_YAKIN(n1.renk.y, 1.0f, 1e-2); // guncelSure 10 (>100 degil → ham 10) FIKO_YAKIN(n1.guncelSure, 10.0, 1e-6); // n2: x=50, tip miras linear FIKO_YAKIN(n2.konum.x, 50.0, 1e-4); FIKO_KONTROL(n2.tip == "linear"); } // Takim: cap 3000000/100000 = 30, boy 20000/100 = 200 FIKO_KONTROL(s.takimlar.size() == 1); if (!s.takimlar.empty()) { FIKO_YAKIN(s.takimlar[0].cap, 30.0, 1e-6); FIKO_YAKIN(s.takimlar[0].radius, 15.0, 1e-6); FIKO_YAKIN(s.takimlar[0].boy, 200.0, 1e-6); FIKO_YAKIN(s.takimlar[0].kesmeBoy, 50.0, 1e-6); } } } // ---- (c) Nested program: Fikogramlar→Fikogram→FikoAPTCAT (ozyineleme) ------ // Web hiyerarsisinde takim yolu ara-grup (Fikogram) altinda olabilir. Okuyucu // children[] icinde ozyineleyerek TUM takim yollarini bulmali. FIKO_TEST(fikoop_nested) { FikoOpSonuc s = fikoOpOku(veriYolu("mini_nested.FikoOp")); FIKO_KONTROL(s.basarili); // Ara Fikogram'a ragmen program bulunmali (flat ile ayni sonuc). FIKO_KONTROL(s.programlar.size() == 1); FIKO_KONTROL(s.toplamNokta == 3); if (!s.programlar.empty()) { FIKO_KONTROL(s.programlar[0].noktalar.size() == 3); FIKO_KONTROL(s.programlar[0].ad == "MiniProg"); } FIKO_KONTROL(s.takimlar.size() == 1); } // ---- (BUYUK) Gercek dosya smoke testi — yalniz FIKO_BUYUK_TEST env varsa ---- // D:/__sistem__/Downloads/Test/ gercek dosyalari repoda DEGIL; bellek/hiz profili // + 223970-nokta uctan-uca dogrulama icin gelistirici makinesinde elle kosar. FIKO_TEST(fikoop_buyuk_smoke) { if (!std::getenv("FIKO_BUYUK_TEST")) return; // gate: normal CI'da atla const std::string yol = "D:/__sistem__/Downloads/Test/Fikoperasyon.3.FikoOp"; FikoOpSonuc s = fikoOpOku(yol); FIKO_KONTROL(s.basarili); FIKO_KONTROL(s.hata.empty()); FIKO_KONTROL(s.cizimler.size() == 1); // 1 FikoCizimYalin mesh FIKO_KONTROL(s.atlananCizim == 0); // sikistirilmis geometri yok FIKO_KONTROL(s.programlar.size() == 1); // 1 FikoAPTCAT FIKO_KONTROL(s.toplamNokta == 223970); // takim yolu nokta sayisi if (!s.programlar.empty()) { const auto& p = s.programlar[0]; // ilk nokta x = 87154484/100000 = 871.54484 mm FIKO_YAKIN(p.noktalar.front().konum.x, 871.54484, 1e-3); } } // ---- gzip roundtrip (miniz deflate → gzipCoz inflate) ---------------------- FIKO_TEST(gzip_roundtrip) { const std::string orij = "FikoYT gzip testi — Turkce karakter: cgiosu 12345 {}[]"; // gzip'le (miniz: gzip baslik+trailer elle sarilir; burada tinfl_compress_... // yerine mz_compress2 ile zlib deretilir. gzipCoz gzip bekler → gzip sar.) // Basit yol: mz_deflate raw + elle gzip baslik/trailer. mz_stream s{}; mz_deflateInit2(&s, MZ_DEFAULT_COMPRESSION, MZ_DEFLATED, -MZ_DEFAULT_WINDOW_BITS, 9, MZ_DEFAULT_STRATEGY); std::string def(orij.size() + 128, '\0'); s.next_in = reinterpret_cast(orij.data()); s.avail_in = (unsigned)orij.size(); s.next_out = reinterpret_cast(def.data()); s.avail_out = (unsigned)def.size(); mz_deflate(&s, MZ_FINISH); const std::size_t defLen = s.total_out; const mz_ulong crc = mz_crc32(MZ_CRC32_INIT, reinterpret_cast(orij.data()), orij.size()); mz_deflateEnd(&s); std::string gz; gz.push_back((char)0x1F); gz.push_back((char)0x8B); gz.push_back(0x08); for (int i = 0; i < 7; ++i) gz.push_back(0x00); // flags+mtime+xfl+os gz.append(def.data(), defLen); auto le32 = [&](std::uint32_t v) { for (int i = 0; i < 4; ++i) gz.push_back((char)((v >> (8 * i)) & 0xFF)); }; le32((std::uint32_t)crc); le32((std::uint32_t)orij.size()); std::string cikti, hata; const bool ok = gzipCoz(gz, cikti, hata); FIKO_KONTROL(ok); FIKO_KONTROL(cikti == orij); // gzip olmayan girdi → aynen dondurulur std::string duz = "{\"duz\":true}", c2, h2; FIKO_KONTROL(gzipCoz(duz, c2, h2)); FIKO_KONTROL(c2 == duz); } // ---- (d) Bozuk girdi cokmez ------------------------------------------------ FIKO_TEST(bozuk_girdi) { // Olmayan dosya WrlSonuc w = wrlOku("olmayan_dosya_xyz.wrl"); FIKO_KONTROL(!w.basarili); FIKO_KONTROL(!w.hata.empty()); FikoOpSonuc f = fikoOpOku("olmayan_dosya_xyz.FikoOp"); FIKO_KONTROL(!f.basarili); // Bozuk gzip imzasi (1F 8B ama govde cop) std::string cop, hata; std::string bozuk = "\x1F\x8B\x08"; bozuk += std::string(20, '\xAA'); const bool ok = gzipCoz(bozuk, cop, hata); FIKO_KONTROL(!ok); // hata dondu ama cokmedi // Bozuk VRML metni WrlSonuc wc = wrlCoz("#VRML V2.0 utf8\nShape { geometry IndexedFaceSet { coord"); FIKO_KONTROL(!wc.basarili); // mesh yok, cokmedi }