shell32/tests: Create_test_association() should either succeed or fail due to insuffi...
[wine.git] / dlls / ucrtbase / tests / string.c
blobc251558607c58b27125317e3f48b0b01d8b53faa
1 /*
2 * Copyright 2015 Martin Storsjo
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <errno.h>
20 #include <stdarg.h>
21 #include <stdlib.h>
22 #include <wchar.h>
23 #include <stdio.h>
25 #include <windef.h>
26 #include <winbase.h>
27 #include "wine/test.h"
29 #include <math.h>
31 #ifndef INFINITY
32 static inline float __port_infinity(void)
34 static const unsigned __inf_bytes = 0x7f800000;
35 return *(const float *)&__inf_bytes;
37 #define INFINITY __port_infinity()
38 #endif
40 #ifndef NAN
41 static inline float __port_nan(void)
43 static const unsigned __nan_bytes = 0x7fc00000;
44 return *(const float *)&__nan_bytes;
46 #define NAN __port_nan()
47 #endif
49 static double (CDECL *p_strtod)(const char*, char** end);
51 static BOOL init(void)
53 HMODULE module;
55 module = LoadLibraryA("ucrtbase.dll");
56 if (!module)
58 win_skip("ucrtbase.dll not installed\n");
59 return FALSE;
62 p_strtod = (void*)GetProcAddress(module, "strtod");
63 return TRUE;
66 static BOOL local_isnan(double d)
68 return d != d;
71 #define test_strtod_str(string, value, length) _test_strtod_str(__LINE__, string, value, length)
72 static void _test_strtod_str(int line, const char* string, double value, int length)
74 char *end;
75 double d;
76 d = p_strtod(string, &end);
77 if (local_isnan(value))
78 ok_(__FILE__, line)(local_isnan(d), "d = %lf (\"%s\")\n", d, string);
79 else
80 ok_(__FILE__, line)(d == value, "d = %lf (\"%s\")\n", d, string);
81 ok_(__FILE__, line)(end == string + length, "incorrect end (%d, \"%s\")\n", (int)(end - string), string);
84 static void test_strtod(void)
86 test_strtod_str("infinity", INFINITY, 8);
87 test_strtod_str("INFINITY", INFINITY, 8);
88 test_strtod_str("InFiNiTy", INFINITY, 8);
89 test_strtod_str("INF", INFINITY, 3);
90 test_strtod_str("-inf", -INFINITY, 4);
91 test_strtod_str("inf42", INFINITY, 3);
92 test_strtod_str("inffoo", INFINITY, 3);
93 test_strtod_str("infini", INFINITY, 3);
95 test_strtod_str("NAN", NAN, 3);
96 test_strtod_str("nan", NAN, 3);
97 test_strtod_str("NaN", NAN, 3);
99 test_strtod_str("0x42", 66, 4);
100 test_strtod_str("0X42", 66, 4);
101 test_strtod_str("-0x42", -66, 5);
102 test_strtod_str("0x1p1", 2, 5);
103 test_strtod_str("0x1P1", 2, 5);
104 test_strtod_str("0x1p+1", 2, 6);
105 test_strtod_str("0x2p-1", 1, 6);
106 test_strtod_str("0xA", 10, 3);
107 test_strtod_str("0xa", 10, 3);
108 test_strtod_str("0xABCDEF", 11259375, 8);
109 test_strtod_str("0Xabcdef", 11259375, 8);
111 test_strtod_str("0x1.1", 1.0625, 5);
112 test_strtod_str("0x1.1p1", 2.125, 7);
113 test_strtod_str("0x1.A", 1.625, 5);
114 test_strtod_str("0x1p1a", 2, 5);
117 START_TEST(string)
119 if (!init()) return;
120 test_strtod();