Add tests for MediaProfiles.

Change-Id: I08e5e66615e88a243d5779ae02a3a68ba15d6b29
diff --git a/tests/tests/media/src/android/media/cts/CamcorderProfileTest.java b/tests/tests/media/src/android/media/cts/CamcorderProfileTest.java
new file mode 100644
index 0000000..b94da11
--- /dev/null
+++ b/tests/tests/media/src/android/media/cts/CamcorderProfileTest.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.media.cts;
+
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargets;
+
+import android.hardware.Camera;
+import android.media.CamcorderProfile;
+import android.test.AndroidTestCase;
+import android.util.Log;
+
+import java.util.List;
+
+@TestTargetClass(CamcorderProfile.class)
+public class CamcorderProfileTest extends AndroidTestCase {
+
+    private static final String TAG = "CamcorderProfileTest";
+
+    private void checkProfile(CamcorderProfile profile) {
+        Log.v(TAG, String.format("profile: duration=%d, quality=%d, " +
+            "fileFormat=%d, videoCodec=%d, videoBitRate=%d, videoFrameRate=%d, " +
+            "videoFrameWidth=%d, videoFrameHeight=%d, audioCodec=%d, " +
+            "audioBitRate=%d, audioSampleRate=%d, audioChannels=%d",
+            profile.duration,
+            profile.quality,
+            profile.fileFormat,
+            profile.videoCodec,
+            profile.videoBitRate,
+            profile.videoFrameRate,
+            profile.videoFrameWidth,
+            profile.videoFrameHeight,
+            profile.audioCodec,
+            profile.audioBitRate,
+            profile.audioSampleRate,
+            profile.audioChannels));
+        assertTrue(profile.duration > 0);
+        assertTrue(profile.quality == CamcorderProfile.QUALITY_LOW ||
+                   profile.quality == CamcorderProfile.QUALITY_HIGH);
+        assertTrue(profile.videoBitRate > 0);
+        assertTrue(profile.videoFrameRate > 0);
+        assertTrue(profile.videoFrameWidth > 0);
+        assertTrue(profile.videoFrameHeight > 0);
+        assertTrue(profile.audioBitRate > 0);
+        assertTrue(profile.audioSampleRate > 0);
+        assertTrue(profile.audioChannels > 0);
+    }
+
+    @TestTargets({
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            method = "get",
+            args = {int.class}
+        )
+    })
+    public void testGet() {
+        CamcorderProfile lowProfile = CamcorderProfile.get(CamcorderProfile.QUALITY_LOW);
+        CamcorderProfile highProfile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);
+        checkProfile(lowProfile);
+        checkProfile(highProfile);
+    }
+
+    @TestTargets({
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            method = "get",
+            args = {int.class, int.class}
+        )
+    })
+    public void testGetWithId() {
+        int nCamera = Camera.getNumberOfCameras();
+        for (int id = 0; id < nCamera; id++) {
+            CamcorderProfile lowProfile = CamcorderProfile.get(id,
+                    CamcorderProfile.QUALITY_LOW);
+            CamcorderProfile highProfile = CamcorderProfile.get(id,
+                    CamcorderProfile.QUALITY_HIGH);
+            checkProfile(lowProfile);
+            checkProfile(highProfile);
+        }
+    }
+}
diff --git a/tests/tests/media/src/android/media/cts/CameraProfileTest.java b/tests/tests/media/src/android/media/cts/CameraProfileTest.java
new file mode 100644
index 0000000..72cd296a
--- /dev/null
+++ b/tests/tests/media/src/android/media/cts/CameraProfileTest.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.media.cts;
+
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargets;
+
+import android.hardware.Camera;
+import android.media.CameraProfile;
+import android.test.AndroidTestCase;
+import android.util.Log;
+
+import java.util.List;
+
+@TestTargetClass(CameraProfile.class)
+public class CameraProfileTest extends AndroidTestCase {
+
+    private static final String TAG = "CameraProfileTest";
+
+    private void checkQuality(int low, int mid, int high) {
+        Log.v(TAG, "low = " + low + ", mid = " + mid + ", high = " + high);
+        assertTrue(low >= 0 && low <= 100);
+        assertTrue(mid >= 0 && mid <= 100);
+        assertTrue(high >= 0 && high <= 100);
+        assertTrue(low <= mid && mid <= high);
+    }
+
+    @TestTargets({
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            method = "getJpegEncodingQualityParameter",
+            args = {int.class}
+        )
+    })
+    public void testGetImageEncodingQualityParameter() {
+        int low = CameraProfile.getJpegEncodingQualityParameter(CameraProfile.QUALITY_LOW);
+        int mid = CameraProfile.getJpegEncodingQualityParameter(CameraProfile.QUALITY_MEDIUM);
+        int high = CameraProfile.getJpegEncodingQualityParameter(CameraProfile.QUALITY_HIGH);
+        checkQuality(low, mid, high);
+    }
+
+    @TestTargets({
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            method = "getJpegEncodingQualityParameter",
+            args = {int.class, int.class}
+        )
+    })
+    public void testGetWithId() {
+        int nCamera = Camera.getNumberOfCameras();
+        for (int id = 0; id < nCamera; id++) {
+            int low = CameraProfile.getJpegEncodingQualityParameter(id, CameraProfile.QUALITY_LOW);
+            int mid = CameraProfile.getJpegEncodingQualityParameter(id, CameraProfile.QUALITY_MEDIUM);
+            int high = CameraProfile.getJpegEncodingQualityParameter(id, CameraProfile.QUALITY_HIGH);
+            checkQuality(low, mid, high);
+        }
+    }
+}