2011-05-14 13:59:04 -04:00
|
|
|
// Override equals to convert functions to message and execute them as tests()
|
2011-05-07 12:25:34 -04:00
|
|
|
function equals(actual, expected, message) {
|
|
|
|
if (typeof actual === 'function') {
|
|
|
|
if (!message) {
|
|
|
|
message = actual.toString().match(
|
|
|
|
/^\s*function[^\{]*\{([\s\S]*)\}\s*$/)[1]
|
|
|
|
.replace(/ /g, '')
|
2011-05-07 12:46:06 -04:00
|
|
|
.replace(/^\s+|\s+$/g, '');
|
|
|
|
if (/^return /.test(message)) {
|
|
|
|
message = message
|
|
|
|
.replace(/^return /, '')
|
|
|
|
.replace(/;$/, '');
|
|
|
|
}
|
2011-05-07 12:25:34 -04:00
|
|
|
}
|
|
|
|
actual = actual();
|
|
|
|
}
|
2011-05-14 13:59:04 -04:00
|
|
|
// Let's be strict
|
2011-05-07 12:25:34 -04:00
|
|
|
return strictEqual(actual, expected, message);
|
|
|
|
}
|
2011-05-05 08:38:20 -04:00
|
|
|
|
2011-05-14 13:59:04 -04:00
|
|
|
function test(testName, expected) {
|
|
|
|
return QUnit.test(testName, function() {
|
2011-05-20 09:08:17 -04:00
|
|
|
var project = new Project();
|
2011-05-14 13:59:04 -04:00
|
|
|
expected();
|
2011-05-20 09:08:17 -04:00
|
|
|
project.remove();
|
2011-05-14 13:59:04 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-02-13 10:48:20 -05:00
|
|
|
function compareNumbers(number1, number2, message) {
|
2011-05-03 03:55:01 -04:00
|
|
|
if (number1 !== 0)
|
2011-03-08 20:25:38 -05:00
|
|
|
number1 = Math.round(number1 * 100) / 100;
|
2011-05-03 03:55:01 -04:00
|
|
|
if (number2 !== 0)
|
2011-03-08 20:25:38 -05:00
|
|
|
number2 = Math.round(number2 * 100) / 100;
|
|
|
|
equals(number1, number2, message);
|
2011-02-13 10:48:20 -05:00
|
|
|
}
|
|
|
|
|
2011-02-07 13:28:09 -05:00
|
|
|
function comparePoints(point1, point2, message) {
|
2011-05-05 08:05:39 -04:00
|
|
|
compareNumbers(point1.x, point2.x,
|
|
|
|
(message || '') + ' x');
|
|
|
|
compareNumbers(point1.y, point2.y,
|
|
|
|
(message || '') + ' y');
|
2011-02-13 09:35:48 -05:00
|
|
|
}
|
|
|
|
|
2011-02-13 10:48:20 -05:00
|
|
|
function compareRectangles(rect1, rect2, message) {
|
2011-05-05 08:05:39 -04:00
|
|
|
compareNumbers(rect1.x, rect2.x,
|
|
|
|
(message || '') + ' x');
|
|
|
|
compareNumbers(rect1.y, rect2.y,
|
|
|
|
(message || '') + ' y');
|
2011-02-13 10:48:20 -05:00
|
|
|
compareNumbers(rect1.width, rect2.width,
|
2011-05-05 08:05:39 -04:00
|
|
|
(message || '') + ' width');
|
2011-02-13 10:48:20 -05:00
|
|
|
compareNumbers(rect1.height, rect2.height,
|
2011-05-05 08:05:39 -04:00
|
|
|
(message || '') + ' height');
|
2011-02-13 10:48:20 -05:00
|
|
|
}
|
2011-02-19 11:11:17 -05:00
|
|
|
|
|
|
|
function compareRGBColors(color1, color2, message) {
|
|
|
|
color1 = new RGBColor(color1);
|
|
|
|
color2 = new RGBColor(color2);
|
|
|
|
|
2011-03-08 20:25:38 -05:00
|
|
|
compareNumbers(color1.red, color2.red,
|
2011-05-05 08:05:39 -04:00
|
|
|
(message || '') + ' red');
|
2011-03-08 20:25:38 -05:00
|
|
|
compareNumbers(color1.green, color2.green,
|
2011-05-05 08:05:39 -04:00
|
|
|
(message || '') + ' green');
|
2011-03-08 20:25:38 -05:00
|
|
|
compareNumbers(color1.blue, color2.blue,
|
2011-05-05 08:05:39 -04:00
|
|
|
(message || '') + ' blue');
|
2011-03-08 20:25:38 -05:00
|
|
|
compareNumbers(color1.alpha, color2.alpha,
|
2011-05-05 08:05:39 -04:00
|
|
|
(message || '') + ' alpha');
|
2011-03-08 20:25:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function compareHSBColors(color1, color2, message) {
|
|
|
|
color1 = new HSBColor(color1);
|
|
|
|
color2 = new HSBColor(color2);
|
|
|
|
|
|
|
|
compareNumbers(color1.hue, color2.hue,
|
2011-05-05 08:05:39 -04:00
|
|
|
(message || '') + ' hue');
|
2011-03-08 20:25:38 -05:00
|
|
|
compareNumbers(color1.saturation, color2.saturation,
|
2011-05-05 08:05:39 -04:00
|
|
|
(message || '') + ' saturation');
|
2011-03-08 20:25:38 -05:00
|
|
|
compareNumbers(color1.brightness, color2.brightness,
|
2011-05-05 08:05:39 -04:00
|
|
|
(message || '') + ' brightness');
|
2011-03-08 20:25:38 -05:00
|
|
|
compareNumbers(color1.alpha, color2.alpha,
|
2011-05-05 08:05:39 -04:00
|
|
|
(message || '') + ' alpha');
|
2011-03-08 20:25:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function compareGrayColors(color1, color2, message) {
|
|
|
|
color1 = new GrayColor(color1);
|
|
|
|
color2 = new GrayColor(color2);
|
|
|
|
|
|
|
|
compareNumbers(color1.gray, color2.gray,
|
2011-05-05 08:05:39 -04:00
|
|
|
(message || '') + ' gray');
|
2011-05-20 13:39:12 -04:00
|
|
|
}
|
|
|
|
|
2011-05-21 06:09:00 -04:00
|
|
|
function compareGradientColors(color1, color2) {
|
|
|
|
Base.each(['origin', 'destination', 'hilite'], function(key) {
|
|
|
|
equals(color1[key].toString(), color2[key].toString(),
|
|
|
|
'color1[' + key + '].toString() == color2[' + key + '].toString()');
|
|
|
|
});
|
|
|
|
equals(function() {
|
|
|
|
return color1.gradient.equals(color2.gradient);
|
|
|
|
}, true);
|
|
|
|
}
|
|
|
|
|
2011-05-20 13:39:12 -04:00
|
|
|
function cloneAndCompare(item) {
|
|
|
|
var copy = item.clone();
|
2011-05-21 06:46:21 -04:00
|
|
|
equals(function() {
|
|
|
|
return item._parent == copy._parent;
|
|
|
|
}, true);
|
|
|
|
equals(function() {
|
|
|
|
return item.nextSibling == copy;
|
|
|
|
}, true);
|
2011-05-21 08:05:52 -04:00
|
|
|
if (item.name) {
|
|
|
|
equals(function() {
|
|
|
|
return copy.parent.children[copy.name] == copy;
|
|
|
|
}, true);
|
|
|
|
}
|
2011-05-20 13:39:12 -04:00
|
|
|
compareItems(item, copy);
|
|
|
|
// Remove the cloned item to restore the document:
|
|
|
|
copy.remove();
|
|
|
|
}
|
|
|
|
|
|
|
|
function compareItems(item, item2) {
|
|
|
|
equals(function() {
|
|
|
|
return item != item2;
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
var itemProperties = ['opacity', 'locked', 'visible', 'blendMode', 'name',
|
|
|
|
'closed', 'selected'];
|
|
|
|
Base.each(itemProperties, function(key) {
|
|
|
|
equals(function() {
|
|
|
|
return item[key] == item2[key];
|
|
|
|
}, true, 'item[\'' + key + '\'] == item2[\'' + key + '\']');
|
|
|
|
});
|
|
|
|
|
|
|
|
equals(function() {
|
|
|
|
return item.id != item2.id;
|
|
|
|
}, true);
|
2011-05-21 06:49:15 -04:00
|
|
|
|
2011-05-20 13:39:12 -04:00
|
|
|
if (item._matrix) {
|
|
|
|
equals(function() {
|
|
|
|
return item._matrix != item2._matrix;
|
2011-05-20 16:03:46 -04:00
|
|
|
}, true);
|
2011-05-20 13:39:12 -04:00
|
|
|
equals(item._matrix.toString(), item2._matrix.toString(),
|
|
|
|
'item._matrix.toString() == item2._matrix.toString()');
|
|
|
|
}
|
2011-05-21 06:48:43 -04:00
|
|
|
|
|
|
|
if (item.matrix) {
|
|
|
|
equals(function() {
|
|
|
|
return item.matrix != item2.matrix;
|
|
|
|
}, true);
|
|
|
|
equals(item.matrix.toString(), item2.matrix.toString(),
|
|
|
|
'item.matrix.toString() == item2.matrix.toString()');
|
|
|
|
}
|
2011-05-20 13:39:12 -04:00
|
|
|
|
|
|
|
if (item2.segments) {
|
|
|
|
equals(item.segments.toString(), item2.segments.toString(),
|
|
|
|
'item.segments.toString() == item2.segments.toString()');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Path specific
|
|
|
|
if (item instanceof PathItem) {
|
|
|
|
equals(function() {
|
|
|
|
return item._clockwise == item2._clockwise;
|
|
|
|
}, true);
|
|
|
|
}
|
2011-05-21 06:49:15 -04:00
|
|
|
|
2011-05-20 13:39:12 -04:00
|
|
|
// Group specific
|
|
|
|
if (item instanceof Group) {
|
|
|
|
equals(function() {
|
|
|
|
return item._clipped == item2._clipped;
|
|
|
|
}, true);
|
|
|
|
}
|
2011-05-21 06:49:15 -04:00
|
|
|
|
2011-05-20 13:39:12 -04:00
|
|
|
// Layer specific
|
|
|
|
if (item instanceof Layer) {
|
|
|
|
equals(function() {
|
|
|
|
return item.project == item2.project;
|
|
|
|
}, true);
|
|
|
|
}
|
2011-05-21 06:49:15 -04:00
|
|
|
|
2011-05-20 13:39:12 -04:00
|
|
|
// PlacedSymbol specific
|
|
|
|
if (item instanceof PlacedSymbol) {
|
|
|
|
equals(function() {
|
|
|
|
return item.symbol == item2.symbol;
|
|
|
|
}, true);
|
|
|
|
}
|
2011-05-21 06:47:58 -04:00
|
|
|
|
|
|
|
// Raster specific
|
|
|
|
if (item instanceof Raster) {
|
|
|
|
if (item._canvas) {
|
|
|
|
equals(function() {
|
|
|
|
return item._canvas != item2._canvas;
|
|
|
|
}, true);
|
|
|
|
}
|
|
|
|
if (item._image) {
|
|
|
|
equals(function() {
|
|
|
|
return item._image = item2._image;
|
|
|
|
}, true);
|
|
|
|
}
|
|
|
|
equals(item._size.toString(), item2._size.toString(),
|
|
|
|
'item._size.toString() == item2._size.toString()');
|
|
|
|
}
|
|
|
|
|
2011-05-20 13:39:12 -04:00
|
|
|
// TextItem specific:
|
|
|
|
if (item instanceof TextItem) {
|
|
|
|
equals(item.content, item2.content, 'item.content == item2.content');
|
|
|
|
var characterStyleKeys = ['fontSize', 'font'];
|
|
|
|
Base.each(characterStyleKeys, function(key) {
|
|
|
|
equals(function() {
|
|
|
|
return item2.characterStyle[key];
|
|
|
|
}, item.characterStyle[key], 'item.characterStyle[\'' + key
|
|
|
|
+ '\'] == item2.characterStyle[\'' + key + '\']');
|
|
|
|
});
|
|
|
|
var paragraphStyleKeys = ['justification'];
|
|
|
|
Base.each(paragraphStyleKeys, function(key) {
|
|
|
|
equals(function() {
|
|
|
|
return item2.paragraphStyle[key];
|
|
|
|
}, item.paragraphStyle[key], 'item.paragraphStyle[\'' + key
|
|
|
|
+ '\'] == item2.paragraphStyle[\'' + key + '\']');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// PointText specific:
|
|
|
|
if (item instanceof PointText) {
|
|
|
|
equals(item.point.toString(), item2.point.toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item._style) {
|
|
|
|
// Path Style
|
2011-05-21 06:10:05 -04:00
|
|
|
|
|
|
|
Base.each(['fillColor', 'strokeColor'], function(key) {
|
|
|
|
if (item[key]) {
|
2011-05-21 08:07:29 -04:00
|
|
|
// The color should not point to the same color object:
|
2011-05-21 06:10:05 -04:00
|
|
|
equals(function() {
|
2011-05-21 08:07:29 -04:00
|
|
|
return item[key] !== item2[key];
|
2011-05-21 06:10:05 -04:00
|
|
|
}, true, 'The ' + key + ' should not point to the same color object:');
|
|
|
|
if (item[key] instanceof GradientColor) {
|
|
|
|
equals(function() {
|
|
|
|
return item[key].gradient == item2[key].gradient;
|
|
|
|
}, true, 'The ' + key + '.gradient should point to the same object:');
|
|
|
|
compareGradientColors(item[key], item2[key],
|
|
|
|
'Compare item[' + key + '] and item2[' + key + ']');
|
|
|
|
} else {
|
|
|
|
equals(item[key].toString(), item2[key].toString(),
|
|
|
|
'item[' + key + '] == item2[' + key + ']');
|
|
|
|
}
|
2011-05-20 13:39:12 -04:00
|
|
|
}
|
2011-05-21 06:10:05 -04:00
|
|
|
});
|
2011-05-20 13:39:12 -04:00
|
|
|
|
|
|
|
Base.each(['strokeCap', 'strokeJoin', 'dashOffset', 'miterLimit',
|
|
|
|
'strokeOverprint', 'fillOverprint'], function(key) {
|
|
|
|
if (item[key]) {
|
|
|
|
equals(function() {
|
|
|
|
return item[key] == item2[key];
|
|
|
|
}, true, 'item[\'' + key + '\'] == item2[\'' + key + '\']');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (item.dashArray) {
|
|
|
|
equals(item.dashArray.toString(), item2.dashArray.toString(),
|
|
|
|
'item.dashArray.toString(), item2.dashArray.toString()');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check length of children and recursively compare them:
|
|
|
|
if (item.children) {
|
|
|
|
equals(function() {
|
|
|
|
return item.children.length == item2.children.length;
|
|
|
|
}, true);
|
|
|
|
for (var i = 0, l = item.children.length; i < l; i++) {
|
|
|
|
compareItems(item.children[i], item2.children[i]);
|
|
|
|
}
|
|
|
|
}
|
2011-02-19 11:11:17 -05:00
|
|
|
}
|