gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] /srv/bzr/gnash/trunk r9626: Add a Perl XMLSocket server a


From: Benjamin Wolsey
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r9626: Add a Perl XMLSocket server and a self-contained test for XMLSocket.onData,
Date: Wed, 20 Aug 2008 13:35:33 +0200
User-agent: Bazaar (1.5)

------------------------------------------------------------
revno: 9626
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Wed 2008-08-20 13:35:33 +0200
message:
  Add a Perl XMLSocket server and a self-contained test for XMLSocket.onData,
  which Gnash fails.
  
  The server must be running before the SWF starts. It sends back everything
  it receives, replacing certain patterns with \n or \0.
  
  Does anyone have any idea how to automate this?
added:
  testsuite/XmlSocketServer.pl
  testsuite/misc-ming.all/XMLSocketTest.c
modified:
  testsuite/misc-ming.all/Makefile.am
=== added file 'testsuite/XmlSocketServer.pl'
--- a/testsuite/XmlSocketServer.pl      1970-01-01 00:00:00 +0000
+++ b/testsuite/XmlSocketServer.pl      2008-08-20 11:35:33 +0000
@@ -0,0 +1,43 @@
+use IO::Socket;
+use IO::Select;
+
+$SIG{PIPE}='IGNORE';
+
+$m=new IO::Socket::INET(Listen=>1,LocalPort=>2229);
+$O=new IO::Select($m);
+
+
+$/ = "\0";
+
+while (@S = $O->can_read) {
+    foreach (@S) {
+        if ($_==$m) {
+            $C=$m->accept;
+            $O->add($C);
+        }
+        else {
+            my $R=sysread($_, $i, 2048);
+            
+            # Log message received:
+            print "XmlSocketServer: received \"$i\"\n";
+            
+            if ($R==0) {
+                $T=syswrite($_, "\n", 2048);
+                if ($T==undef) {
+                    $O->remove($_);
+                }
+            }
+            else {
+
+                print "XmlSocketServer: sending \"$i\" \n";
+              
+                $i =~ s/\*NEWLINE\*/\n/;
+                $i =~ s/\*NULL\*/\0/;
+
+                foreach $C($O->handles) {
+                    $T=syswrite($C, $i, 2048);
+                }
+            }
+        }
+    }
+}

=== modified file 'testsuite/misc-ming.all/Makefile.am'
--- a/testsuite/misc-ming.all/Makefile.am       2008-08-13 00:03:25 +0000
+++ b/testsuite/misc-ming.all/Makefile.am       2008-08-20 11:35:33 +0000
@@ -122,6 +122,7 @@
        attachMovieLoopingTestRunner \
        registerClassTest \
        registerClassTestRunner \
+       XMLSocketTest \
        goto_frame_test \
        consecutive_goto_frame_test \
        matrix_test \
@@ -1401,6 +1402,14 @@
        sh $< $(top_builddir) action_execution_order_extend_test.swf > $@
        chmod 755 $@
 
+XMLSocketTest_SOURCES =        \
+       XMLSocketTest.c \
+       $(NULL)
+XMLSocketTest_LDADD = libgnashmingutils.la
+
+XMLSocketTest.swf: XMLSocketTest
+       ./XMLSocketTest $(top_srcdir)/testsuite/media
+
 registerClassTest_SOURCES =    \
        registerClassTest.c     \
        $(NULL)
@@ -1615,6 +1624,7 @@
        DrawingApiTest.swf      \
        $(NULL)
 
+
 PrototypeEventListeners.swf: $(srcdir)/PrototypeEventListeners.as Dejagnu.swf 
Makefile ../actionscript.all/check.as ../actionscript.all/utils.as
        $(MAKESWF) -r12 -o $@ -v6 -DUSE_DEJAGNU_MODULE -DOUTPUT_VERSION=6 
Dejagnu.swf $(srcdir)/PrototypeEventListeners.as
 

=== added file 'testsuite/misc-ming.all/XMLSocketTest.c'
--- a/testsuite/misc-ming.all/XMLSocketTest.c   1970-01-01 00:00:00 +0000
+++ b/testsuite/misc-ming.all/XMLSocketTest.c   2008-08-20 11:35:33 +0000
@@ -0,0 +1,225 @@
+/*
+ *   Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+ * 
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */ 
+
+
+
+/* The test sends all the 
+
+
+
+*/
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <ming.h>
+
+#include "ming_utils.h"
+
+#define OUTPUT_VERSION 7
+#define OUTPUT_FILENAME "XMLSocketTest.swf"
+
+int
+main(int argc, char** argv)
+{
+
+    /* Basic setup */
+
+       SWFMovieClip dejagnuclip;
+    SWFMovie mo;
+       const char* srcdir = ".";
+
+       if ( argc>1 ) srcdir=argv[1];
+       else
+       {
+               fprintf(stderr, "Usage: %s\n", argv[0]);
+               return 1;
+       }
+
+    Ming_init();
+
+    mo = newSWFMovieWithVersion(OUTPUT_VERSION);
+    SWFMovie_setDimension(mo, 800, 600);
+    SWFMovie_setRate (mo, 12.0);
+
+    dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 
0, 800, 600);
+    SWFMovie_add(mo, (SWFBlock)dejagnuclip);
+
+    /* Setup XMLsocket */
+
+    /* Advance to next frame on connection */
+    add_actions(mo,
+        "function handleConnect(connectionStatus) { "
+        "    if (connectionStatus)                  "
+        "    {                                      "
+        "        trace('Connected');                "
+        "        connected = true;                  "
+        "        play();                            "
+        "    }                                      "
+        "    else { trace('Connection failed.'); }  "
+        "};                                         "
+     );
+
+    /* Add any data recieved to an array, advance to next
+       frame */
+    add_actions(mo, 
+        "function handleData(data) {                "
+        "    trace('Data received: ' + data);       "
+        "    receivedArray.push(data);              "
+        "    _root.gotoAndStop(4);                  "
+        "};                                         "
+    );
+
+    /* Advance to next frame on losing connection */
+    add_actions(mo,
+        "function handleDisconnect() {              "
+        "    trace('Connection lost.');             "
+        "    connected = false;                     "
+        "    play();                                "
+        "};                                         "
+    );
+
+    /* Wait for connection */
+    add_actions(mo, "stop();");
+
+    add_actions(mo,
+        "count = -1;"
+        "connected = false;"
+        "myXML = new XMLSocket;"
+        "myXML.onConnect = handleConnect;"
+        "myXML.onData = handleData;"
+        "myXML.onClose = handleDisconnect;"
+        "myXML.connect(\"localhost\", 2229);"
+    );
+
+/*function closeConnection(){*/
+/*    trace("Closing connection to server.");*/
+/*    myXML.close();*/
+/*}*/
+
+
+    /* The data we're going to send */
+
+    add_actions(mo, 
+        "xmlArray = new Array();"
+        "xmlArray[0] = 'Plain text';"
+        "xmlArray[1] = 'Plain *NEWLINE* text';"
+        "xmlArray[2] = 'Plain *NULL* text';"
+        "xmlArray[3] = 'Plain *NULL**NEWLINE* text';"
+        "xmlArray[4] = '<xml>Some XML</xml>';"
+        "xmlArray[5] = '<xml>Some XML*NEWLINE*</xml>';"
+        "xmlArray[6] = '<xml>Some XML*NULL*</xml>';"
+        "xmlArray[7] = '<xml>Some XML*NEWLINE**NULL*</xml>';"
+        "xmlArray[8] = undefined;"
+        "xmlArray[9] = 9;"
+        "xmlArray[10] = '';"
+    );
+
+    /* The data we should get back */
+    add_actions(mo, 
+        "expectedArray = new Array();"
+        "expectedArray[0] = 'Plain text';"
+        "expectedArray[1] = 'Plain \n text';"
+        "expectedArray[2] = 'Plain ';"
+        "expectedArray[3] = ' text';"
+        "expectedArray[4] = 'Plain ';"
+        "expectedArray[5] = '\n text';"
+        "expectedArray[6] = '<xml>Some XML</xml>';"
+        "expectedArray[7] = '<xml>Some XML\n</xml>';"
+        "expectedArray[8] = '<xml>Some XML';"
+        "expectedArray[9] = '</xml>';"
+        "expectedArray[10] = '<xml>Some XML\n';"
+        "expectedArray[11] = '</xml>';"
+        "expectedArray[12] = 'undefined';"
+        "expectedArray[13] = 9;"
+        "expectedArray[14] = '';"
+    );
+
+
+    /* Where we're going to put the data */
+    add_actions(mo, 
+        "receivedArray = new Array();"
+    );
+
+
+
+    /* Frame 2 */
+    SWFMovie_nextFrame(mo); 
+    /* We should be connected here */
+       check_equals(mo, "connected", "true");
+
+
+
+
+    /* Frame 3 */
+    /* This is where we send the socket data */
+    SWFMovie_nextFrame(mo); 
+
+    add_actions(mo,
+        "count++;"
+        "if (count >= xmlArray.length) { _root.gotoAndStop(5); };"
+        "trace('Frame 3: sending ' + xmlArray[count]);"
+        "myXML.send(xmlArray[count]);"
+        "play();"
+    );
+    
+
+    /* Frame 4 */
+    /* We arrive here when we have data and go back to  */
+    SWFMovie_nextFrame(mo);
+
+    add_actions(mo,
+        "if (count < xmlArray.length - 1 ) { _root.gotoAndStop(3); };"
+        "play();"
+    );
+
+    /* Frame 5 */
+    /* We wait here when we've sent all the data' */
+    SWFMovie_nextFrame(mo); 
+
+    add_actions(mo,
+        "play();"
+    );
+
+
+    /* Last frame (7) */
+    SWFMovie_nextFrame(mo);
+
+
+    check_equals(mo, "receivedArray.length", "expectedArray.length");
+    
+    check_equals(mo, "receivedArray[0]", "expectedArray[0]");
+    check_equals(mo, "receivedArray[1]", "expectedArray[1]");
+    check_equals(mo, "receivedArray[2]", "expectedArray[2]");
+    check_equals(mo, "receivedArray[3]", "expectedArray[3]");
+    check_equals(mo, "receivedArray[4]", "expectedArray[4]");
+    check_equals(mo, "receivedArray[5]", "expectedArray[5]");
+    check_equals(mo, "receivedArray[6]", "expectedArray[6]");
+    check_equals(mo, "receivedArray[7]", "expectedArray[7]");
+    check_equals(mo, "receivedArray[8]", "expectedArray[8]");
+    check_equals(mo, "receivedArray[9]", "expectedArray[9]");
+    check_equals(mo, "receivedArray[10]", "expectedArray[10]");    
+    
+
+    add_actions(mo, "totals(); 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]