blob: 0edf160fcf87665bb0dcf1949ee09f566a71fc7a [file] [log] [blame]
Carl Shapiro12eb78e2011-06-24 14:51:06 -07001// Copyright 2011 Google Inc. All Rights Reserved.
2
Brian Carlstrom578bbdc2011-07-21 14:07:47 -07003#include "dex_instruction_visitor.h"
4#include "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
jeffhaoba5ebb92011-08-25 17:24:37 -070023 void Do_Default(const Instruction* inst) {
Carl Shapiro12eb78e2011-06-24 14:51:06 -070024 ++count_;
25 }
26};
27
Brian Carlstroma331b3c2011-07-18 17:47:56 -070028TEST(InstructionTest, Count) {
Carl Shapiro12eb78e2011-06-24 14:51:06 -070029 CountVisitor v0;
jeffhaoba5ebb92011-08-25 17:24:37 -070030 const uint16_t c0[] = {};
Carl Shapiro12eb78e2011-06-24 14:51:06 -070031 v0.Visit(c0, sizeof(c0));
32 EXPECT_EQ(0, v0.count_);
33
34 CountVisitor v1;
jeffhaoba5ebb92011-08-25 17:24:37 -070035 const uint16_t c1[] = { 0 };
Carl Shapiro12eb78e2011-06-24 14:51:06 -070036 v1.Visit(c1, sizeof(c1));
37 EXPECT_EQ(1, v1.count_);
38
39 CountVisitor v2;
jeffhaoba5ebb92011-08-25 17:24:37 -070040 const uint16_t c2[] = { 0, 0 };
Carl Shapiro12eb78e2011-06-24 14:51:06 -070041 v2.Visit(c2, sizeof(c2));
42 EXPECT_EQ(2, v2.count_);
43
44 CountVisitor v3;
jeffhaoba5ebb92011-08-25 17:24:37 -070045 const uint16_t c3[] = { 0, 0, 0, };
Carl Shapiro12eb78e2011-06-24 14:51:06 -070046 v3.Visit(c3, sizeof(c3));
47 EXPECT_EQ(3, v3.count_);
48
49 CountVisitor v4;
jeffhaoba5ebb92011-08-25 17:24:37 -070050 const uint16_t c4[] = { 0, 0, 0, 0 };
Carl Shapiro12eb78e2011-06-24 14:51:06 -070051 v4.Visit(c4, sizeof(c4));
52 EXPECT_EQ(4, v4.count_);
53}
54
55} // namespace art