blob: fe0f58346e516e4da05211edb8ffec7f9d2ac658 [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"
Carl Shapiro12eb78e2011-06-24 14:51:06 -07004
5#include <iostream>
Elliott Hughes90a33692011-08-30 13:27:07 -07006
7#include "UniquePtr.h"
Carl Shapiro12eb78e2011-06-24 14:51:06 -07008#include "gtest/gtest.h"
9
10namespace art {
11
12class TestVisitor : public DexInstructionVisitor<TestVisitor> {};
13
Brian Carlstroma331b3c2011-07-18 17:47:56 -070014TEST(InstructionTest, Init) {
Elliott Hughes90a33692011-08-30 13:27:07 -070015 UniquePtr<TestVisitor> visitor(new TestVisitor);
Carl Shapiro12eb78e2011-06-24 14:51:06 -070016}
17
18class CountVisitor : public DexInstructionVisitor<CountVisitor> {
19 public:
20 int count_;
21
22 CountVisitor() : count_(0) {}
23
jeffhaoba5ebb92011-08-25 17:24:37 -070024 void Do_Default(const Instruction* inst) {
Carl Shapiro12eb78e2011-06-24 14:51:06 -070025 ++count_;
26 }
27};
28
Brian Carlstroma331b3c2011-07-18 17:47:56 -070029TEST(InstructionTest, Count) {
Carl Shapiro12eb78e2011-06-24 14:51:06 -070030 CountVisitor v0;
jeffhaoba5ebb92011-08-25 17:24:37 -070031 const uint16_t c0[] = {};
Carl Shapiro12eb78e2011-06-24 14:51:06 -070032 v0.Visit(c0, sizeof(c0));
33 EXPECT_EQ(0, v0.count_);
34
35 CountVisitor v1;
jeffhaoba5ebb92011-08-25 17:24:37 -070036 const uint16_t c1[] = { 0 };
Carl Shapiro12eb78e2011-06-24 14:51:06 -070037 v1.Visit(c1, sizeof(c1));
38 EXPECT_EQ(1, v1.count_);
39
40 CountVisitor v2;
jeffhaoba5ebb92011-08-25 17:24:37 -070041 const uint16_t c2[] = { 0, 0 };
Carl Shapiro12eb78e2011-06-24 14:51:06 -070042 v2.Visit(c2, sizeof(c2));
43 EXPECT_EQ(2, v2.count_);
44
45 CountVisitor v3;
jeffhaoba5ebb92011-08-25 17:24:37 -070046 const uint16_t c3[] = { 0, 0, 0, };
Carl Shapiro12eb78e2011-06-24 14:51:06 -070047 v3.Visit(c3, sizeof(c3));
48 EXPECT_EQ(3, v3.count_);
49
50 CountVisitor v4;
jeffhaoba5ebb92011-08-25 17:24:37 -070051 const uint16_t c4[] = { 0, 0, 0, 0 };
Carl Shapiro12eb78e2011-06-24 14:51:06 -070052 v4.Visit(c4, sizeof(c4));
53 EXPECT_EQ(4, v4.count_);
54}
55
56} // namespace art