Carl Shapiro | 12eb78e | 2011-06-24 14:51:06 -0700 | [diff] [blame] | 1 | // Copyright 2011 Google Inc. All Rights Reserved. |
| 2 | |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 3 | #include "dex_instruction_visitor.h" |
| 4 | #include "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 | |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame^] | 23 | void Do_Default(const Instruction* inst) { |
Carl Shapiro | 12eb78e | 2011-06-24 14:51:06 -0700 | [diff] [blame] | 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; |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame^] | 30 | const uint16_t c0[] = {}; |
Carl Shapiro | 12eb78e | 2011-06-24 14:51:06 -0700 | [diff] [blame] | 31 | v0.Visit(c0, sizeof(c0)); |
| 32 | EXPECT_EQ(0, v0.count_); |
| 33 | |
| 34 | CountVisitor v1; |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame^] | 35 | const uint16_t c1[] = { 0 }; |
Carl Shapiro | 12eb78e | 2011-06-24 14:51:06 -0700 | [diff] [blame] | 36 | v1.Visit(c1, sizeof(c1)); |
| 37 | EXPECT_EQ(1, v1.count_); |
| 38 | |
| 39 | CountVisitor v2; |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame^] | 40 | const uint16_t c2[] = { 0, 0 }; |
Carl Shapiro | 12eb78e | 2011-06-24 14:51:06 -0700 | [diff] [blame] | 41 | v2.Visit(c2, sizeof(c2)); |
| 42 | EXPECT_EQ(2, v2.count_); |
| 43 | |
| 44 | CountVisitor v3; |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame^] | 45 | const uint16_t c3[] = { 0, 0, 0, }; |
Carl Shapiro | 12eb78e | 2011-06-24 14:51:06 -0700 | [diff] [blame] | 46 | v3.Visit(c3, sizeof(c3)); |
| 47 | EXPECT_EQ(3, v3.count_); |
| 48 | |
| 49 | CountVisitor v4; |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame^] | 50 | const uint16_t c4[] = { 0, 0, 0, 0 }; |
Carl Shapiro | 12eb78e | 2011-06-24 14:51:06 -0700 | [diff] [blame] | 51 | v4.Visit(c4, sizeof(c4)); |
| 52 | EXPECT_EQ(4, v4.count_); |
| 53 | } |
| 54 | |
| 55 | } // namespace art |