ReactOS 0.4.15-dev-8428-g6910fa6
SHPropertyBag.cpp File Reference
#include <apitest.h>
#include <shlwapi.h>
#include <shlobj.h>
#include <stdio.h>
#include <shlwapi_undoc.h>
#include <versionhelpers.h>
#include <strsafe.h>
#include <pseh/pseh2.h>
Include dependency graph for SHPropertyBag.cpp:

Go to the source code of this file.

Classes

class  CDummyPropertyBag
 

Functions

static void ResetTest (VARTYPE vt, LPCWSTR pszName0=NULL, LPCWSTR pszName1=NULL, LPCWSTR pszName2=NULL, LPCWSTR pszName3=NULL)
 
static SAFEARRAYCreateByteArray (LPCVOID pvSrc, DWORD cbSize)
 
static void SHPropertyBag_ReadTest (void)
 
static void SHPropertyBag_WriteTest (void)
 
static void SHPropertyBag_OnMemory (void)
 
static void SHPropertyBag_OnRegKey (void)
 
static void SHPropertyBag_SHSetIniStringW (void)
 
static void SHPropertyBag_OnIniFile (void)
 
static void SHPropertyBag_PerScreenRes (void)
 
 START_TEST (SHPropertyBag)
 

Variables

static LPCWSTR s_pszPropNames [4] = { NULL, NULL, NULL, NULL }
 
static VARTYPE s_vt
 
static INT s_cRead = 0
 
static INT s_cWrite = 0
 

Function Documentation

◆ CreateByteArray()

static SAFEARRAY * CreateByteArray ( LPCVOID  pvSrc,
DWORD  cbSize 
)
static

Definition at line 35 of file SHPropertyBag.cpp.

36{
37 SAFEARRAYBOUND Bound;
38 Bound.lLbound = 0;
39 Bound.cElements = cbSize;
40
41 SAFEARRAY* pArray = SafeArrayCreate(VT_UI1, 1, &Bound);
42 if (!pArray)
43 return NULL;
44
45 void HUGEP *pvData;
47 if (FAILED(hr))
48 {
49 SafeArrayDestroy(pArray);
50 return NULL;
51 }
52
53 CopyMemory(pvData, pvSrc, cbSize);
55
56 return pArray;
57}
#define NULL
Definition: types.h:112
@ VT_UI1
Definition: compat.h:2311
HRESULT WINAPI SafeArrayAccessData(SAFEARRAY *psa, void **ppvData)
Definition: safearray.c:1137
HRESULT WINAPI SafeArrayUnaccessData(SAFEARRAY *psa)
Definition: safearray.c:1168
HRESULT WINAPI SafeArrayDestroy(SAFEARRAY *psa)
Definition: safearray.c:1347
SAFEARRAY *WINAPI SafeArrayCreate(VARTYPE vt, UINT cDims, SAFEARRAYBOUND *rgsabound)
Definition: safearray.c:600
#define FAILED(hr)
Definition: intsafe.h:51
#define HUGEP
Definition: objbase.h:1052
HRESULT hr
Definition: shlfolder.c:183
#define CopyMemory
Definition: winbase.h:1710
_In_ ULONG _In_opt_ PVOID pvData
Definition: winddi.h:3749

Referenced by CDummyPropertyBag::Read().

◆ ResetTest()

static void ResetTest ( VARTYPE  vt,
LPCWSTR  pszName0 = NULL,
LPCWSTR  pszName1 = NULL,
LPCWSTR  pszName2 = NULL,
LPCWSTR  pszName3 = NULL 
)
static

Definition at line 23 of file SHPropertyBag.cpp.

26{
27 s_vt = vt;
28 s_cRead = s_cWrite = 0;
29 s_pszPropNames[0] = pszName0;
30 s_pszPropNames[1] = pszName1;
31 s_pszPropNames[2] = pszName2;
32 s_pszPropNames[3] = pszName3;
33}
static INT s_cRead
static VARTYPE s_vt
static LPCWSTR s_pszPropNames[4]
static INT s_cWrite
static REFPROPVARIANT PROPVAR_CHANGE_FLAGS VARTYPE vt
Definition: suminfo.c:86

Referenced by SHPropertyBag_ReadTest(), and SHPropertyBag_WriteTest().

◆ SHPropertyBag_OnIniFile()

static void SHPropertyBag_OnIniFile ( void  )
static

Definition at line 692 of file SHPropertyBag.cpp.

693{
694 WCHAR szIniFile[MAX_PATH], szValue[MAX_PATH];
695 HRESULT hr;
696 IPropertyBag *pPropBag;
697 VARIANT vari;
698 DWORD dwRet;
699
700 ExpandEnvironmentStringsW(L"%TEMP%\\SHPropertyBag.ini", szIniFile, _countof(szIniFile));
701
704
705 trace("%ls\n", szIniFile);
706
707 // read-write
709 szIniFile,
710 L"TestSection",
713 (void**)&pPropBag);
714 ok_long(hr, S_OK);
716
717 // Write UI4
718 VariantInit(&vari);
719 V_VT(&vari) = VT_UI4;
720 V_UI4(&vari) = 0xDEADFACE;
721 hr = pPropBag->Write(L"Name1", &vari);
722 ok_long(hr, S_OK);
723 VariantClear(&vari);
724
725 // Write BSTR
726 VariantInit(&vari);
727 V_VT(&vari) = VT_BSTR;
728 V_BSTR(&vari) = SysAllocString(L"StrValue");
729 hr = pPropBag->Write(L"Name2", &vari);
730 ok_long(hr, S_OK);
731 VariantClear(&vari);
732
733 // Write BSTR (dirty UTF-7)
734 VariantInit(&vari);
735 V_VT(&vari) = VT_BSTR;
736 V_BSTR(&vari) = SysAllocString(L"ABC\x3042\x3044\x3046\x2665");
737 hr = pPropBag->Write(L"@Name3", &vari);
738 ok_long(hr, S_OK);
739 VariantClear(&vari);
740
741 // Write BSTR (clean UTF-7)
742 VariantInit(&vari);
743 V_VT(&vari) = VT_BSTR;
744 V_BSTR(&vari) = SysAllocString(L"1234abc");
745 hr = pPropBag->Write(L"@Name4", &vari);
746 ok_long(hr, S_OK);
747 VariantClear(&vari);
748
749 pPropBag->Release();
750
751 // Flush
753
754 // Check INI file
755 dwRet = GetPrivateProfileStringW(L"TestSection", L"Name1", L"BAD", szValue, _countof(szValue), szIniFile);
756 ok_long(dwRet, 10);
757 ok_wstr(szValue, L"3735943886");
758
759 dwRet = GetPrivateProfileStringW(L"TestSection", L"Name2", L"BAD", szValue, _countof(szValue), szIniFile);
760 ok_long(dwRet, 8);
761 ok_wstr(szValue, L"StrValue");
762
763 GetPrivateProfileStringW(L"TestSection", L"Name3", L"NotFound", szValue, _countof(szValue), szIniFile);
764 ok_int(memcmp(szValue, L"ABC", 3 * sizeof(WCHAR)), 0);
765
766 GetPrivateProfileStringW(L"TestSection.A", L"Name3", L"NotFound", szValue, _countof(szValue), szIniFile);
767 ok_int(memcmp(szValue, L"ABC", 3 * sizeof(WCHAR)), 0);
768
769 GetPrivateProfileStringW(L"TestSection.W", L"Name3", L"NotFound", szValue, _countof(szValue), szIniFile);
770 ok_wstr(szValue, L"ABC+MEIwRDBGJmU-"); // UTF-7
771
772 GetPrivateProfileStringW(L"TestSection", L"Name4", L"NotFound", szValue, _countof(szValue), szIniFile);
773 ok_wstr(szValue, L"1234abc");
774
775 GetPrivateProfileStringW(L"TestSection.A", L"Name4", L"NotFound", szValue, _countof(szValue), szIniFile);
776 ok_wstr(szValue, L"NotFound");
777
778 GetPrivateProfileStringW(L"TestSection.W", L"Name4", L"NotFound", szValue, _countof(szValue), szIniFile);
779 ok_wstr(szValue, L"NotFound");
780
781 // read-only
783 szIniFile,
784 NULL,
785 STGM_READ,
787 (void**)&pPropBag);
788 ok_long(hr, S_OK);
789
790 // Read UI4
791 VariantInit(&vari);
792 V_VT(&vari) = VT_UI4;
793 hr = pPropBag->Read(L"TestSection\\Name1", &vari, NULL);
794 ok_long(hr, S_OK);
795 ok_long(V_UI4(&vari), 0xDEADFACE);
796 VariantClear(&vari);
797
798 // Read BSTR
799 VariantInit(&vari);
800 V_VT(&vari) = VT_BSTR;
801 hr = pPropBag->Read(L"TestSection\\Name2", &vari, NULL);
802 ok_long(hr, S_OK);
803 ok_wstr(V_BSTR(&vari), L"StrValue");
804 VariantClear(&vari);
805
806 // Read BSTR (dirty UTF-7)
807 VariantInit(&vari);
808 V_VT(&vari) = VT_BSTR;
809 hr = pPropBag->Read(L"TestSection\\@Name3", &vari, NULL);
810 ok_long(hr, S_OK);
811 ok_wstr(V_BSTR(&vari), L"ABC\x3042\x3044\x3046\x2665");
812 VariantClear(&vari);
813
814 // Read BSTR (clean UTF-7)
815 VariantInit(&vari);
816 V_VT(&vari) = VT_BSTR;
817 hr = pPropBag->Read(L"TestSection\\@Name4", &vari, NULL);
818 ok_long(hr, S_OK);
819 ok_wstr(V_BSTR(&vari), L"1234abc");
820 VariantClear(&vari);
821
822 pPropBag->Release();
823
825}
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
#define ok_long(expression, result)
Definition: atltest.h:133
#define trace
Definition: atltest.h:70
#define ok_wstr(x, y)
Definition: atltest.h:130
#define ok_int(expression, result)
Definition: atltest.h:134
#define TRUE
Definition: types.h:120
#define MAX_PATH
Definition: compat.h:34
@ VT_BSTR
Definition: compat.h:2303
@ VT_UI4
Definition: compat.h:2313
DWORD WINAPI ExpandEnvironmentStringsW(IN LPCWSTR lpSrc, IN LPWSTR lpDst, IN DWORD nSize)
Definition: environ.c:519
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
BOOL WINAPI WritePrivateProfileStringW(LPCWSTR section, LPCWSTR entry, LPCWSTR string, LPCWSTR filename)
Definition: profile.c:1453
INT WINAPI GetPrivateProfileStringW(LPCWSTR section, LPCWSTR entry, LPCWSTR def_val, LPWSTR buffer, UINT len, LPCWSTR filename)
Definition: profile.c:1142
BOOL WINAPI PathFileExistsW(LPCWSTR lpszPath)
Definition: path.c:1777
unsigned long DWORD
Definition: ntddk_ex.h:95
_Check_return_ _CRTIMP FILE *__cdecl _wfopen(_In_z_ const wchar_t *_Filename, _In_z_ const wchar_t *_Mode)
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
HRESULT Write([in] LPCOLESTR pszPropName, [in] VARIANT *pVar)
HRESULT Read([in] LPCOLESTR pszPropName, [in, out] VARIANT *pVar, [in] IErrorLog *pErrorLog)
ULONG Release()
#define S_OK
Definition: intsafe.h:52
#define L(x)
Definition: ntvdm.h:50
#define STGM_READWRITE
Definition: objbase.h:919
#define STGM_READ
Definition: objbase.h:917
BSTR WINAPI SysAllocString(LPCOLESTR str)
Definition: oleaut.c:238
#define V_VT(A)
Definition: oleauto.h:211
#define V_BSTR(A)
Definition: oleauto.h:226
#define V_UI4(A)
Definition: oleauto.h:270
const GUID IID_IPropertyBag
EXTERN_C HRESULT WINAPI SHCreatePropertyBagOnProfileSection(_In_z_ LPCWSTR lpFileName, _In_opt_z_ LPCWSTR pszSection, _In_ DWORD dwMode, _In_ REFIID riid, _Out_ void **ppvObj)
Definition: propbag.cpp:965
TCHAR szIniFile[]
Definition: scrnsave.c:29
#define _countof(array)
Definition: sndvol32.h:70
HRESULT WINAPI DECLSPEC_HOTPATCH VariantClear(VARIANTARG *pVarg)
Definition: variant.c:648
void WINAPI VariantInit(VARIANTARG *pVarg)
Definition: variant.c:568
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by START_TEST().

◆ SHPropertyBag_OnMemory()

static void SHPropertyBag_OnMemory ( void  )
static

Definition at line 330 of file SHPropertyBag.cpp.

331{
332 HRESULT hr;
333 VARIANT vari;
334
335 IPropertyBag *pPropBag = NULL;
337 ok_long(hr, S_OK);
338 if (pPropBag == NULL)
339 {
340 skip("pPropBag was NULL\n");
341 return;
342 }
343
344 VariantInit(&vari);
345 hr = pPropBag->Read(L"InvalidName", &vari, NULL);
346 ok_long(hr, E_FAIL);
347 VariantClear(&vari);
348
349 VariantInit(&vari);
350 V_VT(&vari) = VT_UI4;
351 V_UI4(&vari) = 0xDEADFACE;
352 hr = pPropBag->Write(L"Name1", &vari);
353 ok_long(hr, S_OK);
354 VariantClear(&vari);
355
356 VariantInit(&vari);
357 hr = pPropBag->Read(L"Name1", &vari, NULL);
358 ok_long(hr, S_OK);
359 ok_long(V_VT(&vari), VT_UI4);
360 ok_long(V_UI4(&vari), 0xDEADFACE);
361 VariantClear(&vari);
362
363 pPropBag->Release();
364 pPropBag = NULL;
365
367 ok_long(hr, S_OK);
368
369 VariantInit(&vari);
370 V_VT(&vari) = VT_UI4;
371 V_UI4(&vari) = 0xDEADFACE;
372 hr = pPropBag->Write(L"Name1", &vari);
374 VariantClear(&vari);
375
376 VariantInit(&vari);
377 V_VT(&vari) = VT_UI4;
378 V_UI4(&vari) = 0xFEEDF00D;
379 hr = pPropBag->Read(L"Name1", &vari, NULL);
381 {
382 ok_long(hr, S_OK);
383 ok_int(V_VT(&vari), VT_UI4);
384 ok_long(V_UI4(&vari), 0xDEADFACE);
385 }
386 else
387 {
388 ok_long(hr, E_FAIL);
389 ok_int(V_VT(&vari), VT_EMPTY);
390 ok_long(V_UI4(&vari), 0xFEEDF00D);
391 }
392 VariantClear(&vari);
393
394 pPropBag->Release();
395 pPropBag = NULL;
396
398 ok_long(hr, S_OK);
399
400 VariantInit(&vari);
401 V_VT(&vari) = VT_UI4;
402 V_UI4(&vari) = 0xDEADFACE;
403 hr = pPropBag->Write(L"Name1", &vari);
404 ok_long(hr, S_OK);
405 VariantClear(&vari);
406
407 VariantInit(&vari);
408 V_VT(&vari) = VT_UI4;
409 V_UI4(&vari) = 0xFEEDF00D;
410 hr = pPropBag->Read(L"Name1", &vari, NULL);
412 {
413 ok_long(hr, S_OK);
414 ok_int(V_VT(&vari), VT_UI4);
415 ok_long(V_UI4(&vari), 0xDEADFACE);
416 }
417 else
418 {
420 ok_int(V_VT(&vari), VT_EMPTY);
421 ok_long(V_UI4(&vari), 0xFEEDF00D);
422 }
423 VariantClear(&vari);
424
425 pPropBag->Release();
426
427 hr = SHCreatePropertyBagOnMemory(STGM_READWRITE, IID_IPropertyBag2, (void**)&pPropBag);
429 {
431 }
432 else
433 {
434 ok_long(hr, S_OK);
435 pPropBag->Release();
436 }
437
438 hr = SHCreatePropertyBagOnMemory(STGM_READ, IID_IPropertyBag2, (void**)&pPropBag);
440 {
442 }
443 else
444 {
445 ok_long(hr, S_OK);
446 pPropBag->Release();
447 }
448
449 hr = SHCreatePropertyBagOnMemory(STGM_WRITE, IID_IPropertyBag2, (void**)&pPropBag);
451 {
453 }
454 else
455 {
456 ok_long(hr, S_OK);
457 pPropBag->Release();
458 }
459}
#define skip(...)
Definition: atltest.h:64
#define E_FAIL
Definition: ddrawi.h:102
@ VT_EMPTY
Definition: compat.h:2295
#define STGM_WRITE
Definition: objbase.h:918
EXTERN_C HRESULT WINAPI SHCreatePropertyBagOnMemory(_In_ DWORD dwMode, _In_ REFIID riid, _Out_ void **ppvObj)
Definition: propbag.cpp:254
VERSIONHELPERAPI IsWindowsVistaOrGreater()
#define E_NOINTERFACE
Definition: winerror.h:2364
#define E_ACCESSDENIED
Definition: winerror.h:2849

Referenced by START_TEST().

◆ SHPropertyBag_OnRegKey()

static void SHPropertyBag_OnRegKey ( void  )
static

Definition at line 461 of file SHPropertyBag.cpp.

462{
463 HKEY hKey, hSubKey;
464 LONG error;
465 VARIANT vari;
466 WCHAR szText[MAX_PATH];
467 IStream *pStream;
468 GUID guid;
469 BYTE guid_and_extra[sizeof(GUID) + sizeof(GUID)];
470
471 // Create HKCU\Software\ReactOS registry key
472 error = RegCreateKeyW(HKEY_CURRENT_USER, L"Software\\ReactOS", &hKey);
473 if (error)
474 {
475 skip("FAILED to create HKCU\\Software\\ReactOS\n");
476 return;
477 }
478
479 IPropertyBag *pPropBag;
480 HRESULT hr;
481
482 // Try to create new registry key
483 RegDeleteKeyW(hKey, L"PropBagTest");
484 hr = SHCreatePropertyBagOnRegKey(hKey, L"PropBagTest", 0,
485 IID_IPropertyBag, (void **)&pPropBag);
487
488 // Try to create new registry key
489 RegDeleteKeyW(hKey, L"PropBagTest");
491 IID_IPropertyBag, (void **)&pPropBag);
493
494 // Create new registry key
495 RegDeleteKeyW(hKey, L"PropBagTest");
497 IID_IPropertyBag, (void **)&pPropBag);
498 if (FAILED(hr))
499 {
500 skip("SHCreatePropertyBagOnRegKey FAILED\n");
502 return;
503 }
504
505 // Write UI4
506 VariantInit(&vari);
507 V_VT(&vari) = VT_UI4;
508 V_UI4(&vari) = 0xDEADFACE;
509 hr = pPropBag->Write(L"Name1", &vari);
510 ok_long(hr, S_OK);
511 VariantClear(&vari);
512
513 // Read UI4
514 VariantInit(&vari);
515 hr = pPropBag->Read(L"Name1", &vari, NULL);
516 ok_long(hr, S_OK);
517 ok_long(V_VT(&vari), VT_UI4);
518 ok_long(V_UI4(&vari), 0xDEADFACE);
519 VariantClear(&vari);
520
521 // Write BSTR
522 VariantInit(&vari);
523 V_VT(&vari) = VT_BSTR;
524 V_BSTR(&vari) = SysAllocString(L"StrValue");
525 hr = pPropBag->Write(L"Name2", &vari);
526 ok_long(hr, S_OK);
527 VariantClear(&vari);
528
529 // Read BSTR
530 VariantInit(&vari);
531 V_VT(&vari) = VT_BSTR;
532 hr = pPropBag->Read(L"Name2", &vari, NULL);
533 ok_long(hr, S_OK);
534 ok_long(V_VT(&vari), VT_BSTR);
535 ok_wstr(V_BSTR(&vari), L"StrValue");
536 VariantClear(&vari);
537
538 // Write GUID
539 VariantInit(&vari);
540 V_VT(&vari) = VT_UNKNOWN;
541 V_UNKNOWN(&vari) = SHCreateMemStream((BYTE*)&IID_IShellLinkW, sizeof(IID_IShellLinkW));
542 hr = pPropBag->Write(L"Name4", &vari);
543 ok_long(hr, S_OK);
544 VariantClear(&vari);
545
546 // Read GUID
547 VariantInit(&vari);
548 V_VT(&vari) = VT_EMPTY;
549 hr = pPropBag->Read(L"Name4", &vari, NULL);
551 {
552 ok_long(hr, S_OK);
553 ok_long(V_VT(&vari), VT_UNKNOWN);
554 pStream = (IStream*)V_UNKNOWN(&vari);
555 FillMemory(&guid, sizeof(guid), 0xEE);
556 hr = pStream->Read(&guid, sizeof(guid), NULL);
557 ok_long(hr, S_OK);
558 ok_int(::IsEqualGUID(guid, IID_IShellLinkW), TRUE);
559 }
560 else // XP/2k3 Read is buggy
561 {
562 ok_long(hr, E_FAIL);
563 ok_long(V_VT(&vari), VT_EMPTY);
564 }
565 VariantClear(&vari);
566
567 pPropBag->Release();
568
569 // Check registry
570 error = RegOpenKeyExW(hKey, L"PropBagTest", 0, KEY_READ, &hSubKey);
572 DWORD dwType, dwValue, cbValue = sizeof(dwValue);
573 error = RegQueryValueExW(hSubKey, L"Name1", NULL, &dwType, (BYTE*)&dwValue, &cbValue);
575 ok_long(dwType, REG_DWORD);
576 ok_long(dwValue, 0xDEADFACE);
577 ok_long(cbValue, sizeof(DWORD));
578 cbValue = sizeof(szText);
579 error = RegQueryValueExW(hSubKey, L"Name2", NULL, &dwType, (BYTE*)szText, &cbValue);
581 ok_long(dwType, REG_SZ);
582 ok_wstr(szText, L"StrValue");
583 cbValue = sizeof(guid_and_extra);
584 error = RegQueryValueExW(hSubKey, L"Name4", NULL, &dwType, (BYTE*)&guid_and_extra, &cbValue);
586 ok_long(dwType, REG_BINARY);
587 ok_int(memcmp(&guid_and_extra, &GUID_NULL, sizeof(GUID)), 0);
588 ok_int(memcmp(&guid_and_extra[sizeof(GUID)], &IID_IShellLinkW, sizeof(GUID)), 0);
589 RegCloseKey(hSubKey);
590
591 // Create as read-only
593 IID_IPropertyBag, (void **)&pPropBag);
594 ok_long(hr, S_OK);
595
596 // Read UI4
597 VariantInit(&vari);
598 hr = pPropBag->Read(L"Name1", &vari, NULL);
599 ok_long(hr, S_OK);
600 ok_long(V_VT(&vari), VT_UI4);
601 ok_long(V_UI4(&vari), 0xDEADFACE);
602 VariantClear(&vari);
603
604 // Write UI4
605 VariantInit(&vari);
606 V_VT(&vari) = VT_UI4;
607 V_UI4(&vari) = 0xDEADFACE;
608 hr = pPropBag->Write(L"Name1", &vari);
610 VariantClear(&vari);
611
612 pPropBag->Release();
613
614 // Create as write-only IPropertyBag2
616 IID_IPropertyBag2, (void **)&pPropBag);
617 ok_long(hr, S_OK);
618
619 // Write UI4
620 VariantInit(&vari);
621 V_VT(&vari) = VT_UI4;
622 V_UI4(&vari) = 0xDEADFACE;
623 hr = pPropBag->Write(L"Name3", &vari);
625 VariantClear(&vari);
626
627 // Read UI4
628 VariantInit(&vari);
629 V_UI4(&vari) = 0xFEEDF00D;
630 hr = pPropBag->Read(L"Name3", &vari, NULL);
632 ok_int(V_VT(&vari), VT_EMPTY);
633 ok_long(V_UI4(&vari), 0xFEEDF00D);
634 VariantClear(&vari);
635
636 pPropBag->Release();
637
638 // Clean up
639 RegDeleteKeyW(hKey, L"PropBagTest");
641}
#define RegCloseKey(hKey)
Definition: registry.h:49
#define E_NOTIMPL
Definition: ddrawi.h:99
#define ERROR_SUCCESS
Definition: deptool.c:10
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3333
LONG WINAPI RegDeleteKeyW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey)
Definition: reg.c:1239
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4103
LONG WINAPI RegCreateKeyW(HKEY hKey, LPCWSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:1201
@ VT_UNKNOWN
Definition: compat.h:2308
HRESULT WINAPI SHCreatePropertyBagOnRegKey(HKEY hKey, LPCWSTR subkey, DWORD grfMode, REFIID riid, void **ppv)
Definition: ordinal.c:5177
#define FillMemory(BUF, SIZ, MASK)
Definition: strucsup.c:31
FxAutoRegKey hKey
HRESULT Read([out, size_is(cb), length_is(*pcbRead)] void *pv, [in] ULONG cb, [out] ULONG *pcbRead)
#define GUID_NULL
Definition: ks.h:106
#define REG_SZ
Definition: layer.c:22
const GUID * guid
#define error(str)
Definition: mkdosfs.c:1605
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
#define REG_BINARY
Definition: nt_native.h:1496
#define KEY_READ
Definition: nt_native.h:1023
#define STGM_CREATE
Definition: objbase.h:926
#define V_UNKNOWN(A)
Definition: oleauto.h:281
long LONG
Definition: pedump.c:60
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
IStream *WINAPI SHCreateMemStream(const BYTE *lpbData, UINT dwDataLen)
Definition: regstream.c:652
#define REG_DWORD
Definition: sdbapi.c:596
#define HRESULT_FROM_WIN32(x)
Definition: winerror.h:92
#define HKEY_CURRENT_USER
Definition: winreg.h:11
unsigned char BYTE
Definition: xxhash.c:193

Referenced by START_TEST().

◆ SHPropertyBag_PerScreenRes()

static void SHPropertyBag_PerScreenRes ( void  )
static

Definition at line 827 of file SHPropertyBag.cpp.

828{
829 HDC hDC = GetDC(NULL);
830 INT cxWidth = GetDeviceCaps(hDC, HORZRES);
831 INT cyHeight = GetDeviceCaps(hDC, VERTRES);
832 INT cMonitors = GetSystemMetrics(SM_CMONITORS);
834
835 WCHAR szBuff1[64], szBuff2[64];
836 StringCchPrintfW(szBuff1, _countof(szBuff1), L"%dx%d(%d)", cxWidth, cyHeight, cMonitors);
837
838 szBuff2[0] = UNICODE_NULL;
839 SHGetPerScreenResName(szBuff2, _countof(szBuff2), 0);
840 ok_wstr(szBuff1, szBuff2);
841}
static HDC hDC
Definition: 3dtext.c:33
static HDC
Definition: imagelist.c:92
#define UNICODE_NULL
EXTERN_C INT WINAPI SHGetPerScreenResName(_Out_writes_(cchBuffer) LPWSTR pszBuffer, _In_ INT cchBuffer, _In_ DWORD dwReserved)
Definition: propbag.cpp:1938
STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:530
int32_t INT
Definition: typedefs.h:58
#define HORZRES
Definition: wingdi.h:716
int WINAPI GetDeviceCaps(_In_opt_ HDC, _In_ int)
#define VERTRES
Definition: wingdi.h:717
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
HDC WINAPI GetDC(_In_opt_ HWND)
#define SM_CMONITORS
Definition: winuser.h:1040
int WINAPI GetSystemMetrics(_In_ int)

Referenced by START_TEST().

◆ SHPropertyBag_ReadTest()

static void SHPropertyBag_ReadTest ( void  )
static

Definition at line 156 of file SHPropertyBag.cpp.

157{
158 HRESULT hr;
160 BOOL bValue = 0xDEADFACE;
161 SHORT sValue = 0xDEADu;
162 LONG lValue = 0xDEADDEAD;
163 DWORD dwValue = 0xFEEDF00D;
164 BSTR bstr = NULL;
165 POINTL ptl = { 0xEEEE, 0xDDDD };
166 POINTS pts = { 0x2222, 0x3333 };
167 RECTL rcl = { 123, 456, 789, 101112 };
168 GUID guid = { 0 };
169
170 ResetTest(VT_BOOL, L"BOOL1");
172 ok_long(hr, S_OK);
173 ok_int(s_cRead, 1);
174 ok_int(s_cWrite, 0);
175
176 ResetTest(VT_UI2, L"SHORT1");
178 ok_long(hr, S_OK);
179 ok_int(s_cRead, 1);
180 ok_int(s_cWrite, 0);
181
182 ResetTest(VT_I4, L"LONG1");
184 ok_long(hr, S_OK);
185 ok_int(s_cRead, 1);
186 ok_int(s_cWrite, 0);
187
188 ResetTest(VT_UI4, L"DWORD1");
190 ok_long(hr, S_OK);
191 ok_int(s_cRead, 1);
192 ok_int(s_cWrite, 0);
193
194 ResetTest(VT_BSTR, L"Str1");
196 ok_long(hr, S_OK);
197 ok_int(s_cRead, 1);
198 ok_int(s_cWrite, 0);
199 SysFreeString(bstr);
200
201 ResetTest(VT_I4, L"POINTL1.x", L"POINTL1.y");
202 hr = SHPropertyBag_ReadPOINTL(&dummy, L"POINTL1", &ptl);
203 ok_long(hr, S_OK);
204 ok_int(s_cRead, 2);
205 ok_int(s_cWrite, 0);
206
207 ResetTest(VT_I4, L"POINTS1.x", L"POINTS1.y");
208 hr = SHPropertyBag_ReadPOINTS(&dummy, L"POINTS1", &pts);
209 ok_long(hr, S_OK);
210 ok_int(s_cRead, 2);
211 ok_int(s_cWrite, 0);
212
213 ResetTest(VT_I4, L"RECTL1.left", L"RECTL1.top", L"RECTL1.right", L"RECTL1.bottom");
214 hr = SHPropertyBag_ReadRECTL(&dummy, L"RECTL1", &rcl);
215 ok_long(hr, S_OK);
216 ok_int(s_cRead, 4);
217 ok_int(s_cWrite, 0);
218
219 ResetTest(VT_I4, L"RECTL2.left", L"RECTL2.top", L"RECTL2.right", L"RECTL2.bottom");
220 hr = SHPropertyBag_ReadRECTL(&dummy, L"RECTL2", &rcl);
221 ok_long(hr, E_FAIL);
222 ok_int(s_cRead, 2);
223 ok_int(s_cWrite, 0);
224
225 ResetTest(VT_EMPTY, L"GUID1");
226 hr = SHPropertyBag_ReadGUID(&dummy, L"GUID1", &guid);
227 ok_long(hr, S_OK);
228 ok_int(s_cRead, 1);
229 ok_int(s_cWrite, 0);
230 ok_int(IsEqualGUID(guid, IID_IShellLinkW), TRUE);
231
232 ResetTest(VT_EMPTY, L"GUID2");
233 hr = SHPropertyBag_ReadGUID(&dummy, L"GUID2", &guid);
234 ok_long(hr, S_OK);
235 ok_int(s_cRead, 1);
236 ok_int(s_cWrite, 0);
238
239 ResetTest(VT_EMPTY, L"GUID3");
241 hr = SHPropertyBag_ReadGUID(&dummy, L"GUID3", &guid);
242
245 else
246 ok_long(hr, S_OK);
247
248 ok_int(s_cRead, 1);
249 ok_int(s_cWrite, 0);
251}
static void ResetTest(VARTYPE vt, LPCWSTR pszName0=NULL, LPCWSTR pszName1=NULL, LPCWSTR pszName2=NULL, LPCWSTR pszName3=NULL)
const GUID IID_IUnknown
#define E_INVALIDARG
Definition: ddrawi.h:101
OLECHAR * BSTR
Definition: compat.h:2293
@ VT_UI2
Definition: compat.h:2312
@ VT_I4
Definition: compat.h:2298
@ VT_BOOL
Definition: compat.h:2306
HRESULT WINAPI SHPropertyBag_ReadLONG(IPropertyBag *ppb, LPCWSTR pszPropName, LPLONG pValue)
Definition: ordinal.c:5585
unsigned int BOOL
Definition: ntddk_ex.h:94
void WINAPI DECLSPEC_HOTPATCH SysFreeString(BSTR str)
Definition: oleaut.c:271
short SHORT
Definition: pedump.c:59
#define IID_IExtractIcon
Definition: shlguid.h:132
HRESULT WINAPI SHPropertyBag_ReadDWORD(IPropertyBag *ppb, LPCWSTR pszPropName, DWORD *pdwValue)
HRESULT WINAPI SHPropertyBag_ReadSHORT(IPropertyBag *ppb, LPCWSTR pszPropName, SHORT *psValue)
HRESULT WINAPI SHPropertyBag_ReadGUID(IPropertyBag *ppb, LPCWSTR pszPropName, GUID *pguid)
HRESULT WINAPI SHPropertyBag_ReadPOINTS(IPropertyBag *ppb, LPCWSTR pszPropName, POINTS *ppts)
HRESULT WINAPI SHPropertyBag_ReadPOINTL(IPropertyBag *ppb, LPCWSTR pszPropName, POINTL *pptl)
HRESULT WINAPI SHPropertyBag_ReadBSTR(IPropertyBag *ppb, LPCWSTR pszPropName, BSTR *pbstr)
HRESULT WINAPI SHPropertyBag_ReadRECTL(IPropertyBag *ppb, LPCWSTR pszPropName, RECTL *prcl)
HRESULT WINAPI SHPropertyBag_ReadBOOL(IPropertyBag *ppb, LPCWSTR pszPropName, BOOL *pbValue)

Referenced by START_TEST().

◆ SHPropertyBag_SHSetIniStringW()

static void SHPropertyBag_SHSetIniStringW ( void  )
static

Definition at line 643 of file SHPropertyBag.cpp.

644{
646 WCHAR szValue[MAX_PATH];
647 BOOL bRet;
648 DWORD dwRet;
649
650 ExpandEnvironmentStringsW(L"%TEMP%\\SHSetIniString.ini", szIniFile, _countof(szIniFile));
651
653
654 trace("%ls\n", szIniFile);
655
656 bRet = SHSetIniStringW(L"TestSection", L"Key", L"Value", szIniFile);
657 ok_int(bRet, TRUE);
658
660
661 dwRet = SHGetIniStringW(L"TestSection", L"Key", szValue, _countof(szValue), szIniFile);
662 ok_long(dwRet, 5);
663 ok_wstr(szValue, L"Value");
664
665 bRet = SHSetIniStringW(L"TestSection", L"Key", NULL, szIniFile);
666 ok_int(bRet, TRUE);
667
669
670 dwRet = SHGetIniStringW(L"TestSection", L"Key", szValue, _countof(szValue), szIniFile);
671 ok_long(dwRet, 0);
672 ok_wstr(szValue, L"");
673
674 bRet = SHSetIniStringW(L"TestSection", L"Key", L"ABC\x3042\x3044\x3046\x2665", szIniFile);
675 ok_int(bRet, TRUE);
676
678
679 dwRet = SHGetIniStringW(L"TestSection", L"Key", szValue, _countof(szValue), szIniFile);
680 ok_long(dwRet, 7);
681 ok_wstr(szValue, L"ABC\x3042\x3044\x3046\x2665");
682
683 szValue[0] = 0x3000;
684 szValue[1] = UNICODE_NULL;
685 dwRet = SHGetIniStringW(L"TestSection", L"NotExistentKey", szValue, _countof(szValue), szIniFile);
686 ok_long(dwRet, 0);
687 ok_wstr(szValue, L"");
688
690}
BOOL WINAPI SHSetIniStringW(LPCWSTR appName, LPCWSTR keyName, LPCWSTR str, LPCWSTR filename)
Definition: ordinal.c:3418
DWORD WINAPI SHGetIniStringW(LPCWSTR appName, LPCWSTR keyName, LPWSTR out, DWORD outLen, LPCWSTR filename)
Definition: ordinal.c:3371

Referenced by START_TEST().

◆ SHPropertyBag_WriteTest()

static void SHPropertyBag_WriteTest ( void  )
static

Definition at line 253 of file SHPropertyBag.cpp.

254{
255 HRESULT hr;
257
258 ResetTest(VT_EMPTY, L"EMPTY1");
260 ok_long(hr, S_OK);
261 ok_int(s_cRead, 0);
262 ok_int(s_cWrite, 1);
263
264 ResetTest(VT_BOOL, L"BOOL1");
266 ok_long(hr, S_OK);
267 ok_int(s_cRead, 0);
268 ok_int(s_cWrite, 1);
269
270 ResetTest(VT_UI2, L"SHORT1");
272 ok_long(hr, S_OK);
273 ok_int(s_cRead, 0);
274 ok_int(s_cWrite, 1);
275
276 ResetTest(VT_I4, L"LONG1");
278 ok_long(hr, S_OK);
279 ok_int(s_cRead, 0);
280 ok_int(s_cWrite, 1);
281
282 ResetTest(VT_UI4, L"DWORD1");
284 ok_long(hr, S_OK);
285 ok_int(s_cRead, 0);
286 ok_int(s_cWrite, 1);
287
288 ResetTest(VT_BSTR, L"Str1");
290 ok_long(hr, S_OK);
291 ok_int(s_cRead, 0);
292 ok_int(s_cWrite, 1);
293
294 ResetTest(VT_I4, L"POINTL1.x", L"POINTL1.y");
295 POINTL ptl = { 0xEEEE, 0xDDDD };
296 hr = SHPropertyBag_WritePOINTL(&dummy, L"POINTL1", &ptl);
297 ok_long(hr, S_OK);
298 ok_int(s_cRead, 0);
299 ok_int(s_cWrite, 2);
300
301 ResetTest(VT_I4, L"POINTS1.x", L"POINTS1.y");
302 POINTS pts = { 0x2222, 0x3333 };
303 hr = SHPropertyBag_WritePOINTS(&dummy, L"POINTS1", &pts);
304 ok_long(hr, S_OK);
305 ok_int(s_cRead, 0);
306 ok_int(s_cWrite, 2);
307
308 ResetTest(VT_I4, L"RECTL1.left", L"RECTL1.top", L"RECTL1.right", L"RECTL1.bottom");
309 RECTL rcl = { 123, 456, 789, 101112 };
310 hr = SHPropertyBag_WriteRECTL(&dummy, L"RECTL1", &rcl);
311 ok_long(hr, S_OK);
312 ok_int(s_cRead, 0);
313 ok_int(s_cWrite, 4);
314
315 ResetTest(VT_I4, L"RECTL2.left", L"RECTL2.top", L"RECTL2.right", L"RECTL2.bottom");
316 hr = SHPropertyBag_WriteRECTL(&dummy, L"RECTL2", &rcl);
317 ok_long(hr, S_OK);
318 ok_int(s_cRead, 0);
319 ok_int(s_cWrite, 5);
320
321 GUID guid;
322 ZeroMemory(&guid, sizeof(guid));
323 ResetTest(VT_BSTR, L"GUID1");
324 hr = SHPropertyBag_WriteGUID(&dummy, L"GUID1", &guid);
325 ok_long(hr, S_OK);
326 ok_int(s_cRead, 0);
327 ok_int(s_cWrite, 1);
328}
HRESULT WINAPI SHPropertyBag_WriteRECTL(IPropertyBag *ppb, LPCWSTR pszPropName, const RECTL *prcl)
HRESULT WINAPI SHPropertyBag_WriteBOOL(IPropertyBag *ppb, LPCWSTR pszPropName, BOOL bValue)
HRESULT WINAPI SHPropertyBag_WriteGUID(IPropertyBag *ppb, LPCWSTR pszPropName, const GUID *pguid)
HRESULT WINAPI SHPropertyBag_WriteSHORT(IPropertyBag *ppb, LPCWSTR pszPropName, SHORT sValue)
HRESULT WINAPI SHPropertyBag_Delete(IPropertyBag *ppb, LPCWSTR pszPropName)
HRESULT WINAPI SHPropertyBag_WriteStr(IPropertyBag *ppb, LPCWSTR pszPropName, LPCWSTR pszValue)
HRESULT WINAPI SHPropertyBag_WritePOINTL(IPropertyBag *ppb, LPCWSTR pszPropName, const POINTL *pptl)
HRESULT WINAPI SHPropertyBag_WritePOINTS(IPropertyBag *ppb, LPCWSTR pszPropName, const POINTS *ppts)
HRESULT WINAPI SHPropertyBag_WriteLONG(IPropertyBag *ppb, LPCWSTR pszPropName, LONG lValue)
HRESULT WINAPI SHPropertyBag_WriteDWORD(IPropertyBag *ppb, LPCWSTR pszPropName, DWORD dwValue)
#define ZeroMemory
Definition: winbase.h:1712

Referenced by START_TEST().

◆ START_TEST()

START_TEST ( SHPropertyBag  )

Definition at line 843 of file SHPropertyBag.cpp.

844{
852}
static void SHPropertyBag_SHSetIniStringW(void)
static void SHPropertyBag_OnIniFile(void)
static void SHPropertyBag_WriteTest(void)
static void SHPropertyBag_PerScreenRes(void)
static void SHPropertyBag_ReadTest(void)
static void SHPropertyBag_OnMemory(void)
static void SHPropertyBag_OnRegKey(void)

Variable Documentation

◆ s_cRead

INT s_cRead = 0
static

◆ s_cWrite

INT s_cWrite = 0
static

◆ s_pszPropNames

◆ s_vt

VARTYPE s_vt
static

Definition at line 19 of file SHPropertyBag.cpp.

Referenced by CDummyPropertyBag::Read(), ResetTest(), and CDummyPropertyBag::Write().