Home | History | Annotate | Download | only in testcompat
      1 /*
      2  * Copyright (C) 2017 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 package com.android.rs.testcompat;
     18 
     19 import com.android.rs.unittest.UnitTest;
     20 
     21 import android.content.Context;
     22 import android.support.test.InstrumentationRegistry;
     23 import android.support.test.filters.MediumTest;
     24 import android.util.Log;
     25 
     26 import org.junit.Assert;
     27 import org.junit.Test;
     28 import org.junit.runner.RunWith;
     29 import org.junit.runners.Parameterized;
     30 import org.junit.runners.Parameterized.Parameter;
     31 import org.junit.runners.Parameterized.Parameters;
     32 
     33 import java.util.ArrayList;
     34 import java.util.List;
     35 
     36 /**
     37  * RSTest_CompatLib, functional test for RenderScript Support Library APIs.
     38  * To run the test, please use command
     39  *
     40  * adb shell am instrument -w com.android.rs.testcompat/android.support.test.runner.AndroidJUnitRunner
     41  */
     42 @RunWith(Parameterized.class)
     43 public class RSSupportLibTests {
     44     private static final String TAG = RSSupportLibTests.class.getSimpleName();
     45 
     46     /**
     47      * Returns the list of subclasses of UnitTest to run.
     48      */
     49     @Parameters(name = "{0}")
     50     public static Iterable<?> getParams() throws Exception {
     51         Context ctx = InstrumentationRegistry.getTargetContext();
     52 
     53         List<UnitTest> validUnitTests = new ArrayList<>();
     54 
     55         Iterable<Class<? extends UnitTest>> testClasses = UnitTest.getProperSubclasses(ctx);
     56         for (Class<? extends UnitTest> testClass : testClasses) {
     57             UnitTest test = testClass.getDeclaredConstructor(Context.class).newInstance(ctx);
     58             validUnitTests.add(test);
     59         }
     60 
     61         UnitTest.checkDuplicateNames(validUnitTests);
     62 
     63         return validUnitTests;
     64     }
     65 
     66     @Parameter(0)
     67     public UnitTest mTest;
     68 
     69     @Test
     70     @MediumTest
     71     public void testRSUnitTest() throws Exception {
     72         mTest.logStart(TAG, "RenderScript Support Library Testing");
     73         mTest.runTest();
     74         mTest.logEnd(TAG);
     75         Assert.assertTrue(mTest.getSuccess());
     76     }
     77 }
     78