include: Add definitions of SERVICES_*_DATABASEW for generic compilers.
[wine.git] / dlls / msvcp110 / tests / msvcp110.c
blob36e929f11ff3a02074d0542b7c7b766bba8ca41d
1 /*
2 * Copyright 2015 YongHao Hu
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 <locale.h>
20 #include <stdio.h>
22 #include "wine/test.h"
23 #include "winbase.h"
25 typedef unsigned char MSVCP_bool;
27 #define SECSPERDAY 86400
28 /* 1601 to 1970 is 369 years plus 89 leap days */
29 #define SECS_1601_TO_1970 ((369 * 365 + 89) * (ULONGLONG)SECSPERDAY)
30 #define TICKSPERSEC 10000000
31 #define TICKS_1601_TO_1970 (SECS_1601_TO_1970 * TICKSPERSEC)
33 static int (__cdecl *p_tr2_sys__Make_dir)(char const*);
34 static MSVCP_bool (__cdecl *p_tr2_sys__Remove_dir)(char const*);
35 static __int64 (__cdecl *p_tr2_sys__Last_write_time)(char const*);
36 static void (__cdecl *p_tr2_sys__Last_write_time_set)(char const*, __int64);
38 static HMODULE msvcp;
39 #define SETNOFAIL(x,y) x = (void*)GetProcAddress(msvcp,y)
40 #define SET(x,y) do { SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y); } while(0)
41 static BOOL init(void)
43 msvcp = LoadLibraryA("msvcp110.dll");
44 if(!msvcp)
46 win_skip("msvcp110.dll not installed\n");
47 return FALSE;
50 if(sizeof(void*) == 8) { /* 64-bit initialization */
51 SET(p_tr2_sys__Make_dir,
52 "?_Make_dir@sys@tr2@std@@YAHPEBD@Z");
53 SET(p_tr2_sys__Remove_dir,
54 "?_Remove_dir@sys@tr2@std@@YA_NPEBD@Z");
55 SET(p_tr2_sys__Last_write_time,
56 "?_Last_write_time@sys@tr2@std@@YA_JPEBD@Z");
57 SET(p_tr2_sys__Last_write_time_set,
58 "?_Last_write_time@sys@tr2@std@@YAXPEBD_J@Z");
59 } else {
60 SET(p_tr2_sys__Make_dir,
61 "?_Make_dir@sys@tr2@std@@YAHPBD@Z");
62 SET(p_tr2_sys__Remove_dir,
63 "?_Remove_dir@sys@tr2@std@@YA_NPBD@Z");
64 SET(p_tr2_sys__Last_write_time,
65 "?_Last_write_time@sys@tr2@std@@YA_JPBD@Z");
66 SET(p_tr2_sys__Last_write_time_set,
67 "?_Last_write_time@sys@tr2@std@@YAXPBD_J@Z");
69 return TRUE;
72 static void test_tr2_sys__Last_write_time(void)
74 HANDLE file;
75 int ret;
76 FILETIME lwt;
77 __int64 last_write_time, newtime, margin_of_error = 10 * TICKSPERSEC;
78 ret = p_tr2_sys__Make_dir("tr2_test_dir");
79 ok(ret == 1, "test_tr2_sys__Make_dir(): expect 1 got %d\n", ret);
80 file = CreateFileA("tr2_test_dir/f1", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
81 ok(file != INVALID_HANDLE_VALUE, "CreateFileA failed: INVALID_HANDLE_VALUE\n");
82 CloseHandle(file);
84 last_write_time = p_tr2_sys__Last_write_time("tr2_test_dir/f1");
85 newtime = last_write_time + 222222;
86 p_tr2_sys__Last_write_time_set("tr2_test_dir/f1", newtime);
87 ok(last_write_time != p_tr2_sys__Last_write_time("tr2_test_dir/f1"),
88 "last_write_time should have changed: %s\n",
89 wine_dbgstr_longlong(last_write_time));
91 /* test the formula */
92 file = CreateFileA("tr2_test_dir/f1", 0, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
93 NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
94 ok(file != INVALID_HANDLE_VALUE, "create file failed: INVALID_HANDLE_VALUE\n");
95 ok(GetFileTime(file, 0, 0, &lwt), "GetFileTime failed\n");
96 CloseHandle(file);
97 last_write_time = (((__int64)lwt.dwHighDateTime)<< 32) + lwt.dwLowDateTime;
98 last_write_time -= TICKS_1601_TO_1970;
99 last_write_time /= TICKSPERSEC;
100 ok(newtime-margin_of_error<=last_write_time && last_write_time<=newtime+margin_of_error,
101 "don't fit the formula, last_write_time is %s\n", wine_dbgstr_longlong(last_write_time));
103 newtime = 0;
104 p_tr2_sys__Last_write_time_set("tr2_test_dir/f1", newtime);
105 newtime = p_tr2_sys__Last_write_time("tr2_test_dir/f1");
106 file = CreateFileA("tr2_test_dir/f1", 0, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
107 NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
108 ok(file != INVALID_HANDLE_VALUE, "create file failed: INVALID_HANDLE_VALUE\n");
109 ok(GetFileTime(file, 0, 0, &lwt), "GetFileTime failed\n");
110 CloseHandle(file);
111 last_write_time = (((__int64)lwt.dwHighDateTime)<< 32) + lwt.dwLowDateTime;
112 last_write_time -= TICKS_1601_TO_1970;
113 last_write_time /= TICKSPERSEC;
114 ok(newtime-margin_of_error<=last_write_time && last_write_time<=newtime+margin_of_error,
115 "don't fit the formula, last_write_time is %s\n", wine_dbgstr_longlong(last_write_time));
117 newtime = 123456789;
118 p_tr2_sys__Last_write_time_set("tr2_test_dir/f1", newtime);
119 newtime = p_tr2_sys__Last_write_time("tr2_test_dir/f1");
120 file = CreateFileA("tr2_test_dir/f1", 0, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
121 NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
122 ok(file != INVALID_HANDLE_VALUE, "create file failed: INVALID_HANDLE_VALUE\n");
123 ok(GetFileTime(file, 0, 0, &lwt), "GetFileTime failed\n");
124 CloseHandle(file);
125 last_write_time = (((__int64)lwt.dwHighDateTime)<< 32) + lwt.dwLowDateTime;
126 last_write_time -= TICKS_1601_TO_1970;
127 last_write_time /= TICKSPERSEC;
128 ok(newtime-margin_of_error<=last_write_time && last_write_time<=newtime+margin_of_error,
129 "don't fit the formula, last_write_time is %s\n", wine_dbgstr_longlong(last_write_time));
131 errno = 0xdeadbeef;
132 last_write_time = p_tr2_sys__Last_write_time("not_exist");
133 ok(errno == 0xdeadbeef, "tr2_sys__Last_write_time(): errno expect 0xdeadbeef, got %d\n", errno);
134 ok(last_write_time == 0, "expect 0 got %s\n", wine_dbgstr_longlong(last_write_time));
135 last_write_time = p_tr2_sys__Last_write_time(NULL);
136 ok(last_write_time == 0, "expect 0 got %s\n", wine_dbgstr_longlong(last_write_time));
138 p_tr2_sys__Last_write_time_set("not_exist", newtime);
139 errno = 0xdeadbeef;
140 p_tr2_sys__Last_write_time_set(NULL, newtime);
141 ok(errno == 0xdeadbeef, "tr2_sys__Last_write_time(): errno expect 0xdeadbeef, got %d\n", errno);
143 ok(DeleteFileA("tr2_test_dir/f1"), "expect tr2_test_dir/f1 to exist\n");
144 ret = p_tr2_sys__Remove_dir("tr2_test_dir");
145 ok(ret == 1, "test_tr2_sys__Remove_dir(): expect 1 got %d\n", ret);
148 static struct {
149 int value[2];
150 const char* export_name;
151 } vbtable_size_exports_list[] = {
152 {{0x20, 0x20}, "??_8?$basic_iostream@DU?$char_traits@D@std@@@std@@7B?$basic_istream@DU?$char_traits@D@std@@@1@@"},
153 {{0x10, 0x10}, "??_8?$basic_iostream@DU?$char_traits@D@std@@@std@@7B?$basic_ostream@DU?$char_traits@D@std@@@1@@"},
154 {{0x20, 0x20}, "??_8?$basic_iostream@GU?$char_traits@G@std@@@std@@7B?$basic_istream@GU?$char_traits@G@std@@@1@@"},
155 {{0x10, 0x10}, "??_8?$basic_iostream@GU?$char_traits@G@std@@@std@@7B?$basic_ostream@GU?$char_traits@G@std@@@1@@"},
156 {{0x20, 0x20}, "??_8?$basic_iostream@_WU?$char_traits@_W@std@@@std@@7B?$basic_istream@_WU?$char_traits@_W@std@@@1@@"},
157 {{0x10, 0x10}, "??_8?$basic_iostream@_WU?$char_traits@_W@std@@@std@@7B?$basic_ostream@_WU?$char_traits@_W@std@@@1@@"},
158 {{0x18, 0x18}, "??_8?$basic_istream@DU?$char_traits@D@std@@@std@@7B@"},
159 {{0x18, 0x18}, "??_8?$basic_istream@GU?$char_traits@G@std@@@std@@7B@"},
160 {{0x18, 0x18}, "??_8?$basic_istream@_WU?$char_traits@_W@std@@@std@@7B@"},
161 {{ 0x8, 0x10}, "??_8?$basic_ostream@DU?$char_traits@D@std@@@std@@7B@"},
162 {{ 0x8, 0x10}, "??_8?$basic_ostream@GU?$char_traits@G@std@@@std@@7B@"},
163 {{ 0x8, 0x10}, "??_8?$basic_ostream@_WU?$char_traits@_W@std@@@std@@7B@"},
164 {{ 0x0, 0x0}, 0}
167 static void test_vbtable_size_exports(void)
169 int i;
170 const int *p_vbtable;
171 int arch_idx = (sizeof(void*) == 8);
173 for (i = 0; vbtable_size_exports_list[i].export_name; i++)
175 SET(p_vbtable, vbtable_size_exports_list[i].export_name);
177 ok(p_vbtable[0] == 0, "vbtable[0] wrong, got 0x%x\n", p_vbtable[0]);
178 ok(p_vbtable[1] == vbtable_size_exports_list[i].value[arch_idx],
179 "%d: %s[1] wrong, got 0x%x\n", i, vbtable_size_exports_list[i].export_name, p_vbtable[1]);
183 START_TEST(msvcp110)
185 if(!init()) return;
186 test_tr2_sys__Last_write_time();
187 test_vbtable_size_exports();
188 FreeLibrary(msvcp);