blob: 3889d7306990659b9879670c4b6ff087d2cbe0ae [file] [log] [blame]
Carl Shapiro12eb78e2011-06-24 14:51:06 -07001// Copyright 2011 Google Inc. All Rights Reserved.
2
3#include "src/dex_instruction_visitor.h"
Carl Shapiro1fb86202011-06-27 17:43:13 -07004#include "src/scoped_ptr.h"
Carl Shapiro12eb78e2011-06-24 14:51:06 -07005
6#include <iostream>
7#include "gtest/gtest.h"
8
9namespace art {
10
11class TestVisitor : public DexInstructionVisitor<TestVisitor> {};
12
Brian Carlstroma331b3c2011-07-18 17:47:56 -070013TEST(InstructionTest, Init) {
Carl Shapiro1fb86202011-06-27 17:43:13 -070014 scoped_ptr<TestVisitor> visitor(new TestVisitor);
Carl Shapiro12eb78e2011-06-24 14:51:06 -070015}
16
17class CountVisitor : public DexInstructionVisitor<CountVisitor> {
18 public:
19 int count_;
20
21 CountVisitor() : count_(0) {}
22
23 void Do_Default(Instruction* inst) {
24 ++count_;
25 }
26};
27
Brian Carlstroma331b3c2011-07-18 17:47:56 -070028TEST(InstructionTest, Count) {
Carl Shapiro12eb78e2011-06-24 14:51:06 -070029 CountVisitor v0;
30 uint16_t c0[] = {};
31 v0.Visit(c0, sizeof(c0));
32 EXPECT_EQ(0, v0.count_);
33
34 CountVisitor v1;
35 uint16_t c1[] = { 0 };
36 v1.Visit(c1, sizeof(c1));
37 EXPECT_EQ(1, v1.count_);
38
39 CountVisitor v2;
40 uint16_t c2[] = { 0, 0 };
41 v2.Visit(c2, sizeof(c2));
42 EXPECT_EQ(2, v2.count_);
43
44 CountVisitor v3;
45 uint16_t c3[] = { 0, 0, 0, };
46 v3.Visit(c3, sizeof(c3));
47 EXPECT_EQ(3, v3.count_);
48
49 CountVisitor v4;
50 uint16_t c4[] = { 0, 0, 0, 0 };
51 v4.Visit(c4, sizeof(c4));
52 EXPECT_EQ(4, v4.count_);
53}
54
55} // namespace art