1 /* 2 * Copyright (C) 2007 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.ide.common.resources.configuration; 18 19 import com.android.resources.ScreenOrientation; 20 21 import junit.framework.TestCase; 22 23 public class ScreenOrientationQualifierTest extends TestCase { 24 25 private ScreenOrientationQualifier soq; 26 private FolderConfiguration config; 27 28 @Override 29 protected void setUp() throws Exception { 30 super.setUp(); 31 soq = new ScreenOrientationQualifier(); 32 config = new FolderConfiguration(); 33 } 34 35 @Override 36 protected void tearDown() throws Exception { 37 super.tearDown(); 38 soq = null; 39 config = null; 40 } 41 42 public void testPortrait() { 43 assertEquals(true, soq.checkAndSet("port", config)); //$NON-NLS-1$ 44 assertTrue(config.getScreenOrientationQualifier() != null); 45 assertEquals(ScreenOrientation.PORTRAIT, config.getScreenOrientationQualifier().getValue()); 46 assertEquals("port", config.getScreenOrientationQualifier().toString()); //$NON-NLS-1$ 47 } 48 49 public void testLanscape() { 50 assertEquals(true, soq.checkAndSet("land", config)); //$NON-NLS-1$ 51 assertTrue(config.getScreenOrientationQualifier() != null); 52 assertEquals(ScreenOrientation.LANDSCAPE, 53 config.getScreenOrientationQualifier().getValue()); 54 assertEquals("land", config.getScreenOrientationQualifier().toString()); //$NON-NLS-1$ 55 } 56 57 public void testSquare() { 58 assertEquals(true, soq.checkAndSet("square", config)); //$NON-NLS-1$ 59 assertTrue(config.getScreenOrientationQualifier() != null); 60 assertEquals(ScreenOrientation.SQUARE, 61 config.getScreenOrientationQualifier().getValue()); 62 assertEquals("square", config.getScreenOrientationQualifier().toString()); //$NON-NLS-1$ 63 } 64 65 public void testFailures() { 66 assertEquals(false, soq.checkAndSet("", config));//$NON-NLS-1$ 67 assertEquals(false, soq.checkAndSet("PORT", config));//$NON-NLS-1$ 68 assertEquals(false, soq.checkAndSet("landscape", config));//$NON-NLS-1$ 69 assertEquals(false, soq.checkAndSet("portrait", config));//$NON-NLS-1$ 70 assertEquals(false, soq.checkAndSet("other", config));//$NON-NLS-1$ 71 } 72 } 73