Home | History | Annotate | Download | only in runtime
      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  */
     16 
     17 #include "dex_instruction_visitor.h"
     18 
     19 #include <memory>
     20 
     21 #include "gtest/gtest.h"
     22 
     23 namespace art {
     24 
     25 class TestVisitor : public DexInstructionVisitor<TestVisitor> {};
     26 
     27 TEST(InstructionTest, Init) {
     28   std::unique_ptr<TestVisitor> visitor(new TestVisitor);
     29 }
     30 
     31 class CountVisitor : public DexInstructionVisitor<CountVisitor> {
     32  public:
     33   int count_;
     34 
     35   CountVisitor() : count_(0) {}
     36 
     37   void Do_Default(const Instruction*) {
     38     ++count_;
     39   }
     40 };
     41 
     42 TEST(InstructionTest, Count) {
     43   CountVisitor v0;
     44   const uint16_t c0[] = {};
     45   v0.Visit(c0, sizeof(c0));
     46   EXPECT_EQ(0, v0.count_);
     47 
     48   CountVisitor v1;
     49   const uint16_t c1[] = { 0 };
     50   v1.Visit(c1, sizeof(c1));
     51   EXPECT_EQ(1, v1.count_);
     52 
     53   CountVisitor v2;
     54   const uint16_t c2[] = { 0, 0 };
     55   v2.Visit(c2, sizeof(c2));
     56   EXPECT_EQ(2, v2.count_);
     57 
     58   CountVisitor v3;
     59   const uint16_t c3[] = { 0, 0, 0, };
     60   v3.Visit(c3, sizeof(c3));
     61   EXPECT_EQ(3, v3.count_);
     62 
     63   CountVisitor v4;
     64   const uint16_t c4[] = { 0, 0, 0, 0  };
     65   v4.Visit(c4, sizeof(c4));
     66   EXPECT_EQ(4, v4.count_);
     67 }
     68 
     69 }  // namespace art
     70