Igor Murashkin | 59bc67c | 2013-06-19 17:47:29 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2013 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.mediaframeworktest.unit; |
| 18 | |
| 19 | import android.os.Parcel; |
| 20 | import android.test.suitebuilder.annotation.SmallTest; |
| 21 | import android.hardware.photography.CameraMetadata; |
| 22 | |
| 23 | /** |
| 24 | * <pre> |
| 25 | * adb shell am instrument \ |
| 26 | * -e class 'com.android.mediaframeworktest.unit.CameraMetadataTest' \ |
| 27 | * -w com.android.mediaframeworktest/.MediaFrameworkUnitTestRunner |
| 28 | * </pre> |
| 29 | */ |
| 30 | public class CameraMetadataTest extends junit.framework.TestCase { |
| 31 | |
| 32 | CameraMetadata mMetadata; |
| 33 | Parcel mParcel; |
| 34 | |
| 35 | @Override |
| 36 | public void setUp() { |
| 37 | mMetadata = new CameraMetadata(); |
| 38 | mParcel = Parcel.obtain(); |
| 39 | } |
| 40 | |
| 41 | @Override |
| 42 | public void tearDown() throws Exception { |
| 43 | mMetadata.close(); |
| 44 | mMetadata = null; |
| 45 | |
| 46 | mParcel.recycle(); |
| 47 | mParcel = null; |
| 48 | } |
| 49 | |
| 50 | @SmallTest |
| 51 | public void testNew() { |
| 52 | assertEquals(0, mMetadata.getEntryCount()); |
| 53 | assertTrue(mMetadata.isEmpty()); |
| 54 | } |
| 55 | |
| 56 | @SmallTest |
| 57 | public void testClose() throws Exception { |
| 58 | mMetadata.isEmpty(); // no throw |
| 59 | |
| 60 | assertFalse(mMetadata.isClosed()); |
| 61 | |
| 62 | mMetadata.close(); |
| 63 | |
| 64 | assertTrue(mMetadata.isClosed()); |
| 65 | |
| 66 | // OK: second close should not throw |
| 67 | mMetadata.close(); |
| 68 | |
| 69 | assertTrue(mMetadata.isClosed()); |
| 70 | |
| 71 | // All other calls after close should throw IllegalStateException |
| 72 | |
| 73 | try { |
| 74 | mMetadata.isEmpty(); |
| 75 | fail("Unreachable -- isEmpty after close should throw IllegalStateException"); |
| 76 | } catch (IllegalStateException e) { |
| 77 | // good: we expect calling this method after close to fail |
| 78 | } |
| 79 | |
| 80 | try { |
| 81 | mMetadata.getEntryCount(); |
| 82 | fail("Unreachable -- getEntryCount after close should throw IllegalStateException"); |
| 83 | } catch (IllegalStateException e) { |
| 84 | // good: we expect calling this method after close to fail |
| 85 | } |
| 86 | |
| 87 | |
| 88 | try { |
| 89 | mMetadata.swap(mMetadata); |
| 90 | fail("Unreachable -- swap after close should throw IllegalStateException"); |
| 91 | } catch (IllegalStateException e) { |
| 92 | // good: we expect calling this method after close to fail |
| 93 | } |
| 94 | |
| 95 | try { |
| 96 | mMetadata.readFromParcel(mParcel); |
| 97 | fail("Unreachable -- readFromParcel after close should throw IllegalStateException"); |
| 98 | } catch (IllegalStateException e) { |
| 99 | // good: we expect calling this method after close to fail |
| 100 | } |
| 101 | |
| 102 | try { |
| 103 | mMetadata.writeToParcel(mParcel, /*flags*/0); |
| 104 | fail("Unreachable -- writeToParcel after close should throw IllegalStateException"); |
| 105 | } catch (IllegalStateException e) { |
| 106 | // good: we expect calling this method after close to fail |
| 107 | } |
| 108 | } |
| 109 | } |