gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] /srv/bzr/gnash/trunk r10113: Add more tests to LoadVars,


From: Benjamin Wolsey
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r10113: Add more tests to LoadVars, including a check that empty data is the same as
Date: Sun, 26 Oct 2008 12:09:20 +0100
User-agent: Bazaar (1.5)

------------------------------------------------------------
revno: 10113
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Sun 2008-10-26 12:09:20 +0100
message:
  Add more tests to LoadVars, including a check that empty data is the same as
  a failed load. Gnash has a timing problem: we should always
  wait before calling onData, but Gnash does so immediately if a load fails.
  That means stop() is called after play(), so the test hangs.
  
  Gnash's only job should be to call LoadVars.onData with an undefined argument
  if it receives no data, or a string if it gets something. The default onData
  method handles everything else.
added:
  testsuite/media/empty.txt
modified:
  libbase/URL.cpp
  libcore/namedStrings.cpp
  libcore/namedStrings.h
  testsuite/misc-ming.all/LoadVarsTest.c
    ------------------------------------------------------------
    revno: 10112.1.1
    committer: Benjamin Wolsey <address@hidden>
    branch nick: temp
    timestamp: Sun 2008-10-26 10:15:50 +0100
    message:
      Add more tests and an empty file for loading tests.
    added:
      testsuite/media/empty.txt
    modified:
      testsuite/misc-ming.all/LoadVarsTest.c
    ------------------------------------------------------------
    revno: 10112.1.2
    committer: Benjamin Wolsey <address@hidden>
    branch nick: temp
    timestamp: Sun 2008-10-26 11:39:03 +0100
    message:
      Add "_" to escapees.
    modified:
      libbase/URL.cpp
    ------------------------------------------------------------
    revno: 10112.1.3
    committer: Benjamin Wolsey <address@hidden>
    branch nick: temp
    timestamp: Sun 2008-10-26 11:39:44 +0100
    message:
      Extend LoadVarsTest.
    modified:
      testsuite/misc-ming.all/LoadVarsTest.c
    ------------------------------------------------------------
    revno: 10112.1.4
    committer: Benjamin Wolsey <address@hidden>
    branch nick: temp
    timestamp: Sun 2008-10-26 11:40:03 +0100
    message:
      Add decode to named strings.
    modified:
      libcore/namedStrings.cpp
      libcore/namedStrings.h
=== modified file 'libbase/URL.cpp'
--- a/libbase/URL.cpp   2008-10-24 16:46:27 +0000
+++ b/libbase/URL.cpp   2008-10-26 10:39:03 +0000
@@ -415,7 +415,7 @@
 void
 URL::encode(std::string& input)
 {
-       const std::string escapees = " \"#$%&+,/:;<=>address@hidden|}~";
+       const std::string escapees = " \"#$%&+,/:;<=>address@hidden|}~_";
        const std::string hexdigits = "0123456789ABCDEF";
 
        for (unsigned int i=0;i<input.length(); i++)

=== modified file 'libcore/namedStrings.cpp'
--- a/libcore/namedStrings.cpp  2008-10-23 16:50:44 +0000
+++ b/libcore/namedStrings.cpp  2008-10-26 10:40:03 +0000
@@ -51,6 +51,7 @@
        string_table::svt( "_currentframe", NSV::PROP_uCURRENTFRAME ),
        string_table::svt( "_customHeaders", NSV::PROP_uCUSTOM_HEADERS ),
        string_table::svt( "d", NSV::PROP_D ),
+       string_table::svt( "decode", NSV::PROP_DECODE ),
        string_table::svt( "e", NSV::PROP_E ),  
        string_table::svt( "_droptarget", NSV::PROP_uDROPTARGET ),
        string_table::svt( "enabled", NSV::PROP_ENABLED ),

=== modified file 'libcore/namedStrings.h'
--- a/libcore/namedStrings.h    2008-10-23 16:50:44 +0000
+++ b/libcore/namedStrings.h    2008-10-26 10:40:03 +0000
@@ -114,6 +114,7 @@
                PROP_CONSTRUCTOR,
                PROP_CONTENT_TYPE,
                PROP_D,
+        PROP_DECODE,
                PROP_E,
                PROP_ENABLED,
         PROP_G,

=== added file 'testsuite/media/empty.txt'
=== modified file 'testsuite/misc-ming.all/LoadVarsTest.c'
--- a/testsuite/misc-ming.all/LoadVarsTest.c    2008-10-25 23:46:45 +0000
+++ b/testsuite/misc-ming.all/LoadVarsTest.c    2008-10-26 11:09:20 +0000
@@ -30,192 +30,246 @@
 int
 main(int argc, char** argv)
 {
-       SWFMovie mo;
-       const char *srcdir=".";
-       SWFMovieClip  dejagnuclip;
-
-       char loadvars[1048];
-
-       /*********************************************
-        *
-        * Initialization
-        *
-        *********************************************/
-
-       if ( argc>1 ) srcdir=argv[1];
-       else
-       {
-               fprintf(stderr, "Usage: %s\n", argv[0]);
-               return 1;
-       }
-
-
-       sprintf(loadvars, "e = l.load('%s/vars2.txt');", srcdir);
-       puts("Setting things up");
-
-       Ming_init();
-       Ming_useSWFVersion (OUTPUT_VERSION);
-       Ming_setScale(20.0); /* let's talk pixels */
- 
-       mo = newSWFMovie();
-       SWFMovie_setRate(mo, 12);
-       SWFMovie_setDimension(mo, 640, 400);
-
-       /*********************************************
-        *
-        * Body
-        *
-        *********************************************/
-
-       dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir),
-                       10, 0, 80, 800, 600);
-       SWFMovie_add(mo, (SWFBlock)dejagnuclip);
-
-       /// Construct LoadVars and backup methods.
-       add_actions(mo, "l = new LoadVars;"
-                       "odatB = LoadVars.prototype.onData;"
-                       "olB = LoadVars.prototype.onLoad;"
-                       "odecB = LoadVars.prototype.decode;"
-                       "loadString = '';"
-                       "decodeString = '';"
-                       "dataString = '';");
-
-       add_actions(mo, "ourLoad = function(arg) {"
-                       "loadString += 'onLoad called with ' + typeof(arg)" 
-                       "+ ' argument ' + arg;"
-                       "play();"
-                       "};");
-
-       add_actions(mo, "ourData = function(arg) {"
-                       "dataString += 'onData called with ' + typeof(arg) "
-                       "+ ' argument ' + arg;"
-                       "play();"
-                       "};");
-
-       
-       add_actions(mo, "decodeCalled = 0;");
-       add_actions(mo, "ourDecode = function(arg) {"
-                       "decodeString += 'decode called with ' + typeof(arg)"
-                       "+ ' argument ' + arg;"
-                       "decodeCalled++;"
-                       "};");
-
-       /// The decode method is stays overwritten to see where it gets
-       /// called from. We don't call it ourselves. Don't forget to 
-       /// overwrite it again when the LoadVars object is construct again.
-       add_actions(mo, "l.decode = ourDecode;");
-
-
-       /// What happens when load fails?
-       //
-       /// The onLoad method is called from the default implementation of 
onData.
-       
-       SWFMovie_nextFrame(mo);
-
-       /// onData
-       add_actions(mo, "l.onData = ourData;"
-                       "dataString = '';"
-                       "e = l.load('fail');");
-       check_equals(mo, "e", "true");
-       add_actions(mo, "stop();");
-
-       /// Wait for data before proceeding to next frame.
-       SWFMovie_nextFrame(mo);
-       
-       // Check result, restore builtin method.
-       xcheck_equals(mo, "dataString",
-                       "'onData called with undefined argument undefined'");
-       add_actions(mo, "l.onData = odatB;");
-
-       /// onLoad
-       add_actions(mo, "l.onLoad = ourLoad;"
-                       "loadString = '';"
-                       "e = l.load('fail');");
-       check_equals(mo, "e", "true");
-       add_actions(mo, "stop();");
-
-       SWFMovie_nextFrame(mo);
-               
-       xcheck_equals(mo, "loadString",
-                       "'onLoad called with boolean argument false'");
-       add_actions(mo, "l.onLoad = olB;");
+    SWFMovie mo;
+    const char *srcdir=".";
+    SWFMovieClip  dejagnuclip;
+
+    char loadvars[1048];
+    char loademptyvars[1048];
+
+    /*********************************************
+     *
+     * Initialization
+     *
+     *********************************************/
+
+    if ( argc>1 ) srcdir=argv[1];
+    else
+    {
+       fprintf(stderr, "Usage: %s\n", argv[0]);
+       return 1;
+    }
+
+    sprintf(loadvars, "e = l.load('%s/vars2.txt');", srcdir);
+    sprintf(loademptyvars, "e = l.load('%s/empty.txt');", srcdir);
+    puts("Setting things up");
+
+    Ming_init();
+    Ming_useSWFVersion (OUTPUT_VERSION);
+    Ming_setScale(20.0); /* let's talk pixels */
+
+    mo = newSWFMovie();
+    SWFMovie_setRate(mo, 12);
+    SWFMovie_setDimension(mo, 640, 400);
+
+    /*********************************************
+     *
+     * Body
+     *
+     *********************************************/
+
+    dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir),
+                 10, 0, 80, 800, 600);
+    SWFMovie_add(mo, (SWFBlock)dejagnuclip);
+
+    add_actions(mo, 
+                 "odatB = LoadVars.prototype.onData;"
+                 "olB = LoadVars.prototype.onLoad;"
+                 "odecB = LoadVars.prototype.decode;"
+                 "loadString = '';"
+                 "decodeString = '';"
+                 "dataString = '';"
+                 "callCount = 0;");
+
+    add_actions(mo, "ourLoad = function(arg) {"
+                 "loadString += callCount + ': onLoad called with ' + "
+                 "typeof(arg) + ' argument ' + arg;"
+                 "callCount++;"
+                 "play();"
+                 "};");
+
+    add_actions(mo, "ourData = function(arg) {"
+                 "trace('onData called');"
+                 "dataString += callCount + ': onData called with ' + "
+                 "typeof(arg) + ' argument ' + arg;"
+                 "callCount++;"
+                 "play();"
+                 "};");
+
+   
+    add_actions(mo, "decodeCalled = 0;");
+    add_actions(mo, "ourDecode = function(arg) {"
+                 "decodeString += 'decode called with ' + typeof(arg)"
+                 "+ ' argument ' + arg;"
+                 "decodeCalled++;"
+                 "};");
+
+    /// The decode method is overwritten to see where it gets
+    /// called from. We don't call it ourselves. Don't forget to 
+    /// overwrite it again when the LoadVars object is constructed again.
+
+    /// What happens when load fails?
+    //
+    /// The onLoad method is called from the default implementation of
+    /// onData. The "loaded" property is immediately set to false on a 
+    /// call to "load".
+   
+    SWFMovie_nextFrame(mo);
+
+    /// onData
+    add_actions(mo, "l = new LoadVars;");
+    check_equals(mo, "l.loaded", "undefined");
+    add_actions(mo, "l.decode = ourDecode;");
+
+    add_actions(mo, "l.onData = ourData;"
+                 "dataString = '';"
+                 "e = l.load('fail');");
+    check_equals(mo, "e", "true");
+    add_actions(mo, "stop();");
+
+    /// Wait for data before proceeding to next frame.
+    SWFMovie_nextFrame(mo);
+   
+    // Check result, restore state.
+    xcheck_equals(mo, "dataString",
+                 "'0: onData called with undefined argument undefined'");
+    check_equals(mo, "l.loaded", "false");
+    add_actions(mo, "l.onData = odatB;");
+
+    /// onLoad
+    add_actions(mo, "l = new LoadVars;");
+    check_equals(mo, "l.loaded", "undefined");
+    add_actions(mo, "l.decode = ourDecode;");
+
+    add_actions(mo, "l.onLoad = ourLoad;"
+                 "loadString = '';"
+                 "e = l.load('fail');");
+    check_equals(mo, "e", "true");
+    add_actions(mo, "stop();");
+
+    SWFMovie_nextFrame(mo);
+          
+    xcheck_equals(mo, "loadString",
+                 "'1: onLoad called with boolean argument false'");
+    check_equals(mo, "l.loaded", "false");
+    add_actions(mo, "l.onLoad = olB;");
 
     /// Both onData and onLoad
-       add_actions(mo, "l.onLoad = ourLoad;"
-            "l.onData = ourData;"
-                       "loadString = '';"
-            "dataString = '';"
-                       "e = l.load('fail');");
-       check_equals(mo, "e", "true");
-       add_actions(mo, "stop();");
-
-       SWFMovie_nextFrame(mo);
-               
-       check_equals(mo, "loadString",
-                       "''");
-       xcheck_equals(mo, "dataString",
-                       "'onData called with undefined argument undefined'");
-       add_actions(mo, "l.onLoad = olB;");
+    add_actions(mo, "l = new LoadVars;");
+    check_equals(mo, "l.loaded", "undefined");
+    add_actions(mo, "l.decode = ourDecode;");
+
+    add_actions(mo, "l.onLoad = ourLoad;"
+                    "l.onData = ourData;"
+                    "loadString = '';"
+                    "dataString = '';"
+                    "e = l.load('fail');");
+    check_equals(mo, "e", "true");
+    add_actions(mo, "stop();");
+
+    SWFMovie_nextFrame(mo);
+          
+    check_equals(mo, "loadString", "''");
+    xcheck_equals(mo, "dataString",
+                 "'2: onData called with undefined argument undefined'");
+    check_equals(mo, "l.loaded", "false");
+    add_actions(mo, "l.onLoad = olB;"
+                    "l.onData = odatB;");
+
+    /// What happens when load succeeds?
+    //
+    /// Both methods are called separately. The "loaded" property is set
+    /// to true only when "onData" isn't overwritten.
+
+    // onData
+    add_actions(mo, "l = new LoadVars;");
+    check_equals(mo, "l.loaded", "undefined");
+    add_actions(mo, "l.decode = ourDecode;");
+
+    add_actions(mo, "l.onData = ourData;"
+                     "dataString = '';");
+    add_actions(mo, loadvars);
+    check_equals(mo, "e", "true");
+    add_actions(mo, "stop();");
+
+    SWFMovie_nextFrame(mo);
+    // check_equals is too braindead to do this without escaping.
+    xcheck_equals(mo, "escape(dataString)",
+           "'3%3A%20onData%20called%20with%20string%20argument%20v2%5Fvar1%3D"
+        "val1%26v2%5Fvar2%3Dval2%26%0A'");
+    check_equals(mo, "l.loaded", "false");
     add_actions(mo, "l.onData = odatB;");
 
-       /// What happens when load succeeds?
-       //
-       /// Both methods are called separately.
-
-       // onData
-       add_actions(mo, "l = new LoadVars; l.onData = ourData;"
-            "l.decode = ourDecode;"
-                       "dataString = '';");
-       add_actions(mo, loadvars);
-       check_equals(mo, "e", "true");
-       add_actions(mo, "stop();");
-
-       SWFMovie_nextFrame(mo);
-    // check_equals is too braindead to do this without escaping.
-       xcheck_equals(mo, "escape(dataString)",
-                       
"'onData%20called%20with%20string%20argument%20v2%5Fvar1%3D"
-            "val1%26v2%5Fvar2%3Dval2%26%0A'");
-       add_actions(mo, "l.onData = odatB;");
-
     check_equals(mo, "decodeCalled", "0");
     check_equals(mo, "decodeString", "''");
 
-       // onLoad
-       add_actions(mo, "l = new LoadVars; l.onLoad = ourLoad;"
-            "l.decode = ourDecode;"
-                       "loadString = '';");
-       add_actions(mo, loadvars);
-       check_equals(mo, "e", "true");
-       add_actions(mo, "stop();");
-
-       SWFMovie_nextFrame(mo);
-       check_equals(mo, "loadString",
-                       "'onLoad called with boolean argument true'");
-       add_actions(mo, "l.onLoad = olB;");
+    // onLoad
+    add_actions(mo, "l = new LoadVars;");
+    check_equals(mo, "l.loaded", "undefined");
+    add_actions(mo, "l.decode = ourDecode;");
+
+    add_actions(mo, "l.onLoad = ourLoad;"
+                    "loadString = '';");
+    add_actions(mo, loadvars);
+    check_equals(mo, "e", "true");
+    add_actions(mo, "stop();");
+
+    SWFMovie_nextFrame(mo);
+    xcheck_equals(mo, "loadString",
+                 "'4: onLoad called with boolean argument true'");
+    add_actions(mo, "l.onLoad = olB;");
 
     /// decode is called from onData (i.e. it's called when we overwrite
     /// onLoad, not onData).
     xcheck_equals(mo, "decodeCalled", "1");
     // check_equals is too braindead to do this without escaping.
-       xcheck_equals(mo, "escape(decodeString)",
-                       
"'decode%20called%20with%20string%20argument%20v2%5Fvar1%3D"
-            "val1%26v2%5Fvar2%3Dval2%26%0A'");
-
-       /// End of tests.
-
-       add_actions(mo, "totals(15);");
-       add_actions(mo, "stop();");
-
-       /*****************************************************
-        *
-        * Output movie
-        *
-        *****************************************************/
-
-       puts("Saving " OUTPUT_FILENAME );
-
-       SWFMovie_save(mo, OUTPUT_FILENAME);
-
-       return 0;
+    xcheck_equals(mo, "escape(decodeString)",
+              "'decode%20called%20with%20string%20argument%20v2%5Fvar1%3D"
+        "val1%26v2%5Fvar2%3Dval2%26%0A'");
+
+
+    /// What happens on load of empty data?
+    //
+    /// Same as a load failure.
+
+    // onData
+    add_actions(mo, "l = new LoadVars;");
+    check_equals(mo, "l.loaded", "undefined");
+    add_actions(mo, "l.decode = ourDecode;");
+
+    add_actions(mo, "l.onData = ourData;"
+                     "dataString = '';");
+    add_actions(mo, loademptyvars);
+    check_equals(mo, "e", "true");
+    add_actions(mo, "stop();");
+
+    SWFMovie_nextFrame(mo);
+    // check_equals is too braindead to do this without escaping.
+    xcheck_equals(mo, "escape(dataString)",
+           "'5%3A%20onData%20called%20with%20undefined%20"
+           "argument%20undefined'");
+    check_equals(mo, "l.loaded", "false");
+    add_actions(mo, "l.onData = odatB;");
+
+    // No more calls to decode.
+    xcheck_equals(mo, "decodeCalled", "1");
+
+
+    /// End of tests.
+
+   add_actions(mo, "totals(29);");
+   add_actions(mo, "stop();");
+
+   /*****************************************************
+    *
+    * Output movie
+    *
+    *****************************************************/
+
+   puts("Saving " OUTPUT_FILENAME );
+
+   SWFMovie_save(mo, OUTPUT_FILENAME);
+
+   return 0;
 }
 


reply via email to

[Prev in Thread] Current Thread [Next in Thread]