OpenLayers OpenLayers

Changeset 3687

Show
Ignore:
Timestamp:
07/10/07 18:16:17 (1 year ago)
Author:
euzuro
Message:

add tests for getTilesBounds() and also a whole new section to test moveTo() for grid

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sandbox/euzuro/untiled3/tests/Layer/test_Grid.html

    r3669 r3687  
    9292 
    9393    function test_04_Layer_Grid_getTilesBounds(t) { 
    94         t.plan( 1 ); 
    95  
    96         layer = new OpenLayers.Layer.WMS(name, url, params); 
    97  
     94        t.plan( 3 ); 
     95 
     96        layer = new OpenLayers.Layer.WMS(name, url, params); 
     97 
     98 
     99    //normal grid 
    98100        var bl = { bounds: new OpenLayers.Bounds(1,2,0,0)}; 
    99101        var tr = { bounds: new OpenLayers.Bounds(0,0,3,4)}; 
     
    102104 
    103105        var bounds = layer.getTilesBounds(); 
    104      
    105106        var testBounds = new OpenLayers.Bounds(1,2,3,4); 
    106107         
    107         t.ok( bounds.equals(testBounds), "getTilesBounds() returns correct bounds") 
    108  
    109         layer.grid = null; 
     108        t.ok( bounds.equals(testBounds), "getTilesBounds() returns correct bounds"); 
     109 
     110    //no tiles 
     111        layer.grid = new Array(); 
     112        bounds = layer.getTilesBounds(); 
     113         
     114        t.ok(bounds == null, "getTilesBounds() on a tile-less grid returns null"); 
     115         
     116 
     117    //singleTile 
     118        var singleTile = { bounds: new OpenLayers.Bounds(1,2,3,4)}; 
     119        layer.grid = [ [ singleTile ] ]; 
     120        bounds = layer.getTilesBounds(); 
     121         
     122        t.ok( bounds.equals(testBounds), "getTilesBounds() returns correct bounds"); 
     123         
    110124    } 
    111125 
     
    140154        t.eq( zoom, 2, "getZoomForExtent() returns correct value"); 
    141155    }    
    142  
     156     
     157    function test_07_Layer_Grid_moveTo(t) { 
     158 
     159    t.plan(13); 
     160 
     161        var map = new OpenLayers.Map('map'); 
     162        layer = new OpenLayers.Layer.WMS(name, url, params); 
     163        layer.destroy = function() {}; //we're going to do funky things with the grid 
     164        map.addLayer(layer); 
     165 
     166    //make sure null bounds doesnt cause script error.  
     167    // no test necessary, just action 
     168        map.getExtent = function() { return null; } 
     169        layer.singleTile = false; 
     170        layer.moveTo(); //checks to make sure null bounds doesnt break us 
     171   
     172 
     173 
     174      //observing globals 
     175        layer.initSingleTile = function(bounds) { 
     176            g_WhichFunc = "InitSingle"; 
     177            g_Bounds = bounds; 
     178        }; 
     179        layer.initGriddedTiles = function(bounds) { 
     180            g_WhichFunc = "InitGridded"; 
     181            g_Bounds = bounds; 
     182        }; 
     183        layer.moveGriddedTiles = function(bounds) { 
     184            g_WhichFunc = "MoveGridded"; 
     185            g_Bounds = bounds; 
     186        }; 
     187        var clearTestBounds = function() { 
     188            g_WhichFunc = null; 
     189            g_Bounds = null; 
     190        }; 
     191 
     192      //default map extent (tested every time below) 
     193        b = new OpenLayers.Bounds(0,0,100,100);         
     194        map.getExtent = function() { 
     195            return b; 
     196        }; 
     197        var tilesBounds = null; 
     198        layer.getTilesBounds = function() { 
     199            return tilesBounds; 
     200        } 
     201 
     202 
     203//FORCE 
     204 
     205    //empty grid 
     206        layer.grid = new Array(); 
     207       //grid 
     208        clearTestBounds(); 
     209        layer.singleTile = false; 
     210        layer.moveTo()         
     211        t.ok(g_Bounds.equals(b), "if grid is empty, initGridded called"); 
     212         
     213       //singletile 
     214        clearTestBounds(); 
     215        layer.singleTile = true; 
     216        layer.moveTo()         
     217        t.ok(g_Bounds.equals(b), "if grid is empty, initSingleTile called"); 
     218 
     219    //zoomChanged 
     220        zoomChanged = true; 
     221        layer.grid = [ [ {} ] ]; 
     222 
     223       //grid 
     224        clearTestBounds(); 
     225        layer.singleTile = false; 
     226        layer.moveTo(null, zoomChanged);         
     227        t.ok(g_Bounds.equals(b), "if layer has grid but zoomChanged is called, initGridded called"); 
     228         
     229       //singletile 
     230        clearTestBounds(); 
     231        layer.singleTile = true; 
     232        layer.moveTo(null, zoomChanged); 
     233        t.ok(g_Bounds.equals(b), "if layer has grid but zoomChanged is called, initSingleTile called"); 
     234 
     235 
     236        layer.getTilesBounds = function() { 
     237            return tilesBounds; 
     238        } 
     239         
     240         
     241 
     242//NO FORCE 
     243        zoomChanged = false; 
     244        layer.grid = [ [ {} ] ]; 
     245  
     246   //single tile 
     247        layer.singleTile = true;  
     248         
     249      //DRAGGING    
     250        var dragging = true; 
     251             
     252        //in bounds 
     253        clearTestBounds(); 
     254        tilesBounds = new OpenLayers.Bounds(-10,-10,110,110); 
     255        layer.moveTo(null, zoomChanged, dragging); 
     256        t.ok(g_Bounds == null, "if dragging and tile in bounds, no init()"); 
     257         
     258        //out bounds 
     259        clearTestBounds(); 
     260        tilesBounds = new OpenLayers.Bounds(10,10,120,120); 
     261        layer.moveTo(null, zoomChanged, dragging); 
     262        t.ok(g_Bounds == null, "if dragging and tile out of bounds, no init()"); 
     263 
     264      //NOT DRAGGING 
     265        dragging = false; 
     266 
     267        //in bounds 
     268        clearTestBounds(); 
     269        tilesBounds = new OpenLayers.Bounds(-10,-10,110,110); 
     270        layer.moveTo(null, zoomChanged, dragging); 
     271        t.ok(g_Bounds == null, "if dragging and tile in bounds, no init()"); 
     272         
     273        //out bounds 
     274        clearTestBounds(); 
     275        tilesBounds = new OpenLayers.Bounds(10,10,120,120); 
     276        layer.moveTo(null, zoomChanged, dragging); 
     277        t.ok(g_WhichFunc == "InitSingle", "if not dragging and tile out of bounds, we call initSingleTile()"); 
     278        t.ok(g_Bounds.equals(b), "if not dragging and tile out of bounds, we call initSingleTile() with correct bounds"); 
     279 
     280   
     281   //gridded 
     282        layer.grid = [ [ {} ] ]; 
     283        layer.singleTile = false; 
     284         
     285        // drastic pan 
     286        clearTestBounds(); 
     287        tilesBounds = new OpenLayers.Bounds(-150,-150,-120,-120); 
     288        layer.moveTo(null, zoomChanged); 
     289        t.ok(g_WhichFunc == "InitGridded", "if tiles drastically out of bounds, we call initGriddedTile()"); 
     290        t.ok(g_Bounds.equals(b), "if tiles drastically out of bounds, we call initGriddedTile() with correct bounds"); 
     291        
     292        //regular move  
     293        clearTestBounds(); 
     294        tilesBounds = new OpenLayers.Bounds(10,10,120,120); 
     295        layer.moveTo(null, zoomChanged); 
     296        t.ok(g_WhichFunc == "MoveGridded", "if tiles not drastically out of bounds, we call moveGriddedTile()"); 
     297        t.ok(g_Bounds.equals(b), "if tiles not drastically out of bounds, we call moveGriddedTile() with correct bounds"); 
     298    } 
    143299 
    144300    /** THIS WOULD BE WHERE THE TESTS WOULD GO FOR  
    145301     *      
    146      *    -moveTo 
    147302     *    -insertColumn 
    148303     *    -insertRow 
    149      
    150     function 07_Layer_Grid_moveTo(t) { 
    151     } 
     304     *  
    152305 
    153306    function 08_Layer_Grid_insertColumn(t) {