gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] /srv/bzr/gnash/trunk r12154: add XML to NPVariant parsing


From: Rob Savoye
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r12154: add XML to NPVariant parsing tests.
Date: Wed, 14 Apr 2010 19:22:09 -0600
User-agent: Bazaar (2.0.3)

------------------------------------------------------------
revno: 12154
committer: Rob Savoye <address@hidden>
branch nick: trunk
timestamp: Wed 2010-04-14 19:22:09 -0600
message:
  add XML to NPVariant parsing tests.
modified:
  plugin/npapi/external.cpp
  plugin/npapi/test.cpp
=== modified file 'plugin/npapi/external.cpp'
--- a/plugin/npapi/external.cpp 2010-04-15 00:35:38 +0000
+++ b/plugin/npapi/external.cpp 2010-04-15 01:22:09 +0000
@@ -175,7 +175,6 @@
     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>";
     
@@ -198,18 +197,21 @@
     // Look for the ending > in the first part of the data for the tag
     end = xml.find(">");
     if (end != std::string::npos) {
+        end++;                  // go past the > character
         tag = xml.substr(start, end);
         // Look for the easy ones first
         if (tag == "<null/>") {
             NULL_TO_NPVARIANT(*value);
+        } else if (tag == "<void/>") {
+            VOID_TO_NPVARIANT(*value);
         } else if (tag == "<true/>") {
             BOOLEAN_TO_NPVARIANT(true, *value);
         } else if (tag == "<false/>") {
             BOOLEAN_TO_NPVARIANT(false, *value);
         } else if (tag == "<number>") {
-            start = end + 1;
+            start = end;
             end = xml.find("</number>");
-            std::string str = xml.substr(start, end);
+            std::string str = xml.substr(start, end-start);
             if (str.find(".") != std::string::npos) {
                 double num = strtod(str.c_str(), NULL);
                 DOUBLE_TO_NPVARIANT(num, *value);
@@ -218,9 +220,9 @@
                 INT32_TO_NPVARIANT(num, *value);
             }
         } else if (tag == "<string>") {
-            start = end + 1;
+            start = end;
             end = xml.find("</string>");
-            std::string str = xml.substr(start, end);
+            std::string str = xml.substr(start, end-start);
             int length = str.size();;
             char *data = (char *)NPN_MemAlloc(length+1);
             std::copy(str.begin(), str.end(), data);
@@ -228,6 +230,12 @@
             // When an NPVariant becomes a string object, it *does not* make a 
copy.
             // Instead it stores the pointer (and length) we just allocated.
             STRINGN_TO_NPVARIANT(data, length, *value);
+        } else if (tag == "<array>") {
+            NPObject *obj =  (NPObject *)NPN_MemAlloc(sizeof(NPObject));
+            OBJECT_TO_NPVARIANT(obj, *value);
+        } else if (tag == "<object>") {
+            NPObject *obj =  (NPObject *)NPN_MemAlloc(sizeof(NPObject));
+            OBJECT_TO_NPVARIANT(obj, *value);
         }
     }
     

=== modified file 'plugin/npapi/test.cpp'
--- a/plugin/npapi/test.cpp     2010-04-15 00:35:38 +0000
+++ b/plugin/npapi/test.cpp     2010-04-15 01:22:09 +0000
@@ -110,9 +110,9 @@
     
     str = ei.makeProperty("hi", "Hello World!");
     if (str == "<property id=\"hi\">Hello World!</property>") {
-        runtest.pass("makeProperty()");
+        runtest.pass("ExternalInterface::makeProperty()");
     } else {
-        runtest.fail("makeProperty()");
+        runtest.fail("ExternalInterface::makeProperty()");
     }
     
 #if 0
@@ -149,7 +149,9 @@
     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::string xml = "<object><property 
id=\"test1\"><string>foobar</string></property><property 
id=\"test2\"><number>12.34</number></property><property 
id=\"test3\"><number>56</number></property></object>";
+    
+    regcomp (&regex_pat, xml.c_str(), 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)) {
@@ -158,18 +160,93 @@
         runtest.pass("ExternalInterface::makeObject()");
     }
 
+    //
+    // Parsing tests
+    //
+    xml = "<string>Hello World!</string>";
+    NPVariant *np = ei.parseXML(xml);
+    std::string data = NPVARIANT_TO_STRING(np[0]).UTF8Characters;
+    if (NPVARIANT_IS_STRING(*np) &&
+        (data == "Hello World!")) {
+        runtest.pass("ExternalInterface::parseXML(string)");
+    } else {
+        runtest.fail("ExternalInterface::parseXML(string)");
+    }
+
+    xml = "<number>123.456</number>";
+    np = ei.parseXML(xml);
+    double num = NPVARIANT_TO_DOUBLE(*np);
+    if (NPVARIANT_IS_DOUBLE(*np) &&
+        (num == 123.456)) {
+        runtest.pass("ExternalInterface::parseXML(double)");
+    } else {
+        runtest.fail("ExternalInterface::parseXML(double)");
+    }
+
+    xml = "<number>78</number>";
+    np = ei.parseXML(xml);
+    int inum = NPVARIANT_TO_INT32(*np);
+    if (NPVARIANT_IS_INT32(*np) &&
+        (inum == 78)) {
+        runtest.pass("ExternalInterface::parseXML(int32)");
+    } else {
+        runtest.fail("ExternalInterface::parseXML(int32)");
+    }
+
+    xml = "<true/>";
+    np = ei.parseXML(xml);
+    bool flag = NPVARIANT_TO_BOOLEAN(*np);
+    if (NPVARIANT_IS_BOOLEAN(*np) &&
+        (flag == true)) {
+        runtest.pass("ExternalInterface::parseXML(true)");
+    } else {
+        runtest.fail("ExternalInterface::parseXML(true)");
+    }
+
+    xml = "<false/>";
+    np = ei.parseXML(xml);
+    flag = NPVARIANT_TO_BOOLEAN(*np);
+    if (NPVARIANT_IS_BOOLEAN(*np) &&
+        (flag == false)) {
+        runtest.pass("ExternalInterface::parseXML(false)");
+    } else {
+        runtest.fail("ExternalInterface::parseXML(false)");
+    }
+
+    xml = "<null/>";
+    np = ei.parseXML(xml);
+    if (NPVARIANT_IS_NULL(*np)) {
+        runtest.pass("ExternalInterface::parseXML(null)");
+    } else {
+        runtest.fail("ExternalInterface::parseXML(null)");
+    }
+
+    xml = "<void/>";
+    np = ei.parseXML(xml);
+    if (NPVARIANT_IS_VOID(*np)) {
+        runtest.pass("ExternalInterface::parseXML(void)");
+    } else {
+        runtest.fail("ExternalInterface::parseXML(void)");
+    }
+
+    xml = "<object><property 
id=\"test1\"><string>foobar</string></property><property 
id=\"test2\"><number>12.34</number></property><property 
id=\"test3\"><number>56</number></property></object>";
+    np = ei.parseXML(xml);
+    if (NPVARIANT_IS_OBJECT(*np)) {
+        runtest.pass("ExternalInterface::parseXML(object)");
+    } else {
+        runtest.fail("ExternalInterface::parseXML(object)");
+    }
+
 }
 
 // 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 *


reply via email to

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