1 /*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #include "value/variables.h"
16
17 #include "util/tests/verifier_test.h"
18
19 #include <gtest/gtest.h>
20
21 namespace panda::verifier::test {
22
TEST_F(VerifierTest,Variables)23 TEST_F(VerifierTest, Variables)
24 {
25 Variables vars;
26
27 auto v1 = vars.NewVar();
28 auto v2 = vars.NewVar();
29
30 EXPECT_TRUE(v1 != v2);
31
32 auto v4 = vars.NewVar();
33
34 {
35 auto v3 = vars.NewVar();
36 EXPECT_TRUE(v3 != v2 && v3 != v1 && v3 != v4);
37 EXPECT_EQ(vars.AmountOfUsedVars(), 4);
38 v4 = v3;
39 EXPECT_EQ(vars.AmountOfUsedVars(), 3);
40 }
41
42 auto v5 = vars.NewVar();
43 EXPECT_EQ(vars.AmountOfUsedVars(), 4);
44 EXPECT_FALSE(v4 == v5);
45
46 size_t count = 0;
47
48 ForEach(vars.AllVariables(), [&count, &v1, &v2, &v4, &v5](auto v) {
49 ++count;
50 EXPECT_TRUE(v == v1 || v == v2 || v == v4 || v == v5);
51 });
52
53 EXPECT_EQ(count, 4);
54 }
55
56 } // namespace panda::verifier::test
57