/* ------------------------------------------------------------ */
/*
HTTrack Website Copier, Offline Browser for Windows and Unix
Copyright (C) 2026 Xavier Roche and other contributors

SPDX-License-Identifier: GPL-3.0-or-later

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.

Ethical use: we kindly ask that you NOT use this software to harvest email
addresses or to collect any other private information about people. Doing so
would dishonor our work and waste the many hours we have spent on it.

Please visit our Website: http://www.httrack.com
*/

/* ------------------------------------------------------------ */
/* File: htscache_selftest.h                                    */
/* Author: Xavier Roche                                         */
/* ------------------------------------------------------------ */

#ifndef HTSCACHE_SELFTEST_DEFH
#define HTSCACHE_SELFTEST_DEFH

#ifdef HTS_INTERNAL_BYTECODE

#ifndef HTS_DEF_FWSTRUCT_httrackp
#define HTS_DEF_FWSTRUCT_httrackp
typedef struct httrackp httrackp;
#endif

/* Run the cache create/read/update self-test against a working directory.
   Returns the number of failed checks (0 == success). */
int cache_selftests(httrackp *opt, const char *dir);

/* Read a committed (frozen) cache fixture under <dir>/hts-cache/new.zip and
   assert a fixed set of entries decodes field- and byte-exact. Unlike
   cache_selftests (write-then-read with the same build, a round-trip), this
   reads bytes an earlier build froze, so it catches read-path / format drift.
   regen!=0 first rewrites the fixture from the same table (to regenerate the
   committed file, never by the test). Returns the failed-check count. */
int cache_golden_selftest(httrackp *opt, const char *dir, int regen);

/* Cache write-failure policy (#174/#219): abort on fatal errno or a streak,
   drop just the entry otherwise. Returns the failed-check count. */
int cache_write_failure_selftest(httrackp *opt, const char *dir);

/* Exercise the hts_cache_reconcile() generation policies on file fixtures
   under <dir>. Returns the failed-check count. */
int cache_reconcile_selftest(httrackp *opt, const char *dir);

/* Verify cache_init refuses a pre-3.31 .dat/.ndx cache without touching it.
   Returns the number of failed checks (0 = pass). */
int cache_legacy_refused_selftest(httrackp *opt, const char *dir);

/* A cache entry whose every field sits at its declared cap: the header block
   the writer builds outgrows its fixed buffer, so this pins that the writer
   bounds it, drops whole fields rather than halves, and still round-trips
   everything written before the block filled. Returns the failed-check count.
 */
int cache_header_bounds_selftest(httrackp *opt, const char *dir);

/* URLs at (and past) the cache API's length cap: store and lookup must neither
   abort nor alias two keys. Returns the failed-check count. */
int cache_url_bounds_selftest(httrackp *opt, const char *dir);

/* X-Save is stored relative to path_html_utf8; a name rebuilt under a deeper
   path must fit or the entry be refused, never clipped into a name pointing at
   another file (#1278). Returns the failed-check count. */
int cache_savename_bounds_selftest(httrackp *opt, const char *dir);

/* Inject read-side corruption (zip byte surgery: bad size, header, deflate)
   under <dir> and assert every case degrades to STATUSCODE_INVALID without
   tainting a sibling entry. */
int cache_corruption_selftest(httrackp *opt, const char *dir);

/* A failed read of the source file must abandon the cache entry rather than
   commit a silently truncated body. */
int cache_readfail_selftest(httrackp *opt, const char *dir);

#endif

#endif
