1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
|
// Licensed under the MIT License.
// Copyright David LeBlanc - dcl@dleblanc.net
#if defined _MSC_VER
// Inline expansion warnings
#pragma warning(disable:4710 4711)
#endif
#include "safe_math_test.h"
#include "../TestCase.h"
extern "C" void mult_test();
static void mult_test_uint64_uint64()
{
typedef bool (*test_fcn)(std::uint64_t, std::uint64_t, std::uint64_t*);
typedef std::uint64_t(*check_fcn)(std::uint64_t, std::uint64_t);
test_base<std::uint64_t, std::uint64_t, test_fcn, check_fcn, OpType::Mult>("uint64_uint64", &check_mul_uint64_uint64, &safe_mul_uint64_uint64);
}
static void mult_test_uint64_uint32()
{
typedef bool (*test_fcn)(std::uint64_t, std::uint32_t, std::uint64_t*);
typedef std::uint64_t(*check_fcn)(std::uint64_t, std::uint32_t);
test_base<std::uint64_t, std::uint32_t, test_fcn, check_fcn, OpType::Mult>("uint64_uint32", &check_mul_uint64_uint32, &safe_mul_uint64_uint32);
}
static void mult_test_uint64_int64()
{
typedef bool (*test_fcn)(std::uint64_t, std::int64_t, std::uint64_t*);
typedef std::uint64_t(*check_fcn)(std::uint64_t, std::int64_t);
test_base<std::uint64_t, std::int64_t, test_fcn, check_fcn, OpType::Mult>("uint64_int64", &check_mul_uint64_int64, &safe_mul_uint64_int64);
}
static void mult_test_uint64_int32()
{
typedef bool (*test_fcn)(std::uint64_t, std::int32_t, std::uint64_t*);
typedef std::uint64_t(*check_fcn)(std::uint64_t, std::int32_t);
test_base<std::uint64_t, std::int32_t, test_fcn, check_fcn, OpType::Mult>("uint64_int32", &check_mul_uint64_int32, &safe_mul_uint64_int32);
}
static void mult_test_int64_uint64()
{
typedef bool (*test_fcn)(std::int64_t, std::uint64_t, std::int64_t*);
typedef std::int64_t(*check_fcn)(std::int64_t, std::uint64_t);
test_base<std::int64_t, std::uint64_t, test_fcn, check_fcn, OpType::Mult>("int64_uint64", &check_mul_int64_uint64, &safe_mul_int64_uint64);
}
static void mult_test_int64_uint32()
{
typedef bool (*test_fcn)(std::int64_t, std::uint32_t, std::int64_t*);
typedef std::int64_t(*check_fcn)(std::int64_t, std::uint32_t);
test_base<std::int64_t, std::uint32_t, test_fcn, check_fcn, OpType::Mult>("int64_uint32", &check_mul_int64_uint32, &safe_mul_int64_uint32);
}
static void mult_test_int64_int64()
{
typedef bool (*test_fcn)(std::int64_t, std::int64_t, std::int64_t*);
typedef std::int64_t(*check_fcn)(std::int64_t, std::int64_t);
test_base<std::int64_t, std::int64_t, test_fcn, check_fcn, OpType::Mult>("int64_int64", &check_mul_int64_int64, &safe_mul_int64_int64);
}
static void mult_test_int64_int32()
{
typedef bool (*test_fcn)(std::int64_t, std::int32_t, std::int64_t*);
typedef std::int64_t(*check_fcn)(std::int64_t, std::int32_t);
test_base<std::int64_t, std::int32_t, test_fcn, check_fcn, OpType::Mult>("int64_int32", &check_mul_int64_int32, &safe_mul_int64_int32);
}
static void mult_test_uint32_uint64()
{
typedef bool (*test_fcn)(std::uint32_t, std::uint64_t, std::uint32_t*);
typedef std::uint32_t(*check_fcn)(std::uint32_t, std::uint64_t);
test_base<std::uint32_t, std::uint64_t, test_fcn, check_fcn, OpType::Mult>("uint32_uint64", &check_mul_uint32_uint64, &safe_mul_uint32_uint64);
}
static void mult_test_uint32_uint32()
{
typedef bool (*test_fcn)(std::uint32_t, std::uint32_t, std::uint32_t*);
typedef std::uint32_t(*check_fcn)(std::uint32_t, std::uint32_t);
test_base<std::uint32_t, std::uint32_t, test_fcn, check_fcn, OpType::Mult>("uint32_uint32", &check_mul_uint32_uint32, &safe_mul_uint32_uint32);
}
static void mult_test_uint32_int64()
{
typedef bool (*test_fcn)(std::uint32_t, std::int64_t, std::uint32_t*);
typedef std::uint32_t(*check_fcn)(std::uint32_t, std::int64_t);
test_base<std::uint32_t, std::int64_t, test_fcn, check_fcn, OpType::Mult>("uint32_int64", &check_mul_uint32_int64, &safe_mul_uint32_int64);
}
static void mult_test_uint32_int32()
{
typedef bool (*test_fcn)(std::uint32_t, std::int32_t, std::uint32_t*);
typedef std::uint32_t(*check_fcn)(std::uint32_t, std::int32_t);
test_base<std::uint32_t, std::int32_t, test_fcn, check_fcn, OpType::Mult>("uint32_int32", &check_mul_uint32_int32, &safe_mul_uint32_int32);
}
static void mult_test_int32_uint64()
{
typedef bool (*test_fcn)(std::int32_t, std::uint64_t, std::int32_t*);
typedef std::int32_t(*check_fcn)(std::int32_t, std::uint64_t);
test_base<std::int32_t, std::uint64_t, test_fcn, check_fcn, OpType::Mult>("int32_uint64", &check_mul_int32_uint64, &safe_mul_int32_uint64);
}
static void mult_test_int32_uint32()
{
typedef bool (*test_fcn)(std::int32_t, std::uint32_t, std::int32_t*);
typedef std::int32_t(*check_fcn)(std::int32_t, std::uint32_t);
test_base<std::int32_t, std::uint32_t, test_fcn, check_fcn, OpType::Mult>("int32_uint32", &check_mul_int32_uint32, &safe_mul_int32_uint32);
}
static void mult_test_int32_int64()
{
typedef bool (*test_fcn)(std::int32_t, std::int64_t, std::int32_t*);
typedef std::int32_t(*check_fcn)(std::int32_t, std::int64_t);
test_base<std::int32_t, std::int64_t, test_fcn, check_fcn, OpType::Mult>("int32_int64", &check_mul_int32_int64, &safe_mul_int32_int64);
}
static void mult_test_int32_int32()
{
typedef bool (*test_fcn)(std::int32_t, std::int32_t, std::int32_t*);
typedef std::int32_t(*check_fcn)(std::int32_t, std::int32_t);
test_base<std::int32_t, std::int32_t, test_fcn, check_fcn, OpType::Mult>("int32_int32", &check_mul_int32_int32, &safe_mul_int32_int32);
}
extern "C" void mult_test()
{
try
{
mult_test_uint64_uint64();
mult_test_uint64_uint32();
mult_test_uint64_int64();
mult_test_uint64_int32();
mult_test_int64_uint64();
mult_test_int64_uint32();
mult_test_int64_int64();
mult_test_int64_int32();
mult_test_uint32_uint64();
mult_test_uint32_uint32();
mult_test_uint32_int64();
mult_test_uint32_int32();
mult_test_int32_uint64();
mult_test_int32_uint32();
mult_test_int32_int64();
mult_test_int32_int32();
std::cout << "Multiplication tests completed" << std::endl;
}
catch (std::exception& err)
{
std::cout << "Multiplication tests failed - " << err.what() << std::endl;
}
return;
}
|