liblzma: Defines masks for return values from lzma_index_checks().

This commit is contained in:
Jia Tan 2022-12-29 21:52:15 +08:00
parent 8f38cdd9ab
commit af55191102
2 changed files with 34 additions and 11 deletions

View File

@ -303,6 +303,28 @@ typedef enum {
} lzma_index_iter_mode;
/**
* \brief Mask for return value from lzma_index_checks() for check none
*
* \note This and the other CHECK_MASK macros were added in 5.5.1alpha.
*/
#define LZMA_INDEX_CHECK_MASK_NONE (UINT32_C(1) << LZMA_CHECK_NONE)
/**
* \brief Mask for return value from lzma_index_checks() for check CRC32
*/
#define LZMA_INDEX_CHECK_MASK_CRC32 (UINT32_C(1) << LZMA_CHECK_CRC32)
/**
* \brief Mask for return value from lzma_index_checks() for check CRC64
*/
#define LZMA_INDEX_CHECK_MASK_CRC64 (UINT32_C(1) << LZMA_CHECK_CRC64)
/**
* \brief Mask for return value from lzma_index_checks() for check SHA256
*/
#define LZMA_INDEX_CHECK_MASK_SHA256 (UINT32_C(1) << LZMA_CHECK_SHA256)
/**
* \brief Calculate memory usage of lzma_index
*
@ -433,6 +455,7 @@ extern LZMA_API(lzma_ret) lzma_index_stream_flags(
* showing the Check types to the user.
*
* The bitmask is 1 << check_id, e.g. CRC32 is 1 << 1 and SHA-256 is 1 << 10.
* These masks are defined for convenience as LZMA_INDEX_CHECK_MASK_XXX
*
* \param i Pointer to lzma_index structure
*

View File

@ -204,28 +204,28 @@ test_lzma_index_checks(void)
assert_lzma_ret(lzma_index_stream_flags(idx, &stream_flags),
LZMA_OK);
assert_uint_eq(lzma_index_checks(idx),
UINT32_C(1) << LZMA_CHECK_NONE);
LZMA_INDEX_CHECK_MASK_NONE);
// Set the check type to CRC32 and repeat
stream_flags.check = LZMA_CHECK_CRC32;
assert_lzma_ret(lzma_index_stream_flags(idx, &stream_flags),
LZMA_OK);
assert_uint_eq(lzma_index_checks(idx),
UINT32_C(1) << LZMA_CHECK_CRC32);
LZMA_INDEX_CHECK_MASK_CRC32);
// Set the check type to CRC64 and repeat
stream_flags.check = LZMA_CHECK_CRC64;
assert_lzma_ret(lzma_index_stream_flags(idx, &stream_flags),
LZMA_OK);
assert_uint_eq(lzma_index_checks(idx),
UINT32_C(1) << LZMA_CHECK_CRC64);
LZMA_INDEX_CHECK_MASK_CRC64);
// Set the check type to SHA256 and repeat
stream_flags.check = LZMA_CHECK_SHA256;
assert_lzma_ret(lzma_index_stream_flags(idx, &stream_flags),
LZMA_OK);
assert_uint_eq(lzma_index_checks(idx),
UINT32_C(1) << LZMA_CHECK_SHA256);
LZMA_INDEX_CHECK_MASK_SHA256);
// Create second lzma_index and cat to first
lzma_index *second = lzma_index_init(NULL);
@ -237,14 +237,14 @@ test_lzma_index_checks(void)
LZMA_OK);
assert_uint_eq(lzma_index_checks(second),
UINT32_C(1) << LZMA_CHECK_CRC32);
LZMA_INDEX_CHECK_MASK_CRC32);
assert_lzma_ret(lzma_index_cat(idx, second, NULL), LZMA_OK);
// Index should now have both CRC32 and SHA256
assert_uint_eq(lzma_index_checks(idx),
(UINT32_C(1) << LZMA_CHECK_CRC32) |
(UINT32_C(1) << LZMA_CHECK_SHA256));
LZMA_INDEX_CHECK_MASK_CRC32 |
LZMA_INDEX_CHECK_MASK_SHA256);
// Change the check type of the second Stream to SHA256
stream_flags.check = LZMA_CHECK_SHA256;
@ -253,7 +253,7 @@ test_lzma_index_checks(void)
// Index should now have only SHA256
assert_uint_eq(lzma_index_checks(idx),
UINT32_C(1) << LZMA_CHECK_SHA256);
LZMA_INDEX_CHECK_MASK_SHA256);
// Test with a third Stream
lzma_index *third = lzma_index_init(NULL);
@ -264,14 +264,14 @@ test_lzma_index_checks(void)
LZMA_OK);
assert_uint_eq(lzma_index_checks(third),
UINT32_C(1) << LZMA_CHECK_CRC64);
LZMA_INDEX_CHECK_MASK_CRC64);
assert_lzma_ret(lzma_index_cat(idx, third, NULL), LZMA_OK);
// Index should now have CRC64 and SHA256
assert_uint_eq(lzma_index_checks(idx),
(UINT32_C(1) << LZMA_CHECK_CRC64) |
(UINT32_C(1) << LZMA_CHECK_SHA256));
LZMA_INDEX_CHECK_MASK_CRC64 |
LZMA_INDEX_CHECK_MASK_SHA256);
lzma_index_end(idx, NULL);
}