Home | History | Annotate | Download | only in database
      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.database;
     18 
     19 import android.test.suitebuilder.annotation.SmallTest;
     20 import android.database.CursorWindow;
     21 import android.test.PerformanceTestCase;
     22 
     23 import java.util.Arrays;
     24 
     25 import junit.framework.TestCase;
     26 
     27 public class CursorWindowTest extends TestCase implements PerformanceTestCase {
     28     public boolean isPerformanceOnly() {
     29         return false;
     30     }
     31 
     32     // These test can only be run once.
     33     public int startPerformance(Intermediates intermediates) {
     34         return 1;
     35     }
     36 
     37     @SmallTest
     38     public void testValuesLocalWindow() {
     39         doTestValues(new CursorWindow(true));
     40     }
     41 
     42     @SmallTest
     43     public void testValuesRemoteWindow() {
     44         doTestValues(new CursorWindow(false));
     45     }
     46 
     47     private void doTestValues(CursorWindow window) {
     48         assertTrue(window.setNumColumns(7));
     49         assertTrue(window.allocRow());
     50         double db1 = 1.26;
     51         assertTrue(window.putDouble(db1, 0, 0));
     52         double db2 = window.getDouble(0, 0);
     53         assertEquals(db1, db2);
     54 
     55         long int1 = Long.MAX_VALUE;
     56         assertTrue(window.putLong(int1, 0, 1));
     57         long int2 = window.getLong(0, 1);
     58         assertEquals(int1, int2);
     59 
     60         assertTrue(window.putString("1198032740000", 0, 3));
     61         assertEquals("1198032740000", window.getString(0, 3));
     62         assertEquals(1198032740000L, window.getLong(0, 3));
     63 
     64         assertTrue(window.putString(Long.toString(1198032740000L), 0, 3));
     65         assertEquals(Long.toString(1198032740000L), window.getString(0, 3));
     66         assertEquals(1198032740000L, window.getLong(0, 3));
     67 
     68         assertTrue(window.putString(Double.toString(42.0), 0, 4));
     69         assertEquals(Double.toString(42.0), window.getString(0, 4));
     70         assertEquals(42.0, window.getDouble(0, 4));
     71 
     72         // put blob
     73         byte[] blob = new byte[1000];
     74         byte value = 99;
     75         Arrays.fill(blob, value);
     76         assertTrue(window.putBlob(blob, 0, 6));
     77         assertTrue(Arrays.equals(blob, window.getBlob(0, 6)));
     78     }
     79 }
     80