1
0
mirror of synced 2024-11-12 02:00:52 +01:00
ImHex/tests/helpers/source/common.cpp

80 lines
2.5 KiB
C++
Raw Normal View History

#include <hex/test/tests.hpp>
#include <hex/test/test_provider.hpp>
#include <hex/helpers/crypto.hpp>
Tests for the CRC and hash algorithms (#335) * Update TEST_ASSERT to do nothing if condition is true The TEST_ASSERT should not return if the condition is true, because: - it prevents the usage of multiple TEST_ASSERT in a single test case, - that behavior differs from how the assert in the standard library works, and thus may give unexpected results. Make the TEST_ASSERT to print an error message (with an formatted optional user part) when it fails to make debugging easier. * Fix some bugs in TestProvider, add unit tests Use pointer-to-vector in TestProvider so writes can be tested, too. * Add test EncodeDecode16, fix some encode16 bugs The function mbedtls_mpi_write_string needs a bit longer buffer than the resulting string actually will be. Known bug: mbedtls_mpi_read_binary ingores initial null bytes * Add test EncodeDecode64, fix some bugs The functions mbedtls_base64_encode and mbedtls_base64_decode needs a bit longer buffer than the resulting string actually will be. * Remove check for empty data from TestProvider It can be valid to get the hash of empty string. * Add tests for CRC calculation Two type of thests: - compare the result of the CRC calculation to a known to be good results, - generate random data as message, calculate of it's CRC and append that to the message, the CRC of this new data should be 0. * Add test for hash algorithms * Add includes in tests * Remove the use of C++20 ranges It seems that Apple Clang does not support range-based constrained algorithms at this time. * Replace encode16 implementation To encode the zero bytes at the begining of the input vector, too.
2021-11-26 22:14:44 +01:00
#include <algorithm>
#include <vector>
Tests for the CRC and hash algorithms (#335) * Update TEST_ASSERT to do nothing if condition is true The TEST_ASSERT should not return if the condition is true, because: - it prevents the usage of multiple TEST_ASSERT in a single test case, - that behavior differs from how the assert in the standard library works, and thus may give unexpected results. Make the TEST_ASSERT to print an error message (with an formatted optional user part) when it fails to make debugging easier. * Fix some bugs in TestProvider, add unit tests Use pointer-to-vector in TestProvider so writes can be tested, too. * Add test EncodeDecode16, fix some encode16 bugs The function mbedtls_mpi_write_string needs a bit longer buffer than the resulting string actually will be. Known bug: mbedtls_mpi_read_binary ingores initial null bytes * Add test EncodeDecode64, fix some bugs The functions mbedtls_base64_encode and mbedtls_base64_decode needs a bit longer buffer than the resulting string actually will be. * Remove check for empty data from TestProvider It can be valid to get the hash of empty string. * Add tests for CRC calculation Two type of thests: - compare the result of the CRC calculation to a known to be good results, - generate random data as message, calculate of it's CRC and append that to the message, the CRC of this new data should be 0. * Add test for hash algorithms * Add includes in tests * Remove the use of C++20 ranges It seems that Apple Clang does not support range-based constrained algorithms at this time. * Replace encode16 implementation To encode the zero bytes at the begining of the input vector, too.
2021-11-26 22:14:44 +01:00
TEST_SEQUENCE("TestSucceeding") {
TEST_SUCCESS();
};
TEST_SEQUENCE("TestFailing", FAILING) {
TEST_FAIL();
Tests for the CRC and hash algorithms (#335) * Update TEST_ASSERT to do nothing if condition is true The TEST_ASSERT should not return if the condition is true, because: - it prevents the usage of multiple TEST_ASSERT in a single test case, - that behavior differs from how the assert in the standard library works, and thus may give unexpected results. Make the TEST_ASSERT to print an error message (with an formatted optional user part) when it fails to make debugging easier. * Fix some bugs in TestProvider, add unit tests Use pointer-to-vector in TestProvider so writes can be tested, too. * Add test EncodeDecode16, fix some encode16 bugs The function mbedtls_mpi_write_string needs a bit longer buffer than the resulting string actually will be. Known bug: mbedtls_mpi_read_binary ingores initial null bytes * Add test EncodeDecode64, fix some bugs The functions mbedtls_base64_encode and mbedtls_base64_decode needs a bit longer buffer than the resulting string actually will be. * Remove check for empty data from TestProvider It can be valid to get the hash of empty string. * Add tests for CRC calculation Two type of thests: - compare the result of the CRC calculation to a known to be good results, - generate random data as message, calculate of it's CRC and append that to the message, the CRC of this new data should be 0. * Add test for hash algorithms * Add includes in tests * Remove the use of C++20 ranges It seems that Apple Clang does not support range-based constrained algorithms at this time. * Replace encode16 implementation To encode the zero bytes at the begining of the input vector, too.
2021-11-26 22:14:44 +01:00
};
TEST_SEQUENCE("TestProvider_read") {
std::vector<u8> data { 0xde, 0xad, 0xbe, 0xef, 0x42, 0x2a, 0x00, 0xff };
Tests for the CRC and hash algorithms (#335) * Update TEST_ASSERT to do nothing if condition is true The TEST_ASSERT should not return if the condition is true, because: - it prevents the usage of multiple TEST_ASSERT in a single test case, - that behavior differs from how the assert in the standard library works, and thus may give unexpected results. Make the TEST_ASSERT to print an error message (with an formatted optional user part) when it fails to make debugging easier. * Fix some bugs in TestProvider, add unit tests Use pointer-to-vector in TestProvider so writes can be tested, too. * Add test EncodeDecode16, fix some encode16 bugs The function mbedtls_mpi_write_string needs a bit longer buffer than the resulting string actually will be. Known bug: mbedtls_mpi_read_binary ingores initial null bytes * Add test EncodeDecode64, fix some bugs The functions mbedtls_base64_encode and mbedtls_base64_decode needs a bit longer buffer than the resulting string actually will be. * Remove check for empty data from TestProvider It can be valid to get the hash of empty string. * Add tests for CRC calculation Two type of thests: - compare the result of the CRC calculation to a known to be good results, - generate random data as message, calculate of it's CRC and append that to the message, the CRC of this new data should be 0. * Add test for hash algorithms * Add includes in tests * Remove the use of C++20 ranges It seems that Apple Clang does not support range-based constrained algorithms at this time. * Replace encode16 implementation To encode the zero bytes at the begining of the input vector, too.
2021-11-26 22:14:44 +01:00
hex::test::TestProvider provider(&data);
hex::prv::Provider *provider2 = &provider;
Tests for the CRC and hash algorithms (#335) * Update TEST_ASSERT to do nothing if condition is true The TEST_ASSERT should not return if the condition is true, because: - it prevents the usage of multiple TEST_ASSERT in a single test case, - that behavior differs from how the assert in the standard library works, and thus may give unexpected results. Make the TEST_ASSERT to print an error message (with an formatted optional user part) when it fails to make debugging easier. * Fix some bugs in TestProvider, add unit tests Use pointer-to-vector in TestProvider so writes can be tested, too. * Add test EncodeDecode16, fix some encode16 bugs The function mbedtls_mpi_write_string needs a bit longer buffer than the resulting string actually will be. Known bug: mbedtls_mpi_read_binary ingores initial null bytes * Add test EncodeDecode64, fix some bugs The functions mbedtls_base64_encode and mbedtls_base64_decode needs a bit longer buffer than the resulting string actually will be. * Remove check for empty data from TestProvider It can be valid to get the hash of empty string. * Add tests for CRC calculation Two type of thests: - compare the result of the CRC calculation to a known to be good results, - generate random data as message, calculate of it's CRC and append that to the message, the CRC of this new data should be 0. * Add test for hash algorithms * Add includes in tests * Remove the use of C++20 ranges It seems that Apple Clang does not support range-based constrained algorithms at this time. * Replace encode16 implementation To encode the zero bytes at the begining of the input vector, too.
2021-11-26 22:14:44 +01:00
u8 buff[1024];
std::fill(std::begin(buff), std::end(buff), 22);
provider2->read(0, buff + 1, 4);
TEST_ASSERT(buff[0] == 22); // should be unchanged
Tests for the CRC and hash algorithms (#335) * Update TEST_ASSERT to do nothing if condition is true The TEST_ASSERT should not return if the condition is true, because: - it prevents the usage of multiple TEST_ASSERT in a single test case, - that behavior differs from how the assert in the standard library works, and thus may give unexpected results. Make the TEST_ASSERT to print an error message (with an formatted optional user part) when it fails to make debugging easier. * Fix some bugs in TestProvider, add unit tests Use pointer-to-vector in TestProvider so writes can be tested, too. * Add test EncodeDecode16, fix some encode16 bugs The function mbedtls_mpi_write_string needs a bit longer buffer than the resulting string actually will be. Known bug: mbedtls_mpi_read_binary ingores initial null bytes * Add test EncodeDecode64, fix some bugs The functions mbedtls_base64_encode and mbedtls_base64_decode needs a bit longer buffer than the resulting string actually will be. * Remove check for empty data from TestProvider It can be valid to get the hash of empty string. * Add tests for CRC calculation Two type of thests: - compare the result of the CRC calculation to a known to be good results, - generate random data as message, calculate of it's CRC and append that to the message, the CRC of this new data should be 0. * Add test for hash algorithms * Add includes in tests * Remove the use of C++20 ranges It seems that Apple Clang does not support range-based constrained algorithms at this time. * Replace encode16 implementation To encode the zero bytes at the begining of the input vector, too.
2021-11-26 22:14:44 +01:00
TEST_ASSERT(buff[1] == 0xde);
TEST_ASSERT(buff[2] == 0xad);
TEST_ASSERT(buff[3] == 0xbe);
TEST_ASSERT(buff[4] == 0xef);
TEST_ASSERT(buff[5] == 22); // should be unchanged
Tests for the CRC and hash algorithms (#335) * Update TEST_ASSERT to do nothing if condition is true The TEST_ASSERT should not return if the condition is true, because: - it prevents the usage of multiple TEST_ASSERT in a single test case, - that behavior differs from how the assert in the standard library works, and thus may give unexpected results. Make the TEST_ASSERT to print an error message (with an formatted optional user part) when it fails to make debugging easier. * Fix some bugs in TestProvider, add unit tests Use pointer-to-vector in TestProvider so writes can be tested, too. * Add test EncodeDecode16, fix some encode16 bugs The function mbedtls_mpi_write_string needs a bit longer buffer than the resulting string actually will be. Known bug: mbedtls_mpi_read_binary ingores initial null bytes * Add test EncodeDecode64, fix some bugs The functions mbedtls_base64_encode and mbedtls_base64_decode needs a bit longer buffer than the resulting string actually will be. * Remove check for empty data from TestProvider It can be valid to get the hash of empty string. * Add tests for CRC calculation Two type of thests: - compare the result of the CRC calculation to a known to be good results, - generate random data as message, calculate of it's CRC and append that to the message, the CRC of this new data should be 0. * Add test for hash algorithms * Add includes in tests * Remove the use of C++20 ranges It seems that Apple Clang does not support range-based constrained algorithms at this time. * Replace encode16 implementation To encode the zero bytes at the begining of the input vector, too.
2021-11-26 22:14:44 +01:00
std::fill(std::begin(buff), std::end(buff), 22);
provider2->read(6, buff, 2);
TEST_ASSERT(buff[0] == 0x00);
TEST_ASSERT(buff[1] == 0xff);
TEST_ASSERT(buff[2] == 22); // should be unchanged
Tests for the CRC and hash algorithms (#335) * Update TEST_ASSERT to do nothing if condition is true The TEST_ASSERT should not return if the condition is true, because: - it prevents the usage of multiple TEST_ASSERT in a single test case, - that behavior differs from how the assert in the standard library works, and thus may give unexpected results. Make the TEST_ASSERT to print an error message (with an formatted optional user part) when it fails to make debugging easier. * Fix some bugs in TestProvider, add unit tests Use pointer-to-vector in TestProvider so writes can be tested, too. * Add test EncodeDecode16, fix some encode16 bugs The function mbedtls_mpi_write_string needs a bit longer buffer than the resulting string actually will be. Known bug: mbedtls_mpi_read_binary ingores initial null bytes * Add test EncodeDecode64, fix some bugs The functions mbedtls_base64_encode and mbedtls_base64_decode needs a bit longer buffer than the resulting string actually will be. * Remove check for empty data from TestProvider It can be valid to get the hash of empty string. * Add tests for CRC calculation Two type of thests: - compare the result of the CRC calculation to a known to be good results, - generate random data as message, calculate of it's CRC and append that to the message, the CRC of this new data should be 0. * Add test for hash algorithms * Add includes in tests * Remove the use of C++20 ranges It seems that Apple Clang does not support range-based constrained algorithms at this time. * Replace encode16 implementation To encode the zero bytes at the begining of the input vector, too.
2021-11-26 22:14:44 +01:00
std::fill(std::begin(buff), std::end(buff), 22);
provider2->read(7, buff, 2);
TEST_ASSERT(std::count(std::begin(buff), std::end(buff), 22) == std::size(buff)); // buff should be unchanged
Tests for the CRC and hash algorithms (#335) * Update TEST_ASSERT to do nothing if condition is true The TEST_ASSERT should not return if the condition is true, because: - it prevents the usage of multiple TEST_ASSERT in a single test case, - that behavior differs from how the assert in the standard library works, and thus may give unexpected results. Make the TEST_ASSERT to print an error message (with an formatted optional user part) when it fails to make debugging easier. * Fix some bugs in TestProvider, add unit tests Use pointer-to-vector in TestProvider so writes can be tested, too. * Add test EncodeDecode16, fix some encode16 bugs The function mbedtls_mpi_write_string needs a bit longer buffer than the resulting string actually will be. Known bug: mbedtls_mpi_read_binary ingores initial null bytes * Add test EncodeDecode64, fix some bugs The functions mbedtls_base64_encode and mbedtls_base64_decode needs a bit longer buffer than the resulting string actually will be. * Remove check for empty data from TestProvider It can be valid to get the hash of empty string. * Add tests for CRC calculation Two type of thests: - compare the result of the CRC calculation to a known to be good results, - generate random data as message, calculate of it's CRC and append that to the message, the CRC of this new data should be 0. * Add test for hash algorithms * Add includes in tests * Remove the use of C++20 ranges It seems that Apple Clang does not support range-based constrained algorithms at this time. * Replace encode16 implementation To encode the zero bytes at the begining of the input vector, too.
2021-11-26 22:14:44 +01:00
TEST_SUCCESS();
};
TEST_SEQUENCE("TestProvider_write") {
std::vector<u8> buff(8);
hex::test::TestProvider provider(&buff);
hex::prv::Provider *provider2 = &provider;
Tests for the CRC and hash algorithms (#335) * Update TEST_ASSERT to do nothing if condition is true The TEST_ASSERT should not return if the condition is true, because: - it prevents the usage of multiple TEST_ASSERT in a single test case, - that behavior differs from how the assert in the standard library works, and thus may give unexpected results. Make the TEST_ASSERT to print an error message (with an formatted optional user part) when it fails to make debugging easier. * Fix some bugs in TestProvider, add unit tests Use pointer-to-vector in TestProvider so writes can be tested, too. * Add test EncodeDecode16, fix some encode16 bugs The function mbedtls_mpi_write_string needs a bit longer buffer than the resulting string actually will be. Known bug: mbedtls_mpi_read_binary ingores initial null bytes * Add test EncodeDecode64, fix some bugs The functions mbedtls_base64_encode and mbedtls_base64_decode needs a bit longer buffer than the resulting string actually will be. * Remove check for empty data from TestProvider It can be valid to get the hash of empty string. * Add tests for CRC calculation Two type of thests: - compare the result of the CRC calculation to a known to be good results, - generate random data as message, calculate of it's CRC and append that to the message, the CRC of this new data should be 0. * Add test for hash algorithms * Add includes in tests * Remove the use of C++20 ranges It seems that Apple Clang does not support range-based constrained algorithms at this time. * Replace encode16 implementation To encode the zero bytes at the begining of the input vector, too.
2021-11-26 22:14:44 +01:00
u8 data[1024] = { 0xde, 0xad, 0xbe, 0xef, 0x42, 0x2a, 0x00, 0xff };
Tests for the CRC and hash algorithms (#335) * Update TEST_ASSERT to do nothing if condition is true The TEST_ASSERT should not return if the condition is true, because: - it prevents the usage of multiple TEST_ASSERT in a single test case, - that behavior differs from how the assert in the standard library works, and thus may give unexpected results. Make the TEST_ASSERT to print an error message (with an formatted optional user part) when it fails to make debugging easier. * Fix some bugs in TestProvider, add unit tests Use pointer-to-vector in TestProvider so writes can be tested, too. * Add test EncodeDecode16, fix some encode16 bugs The function mbedtls_mpi_write_string needs a bit longer buffer than the resulting string actually will be. Known bug: mbedtls_mpi_read_binary ingores initial null bytes * Add test EncodeDecode64, fix some bugs The functions mbedtls_base64_encode and mbedtls_base64_decode needs a bit longer buffer than the resulting string actually will be. * Remove check for empty data from TestProvider It can be valid to get the hash of empty string. * Add tests for CRC calculation Two type of thests: - compare the result of the CRC calculation to a known to be good results, - generate random data as message, calculate of it's CRC and append that to the message, the CRC of this new data should be 0. * Add test for hash algorithms * Add includes in tests * Remove the use of C++20 ranges It seems that Apple Clang does not support range-based constrained algorithms at this time. * Replace encode16 implementation To encode the zero bytes at the begining of the input vector, too.
2021-11-26 22:14:44 +01:00
std::fill(std::begin(buff), std::end(buff), 22);
provider2->writeRaw(1, data, 4);
TEST_ASSERT(buff[0] == 22); // should be unchanged
Tests for the CRC and hash algorithms (#335) * Update TEST_ASSERT to do nothing if condition is true The TEST_ASSERT should not return if the condition is true, because: - it prevents the usage of multiple TEST_ASSERT in a single test case, - that behavior differs from how the assert in the standard library works, and thus may give unexpected results. Make the TEST_ASSERT to print an error message (with an formatted optional user part) when it fails to make debugging easier. * Fix some bugs in TestProvider, add unit tests Use pointer-to-vector in TestProvider so writes can be tested, too. * Add test EncodeDecode16, fix some encode16 bugs The function mbedtls_mpi_write_string needs a bit longer buffer than the resulting string actually will be. Known bug: mbedtls_mpi_read_binary ingores initial null bytes * Add test EncodeDecode64, fix some bugs The functions mbedtls_base64_encode and mbedtls_base64_decode needs a bit longer buffer than the resulting string actually will be. * Remove check for empty data from TestProvider It can be valid to get the hash of empty string. * Add tests for CRC calculation Two type of thests: - compare the result of the CRC calculation to a known to be good results, - generate random data as message, calculate of it's CRC and append that to the message, the CRC of this new data should be 0. * Add test for hash algorithms * Add includes in tests * Remove the use of C++20 ranges It seems that Apple Clang does not support range-based constrained algorithms at this time. * Replace encode16 implementation To encode the zero bytes at the begining of the input vector, too.
2021-11-26 22:14:44 +01:00
TEST_ASSERT(buff[1] == 0xde);
TEST_ASSERT(buff[2] == 0xad);
TEST_ASSERT(buff[3] == 0xbe);
TEST_ASSERT(buff[4] == 0xef);
TEST_ASSERT(buff[5] == 22); // should be unchanged
Tests for the CRC and hash algorithms (#335) * Update TEST_ASSERT to do nothing if condition is true The TEST_ASSERT should not return if the condition is true, because: - it prevents the usage of multiple TEST_ASSERT in a single test case, - that behavior differs from how the assert in the standard library works, and thus may give unexpected results. Make the TEST_ASSERT to print an error message (with an formatted optional user part) when it fails to make debugging easier. * Fix some bugs in TestProvider, add unit tests Use pointer-to-vector in TestProvider so writes can be tested, too. * Add test EncodeDecode16, fix some encode16 bugs The function mbedtls_mpi_write_string needs a bit longer buffer than the resulting string actually will be. Known bug: mbedtls_mpi_read_binary ingores initial null bytes * Add test EncodeDecode64, fix some bugs The functions mbedtls_base64_encode and mbedtls_base64_decode needs a bit longer buffer than the resulting string actually will be. * Remove check for empty data from TestProvider It can be valid to get the hash of empty string. * Add tests for CRC calculation Two type of thests: - compare the result of the CRC calculation to a known to be good results, - generate random data as message, calculate of it's CRC and append that to the message, the CRC of this new data should be 0. * Add test for hash algorithms * Add includes in tests * Remove the use of C++20 ranges It seems that Apple Clang does not support range-based constrained algorithms at this time. * Replace encode16 implementation To encode the zero bytes at the begining of the input vector, too.
2021-11-26 22:14:44 +01:00
std::fill(std::begin(buff), std::end(buff), 22);
provider2->writeRaw(0, data + 6, 2);
Tests for the CRC and hash algorithms (#335) * Update TEST_ASSERT to do nothing if condition is true The TEST_ASSERT should not return if the condition is true, because: - it prevents the usage of multiple TEST_ASSERT in a single test case, - that behavior differs from how the assert in the standard library works, and thus may give unexpected results. Make the TEST_ASSERT to print an error message (with an formatted optional user part) when it fails to make debugging easier. * Fix some bugs in TestProvider, add unit tests Use pointer-to-vector in TestProvider so writes can be tested, too. * Add test EncodeDecode16, fix some encode16 bugs The function mbedtls_mpi_write_string needs a bit longer buffer than the resulting string actually will be. Known bug: mbedtls_mpi_read_binary ingores initial null bytes * Add test EncodeDecode64, fix some bugs The functions mbedtls_base64_encode and mbedtls_base64_decode needs a bit longer buffer than the resulting string actually will be. * Remove check for empty data from TestProvider It can be valid to get the hash of empty string. * Add tests for CRC calculation Two type of thests: - compare the result of the CRC calculation to a known to be good results, - generate random data as message, calculate of it's CRC and append that to the message, the CRC of this new data should be 0. * Add test for hash algorithms * Add includes in tests * Remove the use of C++20 ranges It seems that Apple Clang does not support range-based constrained algorithms at this time. * Replace encode16 implementation To encode the zero bytes at the begining of the input vector, too.
2021-11-26 22:14:44 +01:00
TEST_ASSERT(buff[0] == 0x00);
TEST_ASSERT(buff[1] == 0xff);
TEST_ASSERT(buff[2] == 22); // should be unchanged
Tests for the CRC and hash algorithms (#335) * Update TEST_ASSERT to do nothing if condition is true The TEST_ASSERT should not return if the condition is true, because: - it prevents the usage of multiple TEST_ASSERT in a single test case, - that behavior differs from how the assert in the standard library works, and thus may give unexpected results. Make the TEST_ASSERT to print an error message (with an formatted optional user part) when it fails to make debugging easier. * Fix some bugs in TestProvider, add unit tests Use pointer-to-vector in TestProvider so writes can be tested, too. * Add test EncodeDecode16, fix some encode16 bugs The function mbedtls_mpi_write_string needs a bit longer buffer than the resulting string actually will be. Known bug: mbedtls_mpi_read_binary ingores initial null bytes * Add test EncodeDecode64, fix some bugs The functions mbedtls_base64_encode and mbedtls_base64_decode needs a bit longer buffer than the resulting string actually will be. * Remove check for empty data from TestProvider It can be valid to get the hash of empty string. * Add tests for CRC calculation Two type of thests: - compare the result of the CRC calculation to a known to be good results, - generate random data as message, calculate of it's CRC and append that to the message, the CRC of this new data should be 0. * Add test for hash algorithms * Add includes in tests * Remove the use of C++20 ranges It seems that Apple Clang does not support range-based constrained algorithms at this time. * Replace encode16 implementation To encode the zero bytes at the begining of the input vector, too.
2021-11-26 22:14:44 +01:00
std::fill(std::begin(buff), std::end(buff), 22);
provider2->writeRaw(6, data, 2);
TEST_ASSERT(buff[5] == 22); // should be unchanged
Tests for the CRC and hash algorithms (#335) * Update TEST_ASSERT to do nothing if condition is true The TEST_ASSERT should not return if the condition is true, because: - it prevents the usage of multiple TEST_ASSERT in a single test case, - that behavior differs from how the assert in the standard library works, and thus may give unexpected results. Make the TEST_ASSERT to print an error message (with an formatted optional user part) when it fails to make debugging easier. * Fix some bugs in TestProvider, add unit tests Use pointer-to-vector in TestProvider so writes can be tested, too. * Add test EncodeDecode16, fix some encode16 bugs The function mbedtls_mpi_write_string needs a bit longer buffer than the resulting string actually will be. Known bug: mbedtls_mpi_read_binary ingores initial null bytes * Add test EncodeDecode64, fix some bugs The functions mbedtls_base64_encode and mbedtls_base64_decode needs a bit longer buffer than the resulting string actually will be. * Remove check for empty data from TestProvider It can be valid to get the hash of empty string. * Add tests for CRC calculation Two type of thests: - compare the result of the CRC calculation to a known to be good results, - generate random data as message, calculate of it's CRC and append that to the message, the CRC of this new data should be 0. * Add test for hash algorithms * Add includes in tests * Remove the use of C++20 ranges It seems that Apple Clang does not support range-based constrained algorithms at this time. * Replace encode16 implementation To encode the zero bytes at the begining of the input vector, too.
2021-11-26 22:14:44 +01:00
TEST_ASSERT(buff[6] == 0xde);
TEST_ASSERT(buff[7] == 0xad);
std::fill(std::begin(buff), std::end(buff), 22);
provider2->writeRaw(7, data, 2);
TEST_ASSERT(std::count(std::begin(buff), std::end(buff), 22) == std::size(buff)); // buff should be unchanged
Tests for the CRC and hash algorithms (#335) * Update TEST_ASSERT to do nothing if condition is true The TEST_ASSERT should not return if the condition is true, because: - it prevents the usage of multiple TEST_ASSERT in a single test case, - that behavior differs from how the assert in the standard library works, and thus may give unexpected results. Make the TEST_ASSERT to print an error message (with an formatted optional user part) when it fails to make debugging easier. * Fix some bugs in TestProvider, add unit tests Use pointer-to-vector in TestProvider so writes can be tested, too. * Add test EncodeDecode16, fix some encode16 bugs The function mbedtls_mpi_write_string needs a bit longer buffer than the resulting string actually will be. Known bug: mbedtls_mpi_read_binary ingores initial null bytes * Add test EncodeDecode64, fix some bugs The functions mbedtls_base64_encode and mbedtls_base64_decode needs a bit longer buffer than the resulting string actually will be. * Remove check for empty data from TestProvider It can be valid to get the hash of empty string. * Add tests for CRC calculation Two type of thests: - compare the result of the CRC calculation to a known to be good results, - generate random data as message, calculate of it's CRC and append that to the message, the CRC of this new data should be 0. * Add test for hash algorithms * Add includes in tests * Remove the use of C++20 ranges It seems that Apple Clang does not support range-based constrained algorithms at this time. * Replace encode16 implementation To encode the zero bytes at the begining of the input vector, too.
2021-11-26 22:14:44 +01:00
TEST_SUCCESS();
};