Home | History | Annotate | Download | only in cts
      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 package android.app.cts;
     17 
     18 import android.app.ActivityManager;
     19 import android.os.Parcel;
     20 import android.os.Process;
     21 import android.test.AndroidTestCase;
     22 
     23 public class ActivityManagerMemoryInfoTest extends AndroidTestCase {
     24     protected ActivityManager.MemoryInfo mMemory;
     25 
     26     @Override
     27     protected void setUp() throws Exception {
     28         super.setUp();
     29         mMemory = new ActivityManager.MemoryInfo();
     30     }
     31 
     32     public void testDescribeContents() {
     33         assertEquals(0, mMemory.describeContents());
     34     }
     35 
     36     public void testWriteToParcel() throws Exception {
     37         final long AVAILMEM = 1000l;
     38         mMemory.availMem = AVAILMEM;
     39         final long THRESHOLD = 500l;
     40         mMemory.threshold = THRESHOLD;
     41         final boolean LOWMEMORY = true;
     42         mMemory.lowMemory = LOWMEMORY;
     43         Parcel parcel = Parcel.obtain();
     44         mMemory.writeToParcel(parcel, 0);
     45         parcel.setDataPosition(0);
     46         ActivityManager.MemoryInfo values =
     47             ActivityManager.MemoryInfo.CREATOR.createFromParcel(parcel);
     48         assertEquals(AVAILMEM, values.availMem);
     49         assertEquals(THRESHOLD, values.threshold);
     50         assertEquals(LOWMEMORY, values.lowMemory);
     51 
     52         // test null condition.
     53         try {
     54             mMemory.writeToParcel(null, 0);
     55             fail("writeToParcel should throw out NullPointerException when Parcel is null");
     56         } catch (NullPointerException e) {
     57             // expected
     58         }
     59     }
     60 
     61     public void testReadFromParcel() throws Exception {
     62         final long AVAILMEM = 1000l;
     63         mMemory.availMem = AVAILMEM;
     64         final long THRESHOLD = 500l;
     65         mMemory.threshold = THRESHOLD;
     66         final boolean LOWMEMORY = true;
     67         mMemory.lowMemory = LOWMEMORY;
     68         Parcel parcel = Parcel.obtain();
     69         mMemory.writeToParcel(parcel, 0);
     70         parcel.setDataPosition(0);
     71         ActivityManager.MemoryInfo result = new ActivityManager.MemoryInfo();
     72         result.readFromParcel(parcel);
     73         assertEquals(AVAILMEM, result.availMem);
     74         assertEquals(THRESHOLD, result.threshold);
     75         assertEquals(LOWMEMORY, result.lowMemory);
     76 
     77         // test null condition.
     78         result = new ActivityManager.MemoryInfo();
     79         try {
     80             result.readFromParcel(null);
     81             fail("readFromParcel should throw out NullPointerException when Parcel is null");
     82         } catch (NullPointerException e) {
     83             // expected
     84         }
     85     }
     86 
     87 }
     88