diff options
| author | Sean Hall <r.sean.hall@gmail.com> | 2020-07-31 17:06:35 -0600 |
|---|---|---|
| committer | Sean Hall <r.sean.hall@gmail.com> | 2020-08-09 10:33:49 -0600 |
| commit | d21eed76c48960707561c45c492c10a6a23c052e (patch) | |
| tree | ebab09d099a699a24801fcfb4d7152cf82cc4a06 /src/test | |
| parent | ad80d6dc10f9bd6cb6a084857a8fb546cc55e756 (diff) | |
| download | wix-d21eed76c48960707561c45c492c10a6a23c052e.tar.gz wix-d21eed76c48960707561c45c492c10a6a23c052e.tar.bz2 wix-d21eed76c48960707561c45c492c10a6a23c052e.zip | |
WIXFEAT:4763 Change "string" variable type to literal and add "formatted".
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/BurnUnitTest/SearchTest.cpp | 87 | ||||
| -rw-r--r-- | src/test/BurnUnitTest/VariableHelpers.cpp | 4 | ||||
| -rw-r--r-- | src/test/BurnUnitTest/VariableHelpers.h | 2 | ||||
| -rw-r--r-- | src/test/BurnUnitTest/VariableTest.cpp | 69 | ||||
| -rw-r--r-- | src/test/BurnUnitTest/VariantTest.cpp | 56 |
5 files changed, 181 insertions, 37 deletions
diff --git a/src/test/BurnUnitTest/SearchTest.cpp b/src/test/BurnUnitTest/SearchTest.cpp index 48ab60aa..32107d87 100644 --- a/src/test/BurnUnitTest/SearchTest.cpp +++ b/src/test/BurnUnitTest/SearchTest.cpp | |||
| @@ -66,8 +66,8 @@ namespace Bootstrapper | |||
| 66 | pin_ptr<const WCHAR> wzDirectory1 = PtrToStringChars(this->TestContext->TestDirectory); | 66 | pin_ptr<const WCHAR> wzDirectory1 = PtrToStringChars(this->TestContext->TestDirectory); |
| 67 | pin_ptr<const WCHAR> wzDirectory2 = PtrToStringChars(System::IO::Path::Combine(this->TestContext->TestDirectory, gcnew String(L"none"))); | 67 | pin_ptr<const WCHAR> wzDirectory2 = PtrToStringChars(System::IO::Path::Combine(this->TestContext->TestDirectory, gcnew String(L"none"))); |
| 68 | 68 | ||
| 69 | VariableSetStringHelper(&variables, L"Directory1", wzDirectory1); | 69 | VariableSetStringHelper(&variables, L"Directory1", wzDirectory1, FALSE); |
| 70 | VariableSetStringHelper(&variables, L"Directory2", wzDirectory2); | 70 | VariableSetStringHelper(&variables, L"Directory2", wzDirectory2, FALSE); |
| 71 | 71 | ||
| 72 | LPCWSTR wzDocument = | 72 | LPCWSTR wzDocument = |
| 73 | L"<Bundle>" | 73 | L"<Bundle>" |
| @@ -117,8 +117,8 @@ namespace Bootstrapper | |||
| 117 | hr = FileVersion(wzFile2, &uliVersion.HighPart, &uliVersion.LowPart); | 117 | hr = FileVersion(wzFile2, &uliVersion.HighPart, &uliVersion.LowPart); |
| 118 | TestThrowOnFailure(hr, L"Failed to get DLL version."); | 118 | TestThrowOnFailure(hr, L"Failed to get DLL version."); |
| 119 | 119 | ||
| 120 | VariableSetStringHelper(&variables, L"File1", wzFile1); | 120 | VariableSetStringHelper(&variables, L"File1", wzFile1, FALSE); |
| 121 | VariableSetStringHelper(&variables, L"File2", wzFile2); | 121 | VariableSetStringHelper(&variables, L"File2", wzFile2, FALSE); |
| 122 | 122 | ||
| 123 | LPCWSTR wzDocument = | 123 | LPCWSTR wzDocument = |
| 124 | L"<Bundle>" | 124 | L"<Bundle>" |
| @@ -191,8 +191,8 @@ namespace Bootstrapper | |||
| 191 | Assert::True(SUCCEEDED(hr)); | 191 | Assert::True(SUCCEEDED(hr)); |
| 192 | } | 192 | } |
| 193 | 193 | ||
| 194 | VariableSetStringHelper(&variables, L"MyKey", L"SOFTWARE\\Microsoft\\WiX_Burn_UnitTest\\Value"); | 194 | VariableSetStringHelper(&variables, L"MyKey", L"SOFTWARE\\Microsoft\\WiX_Burn_UnitTest\\Value", FALSE); |
| 195 | VariableSetStringHelper(&variables, L"MyValue", L"String"); | 195 | VariableSetStringHelper(&variables, L"MyValue", L"String", FALSE); |
| 196 | 196 | ||
| 197 | LPCWSTR wzDocument = | 197 | LPCWSTR wzDocument = |
| 198 | L"<Bundle>" | 198 | L"<Bundle>" |
| @@ -219,8 +219,9 @@ namespace Bootstrapper | |||
| 219 | L" <RegistrySearch Id='Search21' Type='value' Root='HKCU' Key='SOFTWARE\\Classes\\CLSID\\WiX_Burn_UnitTest\\Bitness' Value='TestStringSpecificToBitness' Variable='Variable21' VariableType='string' Win64='no' />" | 219 | L" <RegistrySearch Id='Search21' Type='value' Root='HKCU' Key='SOFTWARE\\Classes\\CLSID\\WiX_Burn_UnitTest\\Bitness' Value='TestStringSpecificToBitness' Variable='Variable21' VariableType='string' Win64='no' />" |
| 220 | L" <RegistrySearch Id='Search22' Type='value' Root='HKCU' Key='SOFTWARE\\Classes\\CLSID\\WiX_Burn_UnitTest\\Bitness' Value='TestStringSpecificToBitness' Variable='Variable22' VariableType='string' Win64='yes' />" | 220 | L" <RegistrySearch Id='Search22' Type='value' Root='HKCU' Key='SOFTWARE\\Classes\\CLSID\\WiX_Burn_UnitTest\\Bitness' Value='TestStringSpecificToBitness' Variable='Variable22' VariableType='string' Win64='yes' />" |
| 221 | L" <RegistrySearch Id='Search23' Type='exists' Root='HKU' Key='.DEFAULT\\Environment' Variable='Variable23' />" | 221 | L" <RegistrySearch Id='Search23' Type='exists' Root='HKU' Key='.DEFAULT\\Environment' Variable='Variable23' />" |
| 222 | L" <RegistrySearch Id='Search23' Type='exists' Root='HKU' Key='.DEFAULT\\System\\NetworkServiceSidSubkeyDoesNotExist' Variable='Variable24' />" | 222 | L" <RegistrySearch Id='Search24' Type='exists' Root='HKU' Key='.DEFAULT\\System\\NetworkServiceSidSubkeyDoesNotExist' Variable='Variable24' />" |
| 223 | L" <RegistrySearch Id='Search24' Type='value' Root='HKCR' Key='.msi' Variable='Variable25' VariableType='string' />" | 223 | L" <RegistrySearch Id='Search25' Type='value' Root='HKCR' Key='.msi' Variable='Variable25' VariableType='string' />" |
| 224 | L" <RegistrySearch Id='Search26' Type='value' Root='HKCR' Key='.msi' Variable='Variable26' VariableType='formatted' />" | ||
| 224 | L"</Bundle>"; | 225 | L"</Bundle>"; |
| 225 | 226 | ||
| 226 | // load XML document | 227 | // load XML document |
| @@ -263,6 +264,7 @@ namespace Bootstrapper | |||
| 263 | Assert::Equal(1ll, VariableGetNumericHelper(&variables, L"Variable23")); | 264 | Assert::Equal(1ll, VariableGetNumericHelper(&variables, L"Variable23")); |
| 264 | Assert::Equal(0ll, VariableGetNumericHelper(&variables, L"Variable24")); | 265 | Assert::Equal(0ll, VariableGetNumericHelper(&variables, L"Variable24")); |
| 265 | Assert::Equal<String^>(gcnew String(L"Msi.Package"), VariableGetStringHelper(&variables, L"Variable25")); | 266 | Assert::Equal<String^>(gcnew String(L"Msi.Package"), VariableGetStringHelper(&variables, L"Variable25")); |
| 267 | Assert::Equal<String^>(gcnew String(L"Msi.Package"), VariableGetStringHelper(&variables, L"Variable26")); | ||
| 266 | } | 268 | } |
| 267 | finally | 269 | finally |
| 268 | { | 270 | { |
| @@ -525,6 +527,75 @@ namespace Bootstrapper | |||
| 525 | SearchesUninitialize(&searches); | 527 | SearchesUninitialize(&searches); |
| 526 | } | 528 | } |
| 527 | } | 529 | } |
| 530 | |||
| 531 | [Fact] | ||
| 532 | void SetVariableSearchTest() | ||
| 533 | { | ||
| 534 | HRESULT hr = S_OK; | ||
| 535 | IXMLDOMElement* pixeBundle = NULL; | ||
| 536 | BURN_VARIABLES variables = { }; | ||
| 537 | BURN_SEARCHES searches = { }; | ||
| 538 | BURN_EXTENSIONS burnExtensions = { }; | ||
| 539 | try | ||
| 540 | { | ||
| 541 | LPCWSTR wzDocument = | ||
| 542 | L"<Bundle>" | ||
| 543 | L" <SetVariable Id='Search1' Type='string' Value='VAL1' Variable='PROP1' />" | ||
| 544 | L" <SetVariable Id='Search2' Type='numeric' Value='2' Variable='PROP2' />" | ||
| 545 | L" <SetVariable Id='Search3' Type='string' Value='VAL3' Variable='PROP3' />" | ||
| 546 | L" <SetVariable Id='Search4' Type='string' Value='VAL4' Variable='PROP4' />" | ||
| 547 | L" <SetVariable Id='Search5' Type='string' Value='VAL5' Variable='PROP5' />" | ||
| 548 | L" <SetVariable Id='Search6' Type='string' Value='VAL6' Variable='PROP6' />" | ||
| 549 | L" <SetVariable Id='Search7' Type='string' Value='7' Variable='PROP7' />" | ||
| 550 | L" <SetVariable Id='Search8' Type='version' Value='1.1.0.0' Variable='PROP8' />" | ||
| 551 | L" <SetVariable Id='Search9' Type='formatted' Value='[VAL9]' Variable='PROP9' />" | ||
| 552 | L" <SetVariable Id='Search10' Type='numeric' Value='42' Variable='OVERWRITTEN_STRING' />" | ||
| 553 | L" <SetVariable Id='Search11' Type='string' Value='NEW' Variable='OVERWRITTEN_NUMBER' />" | ||
| 554 | L" <SetVariable Id='Search12' Variable='REMOVED_NUMBER' />" | ||
| 555 | L"</Bundle>"; | ||
| 556 | |||
| 557 | hr = VariableInitialize(&variables); | ||
| 558 | TestThrowOnFailure(hr, L"Failed to initialize variables."); | ||
| 559 | |||
| 560 | // set variables | ||
| 561 | VariableSetStringHelper(&variables, L"OVERWRITTEN_STRING", L"ORIGINAL", FALSE); | ||
| 562 | VariableSetNumericHelper(&variables, L"OVERWRITTEN_NUMBER", 5); | ||
| 563 | VariableSetNumericHelper(&variables, L"REMOVED_NUMBER", 22); | ||
| 564 | |||
| 565 | // load XML document | ||
| 566 | LoadBundleXmlHelper(wzDocument, &pixeBundle); | ||
| 567 | |||
| 568 | hr = SearchesParseFromXml(&searches, &burnExtensions, pixeBundle); | ||
| 569 | TestThrowOnFailure(hr, L"Failed to parse searches from XML."); | ||
| 570 | |||
| 571 | // execute searches | ||
| 572 | hr = SearchesExecute(&searches, &variables); | ||
| 573 | TestThrowOnFailure(hr, L"Failed to execute searches."); | ||
| 574 | |||
| 575 | // check variable values | ||
| 576 | Assert::Equal<String^>(gcnew String(L"VAL1"), VariableGetStringHelper(&variables, L"PROP1")); | ||
| 577 | Assert::Equal(2ll, VariableGetNumericHelper(&variables, L"PROP2")); | ||
| 578 | Assert::Equal<String^>(gcnew String(L"2"), VariableGetStringHelper(&variables, L"PROP2")); | ||
| 579 | Assert::Equal<String^>(gcnew String(L"VAL3"), VariableGetStringHelper(&variables, L"PROP3")); | ||
| 580 | Assert::Equal<String^>(gcnew String(L"VAL4"), VariableGetStringHelper(&variables, L"PROP4")); | ||
| 581 | Assert::Equal<String^>(gcnew String(L"VAL5"), VariableGetStringHelper(&variables, L"PROP5")); | ||
| 582 | Assert::Equal<String^>(gcnew String(L"VAL6"), VariableGetStringHelper(&variables, L"PROP6")); | ||
| 583 | Assert::Equal(7ll, VariableGetNumericHelper(&variables, L"PROP7")); | ||
| 584 | Assert::Equal(MAKEQWORDVERSION(1, 1, 0, 0), VariableGetVersionHelper(&variables, L"PROP8")); | ||
| 585 | Assert::Equal<String^>(gcnew String(L"1.1.0.0"), VariableGetStringHelper(&variables, L"PROP8")); | ||
| 586 | Assert::Equal<String^>(gcnew String(L"[VAL9]"), VariableGetStringHelper(&variables, L"PROP9")); | ||
| 587 | |||
| 588 | Assert::Equal(42ll, VariableGetNumericHelper(&variables, L"OVERWRITTEN_STRING")); | ||
| 589 | Assert::Equal<String^>(gcnew String(L"NEW"), VariableGetStringHelper(&variables, L"OVERWRITTEN_NUMBER")); | ||
| 590 | Assert::Equal((int)BURN_VARIANT_TYPE_NONE, VariableGetTypeHelper(&variables, L"REMOVED_NUMBER")); | ||
| 591 | } | ||
| 592 | finally | ||
| 593 | { | ||
| 594 | ReleaseObject(pixeBundle); | ||
| 595 | VariablesUninitialize(&variables); | ||
| 596 | SearchesUninitialize(&searches); | ||
| 597 | } | ||
| 598 | } | ||
| 528 | }; | 599 | }; |
| 529 | } | 600 | } |
| 530 | } | 601 | } |
diff --git a/src/test/BurnUnitTest/VariableHelpers.cpp b/src/test/BurnUnitTest/VariableHelpers.cpp index 9ce46a76..fdfb9191 100644 --- a/src/test/BurnUnitTest/VariableHelpers.cpp +++ b/src/test/BurnUnitTest/VariableHelpers.cpp | |||
| @@ -17,11 +17,11 @@ namespace Test | |||
| 17 | { | 17 | { |
| 18 | namespace Bootstrapper | 18 | namespace Bootstrapper |
| 19 | { | 19 | { |
| 20 | void VariableSetStringHelper(BURN_VARIABLES* pVariables, LPCWSTR wzVariable, LPCWSTR wzValue) | 20 | void VariableSetStringHelper(BURN_VARIABLES* pVariables, LPCWSTR wzVariable, LPCWSTR wzValue, BOOL fFormatted) |
| 21 | { | 21 | { |
| 22 | HRESULT hr = S_OK; | 22 | HRESULT hr = S_OK; |
| 23 | 23 | ||
| 24 | hr = VariableSetString(pVariables, wzVariable, wzValue, FALSE); | 24 | hr = VariableSetString(pVariables, wzVariable, wzValue, FALSE, fFormatted); |
| 25 | TestThrowOnFailure2(hr, L"Failed to set %s to: %s", wzVariable, wzValue); | 25 | TestThrowOnFailure2(hr, L"Failed to set %s to: %s", wzVariable, wzValue); |
| 26 | } | 26 | } |
| 27 | 27 | ||
diff --git a/src/test/BurnUnitTest/VariableHelpers.h b/src/test/BurnUnitTest/VariableHelpers.h index 98c52649..8c2b081a 100644 --- a/src/test/BurnUnitTest/VariableHelpers.h +++ b/src/test/BurnUnitTest/VariableHelpers.h | |||
| @@ -14,7 +14,7 @@ namespace Bootstrapper | |||
| 14 | { | 14 | { |
| 15 | 15 | ||
| 16 | 16 | ||
| 17 | void VariableSetStringHelper(BURN_VARIABLES* pVariables, LPCWSTR wzVariable, LPCWSTR wzValue); | 17 | void VariableSetStringHelper(BURN_VARIABLES* pVariables, LPCWSTR wzVariable, LPCWSTR wzValue, BOOL fFormatted); |
| 18 | void VariableSetNumericHelper(BURN_VARIABLES* pVariables, LPCWSTR wzVariable, LONGLONG llValue); | 18 | void VariableSetNumericHelper(BURN_VARIABLES* pVariables, LPCWSTR wzVariable, LONGLONG llValue); |
| 19 | void VariableSetVersionHelper(BURN_VARIABLES* pVariables, LPCWSTR wzVariable, DWORD64 qwValue); | 19 | void VariableSetVersionHelper(BURN_VARIABLES* pVariables, LPCWSTR wzVariable, DWORD64 qwValue); |
| 20 | System::String^ VariableGetStringHelper(BURN_VARIABLES* pVariables, LPCWSTR wzVariable); | 20 | System::String^ VariableGetStringHelper(BURN_VARIABLES* pVariables, LPCWSTR wzVariable); |
diff --git a/src/test/BurnUnitTest/VariableTest.cpp b/src/test/BurnUnitTest/VariableTest.cpp index 7d670744..0b49a530 100644 --- a/src/test/BurnUnitTest/VariableTest.cpp +++ b/src/test/BurnUnitTest/VariableTest.cpp | |||
| @@ -35,21 +35,22 @@ namespace Bootstrapper | |||
| 35 | TestThrowOnFailure(hr, L"Failed to initialize variables."); | 35 | TestThrowOnFailure(hr, L"Failed to initialize variables."); |
| 36 | 36 | ||
| 37 | // set variables | 37 | // set variables |
| 38 | VariableSetStringHelper(&variables, L"PROP1", L"VAL1"); | 38 | VariableSetStringHelper(&variables, L"PROP1", L"VAL1", FALSE); |
| 39 | VariableSetNumericHelper(&variables, L"PROP2", 2); | 39 | VariableSetNumericHelper(&variables, L"PROP2", 2); |
| 40 | VariableSetStringHelper(&variables, L"PROP5", L"VAL5"); | 40 | VariableSetStringHelper(&variables, L"PROP5", L"VAL5", FALSE); |
| 41 | VariableSetStringHelper(&variables, L"PROP3", L"VAL3"); | 41 | VariableSetStringHelper(&variables, L"PROP3", L"VAL3", FALSE); |
| 42 | VariableSetStringHelper(&variables, L"PROP4", L"VAL4"); | 42 | VariableSetStringHelper(&variables, L"PROP4", L"VAL4", FALSE); |
| 43 | VariableSetStringHelper(&variables, L"PROP6", L"VAL6"); | 43 | VariableSetStringHelper(&variables, L"PROP6", L"VAL6", FALSE); |
| 44 | VariableSetStringHelper(&variables, L"PROP7", L"7"); | 44 | VariableSetStringHelper(&variables, L"PROP7", L"7", FALSE); |
| 45 | VariableSetVersionHelper(&variables, L"PROP8", MAKEQWORDVERSION(1,1,0,0)); | 45 | VariableSetVersionHelper(&variables, L"PROP8", MAKEQWORDVERSION(1,1,0,0)); |
| 46 | VariableSetStringHelper(&variables, L"PROP9", L"[VAL9]", TRUE); | ||
| 46 | 47 | ||
| 47 | // set overwritten variables | 48 | // set overwritten variables |
| 48 | VariableSetStringHelper(&variables, L"OVERWRITTEN_STRING", L"ORIGINAL"); | 49 | VariableSetStringHelper(&variables, L"OVERWRITTEN_STRING", L"ORIGINAL", FALSE); |
| 49 | VariableSetNumericHelper(&variables, L"OVERWRITTEN_STRING", 42); | 50 | VariableSetNumericHelper(&variables, L"OVERWRITTEN_STRING", 42); |
| 50 | 51 | ||
| 51 | VariableSetNumericHelper(&variables, L"OVERWRITTEN_NUMBER", 5); | 52 | VariableSetNumericHelper(&variables, L"OVERWRITTEN_NUMBER", 5); |
| 52 | VariableSetStringHelper(&variables, L"OVERWRITTEN_NUMBER", L"NEW"); | 53 | VariableSetStringHelper(&variables, L"OVERWRITTEN_NUMBER", L"NEW", FALSE); |
| 53 | 54 | ||
| 54 | // get and verify variable values | 55 | // get and verify variable values |
| 55 | Assert::Equal<String^>(gcnew String(L"VAL1"), VariableGetStringHelper(&variables, L"PROP1")); | 56 | Assert::Equal<String^>(gcnew String(L"VAL1"), VariableGetStringHelper(&variables, L"PROP1")); |
| @@ -62,6 +63,7 @@ namespace Bootstrapper | |||
| 62 | Assert::Equal(7ll, VariableGetNumericHelper(&variables, L"PROP7")); | 63 | Assert::Equal(7ll, VariableGetNumericHelper(&variables, L"PROP7")); |
| 63 | Assert::Equal(MAKEQWORDVERSION(1,1,0,0), VariableGetVersionHelper(&variables, L"PROP8")); | 64 | Assert::Equal(MAKEQWORDVERSION(1,1,0,0), VariableGetVersionHelper(&variables, L"PROP8")); |
| 64 | Assert::Equal<String^>(gcnew String(L"1.1.0.0"), VariableGetStringHelper(&variables, L"PROP8")); | 65 | Assert::Equal<String^>(gcnew String(L"1.1.0.0"), VariableGetStringHelper(&variables, L"PROP8")); |
| 66 | Assert::Equal<String^>(gcnew String(L"[VAL9]"), VariableGetStringHelper(&variables, L"PROP9")); | ||
| 65 | 67 | ||
| 66 | Assert::Equal(42ll, VariableGetNumericHelper(&variables, L"OVERWRITTEN_STRING")); | 68 | Assert::Equal(42ll, VariableGetNumericHelper(&variables, L"OVERWRITTEN_STRING")); |
| 67 | Assert::Equal<String^>(gcnew String(L"NEW"), VariableGetStringHelper(&variables, L"OVERWRITTEN_NUMBER")); | 69 | Assert::Equal<String^>(gcnew String(L"NEW"), VariableGetStringHelper(&variables, L"OVERWRITTEN_NUMBER")); |
| @@ -87,6 +89,7 @@ namespace Bootstrapper | |||
| 87 | L" <Variable Id='Var3' Type='version' Value='1.2.3.4' Hidden='no' Persisted='no' />" | 89 | L" <Variable Id='Var3' Type='version' Value='1.2.3.4' Hidden='no' Persisted='no' />" |
| 88 | L" <Variable Id='Var4' Hidden='no' Persisted='no' />" | 90 | L" <Variable Id='Var4' Hidden='no' Persisted='no' />" |
| 89 | L" <Variable Id='Var5' Type='string' Value='' Hidden='no' Persisted='no' />" | 91 | L" <Variable Id='Var5' Type='string' Value='' Hidden='no' Persisted='no' />" |
| 92 | L" <Variable Id='Var6' Type='formatted' Value='[Formatted]' Hidden='no' Persisted='no' />" | ||
| 90 | L"</Bundle>"; | 93 | L"</Bundle>"; |
| 91 | 94 | ||
| 92 | hr = VariableInitialize(&variables); | 95 | hr = VariableInitialize(&variables); |
| @@ -103,10 +106,12 @@ namespace Bootstrapper | |||
| 103 | Assert::Equal((int)BURN_VARIANT_TYPE_STRING, VariableGetTypeHelper(&variables, L"Var2")); | 106 | Assert::Equal((int)BURN_VARIANT_TYPE_STRING, VariableGetTypeHelper(&variables, L"Var2")); |
| 104 | Assert::Equal((int)BURN_VARIANT_TYPE_VERSION, VariableGetTypeHelper(&variables, L"Var3")); | 107 | Assert::Equal((int)BURN_VARIANT_TYPE_VERSION, VariableGetTypeHelper(&variables, L"Var3")); |
| 105 | Assert::Equal((int)BURN_VARIANT_TYPE_NONE, VariableGetTypeHelper(&variables, L"Var4")); | 108 | Assert::Equal((int)BURN_VARIANT_TYPE_NONE, VariableGetTypeHelper(&variables, L"Var4")); |
| 109 | Assert::Equal((int)BURN_VARIANT_TYPE_FORMATTED, VariableGetTypeHelper(&variables, L"Var6")); | ||
| 106 | 110 | ||
| 107 | Assert::Equal(1ll, VariableGetNumericHelper(&variables, L"Var1")); | 111 | Assert::Equal(1ll, VariableGetNumericHelper(&variables, L"Var1")); |
| 108 | Assert::Equal<String^>(gcnew String(L"String value."), VariableGetStringHelper(&variables, L"Var2")); | 112 | Assert::Equal<String^>(gcnew String(L"String value."), VariableGetStringHelper(&variables, L"Var2")); |
| 109 | Assert::Equal(MAKEQWORDVERSION(1,2,3,4), VariableGetVersionHelper(&variables, L"Var3")); | 113 | Assert::Equal(MAKEQWORDVERSION(1,2,3,4), VariableGetVersionHelper(&variables, L"Var3")); |
| 114 | Assert::Equal<String^>(gcnew String(L"[Formatted]"), VariableGetStringHelper(&variables, L"Var6")); | ||
| 110 | } | 115 | } |
| 111 | finally | 116 | finally |
| 112 | { | 117 | { |
| @@ -128,9 +133,13 @@ namespace Bootstrapper | |||
| 128 | TestThrowOnFailure(hr, L"Failed to initialize variables."); | 133 | TestThrowOnFailure(hr, L"Failed to initialize variables."); |
| 129 | 134 | ||
| 130 | // set variables | 135 | // set variables |
| 131 | VariableSetStringHelper(&variables, L"PROP1", L"VAL1"); | 136 | VariableSetStringHelper(&variables, L"PROP1", L"VAL1", FALSE); |
| 132 | VariableSetStringHelper(&variables, L"PROP2", L"VAL2"); | 137 | VariableSetStringHelper(&variables, L"PROP2", L"VAL2", FALSE); |
| 133 | VariableSetNumericHelper(&variables, L"PROP3", 3); | 138 | VariableSetNumericHelper(&variables, L"PROP3", 3); |
| 139 | VariableSetStringHelper(&variables, L"PROP4", L"[PROP1]", FALSE); | ||
| 140 | VariableSetStringHelper(&variables, L"PROP5", L"[PROP2]", FALSE); | ||
| 141 | VariableSetStringHelper(&variables, L"PROP6", L"[PROP4]", TRUE); | ||
| 142 | VariableSetStringHelper(&variables, L"PROP7", L"[PROP5]", TRUE); | ||
| 134 | 143 | ||
| 135 | // test string formatting | 144 | // test string formatting |
| 136 | Assert::Equal<String^>(gcnew String(L"NOPROP"), VariableFormatStringHelper(&variables, L"NOPROP")); | 145 | Assert::Equal<String^>(gcnew String(L"NOPROP"), VariableFormatStringHelper(&variables, L"NOPROP")); |
| @@ -148,6 +157,10 @@ namespace Bootstrapper | |||
| 148 | Assert::Equal<String^>(gcnew String(L"[NONE"), VariableFormatStringHelper(&variables, L"[NONE")); | 157 | Assert::Equal<String^>(gcnew String(L"[NONE"), VariableFormatStringHelper(&variables, L"[NONE")); |
| 149 | Assert::Equal<String^>(gcnew String(L"VAL2"), VariableGetFormattedHelper(&variables, L"PROP2")); | 158 | Assert::Equal<String^>(gcnew String(L"VAL2"), VariableGetFormattedHelper(&variables, L"PROP2")); |
| 150 | Assert::Equal<String^>(gcnew String(L"3"), VariableGetFormattedHelper(&variables, L"PROP3")); | 159 | Assert::Equal<String^>(gcnew String(L"3"), VariableGetFormattedHelper(&variables, L"PROP3")); |
| 160 | Assert::Equal<String^>(gcnew String(L"[PROP1]"), VariableGetFormattedHelper(&variables, L"PROP4")); | ||
| 161 | Assert::Equal<String^>(gcnew String(L"[PROP2]"), VariableGetFormattedHelper(&variables, L"PROP5")); | ||
| 162 | Assert::Equal<String^>(gcnew String(L"[PROP1]"), VariableGetFormattedHelper(&variables, L"PROP6")); | ||
| 163 | Assert::Equal<String^>(gcnew String(L"[PROP2]"), VariableGetFormattedHelper(&variables, L"PROP7")); | ||
| 151 | 164 | ||
| 152 | hr = VariableFormatString(&variables, L"PRE [PROP1] POST", &scz, &cch); | 165 | hr = VariableFormatString(&variables, L"PRE [PROP1] POST", &scz, &cch); |
| 153 | TestThrowOnFailure(hr, L"Failed to format string"); | 166 | TestThrowOnFailure(hr, L"Failed to format string"); |
| @@ -186,15 +199,15 @@ namespace Bootstrapper | |||
| 186 | TestThrowOnFailure(hr, L"Failed to initialize variables."); | 199 | TestThrowOnFailure(hr, L"Failed to initialize variables."); |
| 187 | 200 | ||
| 188 | // set variables | 201 | // set variables |
| 189 | VariableSetStringHelper(&variables, L"PROP1", L"VAL1"); | 202 | VariableSetStringHelper(&variables, L"PROP1", L"VAL1", FALSE); |
| 190 | VariableSetStringHelper(&variables, L"PROP2", L"VAL2"); | 203 | VariableSetStringHelper(&variables, L"PROP2", L"VAL2", FALSE); |
| 191 | VariableSetStringHelper(&variables, L"PROP3", L"VAL3"); | 204 | VariableSetStringHelper(&variables, L"PROP3", L"VAL3", FALSE); |
| 192 | VariableSetStringHelper(&variables, L"PROP4", L"BEGIN MID END"); | 205 | VariableSetStringHelper(&variables, L"PROP4", L"BEGIN MID END", FALSE); |
| 193 | VariableSetNumericHelper(&variables, L"PROP5", 5); | 206 | VariableSetNumericHelper(&variables, L"PROP5", 5); |
| 194 | VariableSetNumericHelper(&variables, L"PROP6", 6); | 207 | VariableSetNumericHelper(&variables, L"PROP6", 6); |
| 195 | VariableSetStringHelper(&variables, L"PROP7", L""); | 208 | VariableSetStringHelper(&variables, L"PROP7", L"", FALSE); |
| 196 | VariableSetNumericHelper(&variables, L"PROP8", 0); | 209 | VariableSetNumericHelper(&variables, L"PROP8", 0); |
| 197 | VariableSetStringHelper(&variables, L"_PROP9", L"VAL9"); | 210 | VariableSetStringHelper(&variables, L"_PROP9", L"VAL9", FALSE); |
| 198 | VariableSetNumericHelper(&variables, L"PROP10", -10); | 211 | VariableSetNumericHelper(&variables, L"PROP10", -10); |
| 199 | VariableSetNumericHelper(&variables, L"PROP11", 9223372036854775807ll); | 212 | VariableSetNumericHelper(&variables, L"PROP11", 9223372036854775807ll); |
| 200 | VariableSetNumericHelper(&variables, L"PROP12", -9223372036854775808ll); | 213 | VariableSetNumericHelper(&variables, L"PROP12", -9223372036854775808ll); |
| @@ -208,7 +221,11 @@ namespace Bootstrapper | |||
| 208 | VariableSetVersionHelper(&variables, L"PROP20", MAKEQWORDVERSION(1,1,1,1)); | 221 | VariableSetVersionHelper(&variables, L"PROP20", MAKEQWORDVERSION(1,1,1,1)); |
| 209 | VariableSetNumericHelper(&variables, L"vPROP21", 1); | 222 | VariableSetNumericHelper(&variables, L"vPROP21", 1); |
| 210 | VariableSetVersionHelper(&variables, L"PROP22", MAKEQWORDVERSION(65535,65535,65535,65535)); | 223 | VariableSetVersionHelper(&variables, L"PROP22", MAKEQWORDVERSION(65535,65535,65535,65535)); |
| 211 | VariableSetStringHelper(&variables, L"PROP23", L"1.1.1"); | 224 | VariableSetStringHelper(&variables, L"PROP23", L"1.1.1", FALSE); |
| 225 | VariableSetStringHelper(&variables, L"PROP24", L"[PROP1]", TRUE); | ||
| 226 | VariableSetStringHelper(&variables, L"PROP25", L"[PROP7]", TRUE); | ||
| 227 | VariableSetStringHelper(&variables, L"PROP26", L"[PROP8]", TRUE); | ||
| 228 | VariableSetStringHelper(&variables, L"PROP27", L"[PROP16]", TRUE); | ||
| 212 | 229 | ||
| 213 | // test conditions | 230 | // test conditions |
| 214 | Assert::True(EvaluateConditionHelper(&variables, L"PROP1")); | 231 | Assert::True(EvaluateConditionHelper(&variables, L"PROP1")); |
| @@ -218,6 +235,10 @@ namespace Bootstrapper | |||
| 218 | Assert::True(EvaluateConditionHelper(&variables, L"_PROP9")); | 235 | Assert::True(EvaluateConditionHelper(&variables, L"_PROP9")); |
| 219 | Assert::False(EvaluateConditionHelper(&variables, L"PROP16")); | 236 | Assert::False(EvaluateConditionHelper(&variables, L"PROP16")); |
| 220 | Assert::True(EvaluateConditionHelper(&variables, L"PROP17")); | 237 | Assert::True(EvaluateConditionHelper(&variables, L"PROP17")); |
| 238 | Assert::True(EvaluateConditionHelper(&variables, L"PROP24")); | ||
| 239 | Assert::True(EvaluateConditionHelper(&variables, L"PROP25")); | ||
| 240 | Assert::True(EvaluateConditionHelper(&variables, L"PROP26")); | ||
| 241 | Assert::True(EvaluateConditionHelper(&variables, L"PROP27")); | ||
| 221 | 242 | ||
| 222 | Assert::True(EvaluateConditionHelper(&variables, L"PROP1 = \"VAL1\"")); | 243 | Assert::True(EvaluateConditionHelper(&variables, L"PROP1 = \"VAL1\"")); |
| 223 | Assert::False(EvaluateConditionHelper(&variables, L"NONE = \"NOT\"")); | 244 | Assert::False(EvaluateConditionHelper(&variables, L"NONE = \"NOT\"")); |
| @@ -365,10 +386,11 @@ namespace Bootstrapper | |||
| 365 | hr = VariableInitialize(&variables1); | 386 | hr = VariableInitialize(&variables1); |
| 366 | TestThrowOnFailure(hr, L"Failed to initialize variables."); | 387 | TestThrowOnFailure(hr, L"Failed to initialize variables."); |
| 367 | 388 | ||
| 368 | VariableSetStringHelper(&variables1, L"PROP1", L"VAL1"); | 389 | VariableSetStringHelper(&variables1, L"PROP1", L"VAL1", FALSE); |
| 369 | VariableSetNumericHelper(&variables1, L"PROP2", 2); | 390 | VariableSetNumericHelper(&variables1, L"PROP2", 2); |
| 370 | VariableSetVersionHelper(&variables1, L"PROP3", MAKEQWORDVERSION(1,1,1,1)); | 391 | VariableSetVersionHelper(&variables1, L"PROP3", MAKEQWORDVERSION(1,1,1,1)); |
| 371 | VariableSetStringHelper(&variables1, L"PROP4", L"VAL4"); | 392 | VariableSetStringHelper(&variables1, L"PROP4", L"VAL4", FALSE); |
| 393 | VariableSetStringHelper(&variables1, L"PROP5", L"[PROP1]", TRUE); | ||
| 372 | 394 | ||
| 373 | hr = VariableSerialize(&variables1, FALSE, &pbBuffer, &cbBuffer); | 395 | hr = VariableSerialize(&variables1, FALSE, &pbBuffer, &cbBuffer); |
| 374 | TestThrowOnFailure(hr, L"Failed to serialize variables."); | 396 | TestThrowOnFailure(hr, L"Failed to serialize variables."); |
| @@ -384,6 +406,13 @@ namespace Bootstrapper | |||
| 384 | Assert::Equal(2ll, VariableGetNumericHelper(&variables2, L"PROP2")); | 406 | Assert::Equal(2ll, VariableGetNumericHelper(&variables2, L"PROP2")); |
| 385 | Assert::Equal(MAKEQWORDVERSION(1,1,1,1), VariableGetVersionHelper(&variables2, L"PROP3")); | 407 | Assert::Equal(MAKEQWORDVERSION(1,1,1,1), VariableGetVersionHelper(&variables2, L"PROP3")); |
| 386 | Assert::Equal<String^>(gcnew String(L"VAL4"), VariableGetStringHelper(&variables2, L"PROP4")); | 408 | Assert::Equal<String^>(gcnew String(L"VAL4"), VariableGetStringHelper(&variables2, L"PROP4")); |
| 409 | Assert::Equal<String^>(gcnew String(L"[PROP1]"), VariableGetStringHelper(&variables2, L"PROP5")); | ||
| 410 | |||
| 411 | Assert::Equal((int)BURN_VARIANT_TYPE_STRING, VariableGetTypeHelper(&variables2, L"PROP1")); | ||
| 412 | Assert::Equal((int)BURN_VARIANT_TYPE_NUMERIC, VariableGetTypeHelper(&variables2, L"PROP2")); | ||
| 413 | Assert::Equal((int)BURN_VARIANT_TYPE_VERSION, VariableGetTypeHelper(&variables2, L"PROP3")); | ||
| 414 | Assert::Equal((int)BURN_VARIANT_TYPE_STRING, VariableGetTypeHelper(&variables2, L"PROP4")); | ||
| 415 | Assert::Equal((int)BURN_VARIANT_TYPE_FORMATTED, VariableGetTypeHelper(&variables2, L"PROP5")); | ||
| 387 | } | 416 | } |
| 388 | finally | 417 | finally |
| 389 | { | 418 | { |
| @@ -420,7 +449,7 @@ namespace Bootstrapper | |||
| 420 | } | 449 | } |
| 421 | 450 | ||
| 422 | // attempt to set a built-in property | 451 | // attempt to set a built-in property |
| 423 | hr = VariableSetString(&variables, L"VersionNT", L"VAL", FALSE); | 452 | hr = VariableSetString(&variables, L"VersionNT", L"VAL", FALSE, FALSE); |
| 424 | Assert::Equal(E_INVALIDARG, hr); | 453 | Assert::Equal(E_INVALIDARG, hr); |
| 425 | Assert::False(EvaluateConditionHelper(&variables, L"VersionNT = \"VAL\"")); | 454 | Assert::False(EvaluateConditionHelper(&variables, L"VersionNT = \"VAL\"")); |
| 426 | 455 | ||
diff --git a/src/test/BurnUnitTest/VariantTest.cpp b/src/test/BurnUnitTest/VariantTest.cpp index d16ac699..c982db72 100644 --- a/src/test/BurnUnitTest/VariantTest.cpp +++ b/src/test/BurnUnitTest/VariantTest.cpp | |||
| @@ -25,9 +25,9 @@ namespace Bootstrapper | |||
| 25 | [Fact] | 25 | [Fact] |
| 26 | void VariantBasicTest() | 26 | void VariantBasicTest() |
| 27 | { | 27 | { |
| 28 | BURN_VARIANT expectedVariants[8]; | 28 | BURN_VARIANT expectedVariants[10]; |
| 29 | BURN_VARIANT actualVariants[8]; | 29 | BURN_VARIANT actualVariants[10]; |
| 30 | for (DWORD i = 0; i < 8; i++) | 30 | for (DWORD i = 0; i < 10; i++) |
| 31 | { | 31 | { |
| 32 | BVariantUninitialize(expectedVariants + i); | 32 | BVariantUninitialize(expectedVariants + i); |
| 33 | BVariantUninitialize(actualVariants + i); | 33 | BVariantUninitialize(actualVariants + i); |
| @@ -43,6 +43,8 @@ namespace Bootstrapper | |||
| 43 | InitVersionValue(expectedVariants + 5, MAKEQWORDVERSION(1, 1, 1, 0), TRUE, L"PROP6", actualVariants + 5); | 43 | InitVersionValue(expectedVariants + 5, MAKEQWORDVERSION(1, 1, 1, 0), TRUE, L"PROP6", actualVariants + 5); |
| 44 | InitStringValue(expectedVariants + 6, L"7", TRUE, L"PROP7", actualVariants + 6); | 44 | InitStringValue(expectedVariants + 6, L"7", TRUE, L"PROP7", actualVariants + 6); |
| 45 | InitNumericValue(expectedVariants + 7, 11, TRUE, L"PROP8", actualVariants + 7); | 45 | InitNumericValue(expectedVariants + 7, 11, TRUE, L"PROP8", actualVariants + 7); |
| 46 | InitFormattedValue(expectedVariants + 8, L"VAL9", FALSE, L"PROP9", actualVariants + 8); | ||
| 47 | InitFormattedValue(expectedVariants + 9, L"VAL10", TRUE, L"PROP10", actualVariants + 9); | ||
| 46 | 48 | ||
| 47 | VerifyNumericValue(expectedVariants + 0, actualVariants + 0); | 49 | VerifyNumericValue(expectedVariants + 0, actualVariants + 0); |
| 48 | VerifyStringValue(expectedVariants + 1, actualVariants + 1); | 50 | VerifyStringValue(expectedVariants + 1, actualVariants + 1); |
| @@ -52,10 +54,12 @@ namespace Bootstrapper | |||
| 52 | VerifyVersionValue(expectedVariants + 5, actualVariants + 5); | 54 | VerifyVersionValue(expectedVariants + 5, actualVariants + 5); |
| 53 | VerifyStringValue(expectedVariants + 6, actualVariants + 6); | 55 | VerifyStringValue(expectedVariants + 6, actualVariants + 6); |
| 54 | VerifyNumericValue(expectedVariants + 7, actualVariants + 7); | 56 | VerifyNumericValue(expectedVariants + 7, actualVariants + 7); |
| 57 | VerifyFormattedValue(expectedVariants + 8, actualVariants + 8); | ||
| 58 | VerifyFormattedValue(expectedVariants + 9, actualVariants + 9); | ||
| 55 | } | 59 | } |
| 56 | finally | 60 | finally |
| 57 | { | 61 | { |
| 58 | for (DWORD i = 0; i < 8; i++) | 62 | for (DWORD i = 0; i < 10; i++) |
| 59 | { | 63 | { |
| 60 | BVariantUninitialize(expectedVariants + i); | 64 | BVariantUninitialize(expectedVariants + i); |
| 61 | BVariantUninitialize(actualVariants + i); | 65 | BVariantUninitialize(actualVariants + i); |
| @@ -64,6 +68,26 @@ namespace Bootstrapper | |||
| 64 | } | 68 | } |
| 65 | 69 | ||
| 66 | private: | 70 | private: |
| 71 | void InitFormattedValue(BURN_VARIANT* pValue, LPWSTR wzValue, BOOL fHidden, LPCWSTR wz, BURN_VARIANT* pActualValue) | ||
| 72 | { | ||
| 73 | HRESULT hr = S_OK; | ||
| 74 | pValue->Type = BURN_VARIANT_TYPE_FORMATTED; | ||
| 75 | |||
| 76 | hr = StrAllocString(&pValue->sczValue, wzValue, 0); | ||
| 77 | NativeAssert::Succeeded(hr, "Failed to alloc string: {0}", wzValue); | ||
| 78 | |||
| 79 | hr = BVariantCopy(pValue, pActualValue); | ||
| 80 | NativeAssert::Succeeded(hr, "Failed to copy variant {0}", wz); | ||
| 81 | |||
| 82 | if (fHidden) | ||
| 83 | { | ||
| 84 | hr = BVariantSetEncryption(pActualValue, TRUE); | ||
| 85 | NativeAssert::Succeeded(hr, "Failed to encrypt variant {0}", wz); | ||
| 86 | |||
| 87 | NativeAssert::True(pActualValue->fEncryptString); | ||
| 88 | } | ||
| 89 | } | ||
| 90 | |||
| 67 | void InitNoneValue(BURN_VARIANT* pValue, BOOL fHidden, LPCWSTR wz, BURN_VARIANT* pActualValue) | 91 | void InitNoneValue(BURN_VARIANT* pValue, BOOL fHidden, LPCWSTR wz, BURN_VARIANT* pActualValue) |
| 68 | { | 92 | { |
| 69 | HRESULT hr = S_OK; | 93 | HRESULT hr = S_OK; |
| @@ -137,6 +161,26 @@ namespace Bootstrapper | |||
| 137 | } | 161 | } |
| 138 | } | 162 | } |
| 139 | 163 | ||
| 164 | void VerifyFormattedValue(BURN_VARIANT* pExpectedValue, BURN_VARIANT* pActualValue) | ||
| 165 | { | ||
| 166 | HRESULT hr = S_OK; | ||
| 167 | LPWSTR sczValue = NULL; | ||
| 168 | NativeAssert::Equal<DWORD>(BURN_VARIANT_TYPE_FORMATTED, pExpectedValue->Type); | ||
| 169 | NativeAssert::Equal<DWORD>(BURN_VARIANT_TYPE_FORMATTED, pActualValue->Type); | ||
| 170 | |||
| 171 | try | ||
| 172 | { | ||
| 173 | hr = BVariantGetString(pActualValue, &sczValue); | ||
| 174 | NativeAssert::Succeeded(hr, "Failed to get string value"); | ||
| 175 | |||
| 176 | NativeAssert::StringEqual(pExpectedValue->sczValue, sczValue); | ||
| 177 | } | ||
| 178 | finally | ||
| 179 | { | ||
| 180 | ReleaseStr(sczValue); | ||
| 181 | } | ||
| 182 | } | ||
| 183 | |||
| 140 | void VerifyNumericValue(BURN_VARIANT* pExpectedValue, BURN_VARIANT* pActualValue) | 184 | void VerifyNumericValue(BURN_VARIANT* pExpectedValue, BURN_VARIANT* pActualValue) |
| 141 | { | 185 | { |
| 142 | HRESULT hr = S_OK; | 186 | HRESULT hr = S_OK; |
| @@ -167,7 +211,7 @@ namespace Bootstrapper | |||
| 167 | try | 211 | try |
| 168 | { | 212 | { |
| 169 | hr = BVariantGetString(pActualValue, &sczValue); | 213 | hr = BVariantGetString(pActualValue, &sczValue); |
| 170 | NativeAssert::Succeeded(hr, "Failed to get numeric value"); | 214 | NativeAssert::Succeeded(hr, "Failed to get string value"); |
| 171 | 215 | ||
| 172 | NativeAssert::StringEqual(pExpectedValue->sczValue, sczValue); | 216 | NativeAssert::StringEqual(pExpectedValue->sczValue, sczValue); |
| 173 | } | 217 | } |
| @@ -185,7 +229,7 @@ namespace Bootstrapper | |||
| 185 | NativeAssert::Equal<DWORD>(BURN_VARIANT_TYPE_VERSION, pActualValue->Type); | 229 | NativeAssert::Equal<DWORD>(BURN_VARIANT_TYPE_VERSION, pActualValue->Type); |
| 186 | 230 | ||
| 187 | hr = BVariantGetVersion(pActualValue, &qwValue); | 231 | hr = BVariantGetVersion(pActualValue, &qwValue); |
| 188 | NativeAssert::Succeeded(hr, "Failed to get numeric value"); | 232 | NativeAssert::Succeeded(hr, "Failed to get version value"); |
| 189 | 233 | ||
| 190 | NativeAssert::Equal<DWORD64>(pExpectedValue->qwValue, qwValue); | 234 | NativeAssert::Equal<DWORD64>(pExpectedValue->qwValue, qwValue); |
| 191 | } | 235 | } |
