10d604e2af9eeed22685fd62e2281c2cd9728d58bWu-cheng Li/* 20d604e2af9eeed22685fd62e2281c2cd9728d58bWu-cheng Li * Copyright (C) 2010 The Android Open Source Project 30d604e2af9eeed22685fd62e2281c2cd9728d58bWu-cheng Li * 40d604e2af9eeed22685fd62e2281c2cd9728d58bWu-cheng Li * Licensed under the Apache License, Version 2.0 (the "License"); 50d604e2af9eeed22685fd62e2281c2cd9728d58bWu-cheng Li * you may not use this file except in compliance with the License. 60d604e2af9eeed22685fd62e2281c2cd9728d58bWu-cheng Li * You may obtain a copy of the License at 70d604e2af9eeed22685fd62e2281c2cd9728d58bWu-cheng Li * 80d604e2af9eeed22685fd62e2281c2cd9728d58bWu-cheng Li * http://www.apache.org/licenses/LICENSE-2.0 90d604e2af9eeed22685fd62e2281c2cd9728d58bWu-cheng Li * 100d604e2af9eeed22685fd62e2281c2cd9728d58bWu-cheng Li * Unless required by applicable law or agreed to in writing, software 110d604e2af9eeed22685fd62e2281c2cd9728d58bWu-cheng Li * distributed under the License is distributed on an "AS IS" BASIS, 120d604e2af9eeed22685fd62e2281c2cd9728d58bWu-cheng Li * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 130d604e2af9eeed22685fd62e2281c2cd9728d58bWu-cheng Li * See the License for the specific language governing permissions and 140d604e2af9eeed22685fd62e2281c2cd9728d58bWu-cheng Li * limitations under the License. 150d604e2af9eeed22685fd62e2281c2cd9728d58bWu-cheng Li */ 160d604e2af9eeed22685fd62e2281c2cd9728d58bWu-cheng Li 174aaa2130af7241f128ee561cafd17a4fb560b92cWu-cheng Lipackage com.android.camera.unittest; 184aaa2130af7241f128ee561cafd17a4fb560b92cWu-cheng Li 19d2db70880e6159413932f747eb82df3e925852c1Wu-cheng Liimport com.android.camera.Util; 204aaa2130af7241f128ee561cafd17a4fb560b92cWu-cheng Li 21d2db70880e6159413932f747eb82df3e925852c1Wu-cheng Liimport android.graphics.Matrix; 224aaa2130af7241f128ee561cafd17a4fb560b92cWu-cheng Liimport android.test.suitebuilder.annotation.SmallTest; 234aaa2130af7241f128ee561cafd17a4fb560b92cWu-cheng Li 244aaa2130af7241f128ee561cafd17a4fb560b92cWu-cheng Liimport junit.framework.TestCase; 254aaa2130af7241f128ee561cafd17a4fb560b92cWu-cheng Li 264aaa2130af7241f128ee561cafd17a4fb560b92cWu-cheng Li@SmallTest 27f40432ca4c8c12e59f2e917a6ccfe4c440db7827Yu Shan Emily Laupublic class CameraUnitTest extends TestCase { 284aaa2130af7241f128ee561cafd17a4fb560b92cWu-cheng Li public void testRoundOrientation() { 29131cf9886c4f34431598be0b1f5b7aaa915277ccEino-Ville Talvala int h = Util.ORIENTATION_HYSTERESIS; 30131cf9886c4f34431598be0b1f5b7aaa915277ccEino-Ville Talvala assertEquals(0, Util.roundOrientation(0, 0)); 31131cf9886c4f34431598be0b1f5b7aaa915277ccEino-Ville Talvala assertEquals(0, Util.roundOrientation(359, 0)); 32131cf9886c4f34431598be0b1f5b7aaa915277ccEino-Ville Talvala assertEquals(0, Util.roundOrientation(0 + 44 + h, 0)); 33131cf9886c4f34431598be0b1f5b7aaa915277ccEino-Ville Talvala assertEquals(90, Util.roundOrientation(0 + 45 + h, 0)); 34131cf9886c4f34431598be0b1f5b7aaa915277ccEino-Ville Talvala assertEquals(0, Util.roundOrientation(360 - 44 - h, 0)); 35131cf9886c4f34431598be0b1f5b7aaa915277ccEino-Ville Talvala assertEquals(270, Util.roundOrientation(360 - 45 - h, 0)); 36131cf9886c4f34431598be0b1f5b7aaa915277ccEino-Ville Talvala 37131cf9886c4f34431598be0b1f5b7aaa915277ccEino-Ville Talvala assertEquals(90, Util.roundOrientation(90, 90)); 38131cf9886c4f34431598be0b1f5b7aaa915277ccEino-Ville Talvala assertEquals(90, Util.roundOrientation(90 + 44 + h, 90)); 39131cf9886c4f34431598be0b1f5b7aaa915277ccEino-Ville Talvala assertEquals(180, Util.roundOrientation(90 + 45 + h, 90)); 40131cf9886c4f34431598be0b1f5b7aaa915277ccEino-Ville Talvala assertEquals(90, Util.roundOrientation(90 - 44 - h, 90)); 41131cf9886c4f34431598be0b1f5b7aaa915277ccEino-Ville Talvala assertEquals(0, Util.roundOrientation(90 - 45 - h, 90)); 42131cf9886c4f34431598be0b1f5b7aaa915277ccEino-Ville Talvala 43131cf9886c4f34431598be0b1f5b7aaa915277ccEino-Ville Talvala assertEquals(180, Util.roundOrientation(180, 180)); 44131cf9886c4f34431598be0b1f5b7aaa915277ccEino-Ville Talvala assertEquals(180, Util.roundOrientation(180 + 44 + h, 180)); 45131cf9886c4f34431598be0b1f5b7aaa915277ccEino-Ville Talvala assertEquals(270, Util.roundOrientation(180 + 45 + h, 180)); 46131cf9886c4f34431598be0b1f5b7aaa915277ccEino-Ville Talvala assertEquals(180, Util.roundOrientation(180 - 44 - h, 180)); 47131cf9886c4f34431598be0b1f5b7aaa915277ccEino-Ville Talvala assertEquals(90, Util.roundOrientation(180 - 45 - h, 180)); 48131cf9886c4f34431598be0b1f5b7aaa915277ccEino-Ville Talvala 49131cf9886c4f34431598be0b1f5b7aaa915277ccEino-Ville Talvala assertEquals(270, Util.roundOrientation(270, 270)); 50131cf9886c4f34431598be0b1f5b7aaa915277ccEino-Ville Talvala assertEquals(270, Util.roundOrientation(270 + 44 + h, 270)); 51131cf9886c4f34431598be0b1f5b7aaa915277ccEino-Ville Talvala assertEquals(0, Util.roundOrientation(270 + 45 + h, 270)); 52131cf9886c4f34431598be0b1f5b7aaa915277ccEino-Ville Talvala assertEquals(270, Util.roundOrientation(270 - 44 - h, 270)); 53131cf9886c4f34431598be0b1f5b7aaa915277ccEino-Ville Talvala assertEquals(180, Util.roundOrientation(270 - 45 - h, 270)); 54131cf9886c4f34431598be0b1f5b7aaa915277ccEino-Ville Talvala 55131cf9886c4f34431598be0b1f5b7aaa915277ccEino-Ville Talvala assertEquals(90, Util.roundOrientation(90, 0)); 56131cf9886c4f34431598be0b1f5b7aaa915277ccEino-Ville Talvala assertEquals(180, Util.roundOrientation(180, 0)); 57131cf9886c4f34431598be0b1f5b7aaa915277ccEino-Ville Talvala assertEquals(270, Util.roundOrientation(270, 0)); 58131cf9886c4f34431598be0b1f5b7aaa915277ccEino-Ville Talvala 59131cf9886c4f34431598be0b1f5b7aaa915277ccEino-Ville Talvala assertEquals(0, Util.roundOrientation(0, 90)); 60131cf9886c4f34431598be0b1f5b7aaa915277ccEino-Ville Talvala assertEquals(180, Util.roundOrientation(180, 90)); 61131cf9886c4f34431598be0b1f5b7aaa915277ccEino-Ville Talvala assertEquals(270, Util.roundOrientation(270, 90)); 62131cf9886c4f34431598be0b1f5b7aaa915277ccEino-Ville Talvala 63131cf9886c4f34431598be0b1f5b7aaa915277ccEino-Ville Talvala assertEquals(0, Util.roundOrientation(0, 180)); 64131cf9886c4f34431598be0b1f5b7aaa915277ccEino-Ville Talvala assertEquals(90, Util.roundOrientation(90, 180)); 65131cf9886c4f34431598be0b1f5b7aaa915277ccEino-Ville Talvala assertEquals(270, Util.roundOrientation(270, 180)); 66131cf9886c4f34431598be0b1f5b7aaa915277ccEino-Ville Talvala 67131cf9886c4f34431598be0b1f5b7aaa915277ccEino-Ville Talvala assertEquals(0, Util.roundOrientation(0, 270)); 68131cf9886c4f34431598be0b1f5b7aaa915277ccEino-Ville Talvala assertEquals(90, Util.roundOrientation(90, 270)); 69131cf9886c4f34431598be0b1f5b7aaa915277ccEino-Ville Talvala assertEquals(180, Util.roundOrientation(180, 270)); 704aaa2130af7241f128ee561cafd17a4fb560b92cWu-cheng Li } 710d604e2af9eeed22685fd62e2281c2cd9728d58bWu-cheng Li 72d2db70880e6159413932f747eb82df3e925852c1Wu-cheng Li public void testPrepareMatrix() { 73d2db70880e6159413932f747eb82df3e925852c1Wu-cheng Li Matrix matrix = new Matrix(); 74d2db70880e6159413932f747eb82df3e925852c1Wu-cheng Li float[] points; 75d2db70880e6159413932f747eb82df3e925852c1Wu-cheng Li int[] expected; 76d2db70880e6159413932f747eb82df3e925852c1Wu-cheng Li 77d2db70880e6159413932f747eb82df3e925852c1Wu-cheng Li Util.prepareMatrix(matrix, false, 0, 800, 480); 78d2db70880e6159413932f747eb82df3e925852c1Wu-cheng Li points = new float[] {-1000, -1000, 0, 0, 1000, 1000, 0, 1000, -750, 250}; 79d2db70880e6159413932f747eb82df3e925852c1Wu-cheng Li expected = new int[] {0, 0, 400, 240, 800, 480, 400, 480, 100, 300}; 80d2db70880e6159413932f747eb82df3e925852c1Wu-cheng Li matrix.mapPoints(points); 81d2db70880e6159413932f747eb82df3e925852c1Wu-cheng Li assertEquals(expected, points); 82d2db70880e6159413932f747eb82df3e925852c1Wu-cheng Li 83d2db70880e6159413932f747eb82df3e925852c1Wu-cheng Li Util.prepareMatrix(matrix, false, 90, 800, 480); 84d2db70880e6159413932f747eb82df3e925852c1Wu-cheng Li points = new float[] {-1000, -1000, 0, 0, 1000, 1000, 0, 1000, -750, 250}; 85d2db70880e6159413932f747eb82df3e925852c1Wu-cheng Li expected = new int[] {800, 0, 400, 240, 0, 480, 0, 240, 300, 60}; 86d2db70880e6159413932f747eb82df3e925852c1Wu-cheng Li matrix.mapPoints(points); 87d2db70880e6159413932f747eb82df3e925852c1Wu-cheng Li assertEquals(expected, points); 88d2db70880e6159413932f747eb82df3e925852c1Wu-cheng Li 89d2db70880e6159413932f747eb82df3e925852c1Wu-cheng Li Util.prepareMatrix(matrix, false, 180, 800, 480); 90d2db70880e6159413932f747eb82df3e925852c1Wu-cheng Li points = new float[] {-1000, -1000, 0, 0, 1000, 1000, 0, 1000, -750, 250}; 91d2db70880e6159413932f747eb82df3e925852c1Wu-cheng Li expected = new int[] {800, 480, 400, 240, 0, 0, 400, 0, 700, 180}; 92d2db70880e6159413932f747eb82df3e925852c1Wu-cheng Li matrix.mapPoints(points); 93d2db70880e6159413932f747eb82df3e925852c1Wu-cheng Li assertEquals(expected, points); 94d2db70880e6159413932f747eb82df3e925852c1Wu-cheng Li 95d2db70880e6159413932f747eb82df3e925852c1Wu-cheng Li Util.prepareMatrix(matrix, true, 180, 800, 480); 96d2db70880e6159413932f747eb82df3e925852c1Wu-cheng Li points = new float[] {-1000, -1000, 0, 0, 1000, 1000, 0, 1000, -750, 250}; 97d2db70880e6159413932f747eb82df3e925852c1Wu-cheng Li expected = new int[] {0, 480, 400, 240, 800, 0, 400, 0, 100, 180}; 98d2db70880e6159413932f747eb82df3e925852c1Wu-cheng Li matrix.mapPoints(points); 99d2db70880e6159413932f747eb82df3e925852c1Wu-cheng Li assertEquals(expected, points); 100d2db70880e6159413932f747eb82df3e925852c1Wu-cheng Li } 101d2db70880e6159413932f747eb82df3e925852c1Wu-cheng Li 102d2db70880e6159413932f747eb82df3e925852c1Wu-cheng Li private void assertEquals(int expected[], float[] actual) { 103d2db70880e6159413932f747eb82df3e925852c1Wu-cheng Li for (int i = 0; i < expected.length; i++) { 104d2db70880e6159413932f747eb82df3e925852c1Wu-cheng Li assertEquals("Array index " + i + " mismatch", expected[i], Math.round(actual[i])); 105d2db70880e6159413932f747eb82df3e925852c1Wu-cheng Li } 106d2db70880e6159413932f747eb82df3e925852c1Wu-cheng Li } 1074aaa2130af7241f128ee561cafd17a4fb560b92cWu-cheng Li} 108