CameraTest.java revision d480002ccad05cf992c628c72884091c36cc654c
1/* 2 * Copyright (C) 2010 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 17package com.android.camera.unittest; 18 19import com.android.camera.Camera; 20import com.android.camera.FocusManager; 21import com.android.camera.Util; 22 23import android.graphics.Matrix; 24import android.graphics.Rect; 25import android.graphics.RectF; 26import android.test.suitebuilder.annotation.SmallTest; 27 28import junit.framework.TestCase; 29 30@SmallTest 31public class CameraTest extends TestCase { 32 public void testRoundOrientation() { 33 assertEquals(0, Camera.roundOrientation(0)); 34 assertEquals(0, Camera.roundOrientation(0 + 44)); 35 assertEquals(90, Camera.roundOrientation(0 + 45)); 36 assertEquals(90, Camera.roundOrientation(90)); 37 assertEquals(90, Camera.roundOrientation(90 + 44)); 38 assertEquals(180, Camera.roundOrientation(90 + 45)); 39 assertEquals(180, Camera.roundOrientation(180)); 40 assertEquals(180, Camera.roundOrientation(180 + 44)); 41 assertEquals(270, Camera.roundOrientation(180 + 45)); 42 assertEquals(270, Camera.roundOrientation(270)); 43 assertEquals(270, Camera.roundOrientation(270 + 44)); 44 assertEquals(0, Camera.roundOrientation(270 + 45)); 45 assertEquals(0, Camera.roundOrientation(359)); 46 } 47 48 public void testConvertToFocusArea() { 49 Rect rect = new Rect(); 50 FocusManager.convertToFocusArea(0, 0, 100, 100, 800, 480, rect); 51 assertEquals(new Rect(-1000, -1000, -750, -583), rect); 52 FocusManager.convertToFocusArea(0, 0, 400, 240, 800, 480, rect); 53 assertEquals(new Rect(-1000, -1000, 0, 0), rect); 54 FocusManager.convertToFocusArea(400, 240, 400, 240, 800, 480, rect); 55 assertEquals(new Rect(0, 0, 1000, 1000), rect); 56 FocusManager.convertToFocusArea(200, 120, 400, 240, 800, 480, rect); 57 assertEquals(new Rect(-500, -500, 500, 500), rect); 58 FocusManager.convertToFocusArea(0, 0, 800, 480, 800, 480, rect); 59 assertEquals(new Rect(-1000, -1000, 1000, 1000), rect); 60 FocusManager.convertToFocusArea(860, 620, 100, 100, 960, 720, rect); 61 assertEquals(new Rect(792, 722, 1000, 1000), rect); 62 } 63 64 public void testPrepareMatrix() { 65 Matrix matrix = new Matrix(); 66 float[] points; 67 int[] expected; 68 69 Util.prepareMatrix(matrix, false, 0, 800, 480); 70 points = new float[] {-1000, -1000, 0, 0, 1000, 1000, 0, 1000, -750, 250}; 71 expected = new int[] {0, 0, 400, 240, 800, 480, 400, 480, 100, 300}; 72 matrix.mapPoints(points); 73 assertEquals(expected, points); 74 75 Util.prepareMatrix(matrix, false, 90, 800, 480); 76 points = new float[] {-1000, -1000, 0, 0, 1000, 1000, 0, 1000, -750, 250}; 77 expected = new int[] {800, 0, 400, 240, 0, 480, 0, 240, 300, 60}; 78 matrix.mapPoints(points); 79 assertEquals(expected, points); 80 81 Util.prepareMatrix(matrix, false, 180, 800, 480); 82 points = new float[] {-1000, -1000, 0, 0, 1000, 1000, 0, 1000, -750, 250}; 83 expected = new int[] {800, 480, 400, 240, 0, 0, 400, 0, 700, 180}; 84 matrix.mapPoints(points); 85 assertEquals(expected, points); 86 87 Util.prepareMatrix(matrix, true, 180, 800, 480); 88 points = new float[] {-1000, -1000, 0, 0, 1000, 1000, 0, 1000, -750, 250}; 89 expected = new int[] {0, 480, 400, 240, 800, 0, 400, 0, 100, 180}; 90 matrix.mapPoints(points); 91 assertEquals(expected, points); 92 } 93 94 private void assertEquals(int expected[], float[] actual) { 95 for (int i = 0; i < expected.length; i++) { 96 assertEquals("Array index " + i + " mismatch", expected[i], Math.round(actual[i])); 97 } 98 } 99} 100