blob: 5273084a9aa84e7a22696fc87d491581150b2b33 [file] [log] [blame]
Elliott Hughes2faa5f12012-01-30 14:42:07 -08001/*
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 Shapiro12eb78e2011-06-24 14:51:06 -070016
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070017#include "dex_instruction_visitor.h"
Carl Shapiro12eb78e2011-06-24 14:51:06 -070018
Ian Rogers700a4022014-05-19 16:49:03 -070019#include <memory>
Elliott Hughes90a33692011-08-30 13:27:07 -070020
Carl Shapiro12eb78e2011-06-24 14:51:06 -070021#include "gtest/gtest.h"
22
23namespace art {
24
25class TestVisitor : public DexInstructionVisitor<TestVisitor> {};
26
Brian Carlstroma331b3c2011-07-18 17:47:56 -070027TEST(InstructionTest, Init) {
Ian Rogers700a4022014-05-19 16:49:03 -070028 std::unique_ptr<TestVisitor> visitor(new TestVisitor);
Carl Shapiro12eb78e2011-06-24 14:51:06 -070029}
30
31class CountVisitor : public DexInstructionVisitor<CountVisitor> {
32 public:
33 int count_;
34
35 CountVisitor() : count_(0) {}
36
Elliott Hughes317eb642012-03-16 14:19:10 -070037 void Do_Default(const Instruction*) {
Carl Shapiro12eb78e2011-06-24 14:51:06 -070038 ++count_;
39 }
40};
41
Brian Carlstroma331b3c2011-07-18 17:47:56 -070042TEST(InstructionTest, Count) {
Carl Shapiro12eb78e2011-06-24 14:51:06 -070043 CountVisitor v0;
jeffhaoba5ebb92011-08-25 17:24:37 -070044 const uint16_t c0[] = {};
Carl Shapiro12eb78e2011-06-24 14:51:06 -070045 v0.Visit(c0, sizeof(c0));
46 EXPECT_EQ(0, v0.count_);
47
48 CountVisitor v1;
jeffhaoba5ebb92011-08-25 17:24:37 -070049 const uint16_t c1[] = { 0 };
Carl Shapiro12eb78e2011-06-24 14:51:06 -070050 v1.Visit(c1, sizeof(c1));
51 EXPECT_EQ(1, v1.count_);
52
53 CountVisitor v2;
jeffhaoba5ebb92011-08-25 17:24:37 -070054 const uint16_t c2[] = { 0, 0 };
Carl Shapiro12eb78e2011-06-24 14:51:06 -070055 v2.Visit(c2, sizeof(c2));
56 EXPECT_EQ(2, v2.count_);
57
58 CountVisitor v3;
jeffhaoba5ebb92011-08-25 17:24:37 -070059 const uint16_t c3[] = { 0, 0, 0, };
Carl Shapiro12eb78e2011-06-24 14:51:06 -070060 v3.Visit(c3, sizeof(c3));
61 EXPECT_EQ(3, v3.count_);
62
63 CountVisitor v4;
jeffhaoba5ebb92011-08-25 17:24:37 -070064 const uint16_t c4[] = { 0, 0, 0, 0 };
Carl Shapiro12eb78e2011-06-24 14:51:06 -070065 v4.Visit(c4, sizeof(c4));
66 EXPECT_EQ(4, v4.count_);
67}
68
69} // namespace art