/** @file test_xxhash.cpp — xxHash 全覆盖 */
#include "xxhash.h"
#include <cstdio>
#include <cstring>
static int P=0,F=0;
#define T(n) do{printf("  %s ... ",n);}while(0)
#define OK() do{printf("OK\n");P++;}while(0)
#define FL(m) do{printf("FAIL: %s\n",m);F++;return;}while(0)
#define CK(c,m) do{if(!(c))FL(m);}while(0)

static void t1(){T("XXH32 hello");XXH32_hash_t h=XXH32("hello",5,0);CK(h==XXH32("hello",5,0),"det");CK(h!=0,"0");OK();}
static void t2(){T("XXH64 hello");XXH64_hash_t h=XXH64("hello",5,0);CK(h==XXH64("hello",5,0),"det");CK(h!=0,"0");OK();}
static void t3(){T("XXH3_64 hello");XXH64_hash_t h=XXH3_64bits("hello",5);CK(h==XXH3_64bits("hello",5),"det");OK();}
static void t4(){T("XXH3_128 hello");XXH128_hash_t h=XXH3_128bits("hello",5);XXH128_hash_t h2=XXH3_128bits("hello",5);CK(h.high64==h2.high64&&h.low64==h2.low64,"det");CK(h.high64||h.low64,"0");OK();}
static void t5(){T("XXH32 diff seed");CK(XXH32("d",1,0)!=XXH32("d",1,12345),"diff");OK();}
static void t6(){T("XXH32 empty");CK(XXH32("",0,0)==XXH32("",0,0),"det");OK();}
static void t7(){T("XXH64 64B");const char*d="AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";CK(XXH64(d,64,0)==XXH64(d,64,0),"det");OK();}
static void t8(){T("XXH128 state API");XXH3_state_t*s=XXH3_createState();CK(s,"c");XXH3_128bits_reset(s);XXH3_128bits_update(s,"hello",5);XXH128_hash_t h=XXH3_128bits_digest(s);XXH128_hash_t e=XXH3_128bits("hello",5);CK(h.high64==e.high64&&h.low64==e.low64,"mismatch");XXH3_freeState(s);OK();}

int main(){printf("\n=== libmy_xxhash ===\n\n");t1();t2();t3();t4();t5();t6();t7();t8();printf("\n========\n  %d pass, %d fail\n========\n",P,F);return F>0?1:0;}
