• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.util.CameraUtil;
20 
21 import android.graphics.Matrix;
22 import android.test.suitebuilder.annotation.SmallTest;
23 
24 import junit.framework.TestCase;
25 
26 @SmallTest
27 public class CameraUnitTest extends TestCase {
testPrepareMatrix()28     public void testPrepareMatrix() {
29         Matrix matrix = new Matrix();
30         float[] points;
31         int[] expected;
32 
33         CameraUtil.prepareMatrix(matrix, false, 0, 800, 480);
34         points = new float[] {-1000, -1000, 0, 0, 1000, 1000, 0, 1000, -750, 250};
35         expected = new int[] {0, 0, 400, 240, 800, 480, 400, 480, 100, 300};
36         matrix.mapPoints(points);
37         assertEquals(expected, points);
38 
39         CameraUtil.prepareMatrix(matrix, false, 90, 800, 480);
40         points = new float[] {-1000, -1000,   0,   0, 1000, 1000, 0, 1000, -750, 250};
41         expected = new int[] {800, 0, 400, 240, 0, 480, 0, 240, 300, 60};
42         matrix.mapPoints(points);
43         assertEquals(expected, points);
44 
45         CameraUtil.prepareMatrix(matrix, false, 180, 800, 480);
46         points = new float[] {-1000, -1000, 0, 0, 1000, 1000, 0, 1000, -750, 250};
47         expected = new int[] {800, 480, 400, 240, 0, 0, 400, 0, 700, 180};
48         matrix.mapPoints(points);
49         assertEquals(expected, points);
50 
51         CameraUtil.prepareMatrix(matrix, true, 180, 800, 480);
52         points = new float[] {-1000, -1000, 0, 0, 1000, 1000, 0, 1000, -750, 250};
53         expected = new int[] {0, 480, 400, 240, 800, 0, 400, 0, 100, 180};
54         matrix.mapPoints(points);
55         assertEquals(expected, points);
56     }
57 
assertEquals(int expected[], float[] actual)58     private void assertEquals(int expected[], float[] actual) {
59         for (int i = 0; i < expected.length; i++) {
60             assertEquals("Array index " + i + " mismatch", expected[i], Math.round(actual[i]));
61         }
62     }
63 }
64