Carl Shapiro | 12eb78e | 2011-06-24 14:51:06 -0700 | [diff] [blame] | 1 | // Copyright 2011 Google Inc. All Rights Reserved. |
| 2 | |
| 3 | #include "src/dex_instruction_visitor.h" |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 4 | #include "src/scoped_ptr.h" |
Carl Shapiro | 12eb78e | 2011-06-24 14:51:06 -0700 | [diff] [blame] | 5 | |
| 6 | #include <iostream> |
| 7 | #include "gtest/gtest.h" |
| 8 | |
| 9 | namespace art { |
| 10 | |
| 11 | class TestVisitor : public DexInstructionVisitor<TestVisitor> {}; |
| 12 | |
Brian Carlstrom | a331b3c | 2011-07-18 17:47:56 -0700 | [diff] [blame^] | 13 | TEST(InstructionTest, Init) { |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 14 | scoped_ptr<TestVisitor> visitor(new TestVisitor); |
Carl Shapiro | 12eb78e | 2011-06-24 14:51:06 -0700 | [diff] [blame] | 15 | } |
| 16 | |
| 17 | class 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 Carlstrom | a331b3c | 2011-07-18 17:47:56 -0700 | [diff] [blame^] | 28 | TEST(InstructionTest, Count) { |
Carl Shapiro | 12eb78e | 2011-06-24 14:51:06 -0700 | [diff] [blame] | 29 | 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 |