summaryrefslogtreecommitdiffstats
path: root/runtime/dex_instruction_visitor_test.cc
blob: 5273084a9aa84e7a22696fc87d491581150b2b33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
 * Copyright (C) 2011 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "dex_instruction_visitor.h"

#include <memory>

#include "gtest/gtest.h"

namespace art {

class TestVisitor : public DexInstructionVisitor<TestVisitor> {};

TEST(InstructionTest, Init) {
  std::unique_ptr<TestVisitor> visitor(new TestVisitor);
}

class CountVisitor : public DexInstructionVisitor<CountVisitor> {
 public:
  int count_;

  CountVisitor() : count_(0) {}

  void Do_Default(const Instruction*) {
    ++count_;
  }
};

TEST(InstructionTest, Count) {
  CountVisitor v0;
  const uint16_t c0[] = {};
  v0.Visit(c0, sizeof(c0));
  EXPECT_EQ(0, v0.count_);

  CountVisitor v1;
  const uint16_t c1[] = { 0 };
  v1.Visit(c1, sizeof(c1));
  EXPECT_EQ(1, v1.count_);

  CountVisitor v2;
  const uint16_t c2[] = { 0, 0 };
  v2.Visit(c2, sizeof(c2));
  EXPECT_EQ(2, v2.count_);

  CountVisitor v3;
  const uint16_t c3[] = { 0, 0, 0, };
  v3.Visit(c3, sizeof(c3));
  EXPECT_EQ(3, v3.count_);

  CountVisitor v4;
  const uint16_t c4[] = { 0, 0, 0, 0  };
  v4.Visit(c4, sizeof(c4));
  EXPECT_EQ(4, v4.count_);
}

}  // namespace art