~mortenoh/+junk/dhis2-detailed-import-export

« back to all changes in this revision

Viewing changes to gis/dhis-gis-geostat/mfbase/openlayers/tests/BaseTypes/Pixel.html

  • Committer: larshelge at gmail
  • Date: 2009-03-03 16:46:36 UTC
  • Revision ID: larshelge@gmail.com-20090303164636-2sjlrquo7ib1gf7r
Initial check-in

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<html>
 
2
<head>
 
3
  <script src="../../lib/OpenLayers.js"></script>
 
4
  <script type="text/javascript">
 
5
    var pixel; 
 
6
    
 
7
    function test_Pixel_constructor (t) {
 
8
        t.plan( 4 );
 
9
        pixel = new OpenLayers.Pixel(5,6);
 
10
        t.ok( pixel instanceof OpenLayers.Pixel, "new OpenLayers.Pixel returns Pixel object" );
 
11
        t.eq( pixel.CLASS_NAME, "OpenLayers.Pixel", "pixel.CLASS_NAME is set correctly");
 
12
        t.eq( pixel.x, 5, "pixel.x is set correctly");
 
13
        t.eq( pixel.y, 6, "pixel.y is set correctly");
 
14
    }
 
15
 
 
16
    function test_Pixel_constructorFromString (t) {
 
17
        t.plan( 4 );
 
18
        pixel = new OpenLayers.Pixel("5","6");
 
19
        t.ok( pixel instanceof OpenLayers.Pixel, "new OpenLayers.Pixel returns Pixel object" );
 
20
        t.eq( pixel.CLASS_NAME, "OpenLayers.Pixel", "pixel.CLASS_NAME is set correctly");
 
21
        t.eq( pixel.x, 5, "pixel.x is set correctly");
 
22
        t.eq( pixel.y, 6, "pixel.y is set correctly");
 
23
    }
 
24
 
 
25
    function test_Pixel_toString(t) {
 
26
        t.plan( 1 );
 
27
        pixel = new OpenLayers.Pixel(5,6);
 
28
        t.eq( pixel.toString(), "x=5,y=6", "pixel.toString() returns correctly");
 
29
    }
 
30
 
 
31
    function test_Pixel_clone(t) {
 
32
        t.plan( 4 );
 
33
        oldPixel = new OpenLayers.Pixel(5,6);
 
34
        pixel = oldPixel.clone();
 
35
        t.ok( pixel instanceof OpenLayers.Pixel, "clone returns new OpenLayers.Pixel object" );
 
36
        t.eq( pixel.x, 5, "pixel.x is set correctly");
 
37
        t.eq( pixel.y, 6, "pixel.y is set correctly");
 
38
        
 
39
        oldPixel.x = 100;
 
40
        t.eq( pixel.x, 5, "changing oldPixel.x doesn't change pixel.x");
 
41
    }
 
42
 
 
43
    function test_Pixel_equals(t) {
 
44
        t.plan( 5 );
 
45
        pixel = new OpenLayers.Pixel(5,6);
 
46
 
 
47
        px = new OpenLayers.Pixel(5,6);
 
48
        t.eq( pixel.equals(px), true, "(5,6) equals (5,6)");
 
49
 
 
50
        px = new OpenLayers.Pixel(1,6);
 
51
        t.eq( pixel.equals(px), false, "(5,6) does not equal (1,6)");
 
52
 
 
53
        px = new OpenLayers.Pixel(5,2);
 
54
        t.eq( pixel.equals(px), false, "(5,6) does not equal (5,2)");
 
55
 
 
56
        px = new OpenLayers.Pixel(1,2);
 
57
        t.eq( pixel.equals(px), false, "(5,6) does not equal (1,2)");
 
58
 
 
59
        t.ok( !pixel.equals(null), "equals() returns false on comparison to null");
 
60
 
 
61
    }
 
62
 
 
63
    function test_Pixel_add(t) {
 
64
        t.plan( 8 );
 
65
 
 
66
        var origPX = new OpenLayers.Pixel(5,6);
 
67
        var oldPixel = origPX.clone();
 
68
 
 
69
        var pixel = oldPixel.add(10,20);
 
70
        
 
71
        t.ok( oldPixel.equals(origPX), "oldPixel not modified by add operation");
 
72
        
 
73
        var px = new OpenLayers.Pixel(15,26);
 
74
        t.ok( pixel.equals(px), "returned pixel is correct");
 
75
 
 
76
    //null values
 
77
        var desiredMsg = "You must pass both x and y values to the add function.";
 
78
        OpenLayers.Console.error = function(msg) {
 
79
            t.eq(msg, desiredMsg, "error correctly reported");
 
80
        }
 
81
    
 
82
        pixel = oldPixel.add(null, 50);
 
83
        t.ok( oldPixel.equals(origPX), "oldPixel is not modified by erroneous add operation (null x)");
 
84
        t.ok(pixel == null, "returns null on erroneous add operation (null x)");
 
85
 
 
86
        addpx = oldPixel.add(5, null);
 
87
        t.ok( oldPixel.equals(origPX), "oldPixel is not modified by erroneous add operation (null y)");
 
88
        t.ok(pixel == null, "returns null on erroneous add operation (null y)");
 
89
    }
 
90
 
 
91
    function test_Pixel_offset(t) {
 
92
        t.plan( 4 );
 
93
 
 
94
        var oldPixel = new OpenLayers.Pixel(5,6);
 
95
        var offset = new OpenLayers.Pixel(10,20);
 
96
 
 
97
        pixel = oldPixel.offset(offset);
 
98
 
 
99
        t.eq( oldPixel.x, 5, "oldPixel.x not modified by offset operation");
 
100
        t.eq( oldPixel.y, 6, "oldPixel.y not modified by offset operation");
 
101
 
 
102
        t.eq( pixel.x, 15, "pixel.x is set correctly");
 
103
        t.eq( pixel.y, 26, "pixel.y is set correctly");
 
104
    }
 
105
 
 
106
 
 
107
  </script>
 
108
</head>
 
109
<body>
 
110
</body>
 
111
</html>