1 /* 2 * ATL test program 3 * 4 * Copyright 2010 Marcus Meissner 5 * 6 * 7 * This library is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU Lesser General Public 9 * License as published by the Free Software Foundation; either 10 * version 2.1 of the License, or (at your option) any later version. 11 * 12 * This library is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with this library; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 20 */ 21 22 #include <stdarg.h> 23 #include <stdio.h> 24 25 #define COBJMACROS 26 27 #include <wine/atlbase.h> 28 29 #include <wine/test.h> 30 31 #define MAXSIZE 512 32 static void test_StructSize(void) 33 { 34 _ATL_MODULEW *tst; 35 HRESULT hres; 36 int i; 37 38 tst = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, MAXSIZE); 39 40 for (i=0;i<MAXSIZE;i++) { 41 tst->cbSize = i; 42 hres = AtlModuleInit(tst, NULL, NULL); 43 44 switch (i) { 45 case FIELD_OFFSET(_ATL_MODULEW, dwAtlBuildVer): 46 case sizeof(_ATL_MODULEW): 47 #ifdef _WIN64 48 case sizeof(_ATL_MODULEW) + sizeof(void *): 49 #endif 50 ok (hres == S_OK, "AtlModuleInit with %d failed (0x%x).\n", i, (int)hres); 51 break; 52 default: 53 ok (FAILED(hres), "AtlModuleInit with %d succeeded? (0x%x).\n", i, (int)hres); 54 break; 55 } 56 } 57 58 HeapFree (GetProcessHeap(), 0, tst); 59 } 60 61 static void test_winmodule(void) 62 { 63 _AtlCreateWndData create_data[3]; 64 _ATL_MODULEW winmod; 65 void *p; 66 HRESULT hres; 67 68 winmod.cbSize = sizeof(winmod); 69 winmod.m_pCreateWndList = (void*)0xdeadbeef; 70 winmod.m_csWindowCreate.LockCount = 0xdeadbeef; 71 hres = AtlModuleInit(&winmod, NULL, NULL); 72 ok(hres == S_OK, "AtlModuleInit failed: %08x\n", hres); 73 ok(!winmod.m_pCreateWndList, "winmod.m_pCreateWndList = %p\n", winmod.m_pCreateWndList); 74 ok(winmod.m_csWindowCreate.LockCount == -1, "winmod.m_csWindowCreate.LockCount = %d\n", 75 winmod.m_csWindowCreate.LockCount); 76 77 AtlModuleAddCreateWndData(&winmod, create_data, (void*)0xdead0001); 78 ok(winmod.m_pCreateWndList == create_data, "winmod.m_pCreateWndList != create_data\n"); 79 ok(create_data[0].m_pThis == (void*)0xdead0001, "unexpected create_data[0].m_pThis %p\n", create_data[0].m_pThis); 80 ok(create_data[0].m_dwThreadID == GetCurrentThreadId(), "unexpected create_data[0].m_dwThreadID %x\n", 81 create_data[0].m_dwThreadID); 82 ok(!create_data[0].m_pNext, "unexpected create_data[0].m_pNext %p\n", create_data[0].m_pNext); 83 84 AtlModuleAddCreateWndData(&winmod, create_data+1, (void*)0xdead0002); 85 ok(winmod.m_pCreateWndList == create_data+1, "winmod.m_pCreateWndList != create_data\n"); 86 ok(create_data[1].m_pThis == (void*)0xdead0002, "unexpected create_data[1].m_pThis %p\n", create_data[1].m_pThis); 87 ok(create_data[1].m_dwThreadID == GetCurrentThreadId(), "unexpected create_data[1].m_dwThreadID %x\n", 88 create_data[1].m_dwThreadID); 89 ok(create_data[1].m_pNext == create_data, "unexpected create_data[1].m_pNext %p\n", create_data[1].m_pNext); 90 91 AtlModuleAddCreateWndData(&winmod, create_data+2, (void*)0xdead0003); 92 ok(winmod.m_pCreateWndList == create_data+2, "winmod.m_pCreateWndList != create_data\n"); 93 ok(create_data[2].m_pThis == (void*)0xdead0003, "unexpected create_data[2].m_pThis %p\n", create_data[2].m_pThis); 94 ok(create_data[2].m_dwThreadID == GetCurrentThreadId(), "unexpected create_data[2].m_dwThreadID %x\n", 95 create_data[2].m_dwThreadID); 96 ok(create_data[2].m_pNext == create_data+1, "unexpected create_data[2].m_pNext %p\n", create_data[2].m_pNext); 97 98 p = AtlModuleExtractCreateWndData(&winmod); 99 ok(p == (void*)0xdead0003, "unexpected AtlModuleExtractCreateWndData result %p\n", p); 100 ok(winmod.m_pCreateWndList == create_data+1, "winmod.m_pCreateWndList != create_data\n"); 101 ok(create_data[2].m_pNext == create_data+1, "unexpected create_data[2].m_pNext %p\n", create_data[2].m_pNext); 102 103 create_data[1].m_dwThreadID = 0xdeadbeef; 104 105 p = AtlModuleExtractCreateWndData(&winmod); 106 ok(p == (void*)0xdead0001, "unexpected AtlModuleExtractCreateWndData result %p\n", p); 107 ok(winmod.m_pCreateWndList == create_data+1, "winmod.m_pCreateWndList != create_data\n"); 108 ok(!create_data[0].m_pNext, "unexpected create_data[0].m_pNext %p\n", create_data[0].m_pNext); 109 ok(!create_data[1].m_pNext, "unexpected create_data[1].m_pNext %p\n", create_data[1].m_pNext); 110 111 p = AtlModuleExtractCreateWndData(&winmod); 112 ok(!p, "unexpected AtlModuleExtractCreateWndData result %p\n", p); 113 ok(winmod.m_pCreateWndList == create_data+1, "winmod.m_pCreateWndList != create_data\n"); 114 } 115 116 static DWORD cb_val; 117 118 static void WINAPI term_callback(DWORD dw) 119 { 120 cb_val = dw; 121 } 122 123 static void test_term(void) 124 { 125 _ATL_MODULEW test; 126 HRESULT hres; 127 128 test.cbSize = sizeof(_ATL_MODULEW); 129 130 hres = AtlModuleInit(&test, NULL, NULL); 131 ok (hres == S_OK, "AtlModuleInit failed (0x%x).\n", (int)hres); 132 133 hres = AtlModuleAddTermFunc(&test, term_callback, 0x22); 134 ok (hres == S_OK, "AtlModuleAddTermFunc failed (0x%x).\n", (int)hres); 135 136 cb_val = 0xdeadbeef; 137 hres = AtlModuleTerm(&test); 138 ok (hres == S_OK, "AtlModuleTerm failed (0x%x).\n", (int)hres); 139 ok (cb_val == 0x22, "wrong callback value (0x%x).\n", (int)cb_val); 140 141 test.cbSize = FIELD_OFFSET(_ATL_MODULEW, dwAtlBuildVer); 142 143 hres = AtlModuleInit(&test, NULL, NULL); 144 ok (hres == S_OK, "AtlModuleInit failed (0x%x).\n", (int)hres); 145 146 hres = AtlModuleAddTermFunc(&test, term_callback, 0x23); 147 ok (hres == S_OK, "AtlModuleAddTermFunc failed (0x%x).\n", (int)hres); 148 149 cb_val = 0xdeadbeef; 150 hres = AtlModuleTerm(&test); 151 ok (hres == S_OK, "AtlModuleTerm failed (0x%x).\n", (int)hres); 152 ok (cb_val == 0xdeadbeef, "wrong callback value (0x%x).\n", (int)cb_val); 153 } 154 155 START_TEST(module) 156 { 157 test_StructSize(); 158 test_winmodule(); 159 test_term(); 160 } 161