2 * Copyright 2008 James Hawkins
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
28 #include "wine/test.h"
30 /* ok-like statement which takes two unicode strings or one unicode and one ANSI string as arguments */
31 static CHAR string1[MAX_PATH];
33 #define ok_aw(aString, wString) \
34 WideCharToMultiByte(CP_ACP, 0, wString, -1, string1, MAX_PATH, NULL, NULL); \
35 if (lstrcmpA(string1, aString) != 0) \
36 ok(0, "Expected \"%s\", got \"%s\"\n", aString, string1);
38 static HRESULT (WINAPI *pCreateAssemblyNameObject)(LPASSEMBLYNAME *ppAssemblyNameObj,
39 LPCWSTR szAssemblyName, DWORD dwFlags,
41 static HRESULT (WINAPI *pLoadLibraryShim)(LPCWSTR szDllName, LPCWSTR szVersion,
42 LPVOID pvReserved, HMODULE *phModDll);
44 static BOOL init_functionpointers(void)
50 static const WCHAR szFusion[] = {'f','u','s','i','o','n','.','d','l','l',0};
52 hmscoree = LoadLibraryA("mscoree.dll");
56 pLoadLibraryShim = (void *)GetProcAddress(hmscoree, "LoadLibraryShim");
57 if (!pLoadLibraryShim)
59 FreeLibrary(hmscoree);
63 hr = pLoadLibraryShim(szFusion, NULL, NULL, &hfusion);
67 pCreateAssemblyNameObject = (void *)GetProcAddress(hfusion, "CreateAssemblyNameObject");
68 if (!pCreateAssemblyNameObject)
74 typedef struct _tagASMPROP_RES
81 static const ASMPROP_RES defaults[ASM_NAME_MAX_PARAMS] =
98 {S_FALSE, "", MAX_PATH},
99 {S_FALSE, "", MAX_PATH},
101 {S_OK, "", MAX_PATH},
113 static const ASMPROP_RES emptyname[ASM_NAME_MAX_PARAMS] =
130 {S_FALSE, "", MAX_PATH},
131 {S_FALSE, "", MAX_PATH},
133 {S_OK, "", MAX_PATH},
145 static const ASMPROP_RES winename[ASM_NAME_MAX_PARAMS] =
162 {S_FALSE, "", MAX_PATH},
163 {S_FALSE, "", MAX_PATH},
165 {S_OK, "", MAX_PATH},
177 static const ASMPROP_RES vername[ASM_NAME_MAX_PARAMS] =
194 {S_FALSE, "", MAX_PATH},
195 {S_FALSE, "", MAX_PATH},
197 {S_OK, "", MAX_PATH},
209 static const ASMPROP_RES badvername[ASM_NAME_MAX_PARAMS] =
226 {S_FALSE, "", MAX_PATH},
227 {S_FALSE, "", MAX_PATH},
229 {S_OK, "", MAX_PATH},
241 static const ASMPROP_RES neutralname[ASM_NAME_MAX_PARAMS] =
258 {S_FALSE, "", MAX_PATH},
259 {S_FALSE, "", MAX_PATH},
261 {S_OK, "", MAX_PATH},
273 static const ASMPROP_RES enname[ASM_NAME_MAX_PARAMS] =
290 {S_FALSE, "", MAX_PATH},
291 {S_FALSE, "", MAX_PATH},
293 {S_OK, "", MAX_PATH},
305 static const ASMPROP_RES pubkeyname[ASM_NAME_MAX_PARAMS] =
308 {S_OK, "\x12\x34\x56\x78\x90\xab\xcd\xef", 8},
322 {S_OK, "", MAX_PATH},
323 {S_OK, "", MAX_PATH},
325 {S_OK, "", MAX_PATH},
337 static inline void to_widechar(LPWSTR dest, LPCSTR src)
339 MultiByteToWideChar(CP_ACP, 0, src, -1, dest, MAX_PATH);
342 static inline void to_multibyte(LPSTR dest, LPWSTR src)
344 WideCharToMultiByte(CP_ACP, 0, src, -1, dest, MAX_PATH, NULL, NULL);
347 static void test_assembly_name_props_line(IAssemblyName *name,
348 const ASMPROP_RES *vals, int line)
352 WCHAR expect[MAX_PATH];
356 for (i = 0; i < ASM_NAME_MAX_PARAMS; i++)
358 to_widechar(expect, vals[i].val);
361 ZeroMemory(str, MAX_PATH);
362 hr = IAssemblyName_GetProperty(name, i, str, &size);
363 to_multibyte(val, str);
365 if (i == ASM_NAME_PUBLIC_KEY_TOKEN)
366 lstrcpyA((LPSTR)expect, vals[i].val);
368 ok(hr == vals[i].hr, "%d: prop %d: Expected %08x, got %08x\n", line, i, vals[i].hr, hr);
369 ok(!lstrcmpW(str, expect), "%d: prop %d: Expected \"%s\", got \"%s\"\n", line, i, vals[i].val, val);
370 ok(size == vals[i].size, "%d: prop %d: Expected %d, got %d\n", line, i, vals[i].size, size);
374 #define test_assembly_name_props(name, vals) \
375 test_assembly_name_props_line(name, vals, __LINE__);
377 static void test_CreateAssemblyNameObject(void)
381 WCHAR namestr[MAX_PATH];
385 static const WCHAR empty[] = {0};
387 /* NULL ppAssemblyNameObj */
388 to_widechar(namestr, "wine.dll");
389 hr = pCreateAssemblyNameObject(NULL, namestr, 0, NULL);
390 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
392 /* NULL szAssemblyName, CANOF_PARSE_DISPLAY_NAME */
393 name = (IAssemblyName *)0xdeadbeef;
394 hr = pCreateAssemblyNameObject(&name, NULL, CANOF_PARSE_DISPLAY_NAME, NULL);
395 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
396 ok(name == (IAssemblyName *)0xdeadbeef, "Expected 0xdeadbeef, got %p\n", name);
398 /* empty szAssemblyName, CANOF_PARSE_DISPLAY_NAME */
399 name = (IAssemblyName *)0xdeadbeef;
400 hr = pCreateAssemblyNameObject(&name, empty, CANOF_PARSE_DISPLAY_NAME, NULL);
401 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
402 ok(name == (IAssemblyName *)0xdeadbeef, "Expected 0xdeadbeef, got %p\n", name);
404 /* check the contents of the AssemblyName for default values */
406 /* NULL szAssemblyName */
408 hr = pCreateAssemblyNameObject(&name, NULL, CANOF_SET_DEFAULT_VALUES, NULL);
409 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
410 ok(name != NULL, "Expected non-NULLNULL name\n");
413 hr = IAssemblyName_GetDisplayName(name, str, &size, ASM_DISPLAYF_FULL);
414 ok(hr == FUSION_E_INVALID_NAME,
415 "Expected FUSION_E_INVALID_NAME, got %08x\n", hr);
419 hr = IAssemblyName_GetName(name, &size, str);
420 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
421 ok(lstrlenW(str) == 0, "Expected empty name\n");
422 ok(size == 0, "Expected 0, got %d\n", size);
426 hr = IAssemblyName_GetVersion(name, &hi, &lo);
427 ok(hr == FUSION_E_INVALID_NAME,
428 "Expected FUSION_E_INVALID_NAME, got %08x\n", hr);
429 ok(hi == 0, "Expected 0, got %08x\n", hi);
430 ok(lo == 0, "Expected 0, got %08x\n", lo);
432 test_assembly_name_props(name, defaults);
434 IAssemblyName_Release(name);
436 /* empty szAssemblyName */
438 hr = pCreateAssemblyNameObject(&name, empty, CANOF_SET_DEFAULT_VALUES, NULL);
439 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
440 ok(name != NULL, "Expected non-NULLNULL name\n");
443 hr = IAssemblyName_GetDisplayName(name, str, &size, ASM_DISPLAYF_FULL);
444 ok(hr == FUSION_E_INVALID_NAME,
445 "Expected FUSION_E_INVALID_NAME, got %08x\n", hr);
449 hr = IAssemblyName_GetName(name, &size, str);
450 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
451 ok(lstrlenW(str) == 0, "Expected empty name\n");
452 ok(size == 1, "Expected 1, got %d\n", size);
456 hr = IAssemblyName_GetVersion(name, &hi, &lo);
457 ok(hr == FUSION_E_INVALID_NAME,
458 "Expected FUSION_E_INVALID_NAME, got %08x\n", hr);
459 ok(hi == 0, "Expected 0, got %08x\n", hi);
460 ok(lo == 0, "Expected 0, got %08x\n", lo);
462 test_assembly_name_props(name, emptyname);
464 IAssemblyName_Release(name);
467 to_widechar(namestr, "wine");
469 hr = pCreateAssemblyNameObject(&name, namestr, CANOF_SET_DEFAULT_VALUES, NULL);
470 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
471 ok(name != NULL, "Expected non-NULLNULL name\n");
474 hr = IAssemblyName_GetDisplayName(name, str, &size, ASM_DISPLAYF_FULL);
475 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
477 ok(size == 5, "Expected 5, got %d\n", size);
481 hr = IAssemblyName_GetName(name, &size, str);
482 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
484 ok(size == 5, "Expected 5, got %d\n", size);
488 hr = IAssemblyName_GetVersion(name, &hi, &lo);
489 ok(hr == FUSION_E_INVALID_NAME,
490 "Expected FUSION_E_INVALID_NAME, got %08x\n", hr);
491 ok(hi == 0, "Expected 0, got %08x\n", hi);
492 ok(lo == 0, "Expected 0, got %08x\n", lo);
494 test_assembly_name_props(name, winename);
496 IAssemblyName_Release(name);
498 /* check the contents of the AssemblyName with parsing */
501 to_widechar(namestr, "wine");
503 hr = pCreateAssemblyNameObject(&name, namestr, CANOF_PARSE_DISPLAY_NAME, NULL);
504 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
505 ok(name != NULL, "Expected non-NULLNULL name\n");
508 hr = IAssemblyName_GetDisplayName(name, str, &size, ASM_DISPLAYF_FULL);
509 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
511 ok(size == 5, "Expected 5, got %d\n", size);
515 hr = IAssemblyName_GetName(name, &size, str);
516 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
518 ok(size == 5, "Expected 5, got %d\n", size);
522 hr = IAssemblyName_GetVersion(name, &hi, &lo);
523 ok(hr == FUSION_E_INVALID_NAME,
524 "Expected FUSION_E_INVALID_NAME, got %08x\n", hr);
525 ok(hi == 0, "Expected 0, got %08x\n", hi);
526 ok(lo == 0, "Expected 0, got %08x\n", lo);
528 test_assembly_name_props(name, winename);
530 IAssemblyName_Release(name);
532 /* 'wine, Version=1.2.3.4' */
533 to_widechar(namestr, "wine, Version=1.2.3.4");
535 hr = pCreateAssemblyNameObject(&name, namestr, CANOF_PARSE_DISPLAY_NAME, NULL);
536 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
537 ok(name != NULL, "Expected non-NULLNULL name\n");
540 hr = IAssemblyName_GetDisplayName(name, str, &size, ASM_DISPLAYF_FULL);
541 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
542 ok_aw("wine, Version=1.2.3.4", str);
543 ok(size == 22, "Expected 22, got %d\n", size);
547 hr = IAssemblyName_GetName(name, &size, str);
548 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
550 ok(size == 5, "Expected 5, got %d\n", size);
554 hr = IAssemblyName_GetVersion(name, &hi, &lo);
555 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
556 ok(hi == 0x00010002, "Expected 0x00010002, got %08x\n", hi);
557 ok(lo == 0x00030004, "Expected 0x00030004, got %08x\n", lo);
559 test_assembly_name_props(name, vername);
561 IAssemblyName_Release(name);
563 /* Version isn't of the form 1.x.x.x */
564 to_widechar(namestr, "wine, Version=1.5");
566 hr = pCreateAssemblyNameObject(&name, namestr, CANOF_PARSE_DISPLAY_NAME, NULL);
567 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
568 ok(name != NULL, "Expected non-NULLNULL name\n");
571 hr = IAssemblyName_GetDisplayName(name, str, &size, ASM_DISPLAYF_FULL);
572 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
573 ok_aw("wine, Version=1.5", str);
574 ok(size == 18, "Expected 18, got %d\n", size);
578 hr = IAssemblyName_GetName(name, &size, str);
579 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
581 ok(size == 5, "Expected 5, got %d\n", size);
585 hr = IAssemblyName_GetVersion(name, &hi, &lo);
586 ok(hr == FUSION_E_INVALID_NAME,
587 "Expected FUSION_E_INVALID_NAME, got %08x\n", hr);
588 ok(hi == 0, "Expected 0, got %08x\n", hi);
589 ok(lo == 0, "Expected 0, got %08x\n", lo);
591 test_assembly_name_props(name, badvername);
593 IAssemblyName_Release(name);
595 /* 'wine, Culture=neutral' */
596 to_widechar(namestr, "wine, Culture=neutral");
598 hr = pCreateAssemblyNameObject(&name, namestr, CANOF_PARSE_DISPLAY_NAME, NULL);
599 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
600 ok(name != NULL, "Expected non-NULLNULL name\n");
603 hr = IAssemblyName_GetDisplayName(name, str, &size, ASM_DISPLAYF_FULL);
604 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
605 ok_aw("wine, Culture=neutral", str);
606 ok(size == 22, "Expected 22, got %d\n", size);
610 hr = IAssemblyName_GetName(name, &size, str);
611 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
613 ok(size == 5, "Expected 5, got %d\n", size);
617 hr = IAssemblyName_GetVersion(name, &hi, &lo);
618 ok(hr == FUSION_E_INVALID_NAME,
619 "Expected FUSION_E_INVALID_NAME, got %08x\n", hr);
620 ok(hi == 0, "Expected 0, got %08x\n", hi);
621 ok(lo == 0, "Expected 0, got %08x\n", lo);
623 test_assembly_name_props(name, neutralname);
625 IAssemblyName_Release(name);
627 /* 'wine, Culture=en' */
628 to_widechar(namestr, "wine, Culture=en");
630 hr = pCreateAssemblyNameObject(&name, namestr, CANOF_PARSE_DISPLAY_NAME, NULL);
631 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
632 ok(name != NULL, "Expected non-NULLNULL name\n");
635 hr = IAssemblyName_GetDisplayName(name, str, &size, ASM_DISPLAYF_FULL);
636 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
637 ok_aw("wine, Culture=en", str);
638 ok(size == 17, "Expected 17, got %d\n", size);
642 hr = IAssemblyName_GetName(name, &size, str);
643 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
645 ok(size == 5, "Expected 5, got %d\n", size);
649 hr = IAssemblyName_GetVersion(name, &hi, &lo);
650 ok(hr == FUSION_E_INVALID_NAME,
651 "Expected FUSION_E_INVALID_NAME, got %08x\n", hr);
652 ok(hi == 0, "Expected 0, got %08x\n", hi);
653 ok(lo == 0, "Expected 0, got %08x\n", lo);
655 test_assembly_name_props(name, enname);
657 IAssemblyName_Release(name);
659 /* 'wine, PublicKeyToken=1234567890abcdef' */
660 to_widechar(namestr, "wine, PublicKeyToken=1234567890abcdef");
662 hr = pCreateAssemblyNameObject(&name, namestr, CANOF_PARSE_DISPLAY_NAME, NULL);
663 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
664 ok(name != NULL, "Expected non-NULLNULL name\n");
667 hr = IAssemblyName_GetDisplayName(name, str, &size, ASM_DISPLAYF_FULL);
668 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
669 ok_aw("wine, PublicKeyToken=1234567890abcdef", str);
670 ok(size == 38, "Expected 38, got %d\n", size);
674 hr = IAssemblyName_GetName(name, &size, str);
675 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
677 ok(size == 5, "Expected 5, got %d\n", size);
681 hr = IAssemblyName_GetVersion(name, &hi, &lo);
682 ok(hr == FUSION_E_INVALID_NAME,
683 "Expected FUSION_E_INVALID_NAME, got %08x\n", hr);
684 ok(hi == 0, "Expected 0, got %08x\n", hi);
685 ok(lo == 0, "Expected 0, got %08x\n", lo);
687 test_assembly_name_props(name, pubkeyname);
689 IAssemblyName_Release(name);
691 /* PublicKeyToken is not 16 chars long */
692 to_widechar(namestr, "wine, PublicKeyToken=567890abcdef");
693 name = (IAssemblyName *)0xdeadbeef;
694 hr = pCreateAssemblyNameObject(&name, namestr, CANOF_PARSE_DISPLAY_NAME, NULL);
695 ok(hr == FUSION_E_INVALID_NAME,
696 "Expected FUSION_E_INVALID_NAME, got %08x\n", hr);
697 ok(name == (IAssemblyName *)0xdeadbeef, "Expected 0xdeadbeef, got %p\n", name);
699 /* PublicKeyToken contains invalid chars */
700 to_widechar(namestr, "wine, PublicKeyToken=1234567890ghijkl");
701 name = (IAssemblyName *)0xdeadbeef;
702 hr = pCreateAssemblyNameObject(&name, namestr, CANOF_PARSE_DISPLAY_NAME, NULL);
703 ok(hr == FUSION_E_INVALID_NAME,
704 "Expected FUSION_E_INVALID_NAME, got %08x\n", hr);
705 ok(name == (IAssemblyName *)0xdeadbeef, "Expected 0xdeadbeef, got %p\n", name);
707 /* no comma separator */
708 to_widechar(namestr, "wine PublicKeyToken=1234567890abcdef");
709 name = (IAssemblyName *)0xdeadbeef;
710 hr = pCreateAssemblyNameObject(&name, namestr, CANOF_PARSE_DISPLAY_NAME, NULL);
713 ok(hr == FUSION_E_INVALID_NAME,
714 "Expected FUSION_E_INVALID_NAME, got %08x\n", hr);
715 ok(name == (IAssemblyName *)0xdeadbeef, "Expected 0xdeadbeef, got %p\n", name);
719 to_widechar(namestr, "wine, PublicKeyToken");
720 name = (IAssemblyName *)0xdeadbeef;
721 hr = pCreateAssemblyNameObject(&name, namestr, CANOF_PARSE_DISPLAY_NAME, NULL);
722 ok(hr == FUSION_E_INVALID_NAME,
723 "Expected FUSION_E_INVALID_NAME, got %08x\n", hr);
724 ok(name == (IAssemblyName *)0xdeadbeef, "Expected 0xdeadbeef, got %p\n", name);
727 to_widechar(namestr, "wine, PublicKeyToken=");
728 name = (IAssemblyName *)0xdeadbeef;
729 hr = pCreateAssemblyNameObject(&name, namestr, CANOF_PARSE_DISPLAY_NAME, NULL);
730 ok(hr == FUSION_E_INVALID_NAME,
731 "Expected FUSION_E_INVALID_NAME, got %08x\n", hr);
732 ok(name == (IAssemblyName *)0xdeadbeef, "Expected 0xdeadbeef, got %p\n", name);
734 /* invalid property */
735 to_widechar(namestr, "wine, BadProp=42");
737 hr = pCreateAssemblyNameObject(&name, namestr, CANOF_PARSE_DISPLAY_NAME, NULL);
738 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
739 ok(name != NULL, "Expected non-NULLNULL name\n");
742 hr = IAssemblyName_GetDisplayName(name, str, &size, ASM_DISPLAYF_FULL);
743 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
747 ok(size == 5, "Expected 5, got %d\n", size);
752 hr = IAssemblyName_GetName(name, &size, str);
753 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
755 ok(size == 5, "Expected 5, got %d\n", size);
759 hr = IAssemblyName_GetVersion(name, &hi, &lo);
760 ok(hr == FUSION_E_INVALID_NAME,
761 "Expected FUSION_E_INVALID_NAME, got %08x\n", hr);
762 ok(hi == 0, "Expected 0, got %08x\n", hi);
763 ok(lo == 0, "Expected 0, got %08x\n", lo);
765 test_assembly_name_props(name, winename);
767 IAssemblyName_Release(name);
772 if (!init_functionpointers())
774 skip("fusion.dll not available\n");
778 test_CreateAssemblyNameObject();