From ygrego@users.nuiton.org Mon Mar 23 16:57:01 2015
From: ygrego@users.nuiton.org
To: sandbox-commits@list.nuiton.org
Subject: [Sandbox-commits] r964 - oipf/js/test
Date: Mon, 23 Mar 2015 16:57:01 +0000
Message-ID: <20150323165701.997375C7FA8@goh.codelutin.com>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="===============2310176208757079012=="

--===============2310176208757079012==
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable

Author: ygrego
Date: 2015-03-23 16:57:00 +0000 (Mon, 23 Mar 2015)
New Revision: 964

Url: http://forge.nuiton.org/projects/sandbox/repository/revisions/964

Log:
Deletion of field "callBeforeAnyTest" into property "testsObjects".
Addition of method "runLoop" in order to launch a set of test in sequence and=
 "run" which perform one test exactly.
Modification of method "runAll" which call method "runLoop".

Modified:
   oipf/js/test/Test.js

Modified: oipf/js/test/Test.js
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- oipf/js/test/Test.js	2015-03-23 16:40:51 UTC (rev 963)
+++ oipf/js/test/Test.js	2015-03-23 16:57:00 UTC (rev 964)
@@ -7,11 +7,10 @@
     testsObjects: [{
         name : "VideoBroadcastTest",
         object: new VideoBroadcastTest(),
-        callBeforeAnyTest : "beforeAnyTest",
         tests: [
             {
                 label: "Video broadcast creation.",
-                method: "testVideoBroadcastInit"
+                method: "testBind2Stop"
             },
             {
                 label: "Bind the current channel stream with a video broadca=
st object.",
@@ -36,7 +35,6 @@
         ]},{
         name: "SearchManagerTest",
         object: new SearchManagerTest(),
-        callBeforeAnyTest : "beforeAnyTest",
         tests: [
             {
                 label: "Search manager creation.",
@@ -54,21 +52,36 @@
     },
    =20
     runAll: function() {
-        for (var i =3D 0; i < this.testsObjects.length; i++) {
-            var element =3D this.testsObjects[i];
-
-            var object =3D element["object"];
-
-            var tests =3D element["tests"];
-
-            for (var j =3D 0; j < tests.length; j++) {
-                var currentTest =3D tests[j];
-                this.updateTestResult(currentTest, object, element["callBefo=
reAnyTest"]);
-              =20
+        this.runLoop(0, 0);
+    },
+   =20
+    runLoop: function(indexObject, indexTest) {   =20
+        var element =3D this.testsObjects[indexObject];=20
+        var object =3D element.object;
+        var tests =3D element.tests;
+       =20
+        var self =3D this;
+        var loop =3D function() {
+            if (indexTest < tests.length - 1) {
+                self.runLoop(indexObject, indexTest + 1);
+           =20
+            } else if (indexObject < self.testsObjects.length -1) {
+                self.runLoop(indexObject + 1, 0);               =20
             }
-        }
+        };
+       =20
+        this.updateTestResult(tests[indexTest], object)
+        .then(loop).catch(loop);
     },
    =20
+    run: function(indexObject, indexTest) {
+        var element =3D this.testsObjects[indexObject];=20
+        var object =3D element.object;
+        var tests =3D element.tests;
+       =20
+        return this.updateTestResult(tests[indexTest], object);
+    },
+   =20
     displayInLineArray: function() {
         var content =3D "<div id=3D'testsDisplay'>Test Page <button id=3D'ru=
nAllBtn'>Run All</button>";
         var testsObjects =3D this.testsObjects;
@@ -111,51 +124,45 @@
         document.body.innerHTML =3D content;
     },
    =20
-    updateTestResult: function(currentTest, object, methodToCallBeforeAnyTes=
t) {
+    updateTestResult: function(currentTest, object) {
         console.group(currentTest["label"]);
         var timeStart =3D performance.now();
-        var result =3D false;
-        object[methodToCallBeforeAnyTest]();
-       =20
-        new Promise(object[currentTest["method"]].bind(object))
+        var self =3D this;
+      =20
+        return new Promise(function(resolve, reject) {
+            try {
+                object.beforeTest && object.beforeTest(resolve, reject);
+                object[currentTest["method"]](resolve, reject);
+                timeout(5000).then(reject("No result returned."));
+            } catch (error) {
+                reject(error);
+            }
+        })
         .then(function(val) {
             console.groupEnd(currentTest["label"]);
-            result =3D true;
             var timeEnd =3D performance.now();
-            document.getElementById(currentTest["method"] + "Result").textCo=
ntent =3D val;
-            document.getElementById(currentTest["method"] + "Result").style.=
backgroundColor =3D "limegreen";
-            document.getElementById(currentTest["method"] + "Duration").text=
Content =3D (timeEnd - timeStart).toFixed(2) + " ms";   =20
+            self.updateTestResultSuccess(timeStart, timeEnd, currentTest, va=
l);   =20
         })
         .catch(function(val) {
             console.log(val);
             console.groupEnd(currentTest["label"]);
-            result =3D true;
             var timeEnd =3D performance.now();
-            document.getElementById(currentTest["method"] + "Result").textCo=
ntent =3D val;
-            document.getElementById(currentTest["method"] + "Result").style.=
backgroundColor =3D "red";
-            document.getElementById(currentTest["method"] + "Duration").text=
Content =3D (timeEnd - timeStart).toFixed(2) + " ms";
+            self.updateTestResultError(timeStart, timeEnd, currentTest, val)=
;                   =20
         });
-       =20
-        var afterTimeOver =3D function() {
-            if (!result) {
-                try {
-                    var message =3D "Any result have been return.";
-                    var timeEnd =3D performance.now();
-                    document.getElementById(currentTest["method"] + "Result"=
).textContent =3D message;
-                    document.getElementById(currentTest["method"] + "Result"=
).style.backgroundColor =3D "red";
-                    document.getElementById(currentTest["method"] + "Duratio=
n").textContent =3D (timeEnd - timeStart).toFixed(2) + " ms";
-                    throw new Error(message);
-                } catch (error) {
-                    console.log("[INFO]", error.message);
-                    console.groupEnd(currentTest["label"]);
-                }=20
-            }
-        };
-       =20
-        timeout(5000)
-        .then(afterTimeOver.bind(afterTimeOver));
-                =20
+    },
+   =20
+    updateTestResultSuccess: function(timeStart, timeEnd, currentTest, messa=
ge) {
+        document.getElementById(currentTest["method"] + "Result").textConten=
t =3D message || "Success";
+        document.getElementById(currentTest["method"] + "Result").style.back=
groundColor =3D "limegreen";
+        document.getElementById(currentTest["method"] + "Duration").textCont=
ent =3D (timeEnd - timeStart).toFixed(2) + " ms";
+},
+   =20
+    updateTestResultError: function(timeStart, timeEnd, currentTest, message=
) {
+        document.getElementById(currentTest["method"] + "Result").textConten=
t =3D message || "Error";
+        document.getElementById(currentTest["method"] + "Result").style.back=
groundColor =3D "red";
+        document.getElementById(currentTest["method"] + "Duration").textCont=
ent =3D (timeEnd - timeStart).toFixed(2) + " ms";
     }
+   =20
=20
 });
=20


--===============2310176208757079012==--


