Elliott Hughes | 2faa5f1 | 2012-01-30 14:42:07 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Carl Shapiro | 12eb78e | 2011-06-24 14:51:06 -0700 | [diff] [blame] | 16 | |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 17 | #include "dex_instruction_visitor.h" |
Carl Shapiro | 12eb78e | 2011-06-24 14:51:06 -0700 | [diff] [blame] | 18 | |
| 19 | #include <iostream> |
Elliott Hughes | 90a3369 | 2011-08-30 13:27:07 -0700 | [diff] [blame] | 20 | |
Ian Rogers | 507dfdd | 2014-05-15 16:42:40 -0700 | [diff] [blame] | 21 | #include "UniquePtrCompat.h" |
Carl Shapiro | 12eb78e | 2011-06-24 14:51:06 -0700 | [diff] [blame] | 22 | #include "gtest/gtest.h" |
| 23 | |
| 24 | namespace art { |
| 25 | |
| 26 | class TestVisitor : public DexInstructionVisitor<TestVisitor> {}; |
| 27 | |
Brian Carlstrom | a331b3c | 2011-07-18 17:47:56 -0700 | [diff] [blame] | 28 | TEST(InstructionTest, Init) { |
Elliott Hughes | 90a3369 | 2011-08-30 13:27:07 -0700 | [diff] [blame] | 29 | UniquePtr<TestVisitor> visitor(new TestVisitor); |
Carl Shapiro | 12eb78e | 2011-06-24 14:51:06 -0700 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | class CountVisitor : public DexInstructionVisitor<CountVisitor> { |
| 33 | public: |
| 34 | int count_; |
| 35 | |
| 36 | CountVisitor() : count_(0) {} |
| 37 | |
Elliott Hughes | 317eb64 | 2012-03-16 14:19:10 -0700 | [diff] [blame] | 38 | void Do_Default(const Instruction*) { |
Carl Shapiro | 12eb78e | 2011-06-24 14:51:06 -0700 | [diff] [blame] | 39 | ++count_; |
| 40 | } |
| 41 | }; |
| 42 | |
Brian Carlstrom | a331b3c | 2011-07-18 17:47:56 -0700 | [diff] [blame] | 43 | TEST(InstructionTest, Count) { |
Carl Shapiro | 12eb78e | 2011-06-24 14:51:06 -0700 | [diff] [blame] | 44 | CountVisitor v0; |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 45 | const uint16_t c0[] = {}; |
Carl Shapiro | 12eb78e | 2011-06-24 14:51:06 -0700 | [diff] [blame] | 46 | v0.Visit(c0, sizeof(c0)); |
| 47 | EXPECT_EQ(0, v0.count_); |
| 48 | |
| 49 | CountVisitor v1; |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 50 | const uint16_t c1[] = { 0 }; |
Carl Shapiro | 12eb78e | 2011-06-24 14:51:06 -0700 | [diff] [blame] | 51 | v1.Visit(c1, sizeof(c1)); |
| 52 | EXPECT_EQ(1, v1.count_); |
| 53 | |
| 54 | CountVisitor v2; |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 55 | const uint16_t c2[] = { 0, 0 }; |
Carl Shapiro | 12eb78e | 2011-06-24 14:51:06 -0700 | [diff] [blame] | 56 | v2.Visit(c2, sizeof(c2)); |
| 57 | EXPECT_EQ(2, v2.count_); |
| 58 | |
| 59 | CountVisitor v3; |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 60 | const uint16_t c3[] = { 0, 0, 0, }; |
Carl Shapiro | 12eb78e | 2011-06-24 14:51:06 -0700 | [diff] [blame] | 61 | v3.Visit(c3, sizeof(c3)); |
| 62 | EXPECT_EQ(3, v3.count_); |
| 63 | |
| 64 | CountVisitor v4; |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 65 | const uint16_t c4[] = { 0, 0, 0, 0 }; |
Carl Shapiro | 12eb78e | 2011-06-24 14:51:06 -0700 | [diff] [blame] | 66 | v4.Visit(c4, sizeof(c4)); |
| 67 | EXPECT_EQ(4, v4.count_); |
| 68 | } |
| 69 | |
| 70 | } // namespace art |