]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
[#289] Documented, expanded tests
authorstevenaw <sweerdenburg@gmail.com>
Sat, 29 Jan 2011 02:43:32 +0000 (21:43 -0500)
committerstevenaw <sweerdenburg@gmail.com>
Sat, 29 Jan 2011 02:43:32 +0000 (21:43 -0500)
parsers/parserTTXT/popcorn.parseTTXT.html
parsers/parserTTXT/popcorn.parseTTXT.js
parsers/parserTTXT/popcorn.parseTTXT.unit.js

index 53a7faad5be23585b59c173173d5f4650fe6afc0..f61f89a52b3d69d808a8af256ebea84b8afb6071 100644 (file)
 <body>
   <h1 id="qunit-header">Popcorn 0.3 TTXT parser Plug-in Demo</h1>
   <p>Subtitles are processed from <a href="data/data.TTXT">here</a></p>
+  <p>From 2.4 to 5.2 seconds, "[Background Music Playing]" is shown</p>
+  <p>From 15.712 to 17.399 seconds, "Heay!!" is shown</p>
+  <p>From 25.712 to 30.399 seconds, "[Bird noises]" is shown</p>
   <div>
-    <video id='video' data-timeline-sources="data/data.TTXT"
+    <video id='video'
+      data-timeline-sources="data/data.TTXT"
       controls
       width= '250px'
       poster="../../test/poster.png"> 
index b996c0a9103184456a0428d732655d9c53b2c58f..6b8193bf46a6cdfea257f465df6f04fc66faba27 100644 (file)
@@ -24,6 +24,7 @@
         };
 
     // Simple function to convert HH:MM:SS.MMM to SS.MMM
+    // Assume valid, returns 0 on error
     var toSeconds = function(t_in) {
       var t = t_in.split(":");
       var time = 0;
 
     // this is where things actually start
     var node = data.xml.lastChild.lastChild; // Last Child of TextStreamHeader
-    var lastStart = 3.4028235e+38;
+    var lastStart = Number.MAX_VALUE;
     var cmds = [];
     
+    // Work backwards through DOM, processing TextSample nodes
     while (node) {
       if ( node.nodeType === 1 && node.nodeName === "TextSample") {
         var sub = {};
         sub.start = toSeconds(node.getAttribute('sampleTime'));
         sub.text = node.getAttribute('text');
         
-        // Infer end time, ms accuracy
-        sub.end = lastStart;
+        // Infer end time from prior element, ms accuracy
+        sub.end = lastStart - 0.001;
         
         cmds.push( createTrack("subtitle", sub) );
-        lastStart = sub.start - 0.001;
+        lastStart = sub.start;
       }
       node = node.previousSibling;
     }
index c67537a6f259a617d2598a6b30cc018b5aec9a82..eab63bf4aebf94f781f3328a4ae77bf89d04ae4b 100644 (file)
@@ -1,18 +1,47 @@
 test("Popcorn 0.3 TTXT Parser Plugin", function () {
   
-  var expects = 8,
+  var expects = 0,
       count = 0,
+      sub = {},
       numSubs = 0,
       poppercorn = Popcorn( "#video" ),
-      subs = { // Expected values
-        "0": "",
-        "2.4": "[Background Music Playing]",
-        "5.2": "",
-        "15.712": "Heay!!",
-        "17.399": "",
-        "25.712": "[Bird noises]",
-        "30.399": ""
-      };
+      subs = [ // Expected values
+        {
+          start: 0,
+          end: 2.399,
+          text: ""
+        },
+        {
+          start: 2.4,
+          end: 5.199,
+          text: "[Background Music Playing]"
+        },
+        {
+          start: 5.2,
+          end: 15.711,
+          text: ""
+        },
+        {
+          start: 15.712,
+          end: 17.398,
+          text: "Heay!!"
+        },
+        {
+          start: 17.399,
+          end: 25.711,
+          text: ""
+        },
+        {
+          start: 25.712,
+          end: 30.398,
+          text: "[Bird noises]"
+        },
+        {
+          start: 30.399,
+          end: Number.MAX_VALUE,
+          text: ""
+        }
+      ];
       
   function plus() {
     if ( ++count === expects ) {
@@ -22,6 +51,7 @@ test("Popcorn 0.3 TTXT Parser Plugin", function () {
   
   poppercorn.parseTTXT(document.getElementById('video').getAttribute('data-timeline-sources'));
   
+  expects = subs.length*3+1;
   expect(expects);
   
   stop( 5000 );
@@ -30,15 +60,22 @@ test("Popcorn 0.3 TTXT Parser Plugin", function () {
   setTimeout(function () {
     Popcorn.forEach(poppercorn.getTrackEvents(), function(evt) {
       if(evt._natives.type === "subtitle") {
-        numSubs++;
-        equals(subs[evt.start.toString()],  evt.text , "Correct text" );
+        sub = subs[numSubs++];
+        
+        equals(sub.end,  evt.end , "Correct end" );
+        plus();
+        
+        equals(sub.start,  evt.start , "Correct start" );
+        plus();
+        
+        equals(sub.text,  evt.text , "Correct text" );
         plus();
       }
     });
     
-    equals(7, numSubs , "Correctly parsed all subs" );
+    equals(subs.length, numSubs , "Correctly parsed all subs" );
     plus();
 
-  }, 1500);
+  }, 500);
   
 });