Home | History | Annotate | Download | only in layout
      1 /*
      2  * Copyright (C) 2011 The Android Open Source Project
      3  *
      4  * Licensed under the Eclipse Public License, Version 1.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.eclipse.org/org/documents/epl-v10.php
      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 package com.android.ide.common.layout;
     17 
     18 import static com.android.ide.common.layout.GravityHelper.GRAVITY_BOTTOM;
     19 import static com.android.ide.common.layout.GravityHelper.GRAVITY_CENTER_HORIZ;
     20 import static com.android.ide.common.layout.GravityHelper.GRAVITY_CENTER_VERT;
     21 import static com.android.ide.common.layout.GravityHelper.GRAVITY_FILL_HORIZ;
     22 import static com.android.ide.common.layout.GravityHelper.GRAVITY_FILL_VERT;
     23 import static com.android.ide.common.layout.GravityHelper.GRAVITY_LEFT;
     24 import static com.android.ide.common.layout.GravityHelper.GRAVITY_RIGHT;
     25 import static com.android.ide.common.layout.GravityHelper.GRAVITY_TOP;
     26 import static com.android.ide.common.layout.GravityHelper.getGravity;
     27 import junit.framework.TestCase;
     28 
     29 @SuppressWarnings("javadoc")
     30 public class GravityHelperTest extends TestCase {
     31     public void testGravity() throws Exception {
     32         assertEquals(GRAVITY_BOTTOM, GravityHelper.getGravity("bottom", 0));
     33         assertEquals(GRAVITY_BOTTOM | GRAVITY_LEFT, GravityHelper.getGravity("bottom|left", 0));
     34         assertEquals(GRAVITY_CENTER_HORIZ | GRAVITY_CENTER_VERT,
     35                 GravityHelper.getGravity("center", 0));
     36     }
     37 
     38     public void testGravityString() throws Exception {
     39         assertEquals("left", getGravity(GRAVITY_LEFT));
     40         assertEquals("right", getGravity(GRAVITY_RIGHT));
     41         assertEquals("top", getGravity(GRAVITY_TOP));
     42         assertEquals("bottom", getGravity(GRAVITY_BOTTOM));
     43         assertEquals("center_horizontal", getGravity(GRAVITY_CENTER_HORIZ));
     44         assertEquals("center_vertical", getGravity(GRAVITY_CENTER_VERT));
     45         assertEquals("fill_horizontal", getGravity(GRAVITY_FILL_HORIZ));
     46         assertEquals("fill_vertical", getGravity(GRAVITY_FILL_VERT));
     47 
     48         assertEquals("center", getGravity(GRAVITY_CENTER_HORIZ|GRAVITY_CENTER_VERT));
     49 
     50         assertEquals("left|bottom", getGravity(GRAVITY_LEFT|GRAVITY_BOTTOM));
     51         assertEquals("center_horizontal|top", getGravity(GRAVITY_CENTER_HORIZ|GRAVITY_TOP));
     52     }
     53 
     54     public void testConstrained() throws Exception {
     55         assertTrue(GravityHelper.isConstrainedHorizontally(GRAVITY_LEFT));
     56         assertTrue(GravityHelper.isConstrainedHorizontally(GRAVITY_RIGHT));
     57         assertTrue(GravityHelper.isConstrainedHorizontally(GRAVITY_CENTER_HORIZ));
     58         assertTrue(GravityHelper.isConstrainedHorizontally(GRAVITY_FILL_HORIZ));
     59 
     60         assertFalse(GravityHelper.isConstrainedVertically(GRAVITY_LEFT));
     61         assertFalse(GravityHelper.isConstrainedVertically(GRAVITY_RIGHT));
     62         assertFalse(GravityHelper.isConstrainedVertically(GRAVITY_CENTER_HORIZ));
     63         assertFalse(GravityHelper.isConstrainedVertically(GRAVITY_FILL_HORIZ));
     64 
     65         assertTrue(GravityHelper.isConstrainedVertically(GRAVITY_TOP));
     66         assertTrue(GravityHelper.isConstrainedVertically(GRAVITY_BOTTOM));
     67         assertTrue(GravityHelper.isConstrainedVertically(GRAVITY_CENTER_VERT));
     68         assertTrue(GravityHelper.isConstrainedVertically(GRAVITY_FILL_VERT));
     69 
     70         assertFalse(GravityHelper.isConstrainedHorizontally(GRAVITY_TOP));
     71         assertFalse(GravityHelper.isConstrainedHorizontally(GRAVITY_BOTTOM));
     72         assertFalse(GravityHelper.isConstrainedHorizontally(GRAVITY_CENTER_VERT));
     73         assertFalse(GravityHelper.isConstrainedHorizontally(GRAVITY_FILL_VERT));
     74     }
     75 
     76     public void testAligned() throws Exception {
     77         assertTrue(GravityHelper.isLeftAligned(GRAVITY_LEFT|GRAVITY_TOP));
     78         assertTrue(GravityHelper.isLeftAligned(GRAVITY_LEFT));
     79         assertFalse(GravityHelper.isLeftAligned(GRAVITY_RIGHT));
     80 
     81         assertTrue(GravityHelper.isTopAligned(GRAVITY_LEFT|GRAVITY_TOP));
     82         assertTrue(GravityHelper.isTopAligned(GRAVITY_TOP));
     83         assertFalse(GravityHelper.isTopAligned(GRAVITY_BOTTOM));
     84     }
     85 }
     86