diff options
Diffstat (limited to 'src/test/DUtilUnitTest/VarHelpers.cpp')
| -rw-r--r-- | src/test/DUtilUnitTest/VarHelpers.cpp | 147 |
1 files changed, 147 insertions, 0 deletions
diff --git a/src/test/DUtilUnitTest/VarHelpers.cpp b/src/test/DUtilUnitTest/VarHelpers.cpp new file mode 100644 index 00000000..aba69438 --- /dev/null +++ b/src/test/DUtilUnitTest/VarHelpers.cpp | |||
| @@ -0,0 +1,147 @@ | |||
| 1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. | ||
| 2 | |||
| 3 | #include "precomp.h" | ||
| 4 | |||
| 5 | |||
| 6 | namespace DutilTests | ||
| 7 | { | ||
| 8 | using namespace System; | ||
| 9 | using namespace WixTest; | ||
| 10 | |||
| 11 | void VarSetStringHelper(VARIABLES_HANDLE pVariables, LPCWSTR wzVariable, LPCWSTR wzValue) | ||
| 12 | { | ||
| 13 | HRESULT hr = S_OK; | ||
| 14 | |||
| 15 | hr = VarSetString(pVariables, wzVariable, wzValue); | ||
| 16 | NativeAssert::Succeeded(hr, "Failed to set {0} to: {1}", wzVariable, wzValue); | ||
| 17 | } | ||
| 18 | |||
| 19 | void VarSetNumericHelper(VARIABLES_HANDLE pVariables, LPCWSTR wzVariable, LONGLONG llValue) | ||
| 20 | { | ||
| 21 | HRESULT hr = S_OK; | ||
| 22 | |||
| 23 | hr = VarSetNumeric(pVariables, wzVariable, llValue); | ||
| 24 | NativeAssert::Succeeded(hr, gcnew String("Failed to set {0} to: {1}"), gcnew String(wzVariable), llValue); | ||
| 25 | } | ||
| 26 | |||
| 27 | void VarSetVersionHelper(VARIABLES_HANDLE pVariables, LPCWSTR wzVariable, DWORD64 qwValue) | ||
| 28 | { | ||
| 29 | HRESULT hr = S_OK; | ||
| 30 | |||
| 31 | hr = VarSetVersion(pVariables, wzVariable, qwValue); | ||
| 32 | NativeAssert::Succeeded(hr, gcnew String("Failed to set {0} to: 0x{1:X8}"), gcnew String(wzVariable), qwValue); | ||
| 33 | } | ||
| 34 | |||
| 35 | void VarGetStringHelper(VARIABLES_HANDLE pVariables, LPCWSTR wzVariable, LPCWSTR wzExpectedValue) | ||
| 36 | { | ||
| 37 | HRESULT hr = S_OK; | ||
| 38 | LPWSTR scz = NULL; | ||
| 39 | |||
| 40 | try | ||
| 41 | { | ||
| 42 | hr = VarGetString(pVariables, wzVariable, &scz); | ||
| 43 | NativeAssert::Succeeded(hr, "Failed to get: {0}", wzVariable); | ||
| 44 | NativeAssert::StringEqual(wzExpectedValue, scz); | ||
| 45 | } | ||
| 46 | finally | ||
| 47 | { | ||
| 48 | ReleaseStr(scz); | ||
| 49 | } | ||
| 50 | } | ||
| 51 | |||
| 52 | void VarGetNumericHelper(VARIABLES_HANDLE pVariables, LPCWSTR wzVariable, LONGLONG llExpectedValue) | ||
| 53 | { | ||
| 54 | HRESULT hr = S_OK; | ||
| 55 | LONGLONG llValue = 0; | ||
| 56 | |||
| 57 | hr = VarGetNumeric(pVariables, wzVariable, &llValue); | ||
| 58 | NativeAssert::Succeeded(hr, "Failed to get: {0}", wzVariable); | ||
| 59 | NativeAssert::Equal(llExpectedValue, llValue); | ||
| 60 | } | ||
| 61 | |||
| 62 | void VarGetVersionHelper(VARIABLES_HANDLE pVariables, LPCWSTR wzVariable, DWORD64 qwExpectedValue) | ||
| 63 | { | ||
| 64 | HRESULT hr = S_OK; | ||
| 65 | DWORD64 qwValue = 0; | ||
| 66 | |||
| 67 | hr = VarGetVersion(pVariables, wzVariable, &qwValue); | ||
| 68 | NativeAssert::Succeeded(hr, "Failed to get: {0}", wzVariable); | ||
| 69 | NativeAssert::Equal(qwExpectedValue, qwValue); | ||
| 70 | } | ||
| 71 | |||
| 72 | void VarGetFormattedHelper(VARIABLES_HANDLE pVariables, LPCWSTR wzVariable, LPCWSTR wzExpectedValue) | ||
| 73 | { | ||
| 74 | HRESULT hr = S_OK; | ||
| 75 | LPWSTR scz = NULL; | ||
| 76 | |||
| 77 | try | ||
| 78 | { | ||
| 79 | hr = VarGetFormatted(pVariables, wzVariable, &scz); | ||
| 80 | NativeAssert::Succeeded(hr, "Failed to get formatted: {0}", wzVariable); | ||
| 81 | NativeAssert::StringEqual(wzExpectedValue, scz); | ||
| 82 | } | ||
| 83 | finally | ||
| 84 | { | ||
| 85 | ReleaseStr(scz); | ||
| 86 | } | ||
| 87 | } | ||
| 88 | |||
| 89 | void VarFormatStringHelper(VARIABLES_HANDLE pVariables, LPCWSTR wzIn, LPCWSTR wzExpectedValue) | ||
| 90 | { | ||
| 91 | HRESULT hr = S_OK; | ||
| 92 | LPWSTR scz = NULL; | ||
| 93 | |||
| 94 | try | ||
| 95 | { | ||
| 96 | hr = VarFormatString(pVariables, wzIn, &scz, NULL); | ||
| 97 | NativeAssert::Succeeded(hr, "Failed to format string: '{0}'", wzIn); | ||
| 98 | NativeAssert::StringEqual(wzExpectedValue, scz); | ||
| 99 | } | ||
| 100 | finally | ||
| 101 | { | ||
| 102 | ReleaseStr(scz); | ||
| 103 | } | ||
| 104 | } | ||
| 105 | |||
| 106 | void VarEscapeStringHelper(LPCWSTR wzIn, LPCWSTR wzExpectedValue) | ||
| 107 | { | ||
| 108 | HRESULT hr = S_OK; | ||
| 109 | LPWSTR scz = NULL; | ||
| 110 | |||
| 111 | try | ||
| 112 | { | ||
| 113 | hr = VarEscapeString(wzIn, &scz); | ||
| 114 | NativeAssert::Succeeded(hr, "Failed to escape string: '{0}'", wzIn); | ||
| 115 | NativeAssert::StringEqual(wzExpectedValue, scz); | ||
| 116 | } | ||
| 117 | finally | ||
| 118 | { | ||
| 119 | ReleaseStr(scz); | ||
| 120 | } | ||
| 121 | } | ||
| 122 | |||
| 123 | bool EvaluateConditionHelper(VARIABLES_HANDLE pVariables, LPCWSTR wzCondition) | ||
| 124 | { | ||
| 125 | HRESULT hr = S_OK; | ||
| 126 | BOOL f = FALSE; | ||
| 127 | |||
| 128 | hr = CondEvaluate(pVariables, wzCondition, &f); | ||
| 129 | NativeAssert::Succeeded(hr, "Failed to evaluate condition: '{0}'", wzCondition); | ||
| 130 | |||
| 131 | return f ? true : false; | ||
| 132 | } | ||
| 133 | |||
| 134 | bool EvaluateFailureConditionHelper(VARIABLES_HANDLE pVariables, LPCWSTR wzCondition) | ||
| 135 | { | ||
| 136 | HRESULT hr = S_OK; | ||
| 137 | BOOL f = FALSE; | ||
| 138 | |||
| 139 | hr = CondEvaluate(pVariables, wzCondition, &f); | ||
| 140 | if (E_INVALIDDATA != hr) | ||
| 141 | { | ||
| 142 | NativeAssert::Succeeded(hr, "Failed to evaluate condition: '{0}'", wzCondition); | ||
| 143 | } | ||
| 144 | |||
| 145 | return E_INVALIDDATA == hr ? true : false; | ||
| 146 | } | ||
| 147 | } | ||
