aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests/test_bigint.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/test_bigint.cpp')
-rw-r--r--src/tests/test_bigint.cpp48
1 files changed, 47 insertions, 1 deletions
diff --git a/src/tests/test_bigint.cpp b/src/tests/test_bigint.cpp
index f6ae2a654..2bd7df2a7 100644
--- a/src/tests/test_bigint.cpp
+++ b/src/tests/test_bigint.cpp
@@ -17,7 +17,7 @@
#include <cstdlib>
#include <iterator>
-
+#include <sstream>
#include <botan/bigint.h>
#include <botan/exceptn.h>
#include <botan/numthry.h>
@@ -26,6 +26,50 @@ using namespace Botan;
namespace {
+void test_failure(const char* function, const char* file, int line,
+ const std::string& what_failed)
+ {
+ std::cout << "FAIL " << function << " " << file << ":" << line << " "
+ << what_failed << std::endl;
+ }
+
+#define BOTAN_TEST(lhs, rhs, msg) try { \
+ ++tests_run; \
+ const auto lhs_val = lhs; \
+ const auto rhs_val = rhs; \
+ const bool cmp = lhs_val == rhs_val; \
+ if(!cmp) \
+ { \
+ std::ostringstream fmt; \
+ fmt << "expr '" << #lhs << " == " << #rhs << "' false, " \
+ << "actually " << lhs_val << " " << rhs_val \
+ << " (" << msg << ")"; \
+ test_failure(BOTAN_CURRENT_FUNCTION, __FILE__, __LINE__, fmt.str()); \
+ ++tests_failed; \
+ } \
+ } \
+ catch(std::exception& e) \
+ { \
+ std::ostringstream fmt; \
+ fmt << "exception '" << e.what() << "' (" << msg << ")"; \
+ test_failure(BOTAN_CURRENT_FUNCTION, __FILE__, __LINE__, fmt.str()); \
+ ++tests_failed; \
+ }
+
+size_t test_bigint_to_u32bit()
+ {
+ size_t tests_run = 0, tests_failed = 0;
+
+ for(size_t i = 0; i != 32; ++i)
+ {
+ const u32bit in = 1 << i;
+ BOTAN_TEST(in, BigInt(in).to_u32bit(), "In range round trips");
+ }
+
+ test_report("BigInt to_u32bit", tests_run, tests_failed);
+ return tests_failed;
+ }
+
void strip_comments(std::string& line)
{
if(line.find('#') != std::string::npos)
@@ -303,6 +347,8 @@ size_t test_bigint()
bool first = true;
size_t counter = 0;
+ total_errors += test_bigint_to_u32bit();
+
auto& rng = test_rng();
while(!test_data.eof())