Home | History | Annotate | Download | only in os
      1 /*
      2  * Copyright (C) 2008 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 android.os;
     18 
     19 import android.os.Build;
     20 import android.test.suitebuilder.annotation.SmallTest;
     21 import android.util.Log;
     22 import junit.framework.Assert;
     23 import junit.framework.TestCase;
     24 
     25 /**
     26  * Provides test cases for android.os.Build and, in turn, many of the
     27  * system properties set by the build system.
     28  */
     29 public class BuildTest extends TestCase {
     30 
     31     private static final String TAG = "BuildTest";
     32 
     33     /**
     34      * Asserts that a String is non-null and non-empty.  If it is not,
     35      * an AssertionFailedError is thrown with the given message.
     36      */
     37     private static void assertNotEmpty(String message, String string) {
     38         //Log.i(TAG, "" + message + ": " + string);
     39         assertNotNull(message, string);
     40         assertFalse(message, string.equals(""));
     41     }
     42 
     43     /**
     44      * Asserts that a String is non-null and non-empty.  If it is not,
     45      * an AssertionFailedError is thrown.
     46      */
     47     private static void assertNotEmpty(String string) {
     48         assertNotEmpty(null, string);
     49     }
     50 
     51     /**
     52      * Asserts that all android.os.Build fields are non-empty and/or in a valid range.
     53      */
     54     @SmallTest
     55     public void testBuildFields() throws Exception {
     56         assertNotEmpty("ID", Build.ID);
     57         assertNotEmpty("DISPLAY", Build.DISPLAY);
     58         assertNotEmpty("PRODUCT", Build.PRODUCT);
     59         assertNotEmpty("DEVICE", Build.DEVICE);
     60         assertNotEmpty("BOARD", Build.BOARD);
     61         assertNotEmpty("BRAND", Build.BRAND);
     62         assertNotEmpty("MODEL", Build.MODEL);
     63         assertNotEmpty("VERSION.INCREMENTAL", Build.VERSION.INCREMENTAL);
     64         assertNotEmpty("VERSION.RELEASE", Build.VERSION.RELEASE);
     65         assertNotEmpty("TYPE", Build.TYPE);
     66         Assert.assertNotNull("TAGS", Build.TAGS); // TAGS is allowed to be empty.
     67         assertNotEmpty("FINGERPRINT", Build.FINGERPRINT);
     68         Assert.assertTrue("TIME", Build.TIME > 0);
     69         assertNotEmpty("USER", Build.USER);
     70         assertNotEmpty("HOST", Build.HOST);
     71 
     72         // TODO: if any of the android.os.Build fields have additional constraints
     73         // (e.g., must be a C identifier, must be a valid filename, must not contain any spaces)
     74         // add tests for them.
     75     }
     76 }
     77