Code review comment for lp:~zsombi/ubuntu-ui-toolkit/crossFadeImage_SourceSize_fix

Revision history for this message
Michael Zanetti (mzanetti) wrote :

108 +
109 + function test_sourceSize() {
110 + loadImage("../../../examples/ubuntu-ui-toolkit-gallery/demo_image.jpg");
111 + compare(crossFadeImage.sourceSize.width, 640, "Source width incorrectly initialized.");
112 + compare(crossFadeImage.sourceSize.height, 427, "Source height incorrectly initialized.");
113 + crossFadeImage.sourceSize.width = 100;
114 + crossFadeImage.sourceSize.height = 101;
115 + compare(crossFadeImage.sourceSize.width, 100, "Source width incorrectly updated.");
116 + compare(crossFadeImage.sourceSize.height, 101, "Source height incorrectly updated.");
117 + waitForAnimation();
118 + cleanupTest();
119 + }

I've seen many of those tests in the SDK and I personally think this is quite useless. It only tests if the component actually compiles (ok, better than nothing) and if there actually is a property size sourceSize which is not readonly. That's it. But if the sourceSize is actually used by image? This is not tested. Here's an example how to check that:

// Put this into some helper.js, or TestCaseBase class to inherit from as you're gonna need this in every test as of now. In unity we have a UnityTestCase which inherits a TestCase and adds lots of useful helpers. Feel free to copy that too.

    // Find an object with the given name in the children tree of "obj"
    function findChild(obj,objectName) {
        var childs = new Array(0);
        childs.push(obj)
        while (childs.length > 0) {
            if (childs[0].objectName == objectName) {
                return childs[0]
            }
            for (var i in childs[0].children) {
                childs.push(childs[0].children[i])
            }
            childs.splice(0, 1);
        }
        return undefined;
    }

// Now we have a way to look inside the components. Let's do the test using this:

Edit CrossFadeImage.qml and add "objectName" properties to image1 and image2, like this:

Image {
    id: image1
    objectName: "image1"
    ...
}

And now the test

function test_sourceSize() {
  loadImage("../../../examples/ubuntu-ui-toolkit-gallery/demo_image.jpg");
  compare(crossFadeImage.sourceSize.width, 640, "Source width incorrectly initialized.");
  compare(crossFadeImage.sourceSize.height, 427, "Source height incorrectly initialized.");
  crossFadeImage.sourceSize.width = 100;
  crossFadeImage.sourceSize.height = 101;

  var image1 = findChild(crossFadeImage, "image1");
  var image2 = findChild(crossFadeImage, "image2");

  compare(image1.sourceSize.width, 100, "Source width incorrectly updated.");
  compare(image1.sourceSize.height, 101, "Source height incorrectly updated.");

  compare(image2.sourceSize.width, 100, "Source width incorrectly updated.");
  compare(image2.sourceSize.height, 101, "Source height incorrectly updated.");

  waitForAnimation();
  cleanupTest();
}

« Back to merge proposal