diff options
| author | Sean Hall <r.sean.hall@gmail.com> | 2020-07-11 21:11:30 +1000 |
|---|---|---|
| committer | Sean Hall <r.sean.hall@gmail.com> | 2020-07-12 11:51:29 +1000 |
| commit | 9c4b5559ccb55491fe68b0096d1be0496fd6fcc7 (patch) | |
| tree | faa51204fc2e6e3dfd1b00ae03c7184c4fb0b4bf /src/test/DUtilUnitTest/CondUtilTest.cpp | |
| parent | f651268309263fa67fa84caf9fb6dbebb5c900d9 (diff) | |
| download | wix-9c4b5559ccb55491fe68b0096d1be0496fd6fcc7.tar.gz wix-9c4b5559ccb55491fe68b0096d1be0496fd6fcc7.tar.bz2 wix-9c4b5559ccb55491fe68b0096d1be0496fd6fcc7.zip | |
Import DUtilUnitTest from old wix4 repo.
Diffstat (limited to 'src/test/DUtilUnitTest/CondUtilTest.cpp')
| -rw-r--r-- | src/test/DUtilUnitTest/CondUtilTest.cpp | 190 |
1 files changed, 190 insertions, 0 deletions
diff --git a/src/test/DUtilUnitTest/CondUtilTest.cpp b/src/test/DUtilUnitTest/CondUtilTest.cpp new file mode 100644 index 00000000..c808363d --- /dev/null +++ b/src/test/DUtilUnitTest/CondUtilTest.cpp | |||
| @@ -0,0 +1,190 @@ | |||
| 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 | namespace DutilTests | ||
| 6 | { | ||
| 7 | using namespace System; | ||
| 8 | using namespace Xunit; | ||
| 9 | using namespace WixTest; | ||
| 10 | |||
| 11 | public ref class CondUtil | ||
| 12 | { | ||
| 13 | public: | ||
| 14 | [NamedFact(Skip = "condutil Not Implemented Yet.")] | ||
| 15 | void CondEvaluateTest() | ||
| 16 | { | ||
| 17 | HRESULT hr = S_OK; | ||
| 18 | VARIABLES_HANDLE pVariables = NULL; | ||
| 19 | |||
| 20 | try | ||
| 21 | { | ||
| 22 | hr = VarCreate(&pVariables); | ||
| 23 | NativeAssert::Succeeded(hr, "Failed to initialize variables."); | ||
| 24 | |||
| 25 | // set variables | ||
| 26 | VarSetStringHelper(pVariables, L"PROP1", L"VAL1"); | ||
| 27 | VarSetStringHelper(pVariables, L"PROP2", L"VAL2"); | ||
| 28 | VarSetStringHelper(pVariables, L"PROP3", L"VAL3"); | ||
| 29 | VarSetStringHelper(pVariables, L"PROP4", L"BEGIN MID END"); | ||
| 30 | VarSetNumericHelper(pVariables, L"PROP5", 5); | ||
| 31 | VarSetNumericHelper(pVariables, L"PROP6", 6); | ||
| 32 | VarSetStringHelper(pVariables, L"PROP7", L""); | ||
| 33 | VarSetNumericHelper(pVariables, L"PROP8", 0); | ||
| 34 | VarSetStringHelper(pVariables, L"_PROP9", L"VAL9"); | ||
| 35 | VarSetNumericHelper(pVariables, L"PROP10", -10); | ||
| 36 | VarSetNumericHelper(pVariables, L"PROP11", 9223372036854775807ll); | ||
| 37 | VarSetNumericHelper(pVariables, L"PROP12", -9223372036854775808ll); | ||
| 38 | VarSetNumericHelper(pVariables, L"PROP13", 0x00010000); | ||
| 39 | VarSetNumericHelper(pVariables, L"PROP14", 0x00000001); | ||
| 40 | VarSetNumericHelper(pVariables, L"PROP15", 0x00010001); | ||
| 41 | VarSetVersionHelper(pVariables, L"PROP16", MAKEQWORDVERSION(0, 0, 0, 0)); | ||
| 42 | VarSetVersionHelper(pVariables, L"PROP17", MAKEQWORDVERSION(1, 0, 0, 0)); | ||
| 43 | VarSetVersionHelper(pVariables, L"PROP18", MAKEQWORDVERSION(1, 1, 0, 0)); | ||
| 44 | VarSetVersionHelper(pVariables, L"PROP19", MAKEQWORDVERSION(1, 1, 1, 0)); | ||
| 45 | VarSetVersionHelper(pVariables, L"PROP20", MAKEQWORDVERSION(1, 1, 1, 1)); | ||
| 46 | VarSetNumericHelper(pVariables, L"vPROP21", 1); | ||
| 47 | VarSetVersionHelper(pVariables, L"PROP22", MAKEQWORDVERSION(65535, 65535, 65535, 65535)); | ||
| 48 | VarSetStringHelper(pVariables, L"PROP23", L"1.1.1"); | ||
| 49 | |||
| 50 | // test conditions | ||
| 51 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP1")); | ||
| 52 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP5")); | ||
| 53 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP7")); | ||
| 54 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP8")); | ||
| 55 | Assert::True(EvaluateConditionHelper(pVariables, L"_PROP9")); | ||
| 56 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP16")); | ||
| 57 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP17")); | ||
| 58 | |||
| 59 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP1 = \"VAL1\"")); | ||
| 60 | Assert::False(EvaluateConditionHelper(pVariables, L"NONE = \"NOT\"")); | ||
| 61 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP1 <> \"VAL1\"")); | ||
| 62 | Assert::True(EvaluateConditionHelper(pVariables, L"NONE <> \"NOT\"")); | ||
| 63 | |||
| 64 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP1 ~= \"val1\"")); | ||
| 65 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP1 = \"val1\"")); | ||
| 66 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP1 ~<> \"val1\"")); | ||
| 67 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP1 <> \"val1\"")); | ||
| 68 | |||
| 69 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP5 = 5")); | ||
| 70 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP5 = 0")); | ||
| 71 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP5 <> 5")); | ||
| 72 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP5 <> 0")); | ||
| 73 | |||
| 74 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP10 = -10")); | ||
| 75 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP10 <> -10")); | ||
| 76 | |||
| 77 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP17 = v1")); | ||
| 78 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP17 = v0")); | ||
| 79 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP17 <> v1")); | ||
| 80 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP17 <> v0")); | ||
| 81 | |||
| 82 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP16 = v0")); | ||
| 83 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP17 = v1")); | ||
| 84 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP18 = v1.1")); | ||
| 85 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP19 = v1.1.1")); | ||
| 86 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP20 = v1.1.1.1")); | ||
| 87 | Assert::True(EvaluateFailureConditionHelper(pVariables, L"PROP20 = v1.1.1.1.0")); | ||
| 88 | Assert::True(EvaluateFailureConditionHelper(pVariables, L"PROP20 = v1.1.1.1.1")); | ||
| 89 | Assert::True(EvaluateConditionHelper(pVariables, L"vPROP21 = 1")); | ||
| 90 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP23 = v1.1.1")); | ||
| 91 | Assert::True(EvaluateConditionHelper(pVariables, L"v1.1.1 = PROP23")); | ||
| 92 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP1 <> v1.1.1")); | ||
| 93 | Assert::True(EvaluateConditionHelper(pVariables, L"v1.1.1 <> PROP1")); | ||
| 94 | |||
| 95 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP11 = 9223372036854775806")); | ||
| 96 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP11 = 9223372036854775807")); | ||
| 97 | Assert::True(EvaluateFailureConditionHelper(pVariables, L"PROP11 = 9223372036854775808")); | ||
| 98 | Assert::True(EvaluateFailureConditionHelper(pVariables, L"PROP11 = 92233720368547758070000")); | ||
| 99 | |||
| 100 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP12 = -9223372036854775807")); | ||
| 101 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP12 = -9223372036854775808")); | ||
| 102 | Assert::True(EvaluateFailureConditionHelper(pVariables, L"PROP12 = -9223372036854775809")); | ||
| 103 | Assert::True(EvaluateFailureConditionHelper(pVariables, L"PROP12 = -92233720368547758080000")); | ||
| 104 | |||
| 105 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP22 = v65535.65535.65535.65535")); | ||
| 106 | Assert::True(EvaluateFailureConditionHelper(pVariables, L"PROP22 = v65536.65535.65535.65535")); | ||
| 107 | Assert::True(EvaluateFailureConditionHelper(pVariables, L"PROP22 = v65535.655350000.65535.65535")); | ||
| 108 | |||
| 109 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP5 < 6")); | ||
| 110 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP5 < 5")); | ||
| 111 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP5 > 4")); | ||
| 112 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP5 > 5")); | ||
| 113 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP5 <= 6")); | ||
| 114 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP5 <= 5")); | ||
| 115 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP5 <= 4")); | ||
| 116 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP5 >= 4")); | ||
| 117 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP5 >= 5")); | ||
| 118 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP5 >= 6")); | ||
| 119 | |||
| 120 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP4 << \"BEGIN\"")); | ||
| 121 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP4 << \"END\"")); | ||
| 122 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP4 >> \"END\"")); | ||
| 123 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP4 >> \"BEGIN\"")); | ||
| 124 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP4 >< \"MID\"")); | ||
| 125 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP4 >< \"NONE\"")); | ||
| 126 | |||
| 127 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP16 < v1.1")); | ||
| 128 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP16 < v0")); | ||
| 129 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP17 > v0.12")); | ||
| 130 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP17 > v1")); | ||
| 131 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP18 >= v1.0")); | ||
| 132 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP18 >= v1.1")); | ||
| 133 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP18 >= v2.1")); | ||
| 134 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP19 <= v1.1234.1")); | ||
| 135 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP19 <= v1.1.1")); | ||
| 136 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP19 <= v1.0.123")); | ||
| 137 | |||
| 138 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP6 = \"6\"")); | ||
| 139 | Assert::True(EvaluateConditionHelper(pVariables, L"\"6\" = PROP6")); | ||
| 140 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP6 = \"ABC\"")); | ||
| 141 | Assert::False(EvaluateConditionHelper(pVariables, L"\"ABC\" = PROP6")); | ||
| 142 | Assert::False(EvaluateConditionHelper(pVariables, L"\"ABC\" = PROP6")); | ||
| 143 | |||
| 144 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP13 << 1")); | ||
| 145 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP13 << 0")); | ||
| 146 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP14 >> 1")); | ||
| 147 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP14 >> 0")); | ||
| 148 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP15 >< 65537")); | ||
| 149 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP15 >< 0")); | ||
| 150 | |||
| 151 | Assert::False(EvaluateConditionHelper(pVariables, L"NOT PROP1")); | ||
| 152 | Assert::True(EvaluateConditionHelper(pVariables, L"NOT (PROP1 <> \"VAL1\")")); | ||
| 153 | |||
| 154 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP1 = \"VAL1\" AND PROP2 = \"VAL2\"")); | ||
| 155 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP1 = \"VAL1\" AND PROP2 = \"NOT\"")); | ||
| 156 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP1 = \"NOT\" AND PROP2 = \"VAL2\"")); | ||
| 157 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP1 = \"NOT\" AND PROP2 = \"NOT\"")); | ||
| 158 | |||
| 159 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP1 = \"VAL1\" OR PROP2 = \"VAL2\"")); | ||
| 160 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP1 = \"VAL1\" OR PROP2 = \"NOT\"")); | ||
| 161 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP1 = \"NOT\" OR PROP2 = \"VAL2\"")); | ||
| 162 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP1 = \"NOT\" OR PROP2 = \"NOT\"")); | ||
| 163 | |||
| 164 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP1 = \"VAL1\" AND PROP2 = \"VAL2\" OR PROP3 = \"NOT\"")); | ||
| 165 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP1 = \"VAL1\" AND PROP2 = \"NOT\" OR PROP3 = \"VAL3\"")); | ||
| 166 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP1 = \"VAL1\" AND PROP2 = \"NOT\" OR PROP3 = \"NOT\"")); | ||
| 167 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP1 = \"VAL1\" AND (PROP2 = \"NOT\" OR PROP3 = \"VAL3\")")); | ||
| 168 | Assert::True(EvaluateConditionHelper(pVariables, L"(PROP1 = \"VAL1\" AND PROP2 = \"VAL2\") OR PROP3 = \"NOT\"")); | ||
| 169 | |||
| 170 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP3 = \"NOT\" OR PROP1 = \"VAL1\" AND PROP2 = \"VAL2\"")); | ||
| 171 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP3 = \"VAL3\" OR PROP1 = \"VAL1\" AND PROP2 = \"NOT\"")); | ||
| 172 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP3 = \"NOT\" OR PROP1 = \"VAL1\" AND PROP2 = \"NOT\"")); | ||
| 173 | Assert::True(EvaluateConditionHelper(pVariables, L"(PROP3 = \"NOT\" OR PROP1 = \"VAL1\") AND PROP2 = \"VAL2\"")); | ||
| 174 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP3 = \"NOT\" OR (PROP1 = \"VAL1\" AND PROP2 = \"VAL2\")")); | ||
| 175 | |||
| 176 | Assert::True(EvaluateFailureConditionHelper(pVariables, L"=")); | ||
| 177 | Assert::True(EvaluateFailureConditionHelper(pVariables, L"(PROP1")); | ||
| 178 | Assert::True(EvaluateFailureConditionHelper(pVariables, L"(PROP1 = \"")); | ||
| 179 | Assert::True(EvaluateFailureConditionHelper(pVariables, L"1A")); | ||
| 180 | Assert::True(EvaluateFailureConditionHelper(pVariables, L"*")); | ||
| 181 | |||
| 182 | Assert::True(EvaluateFailureConditionHelper(pVariables, L"1 == 1")); | ||
| 183 | } | ||
| 184 | finally | ||
| 185 | { | ||
| 186 | ReleaseVariables(pVariables); | ||
| 187 | } | ||
| 188 | } | ||
| 189 | }; | ||
| 190 | } | ||
