Add a CTS test that iterates through all codecs using MediaCodecList and

calls getCapabilitiesForType for every type supported by any codec. Also
makes sure that all components published through MediaCodecList can at
least be instantiated.

Change-Id: I6e30e92e6846b6045f51bbd5e2aa66e80c317119
diff --git a/tests/tests/media/src/android/media/cts/MediaCodecListTest.java b/tests/tests/media/src/android/media/cts/MediaCodecListTest.java
index e6abe31..0973c1a 100755
--- a/tests/tests/media/src/android/media/cts/MediaCodecListTest.java
+++ b/tests/tests/media/src/android/media/cts/MediaCodecListTest.java
@@ -17,10 +17,11 @@
 package android.media.cts;
 
 
-import android.media.MediaCodecList;
+import android.media.MediaCodec;
 import android.media.MediaCodecInfo;
 import android.media.MediaCodecInfo.CodecProfileLevel;
 import android.media.MediaCodecInfo.CodecCapabilities;
+import android.media.MediaCodecList;
 import android.test.AndroidTestCase;
 import android.util.Log;
 
@@ -53,6 +54,63 @@
         assertTrue("/etc/media_codecs.xml does not exist", file.exists());
     }
 
+    // Each component advertised by MediaCodecList should at least be
+    // instantiate-able.
+    public void testComponentInstantiation() {
+        Log.d(TAG, "testComponentInstantiation");
+
+        int codecCount = MediaCodecList.getCodecCount();
+        for (int i = 0; i < codecCount; ++i) {
+            MediaCodecInfo info = MediaCodecList.getCodecInfoAt(i);
+
+            Log.d(TAG, (i + 1) + ": " + info.getName());
+            Log.d(TAG, "  isEncoder = " + info.isEncoder());
+
+            if (!info.getName().startsWith("OMX.")) {
+                // Unfortunately for legacy reasons, "AACEncoder", a
+                // non OMX component had to be in this list for the video
+                // editor code to work... but it cannot actually be instantiated
+                // using MediaCodec.
+                Log.d(TAG, "  skipping...");
+                continue;
+            }
+
+            MediaCodec codec = MediaCodec.createByCodecName(info.getName());
+
+            codec.release();
+            codec = null;
+        }
+    }
+
+    // For each type advertised by any of the components we should be able
+    // to get capabilities.
+    public void testGetCapabilities() {
+        Log.d(TAG, "testGetCapabilities");
+
+        int codecCount = MediaCodecList.getCodecCount();
+        for (int i = 0; i < codecCount; ++i) {
+            MediaCodecInfo info = MediaCodecList.getCodecInfoAt(i);
+
+            Log.d(TAG, (i + 1) + ": " + info.getName());
+            Log.d(TAG, "  isEncoder = " + info.isEncoder());
+
+            if (!info.getName().startsWith("OMX.")) {
+                // Unfortunately for legacy reasons, "AACEncoder", a
+                // non OMX component had to be in this list for the video
+                // editor code to work... but it cannot actually be instantiated
+                // using MediaCodec.
+                Log.d(TAG, "  skipping...");
+                continue;
+            }
+
+            String[] types = info.getSupportedTypes();
+            for (int j = 0; j < types.length; ++j) {
+                Log.d(TAG, "calling getCapabilitiesForType " + types[j]);
+                CodecCapabilities cap = info.getCapabilitiesForType(types[j]);
+            }
+        }
+    }
+
     public void testRequiredMediaCodecList() {
         List<CodecType> requiredList = getRequiredCodecTypes();
         List<CodecType> supportedList = getSupportedCodecTypes();