[PATCH 3/3] ucrtbase/tests: Add tests for errno with math functions.
Alex Henrie
alexhenrie24 at gmail.com
Wed Jul 19 10:25:14 CDT 2017
Signed-off-by: Alex Henrie <alexhenrie24 at gmail.com>
---
dlls/ucrtbase/tests/misc.c | 225 ++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 224 insertions(+), 1 deletion(-)
diff --git a/dlls/ucrtbase/tests/misc.c b/dlls/ucrtbase/tests/misc.c
index 213700f114..677459431a 100644
--- a/dlls/ucrtbase/tests/misc.c
+++ b/dlls/ucrtbase/tests/misc.c
@@ -55,6 +55,31 @@
expect_ ## func = called_ ## func = FALSE; \
}while(0)
+static inline float __port_infinity(void)
+{
+ static const unsigned __inf_bytes = 0x7f800000;
+ return *(const float *)&__inf_bytes;
+}
+#define INFINITY __port_infinity()
+
+static inline float __port_nan(void)
+{
+ static const unsigned __nan_bytes = 0x7fc00000;
+ return *(const float *)&__nan_bytes;
+}
+#define NAN __port_nan()
+
+static inline float __port_ind(void)
+{
+ static const unsigned __ind_bytes = 0xffc00000;
+ return *(const float *)&__ind_bytes;
+}
+#define IND __port_ind()
+
+#define M_PI_2 1.57079632679489661923
+
+#define FE_TONEAREST 0
+
DEFINE_EXPECT(global_invalid_parameter_handler);
DEFINE_EXPECT(thread_invalid_parameter_handler);
@@ -72,6 +97,8 @@ typedef struct MSVCRT__lldiv_t {
LONGLONG rem; /* remainder */
} MSVCRT_lldiv_t;
+static HMODULE module;
+
static int (CDECL *p_initialize_onexit_table)(MSVCRT__onexit_table_t *table);
static int (CDECL *p_register_onexit_function)(MSVCRT__onexit_table_t *table, MSVCRT__onexit_t func);
static int (CDECL *p_execute_onexit_table)(MSVCRT__onexit_table_t *table);
@@ -92,6 +119,8 @@ static int (CDECL *p__isblank_l)(int,_locale_t);
static int (CDECL *p__iswctype_l)(int,int,_locale_t);
static int (CDECL *p_iswblank)(int);
static int (CDECL *p__iswblank_l)(wint_t,_locale_t);
+static int (CDECL *p_fesetround)(int);
+static int* (CDECL *p_errno)(void);
static void test__initialize_onexit_table(void)
{
@@ -365,7 +394,7 @@ static void test__get_narrow_winmain_command_line(char *path)
static BOOL init(void)
{
- HMODULE module = LoadLibraryA("ucrtbase.dll");
+ module = LoadLibraryA("ucrtbase.dll");
if(!module) {
win_skip("ucrtbase.dll not available\n");
@@ -392,6 +421,8 @@ static BOOL init(void)
p__iswctype_l = (void*)GetProcAddress(module, "_iswctype_l");
p_iswblank = (void*)GetProcAddress(module, "iswblank");
p__iswblank_l = (void*)GetProcAddress(module, "_iswblank_l");
+ p_fesetround = (void*)GetProcAddress(module, "fesetround");
+ p_errno = (void*)GetProcAddress(module, "_errno");
return TRUE;
}
@@ -509,6 +540,197 @@ static void test_isblank(void)
}
}
+static void test_math_errno(void)
+{
+ const struct {
+ char func[8];
+ double x;
+ int err;
+ } testsd[] = {
+ {"acos", NAN, -1},
+ {"acos", IND, -1},
+ {"acos", -INFINITY, EDOM},
+ {"acos", -2, EDOM},
+ {"acos", -1, -1},
+ {"acos", 1, -1},
+ {"acos", 2, EDOM},
+ {"acos", INFINITY, EDOM},
+ {"acosh", NAN, -1},
+ {"acosh", IND, -1},
+ {"acosh", -INFINITY, EDOM},
+ {"acosh", 0, EDOM},
+ {"acosh", 1, -1},
+ {"acosh", INFINITY, -1},
+ {"asin", NAN, -1},
+ {"asin", IND, -1},
+ {"asin", -INFINITY, EDOM},
+ {"asin", -2, EDOM},
+ {"asin", -1, -1},
+ {"asin", 1, -1},
+ {"asin", 2, EDOM},
+ {"asin", INFINITY, EDOM},
+ {"asinh", NAN, -1},
+ {"asinh", IND, -1},
+ {"asinh", -INFINITY, -1},
+ {"asinh", INFINITY, -1},
+ {"atan", NAN, -1},
+ {"atan", IND, -1},
+ {"atan", -INFINITY, -1},
+ {"atan", 0, -1},
+ {"atan", INFINITY, -1},
+ {"atanh", NAN, -1},
+ {"atanh", IND, -1},
+ {"atanh", -INFINITY, EDOM},
+ {"atanh", -2, EDOM},
+ {"atanh", -1, ERANGE},
+ {"atanh", 1, ERANGE},
+ {"atanh", 2, EDOM},
+ {"atanh", INFINITY, EDOM},
+ {"cos", NAN, -1},
+ {"cos", IND, -1},
+ {"cos", -INFINITY, EDOM},
+ {"cos", INFINITY, EDOM},
+ {"cosh", NAN, -1},
+ {"cosh", IND, -1},
+ {"cosh", 0, -1},
+ {"cosh", -INFINITY, -1},
+ {"cosh", INFINITY, -1},
+ {"exp", NAN, -1},
+ {"exp", IND, -1},
+ {"exp", -INFINITY, -1},
+ {"exp", -1e100, -1},
+ {"exp", 1e100, ERANGE},
+ {"exp", INFINITY, -1},
+ {"exp2", NAN, -1},
+ {"exp2", IND, -1},
+ {"exp2", -INFINITY, -1},
+ {"exp2", -1e100, -1},
+ {"exp2", 1e100, ERANGE},
+ {"exp2", INFINITY, -1},
+ {"expm1", NAN, -1},
+ {"expm1", IND, -1},
+ {"expm1", -INFINITY, -1},
+ {"expm1", -1e100, -1},
+ {"expm1", 1e100, ERANGE},
+ {"expm1", INFINITY, -1},
+ {"log", NAN, -1},
+ {"log", IND, -1},
+ {"log", -INFINITY, EDOM},
+ {"log", -1, EDOM},
+ {"log", 0, ERANGE},
+ {"log", INFINITY, -1},
+ {"log10", NAN, -1},
+ {"log10", IND, -1},
+ {"log10", -INFINITY, EDOM},
+ {"log10", -1, EDOM},
+ {"log10", 0, ERANGE},
+ {"log10", INFINITY, -1},
+ {"log1p", NAN, -1},
+ {"log1p", IND, -1},
+ {"log1p", -INFINITY, EDOM},
+ {"log1p", -2, EDOM},
+ {"log1p", -1, ERANGE},
+ {"log1p", INFINITY, -1},
+ {"log2", NAN, -1},
+ {"log2", IND, -1},
+ {"log2", -INFINITY, EDOM},
+ {"log2", -1, EDOM},
+ {"log2", 0, ERANGE},
+ {"log2", INFINITY, -1},
+ {"sin", NAN, -1},
+ {"sin", IND, -1},
+ {"sin", -INFINITY, EDOM},
+ {"sin", INFINITY, EDOM},
+ {"sinh", NAN, -1},
+ {"sinh", IND, -1},
+ {"sinh", 0, -1},
+ {"sinh", -INFINITY, -1},
+ {"sinh", INFINITY, -1},
+ {"tan", NAN, -1},
+ {"tan", IND, -1},
+ {"tan", -INFINITY, EDOM},
+ {"tan", -M_PI_2, -1},
+ {"tan", M_PI_2, -1},
+ {"tan", INFINITY, EDOM},
+ {"tanh", NAN, -1},
+ {"tanh", IND, -1},
+ {"tanh", -INFINITY, -1},
+ {"tanh", 0, -1},
+ {"tanh", INFINITY, -1},
+ };
+ const struct {
+ char func[8];
+ double a;
+ double b;
+ int err;
+ } tests2d[] = {
+ {"atan2", NAN, 0, -1},
+ {"atan2", IND, 0, -1},
+ {"atan2", -INFINITY, 0, -1},
+ {"atan2", 0, 0, -1},
+ {"atan2", INFINITY, 0, -1},
+ {"atan2", 0, NAN, -1},
+ {"atan2", 0, IND, -1},
+ {"atan2", 0, -INFINITY, -1},
+ {"atan2", 0, 0, -1},
+ {"atan2", 0, INFINITY, -1},
+ };
+ const struct {
+ char func[8];
+ double a;
+ long b;
+ int err;
+ } testsdl[] = {
+ {"_scalb", NAN, 1, -1},
+ {"_scalb", IND, 1, -1},
+ {"_scalb", -INFINITY, 1, -1},
+ {"_scalb", -1e100, 1, -1},
+ {"_scalb", 1e100, 1, -1},
+ {"_scalb", INFINITY, 1, -1},
+ {"_scalb", 1, -1e9, -1},
+ {"_scalb", 1, 1e9, ERANGE},
+ {"ldexp", NAN, 1, -1},
+ {"ldexp", IND, 1, -1},
+ {"ldexp", -INFINITY, 1, -1},
+ {"ldexp", -1e100, 1, -1},
+ {"ldexp", 1e100, 1, -1},
+ {"ldexp", INFINITY, 1, -1},
+ {"ldexp", 1, -1e9, -1},
+ {"ldexp", 1, 1e9, ERANGE},
+ };
+ double (CDECL *p_funcd)(double);
+ double (CDECL *p_func2d)(double, double);
+ double (CDECL *p_funcdl)(double, long);
+ int i;
+
+ /* necessary so that exp(1e100)==INFINITY on glibc, we can remove this if we change our implementation */
+ p_fesetround(FE_TONEAREST);
+
+ for(i = 0; i < sizeof(testsd)/sizeof(testsd[0]); i++) {
+ p_funcd = (void*)GetProcAddress(module, testsd[i].func);
+ *p_errno() = -1;
+ p_funcd(testsd[i].x);
+ ok(*p_errno() == testsd[i].err,
+ "%s(%f) got errno %d\n", testsd[i].func, testsd[i].x, *p_errno());
+ }
+
+ for(i = 0; i < sizeof(tests2d)/sizeof(tests2d[0]); i++) {
+ p_func2d = (void*)GetProcAddress(module, tests2d[i].func);
+ *p_errno() = -1;
+ p_func2d(tests2d[i].a, tests2d[i].b);
+ ok(*p_errno() == tests2d[i].err,
+ "%s(%f, %f) got errno %d\n", tests2d[i].func, tests2d[i].a, tests2d[i].b, *p_errno());
+ }
+
+ for(i = 0; i < sizeof(testsdl)/sizeof(testsdl[0]); i++) {
+ p_funcdl = (void*)GetProcAddress(module, testsdl[i].func);
+ *p_errno() = -1;
+ p_funcdl(testsdl[i].a, testsdl[i].b);
+ ok(*p_errno() == testsdl[i].err,
+ "%s(%f, %li) got errno %d\n", testsdl[i].func, testsdl[i].a, testsdl[i].b, *p_errno());
+ }
+}
+
START_TEST(misc)
{
int arg_c;
@@ -533,4 +755,5 @@ START_TEST(misc)
test__sopen_s();
test_lldiv();
test_isblank();
+ test_math_errno();
}
--
2.13.3
More information about the wine-patches
mailing list