Home | History | Annotate | Download | only in unittest
      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 
     17 package com.android.camera.unittest;
     18 
     19 import com.android.camera.Camera;
     20 import com.android.camera.FocusManager;
     21 import com.android.camera.Util;
     22 
     23 import android.graphics.Matrix;
     24 import android.graphics.Rect;
     25 import android.graphics.RectF;
     26 import android.test.suitebuilder.annotation.SmallTest;
     27 
     28 import junit.framework.TestCase;
     29 
     30 @SmallTest
     31 public class CameraTest extends TestCase {
     32     public void testRoundOrientation() {
     33         int h = Util.ORIENTATION_HYSTERESIS;
     34         assertEquals(0, Util.roundOrientation(0, 0));
     35         assertEquals(0, Util.roundOrientation(359, 0));
     36         assertEquals(0, Util.roundOrientation(0 + 44 + h, 0));
     37         assertEquals(90, Util.roundOrientation(0 + 45 + h, 0));
     38         assertEquals(0, Util.roundOrientation(360 - 44 - h, 0));
     39         assertEquals(270, Util.roundOrientation(360 - 45 - h, 0));
     40 
     41         assertEquals(90, Util.roundOrientation(90, 90));
     42         assertEquals(90, Util.roundOrientation(90 + 44 + h, 90));
     43         assertEquals(180, Util.roundOrientation(90 + 45 + h, 90));
     44         assertEquals(90, Util.roundOrientation(90 - 44 - h, 90));
     45         assertEquals(0, Util.roundOrientation(90 - 45 - h, 90));
     46 
     47         assertEquals(180, Util.roundOrientation(180, 180));
     48         assertEquals(180, Util.roundOrientation(180 + 44 + h, 180));
     49         assertEquals(270, Util.roundOrientation(180 + 45 + h, 180));
     50         assertEquals(180, Util.roundOrientation(180 - 44 - h, 180));
     51         assertEquals(90, Util.roundOrientation(180 - 45 - h, 180));
     52 
     53         assertEquals(270, Util.roundOrientation(270, 270));
     54         assertEquals(270, Util.roundOrientation(270 + 44 + h, 270));
     55         assertEquals(0, Util.roundOrientation(270 + 45 + h, 270));
     56         assertEquals(270, Util.roundOrientation(270 - 44 - h, 270));
     57         assertEquals(180, Util.roundOrientation(270 - 45 - h, 270));
     58 
     59         assertEquals(90, Util.roundOrientation(90, 0));
     60         assertEquals(180, Util.roundOrientation(180, 0));
     61         assertEquals(270, Util.roundOrientation(270, 0));
     62 
     63         assertEquals(0, Util.roundOrientation(0, 90));
     64         assertEquals(180, Util.roundOrientation(180, 90));
     65         assertEquals(270, Util.roundOrientation(270, 90));
     66 
     67         assertEquals(0, Util.roundOrientation(0, 180));
     68         assertEquals(90, Util.roundOrientation(90, 180));
     69         assertEquals(270, Util.roundOrientation(270, 180));
     70 
     71         assertEquals(0, Util.roundOrientation(0, 270));
     72         assertEquals(90, Util.roundOrientation(90, 270));
     73         assertEquals(180, Util.roundOrientation(180, 270));
     74     }
     75 
     76     public void testPrepareMatrix() {
     77         Matrix matrix = new Matrix();
     78         float[] points;
     79         int[] expected;
     80 
     81         Util.prepareMatrix(matrix, false, 0, 800, 480);
     82         points = new float[] {-1000, -1000, 0, 0, 1000, 1000, 0, 1000, -750, 250};
     83         expected = new int[] {0, 0, 400, 240, 800, 480, 400, 480, 100, 300};
     84         matrix.mapPoints(points);
     85         assertEquals(expected, points);
     86 
     87         Util.prepareMatrix(matrix, false, 90, 800, 480);
     88         points = new float[] {-1000, -1000,   0,   0, 1000, 1000, 0, 1000, -750, 250};
     89         expected = new int[] {800, 0, 400, 240, 0, 480, 0, 240, 300, 60};
     90         matrix.mapPoints(points);
     91         assertEquals(expected, points);
     92 
     93         Util.prepareMatrix(matrix, false, 180, 800, 480);
     94         points = new float[] {-1000, -1000, 0, 0, 1000, 1000, 0, 1000, -750, 250};
     95         expected = new int[] {800, 480, 400, 240, 0, 0, 400, 0, 700, 180};
     96         matrix.mapPoints(points);
     97         assertEquals(expected, points);
     98 
     99         Util.prepareMatrix(matrix, true, 180, 800, 480);
    100         points = new float[] {-1000, -1000, 0, 0, 1000, 1000, 0, 1000, -750, 250};
    101         expected = new int[] {0, 480, 400, 240, 800, 0, 400, 0, 100, 180};
    102         matrix.mapPoints(points);
    103         assertEquals(expected, points);
    104     }
    105 
    106     private void assertEquals(int expected[], float[] actual) {
    107         for (int i = 0; i < expected.length; i++) {
    108             assertEquals("Array index " + i + " mismatch", expected[i], Math.round(actual[i]));
    109         }
    110     }
    111 }
    112