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