gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] /srv/bzr/gnash/trunk r12152: add support for Arrays and O


From: Rob Savoye
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r12152: add support for Arrays and Objects.
Date: Wed, 14 Apr 2010 18:35:38 -0600
User-agent: Bazaar (2.0.3)

------------------------------------------------------------
revno: 12152
committer: Rob Savoye <address@hidden>
branch nick: trunk
timestamp: Wed 2010-04-14 18:35:38 -0600
message:
  add support for Arrays and Objects.
modified:
  plugin/npapi/external.cpp
  plugin/npapi/external.h
  plugin/npapi/test.cpp
=== modified file 'plugin/npapi/external.cpp'
--- a/plugin/npapi/external.cpp 2010-04-14 22:25:34 +0000
+++ b/plugin/npapi/external.cpp 2010-04-15 00:35:38 +0000
@@ -23,6 +23,7 @@
 #include <string>
 #include <sstream>
 #include <vector>
+#include <map>
 #include <cstring>
 #include <cstdlib>
 
@@ -30,6 +31,7 @@
 #include "npruntime.h"
 #include "external.h"
 
+
 ExternalInterface::ExternalInterface ()
 {
 }
@@ -88,6 +90,33 @@
     return ss.str();
 }
 
+
+std::string
+ExternalInterface::makeProperty (const std::string &id, double num)
+{
+    std::stringstream ss;
+    ss << num;
+    return makeProperty(id, ss.str());
+}
+
+std::string
+ExternalInterface::makeProperty (const std::string &id, int num)
+{
+    std::stringstream ss;
+    ss << num;
+    return makeProperty(id, ss.str());
+}
+
+std::string
+ExternalInterface::makeProperty (const std::string &id, const std::string 
&data)
+{
+    std::stringstream ss;
+
+    ss << "<property id=\"" << id << "\">" << data << "</property>";
+    
+    return ss.str();
+}
+
 std::string
 ExternalInterface::makeNumber (double num)
 {
@@ -119,15 +148,15 @@
 }
 
 std::string
-ExternalInterface::makeArray (std::vector<std::string> args)
+ExternalInterface::makeArray (std::vector<std::string> &args)
 {
     std::stringstream ss;
     std::vector<std::string>::iterator it;
     int index = 0;
     
     ss << "<array>";
-    for (it == args.begin(); it != args.end(); ++it) {
-        ss << "<property is = \">" << index++ << "\"";
+    for (it=args.begin(); it != args.end(); ++it) {
+        ss << "<property id=\"" << index << "\">" << *it << "</property>";
         index++;
     }
     
@@ -137,9 +166,18 @@
 }
 
 std::string
-ExternalInterface::makeObject (std::vector<std::string> args)
+ExternalInterface::makeObject (std::map<std::string, std::string> &args)
 {
     std::stringstream ss;
+    std::map<std::string, std::string>::iterator it;
+    int index = 0;
+
+    ss << "<object>";
+    for (it = args.begin(); it != args.end(); ++it) {
+        ss << "<property id=\"" << it->first << "\">" << it->second << 
"</property>";
+        //makeProperty(it->first, it->second);
+    }
+    ss << "</object>";
     
     return ss.str();
 }
@@ -222,7 +260,7 @@
     } else if (NPVARIANT_IS_VOID(*value)) {
         ss << "<void/>";
     } else if (NPVARIANT_IS_OBJECT(*value)) {
-        ss << "<object>";
+        ss << "<object></object>";
     }    
     
     return ss.str();

=== modified file 'plugin/npapi/external.h'
--- a/plugin/npapi/external.h   2010-04-14 22:25:34 +0000
+++ b/plugin/npapi/external.h   2010-04-15 00:35:38 +0000
@@ -26,32 +26,36 @@
 #include <string>
 #include <sstream>
 #include <vector>
+#include <map>
 
 #include "npapi.h"
 #include "npruntime.h"
 
 class ExternalInterface
 {
- public:
-  ExternalInterface ();
-  ~ExternalInterface ();
-
-  // Create an Invoke message for the standalone Gnash
-  std::string makeInvoke (const std::string &method, std::vector<std::string> 
args);
-
-  std::string makeNull ();
-  std::string makeTrue ();
-  std::string makeFalse ();
-  std::string makeString (const std::string &str);
-  std::string makeNumber (double num);
-  std::string makeNumber (int num);
-  std::string makeNumber (unsigned int num);
-  std::string makeArray (std::vector<std::string> args);
-  std::string makeObject (std::vector<std::string> args);
-
-  NPVariant *parseXML(const std::string &xml);
-  std::string convertNPVariant (NPVariant *npv);
-
+public:
+    ExternalInterface ();
+    ~ExternalInterface ();
+    
+    // Create an Invoke message for the standalone Gnash
+    std::string makeInvoke (const std::string &method, 
std::vector<std::string> args);
+    
+    std::string makeNull ();
+    std::string makeTrue ();
+    std::string makeFalse ();
+    std::string makeString (const std::string &str);
+    std::string makeProperty (const std::string &str, const std::string &data);
+    std::string makeProperty (const std::string &str, double num);
+    std::string makeProperty (const std::string &str, int num);
+    std::string makeNumber (double num);
+    std::string makeNumber (int num);
+    std::string makeNumber (unsigned int num);
+    std::string makeArray (std::vector<std::string> &args);
+    std::string makeObject (std::map<std::string, std::string> &args);
+    
+    NPVariant *parseXML(const std::string &xml);
+    std::string convertNPVariant (NPVariant *npv);
+    
 };
 
 #endif // GNASH_PLUGIN_EXTERNAL_H

=== modified file 'plugin/npapi/test.cpp'
--- a/plugin/npapi/test.cpp     2010-04-14 21:27:32 +0000
+++ b/plugin/npapi/test.cpp     2010-04-15 00:35:38 +0000
@@ -20,11 +20,14 @@
 #include <string>
 #include <cstdlib>
 #include <vector>
+#include <map>
 
 #include "npapi.h"
 #include "npruntime.h"
 #include "pluginbase.h"
+#include "npfunctions.h"
 #include "dejagnu.h"
+#include <regex.h>
 
 #include "external.h"
 
@@ -105,6 +108,13 @@
         runtest.fail("convertNPVariant(string)");
     }
     
+    str = ei.makeProperty("hi", "Hello World!");
+    if (str == "<property id=\"hi\">Hello World!</property>") {
+        runtest.pass("makeProperty()");
+    } else {
+        runtest.fail("makeProperty()");
+    }
+    
 #if 0
     ARRAY_TO_NPVARIANT(*value);
     str = ei.convertNPVariant(value);
@@ -113,18 +123,54 @@
     } else {
         runtest.fail("convertNPVariant(array)");
     }
-
-    OBJECT_TO_NPVARIANT(*value);
-    str = ei.convertNPVariant(value);
-    if (str == "<object></object>") {
-        runtest.pass("convertNPVariant(object)");
-    } else {
-        runtest.fail("convertNPVariant(object)");
-    }
 #endif
-    
-}
-
+
+    NPObject *obj =  (NPObject *)NPN_MemAlloc(sizeof(NPObject));
+    std::string prop1 = ei.makeString("foobar");
+    std::string prop2 = ei.makeNumber(12.34);
+    std::string prop3 = ei.makeNumber(56);
+    std::vector<std::string> aargs;
+    aargs.push_back(prop1);
+    aargs.push_back(prop2);
+    aargs.push_back(prop3);
+    
+    regex_t regex_pat;
+    regcomp (&regex_pat, "<array><property 
id=\"0\"><string>foobar</string></property><property 
id=\"1\"><number>12.34</number></property><property 
id=\"2\"><number>56</number></property></array>", REG_NOSUB|REG_NEWLINE);
+    str = ei.makeArray(aargs);
+    if (regexec (&regex_pat, reinterpret_cast<const char*>(str.c_str()), 0, 
(regmatch_t *)0, 0)) {    
+        runtest.fail("ExternalInterface::makeArray()");
+    } else {
+        runtest.pass("ExternalInterface::makeArray()");
+    }
+
+    std::map<std::string, std::string> margs;
+    margs["test1"] = prop1;
+    margs["test2"] = prop2;
+    margs["test3"] = prop3;
+    
+    str = ei.makeObject(margs);
+    regcomp (&regex_pat, "<object><property 
id=\"test1\"><string>foobar</string></property><property 
id=\"test2\"><number>12.34</number></property><property 
id=\"test3\"><number>56</number></property></object>", REG_NOSUB|REG_NEWLINE);
+
+//    std::cout << str << std::endl;
+    if (regexec (&regex_pat, reinterpret_cast<const char*>(str.c_str()), 0, 
(regmatch_t *)0, 0)) {
+        runtest.fail("ExternalInterface::makeObject()");
+    } else {
+        runtest.pass("ExternalInterface::makeObject()");
+    }
+
+}
+
+// These are just stubs to get the test case to link standalone.
+NPIdentifier NPN_GetStringIdentifier(const NPUTF8 *name)
+{
+  // return getstringidentifier(name);
+}
+
+bool NPN_SetProperty(NPP npp, NPObject* obj, NPIdentifier propertyName,
+                     const NPVariant *value)
+{
+  // return setproperty(npp, obj, propertyName, value);
+}
 
 nsPluginInstanceBase *
 NS_NewPluginInstance(nsPluginCreateData * aCreateDataStruct)


reply via email to

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