Piotr Caban : msvcp90: Added basic complex numbers tests.
Alexandre Julliard
julliard at winehq.org
Wed Jan 16 13:47:44 CST 2013
Module: wine
Branch: master
Commit: 383bbb87f6eb525ace688c0a8107755f56d94172
URL: http://source.winehq.org/git/wine.git/?a=commit;h=383bbb87f6eb525ace688c0a8107755f56d94172
Author: Piotr Caban <piotr at codeweavers.com>
Date: Wed Jan 16 14:27:37 2013 +0100
msvcp90: Added basic complex numbers tests.
---
dlls/msvcp90/tests/misc.c | 96 ++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 95 insertions(+), 1 deletions(-)
diff --git a/dlls/msvcp90/tests/misc.c b/dlls/msvcp90/tests/misc.c
index 2cb7380..d0a41c5 100644
--- a/dlls/msvcp90/tests/misc.c
+++ b/dlls/msvcp90/tests/misc.c
@@ -19,6 +19,7 @@
#include <stdio.h>
#include <locale.h>
#include <wctype.h>
+#include <float.h>
#include <windef.h>
#include <winbase.h>
@@ -49,6 +50,12 @@ typedef struct
size_t res;
} basic_string_char;
+/* class complex<float> */
+typedef struct {
+ float real;
+ float imag;
+} complex_float;
+
static void* (__cdecl *p_set_invalid_parameter_handler)(void*);
static _locale_t (__cdecl *p__get_current_locale)(void);
static void (__cdecl *p__free_locale)(_locale_t);
@@ -101,6 +108,10 @@ static void (__thiscall *p_basic_ostringstream_char_dtor)(/*basic_ostringstream_
static void (__thiscall *p_basic_ostringstream_char_vbase_dtor)(/*basic_ostringstream_char*/void*);
static void (__thiscall *p_basic_ios_char_dtor)(/*basic_ios_char*/void*);
+static complex_float* (__thiscall *p_complex_float_ctor)(complex_float*, const float*, const float*);
+static complex_float* (__cdecl *p_complex_float_add)(complex_float*, const complex_float*, const complex_float*);
+static complex_float* (__cdecl *p_complex_float_div)(complex_float*, const complex_float*, const complex_float*);
+
static int invalid_parameter = 0;
static void __cdecl test_invalid_parameter_handler(const wchar_t *expression,
const wchar_t *function, const wchar_t *file,
@@ -231,6 +242,13 @@ static BOOL init(void)
"??_D?$basic_ostringstream at DU?$char_traits at D@std@@V?$allocator at D@2@@std@@QEAAXXZ");
SET(p_basic_ios_char_dtor,
"??1?$basic_ios at DU?$char_traits at D@std@@@std@@UEAA at XZ");
+
+ SET(p_complex_float_ctor,
+ "??0?$complex at M@std@@QEAA at AEBM0@Z");
+ SET(p_complex_float_add,
+ "??$?HM at std@@YA?AV?$complex at M@0 at AEBV10@0 at Z");
+ SET(p_complex_float_div,
+ "??$?KM at std@@YA?AV?$complex at M@0 at AEBV10@0 at Z");
} else {
SET(p_char_assign, "?assign@?$char_traits at D@std@@SAXAADABD at Z");
SET(p_wchar_assign, "?assign@?$char_traits at _W@std@@SAXAA_WAB_W at Z");
@@ -268,6 +286,13 @@ static BOOL init(void)
"??_D?$basic_ostringstream at DU?$char_traits at D@std@@V?$allocator at D@2@@std@@QAEXXZ");
SET(p_basic_ios_char_dtor,
"??1?$basic_ios at DU?$char_traits at D@std@@@std@@UAE at XZ");
+
+ SET(p_complex_float_ctor,
+ "??0?$complex at M@std@@QAE at ABM0@Z");
+ SET(p_complex_float_add,
+ "??$?HM at std@@YA?AV?$complex at M@0 at ABV10@0 at Z");
+ SET(p_complex_float_div,
+ "??$?KM at std@@YA?AV?$complex at M@0 at ABV10@0 at Z");
}
init_thiscall_thunk();
@@ -550,6 +575,75 @@ static void test_virtual_base_dtors(void)
call_func1(p_basic_ios_char_dtor, this+((int**)this)[0][1]);
}
+static BOOL almost_eq(float f1, float f2)
+{
+ f1 = (f1-f2)/f1;
+ if(f1 < 0)
+ f1 = -f1;
+ return f1 < 0.0001;
+}
+
+static void test_complex(void)
+{
+ complex_float c1, c2, c3;
+ float f1, f2;
+
+ f1 = 1;
+ f2 = 2;
+ call_func3(p_complex_float_ctor, &c1, &f1, &f2);
+ ok(c1.real == 1, "c1.real = %f\n", c1.real);
+ ok(c1.imag == 2, "c1.imag = %f\n", c1.imag);
+
+ f1 = -1;
+ f2 = 1;
+ call_func3(p_complex_float_ctor, &c2, &f1, &f2);
+ ok(c2.real == -1, "c2.real = %f\n", c1.real);
+ ok(c2.imag == 1, "c2.imag = %f\n", c1.imag);
+
+ p_complex_float_add(&c3, &c1, &c2);
+ ok(c3.real == 0, "c3.real = %f\n", c3.real);
+ ok(c3.imag == 3, "c3.imag = %f\n", c3.imag);
+
+ p_complex_float_add(&c2, &c1, &c3);
+ ok(c2.real == 1, "c2.real = %f\n", c1.real);
+ ok(c2.imag == 5, "c2.imag = %f\n", c1.imag);
+
+ /* (1+5i) / (0+3i) */
+ p_complex_float_div(&c1, &c2, &c3);
+ ok(almost_eq(c1.real, 1.666667), "c1.real = %f\n", c1.real);
+ ok(almost_eq(c1.imag, -0.33333), "c1.imag = %f\n", c1.imag);
+
+ /* (1+5i) / (2+0i) */
+ c3.real = 2;
+ c3.imag = 0;
+ p_complex_float_div(&c1, &c2, &c3);
+ ok(almost_eq(c1.real, 0.5), "c1.real = %f\n", c1.real);
+ ok(almost_eq(c1.imag, 2.5), "c1.imag = %f\n", c1.imag);
+
+ /* (1+5i) / 0 */
+ c3.real = 0;
+ p_complex_float_div(&c1, &c2, &c3);
+ ok(_isnan(c1.real), "c1.real = %f\n", c1.real);
+ ok(_isnan(c1.imag), "c1.imag = %f\n", c1.imag);
+
+ /* (1+5i) / (NaN-2i) */
+ c1.imag = -2;
+ p_complex_float_div(&c3, &c2, &c1);
+ ok(_isnan(c3.real), "c3.real = %f\n", c3.real);
+ ok(_isnan(c3.imag), "c3.imag = %f\n", c3.imag);
+
+ /* (NaN-2i) / (1+0i) */
+ c2.imag = 0;
+ p_complex_float_div(&c3, &c1, &c2);
+ ok(_isnan(c3.real), "c3.real = %f\n", c3.real);
+ ok(_isnan(c3.imag), "c3.imag = %f\n", c3.imag);
+
+ /* (1+0i) + (NaN-2i) */
+ p_complex_float_add(&c3, &c2, &c1);
+ ok(_isnan(c3.real), "c3.real = %f\n", c3.real);
+ ok(c3.imag == -2, "c3.imag = %f\n", c3.imag);
+}
+
START_TEST(misc)
{
if(!init())
@@ -564,8 +658,8 @@ START_TEST(misc)
test_towctrans();
test_virtual_call();
test_virtual_base_dtors();
-
test_allocator_char();
+ test_complex();
ok(!invalid_parameter, "invalid_parameter_handler was invoked too many times\n");
}
More information about the wine-cvs
mailing list