@@ -1846,15 +1846,11 @@ static int basicUnitTests(U32 seed, double compressibility, int bigTests)
1846
1846
1847
1847
CHECK (dstBuf == NULL || checkBuf == NULL , "allocation failed" );
1848
1848
1849
- ZSTD_CCtx_reset (zc , ZSTD_reset_session_and_parameters );
1849
+ CHECK_Z ( ZSTD_CCtx_reset (zc , ZSTD_reset_session_and_parameters ) );
1850
1850
1851
1851
/* Reference external matchfinder outside the test loop to
1852
1852
* check that the reference is preserved across compressions */
1853
- ZSTD_registerExternalMatchFinder (
1854
- zc ,
1855
- & externalMatchState ,
1856
- zstreamExternalMatchFinder
1857
- );
1853
+ ZSTD_registerExternalMatchFinder (zc , & externalMatchState , zstreamExternalMatchFinder );
1858
1854
1859
1855
for (enableFallback = 0 ; enableFallback < 1 ; enableFallback ++ ) {
1860
1856
size_t testCaseId ;
@@ -1916,11 +1912,56 @@ static int basicUnitTests(U32 seed, double compressibility, int bigTests)
1916
1912
}
1917
1913
1918
1914
/* Test that reset clears the external matchfinder */
1915
+ CHECK_Z (ZSTD_CCtx_reset (zc , ZSTD_reset_session_and_parameters ));
1916
+ externalMatchState = EMF_BIG_ERROR ; /* ensure zstd will fail if the matchfinder wasn't cleared */
1917
+ CHECK_Z (ZSTD_CCtx_setParameter (zc , ZSTD_c_enableMatchFinderFallback , 0 ));
1918
+ CHECK_Z (ZSTD_compress2 (zc , dstBuf , dstBufSize , CNBuffer , CNBufferSize ));
1919
+
1920
+ /* Test that registering mFinder == NULL clears the external matchfinder */
1919
1921
ZSTD_CCtx_reset (zc , ZSTD_reset_session_and_parameters );
1922
+ ZSTD_registerExternalMatchFinder (zc , & externalMatchState , zstreamExternalMatchFinder );
1920
1923
externalMatchState = EMF_BIG_ERROR ; /* ensure zstd will fail if the matchfinder wasn't cleared */
1921
1924
CHECK_Z (ZSTD_CCtx_setParameter (zc , ZSTD_c_enableMatchFinderFallback , 0 ));
1925
+ ZSTD_registerExternalMatchFinder (zc , NULL , NULL ); /* clear the external matchfinder */
1922
1926
CHECK_Z (ZSTD_compress2 (zc , dstBuf , dstBufSize , CNBuffer , CNBufferSize ));
1923
1927
1928
+ /* Test that external matchfinder doesn't interact with older APIs */
1929
+ ZSTD_CCtx_reset (zc , ZSTD_reset_session_and_parameters );
1930
+ ZSTD_registerExternalMatchFinder (zc , & externalMatchState , zstreamExternalMatchFinder );
1931
+ externalMatchState = EMF_BIG_ERROR ; /* ensure zstd will fail if the matchfinder is used */
1932
+ CHECK_Z (ZSTD_CCtx_setParameter (zc , ZSTD_c_enableMatchFinderFallback , 0 ));
1933
+ CHECK_Z (ZSTD_compressCCtx (zc , dstBuf , dstBufSize , CNBuffer , CNBufferSize , 3 ));
1934
+
1935
+ /* Test that compression returns the correct error with LDM */
1936
+ CHECK_Z (ZSTD_CCtx_reset (zc , ZSTD_reset_session_and_parameters ));
1937
+ {
1938
+ size_t res ;
1939
+ ZSTD_registerExternalMatchFinder (zc , & externalMatchState , zstreamExternalMatchFinder );
1940
+ CHECK_Z (ZSTD_CCtx_setParameter (zc , ZSTD_c_enableLongDistanceMatching , ZSTD_ps_enable ));
1941
+ res = ZSTD_compress2 (zc , dstBuf , dstBufSize , CNBuffer , CNBufferSize );
1942
+ CHECK (!ZSTD_isError (res ), "EMF: Should have raised an error!" );
1943
+ CHECK (
1944
+ ZSTD_getErrorCode (res ) != ZSTD_error_parameter_combination_unsupported ,
1945
+ "EMF: Wrong error code: %s" , ZSTD_getErrorName (res )
1946
+ );
1947
+ }
1948
+
1949
+ #ifdef ZSTD_MULTITHREAD
1950
+ /* Test that compression returns the correct error with nbWorkers > 0 */
1951
+ CHECK_Z (ZSTD_CCtx_reset (zc , ZSTD_reset_session_and_parameters ));
1952
+ {
1953
+ size_t res ;
1954
+ ZSTD_registerExternalMatchFinder (zc , & externalMatchState , zstreamExternalMatchFinder );
1955
+ CHECK_Z (ZSTD_CCtx_setParameter (zc , ZSTD_c_nbWorkers , 1 ));
1956
+ res = ZSTD_compress2 (zc , dstBuf , dstBufSize , CNBuffer , CNBufferSize );
1957
+ CHECK (!ZSTD_isError (res ), "EMF: Should have raised an error!" );
1958
+ CHECK (
1959
+ ZSTD_getErrorCode (res ) != ZSTD_error_parameter_combination_unsupported ,
1960
+ "EMF: Wrong error code: %s" , ZSTD_getErrorName (res )
1961
+ );
1962
+ }
1963
+ #endif
1964
+
1924
1965
free (dstBuf );
1925
1966
free (checkBuf );
1926
1967
}
0 commit comments