|
| 1 | +var test = require('tape'); |
| 2 | +var robot = require('..'); |
| 3 | + |
| 4 | +var params = |
| 5 | +{ |
| 6 | + 'width': 'number', |
| 7 | + 'height': 'number', |
| 8 | + 'byteWidth': 'number', |
| 9 | + 'bitsPerPixel': 'number', |
| 10 | + 'bytesPerPixel': 'number', |
| 11 | + 'image': 'object' |
| 12 | +}; |
| 13 | + |
| 14 | +test('Get a bitmap.', function(t) |
| 15 | +{ |
| 16 | + t.plan(1); |
| 17 | + t.ok(robot.screen.capture(), 'got a bitmap.'); |
| 18 | +}); |
| 19 | + |
| 20 | +test('Get a bitmap and check the parameters.', function(t) |
| 21 | +{ |
| 22 | + t.plan(6); |
| 23 | + var img = robot.screen.capture(); |
| 24 | + |
| 25 | + for (var x in params) |
| 26 | + { |
| 27 | + t.equal(typeof img[x], params[x], 'make sure ' + x + ' is a ' + params[x] + '.'); |
| 28 | + } |
| 29 | +}); |
| 30 | + |
| 31 | +test('Get a bitmap of a specific size.', function(t) |
| 32 | +{ |
| 33 | + var size = 10; |
| 34 | + t.plan(2); |
| 35 | + var img = robot.screen.capture(0, 0, size, size); |
| 36 | + |
| 37 | + t.equals(img.height, size, 'make sure image is expected height.'); |
| 38 | + t.equals(img.width, size, 'make sure image is expected width.'); |
| 39 | +}); |
| 40 | + |
| 41 | +test('Get a bitmap and make sure the colorAt works as expected.', function(t) |
| 42 | +{ |
| 43 | + t.plan(7); |
| 44 | + var img = robot.screen.capture(); |
| 45 | + var hex = img.colorAt(0, 0); |
| 46 | + |
| 47 | + t.ok(/^[0-9A-F]{6}$/i.test(hex), "colorAt returned valid hex."); |
| 48 | + |
| 49 | + var screenSize = robot.getScreenSize(); |
| 50 | + |
| 51 | + t.throws(function() |
| 52 | + { |
| 53 | + img.colorAt(0, screenSize.height); |
| 54 | + }, /are outside the bitmap/, 'colorAt (0, screen.height) threw an error.'); |
| 55 | + |
| 56 | + t.doesNotThrow(function() |
| 57 | + { |
| 58 | + img.colorAt(0, screenSize.height-1); |
| 59 | + }, /are outside the bitmap/, 'colorAt (0, screen.height-1) did not throw an error.'); |
| 60 | + |
| 61 | + t.throws(function() |
| 62 | + { |
| 63 | + img.colorAt(screenSize.width, 0); |
| 64 | + }, /are outside the bitmap/, 'colorAt (screen.width, 0) threw an error.'); |
| 65 | + |
| 66 | + t.doesNotThrow(function() |
| 67 | + { |
| 68 | + img.colorAt(screenSize.width-1, 0); |
| 69 | + }, /are outside the bitmap/, 'colorAt (screen.width-1, 0) did not throw an error.'); |
| 70 | + |
| 71 | + t.throws(function() |
| 72 | + { |
| 73 | + img.colorAt(9999999999999, 0); |
| 74 | + }, /are outside the bitmap/, 'colorAt (9999999999999, 0) threw an error.'); |
| 75 | + |
| 76 | + // Regression test for https://github.com/octalmage/robotjs/commit/c41f38217fd73f59e6ca63015b51565cd1e7cfb7 |
| 77 | + t.throws(function() |
| 78 | + { |
| 79 | + img.colorAt(0, 9999999999999); |
| 80 | + }, /are outside the bitmap/, 'colorAt (0, 9999999999999) threw an error.'); |
| 81 | +}); |
0 commit comments