OSSP CVS Repository

ossp - Difference in ossp-pkg/xds/xds_test_xml.c versions 1.5 and 1.6
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

ossp-pkg/xds/xds_test_xml.c 1.5 -> 1.6

--- xds_test_xml.c       2001/08/30 10:42:24     1.5
+++ xds_test_xml.c       2001/08/30 14:48:45     1.6
@@ -363,13 +363,17 @@
 
 int main(int argc, char *argv[])
 {
-#if 0
     xds_t *xds;
     char *buffer;
     size_t buffer_size;
 
     xds_double_t values[] = {
-        3.14159265358979323844
+        0.0,
+        -0.0,
+        3.141592,
+        -3.141592,
+        298473.141592,
+        -298473.141592
     };
 
     size_t i;
@@ -381,31 +385,45 @@
         printf("Failed to initialize XDS context.\n");
         return 1;
     }
-    if (xds_register(xds, "int", &xml_encode_double, NULL) != XDS_OK) {
+    if (xds_register(xds, "begin", &xml_encode_begin, NULL) != XDS_OK ||
+        xds_register(xds, "end", &xml_encode_end, NULL) != XDS_OK ||
+        xds_register(xds, "double", &xml_encode_double, NULL) != XDS_OK) {
         printf("Failed to register my encoding engines.\n");
         return 1;
     }
-    for (i = 0; i < sizeof (values) / sizeof (xds_double_t); ++i) {
-        if (xds_encode(xds, "int", values[i]) != XDS_OK) {
+    if (xds_encode(xds, "begin") != XDS_OK)
+        {
+        printf("xds_encode_begin() failed!\n");
+        return 1;
+        }
+    for (i = 0; i < sizeof (values) / sizeof (xds_double_t); ++i)
+        {
+        if (xds_encode(xds, "double", values[i]) != XDS_OK)
+            {
             printf("xds_encode(values[%d]) failed!\n", i);
             return 1;
-        }
-    }
-    if (xds_getbuffer(xds, XDS_GIFT, (void **)&buffer, &buffer_size) !=
-        XDS_OK) {
+            }
+        }
+    if (xds_encode(xds, "end") != XDS_OK)
+        {
+        printf("xds_encode_end() failed!\n");
+        return 1;
+        }
+    if (xds_getbuffer(xds, XDS_GIFT, (void **)&buffer, &buffer_size) != XDS_OK)
+        {
         printf("getbuffer() failed.\n");
         return 1;
-    }
+        }
     xds_destroy(xds);
 
-    printf("%s\n", buffer);
-
     xds = xds_init(XDS_DECODE);
     if (xds == NULL) {
         printf("Failed to initialize XDS context.\n");
         return 1;
     }
-    if (xds_register(xds, "int", &xml_decode_double, NULL) != XDS_OK) {
+    if (xds_register(xds, "begin", &xml_decode_begin, NULL) != XDS_OK ||
+        xds_register(xds, "end", &xml_decode_end, NULL) != XDS_OK ||
+        xds_register(xds, "double", &xml_decode_double, NULL) != XDS_OK) {
         printf("Failed to register my decoding engines.\n");
         return 1;
     }
@@ -413,28 +431,138 @@
         printf("setbuffer() failed.\n");
         return 1;
     }
+    if (xds_decode(xds, "begin") != XDS_OK)
+        {
+        printf("xds_decode_begin() failed!\n");
+        return 1;
+        }
     for (i = 0; i < sizeof (values) / sizeof (xds_double_t); ++i) {
         xds_double_t val;
-        if (xds_decode(xds, "int", &val) != XDS_OK) {
+        if (xds_decode(xds, "double", &val) != XDS_OK) {
             printf("xds_decode(values[%d]) failed!\n", i);
             return 1;
         }
         if (val != values[i]) {
-            printf
-                ("Decoded value (%E) does not match the original value (%E)!\n",
-                 val, values[i]);
+            printf("Decoding the %dth value failed!\n", i);
             return 1;
         }
     }
+    if (xds_decode(xds, "end") != XDS_OK)
+        {
+        printf("xds_decode_end() failed!\n");
+        return 1;
+        }
     xds_destroy(xds);
 
     /* Everything went fine. */
-#endif
+
     return 0;
 }
 
 #endif /* XDS_TEST_XML_DOUBLE */
 
+#ifdef XDS_TEST_XML_FLOAT
+
+int main(int argc, char *argv[])
+{
+    xds_t *xds;
+    char *buffer;
+    size_t buffer_size;
+
+    xds_float_t values[] = {
+        0.0,
+        -0.0,
+        3.141592,
+        -3.141592,
+        298473.141592,
+        -298473.141592
+    };
+
+    size_t i;
+
+    /* Encode the values array, then decode it back and compare the numbers. */
+
+    xds = xds_init(XDS_ENCODE);
+    if (xds == NULL) {
+        printf("Failed to initialize XDS context.\n");
+        return 1;
+    }
+    if (xds_register(xds, "begin", &xml_encode_begin, NULL) != XDS_OK ||
+        xds_register(xds, "end", &xml_encode_end, NULL) != XDS_OK ||
+        xds_register(xds, "float", &xml_encode_float, NULL) != XDS_OK) {
+        printf("Failed to register my encoding engines.\n");
+        return 1;
+    }
+    if (xds_encode(xds, "begin") != XDS_OK)
+        {
+        printf("xds_encode_begin() failed!\n");
+        return 1;
+        }
+    for (i = 0; i < sizeof (values) / sizeof (xds_float_t); ++i)
+        {
+        if (xds_encode(xds, "float", values[i]) != XDS_OK)
+            {
+            printf("xds_encode(values[%d]) failed!\n", i);
+            return 1;
+            }
+        }
+    if (xds_encode(xds, "end") != XDS_OK)
+        {
+        printf("xds_encode_end() failed!\n");
+        return 1;
+        }
+    if (xds_getbuffer(xds, XDS_GIFT, (void **)&buffer, &buffer_size) != XDS_OK)
+        {
+        printf("getbuffer() failed.\n");
+        return 1;
+        }
+    xds_destroy(xds);
+
+    xds = xds_init(XDS_DECODE);
+    if (xds == NULL) {
+        printf("Failed to initialize XDS context.\n");
+        return 1;
+    }
+    if (xds_register(xds, "begin", &xml_decode_begin, NULL) != XDS_OK ||
+        xds_register(xds, "end", &xml_decode_end, NULL) != XDS_OK ||
+        xds_register(xds, "float", &xml_decode_float, NULL) != XDS_OK) {
+        printf("Failed to register my decoding engines.\n");
+        return 1;
+    }
+    if (xds_setbuffer(xds, XDS_GIFT, buffer, buffer_size) != XDS_OK) {
+        printf("setbuffer() failed.\n");
+        return 1;
+    }
+    if (xds_decode(xds, "begin") != XDS_OK)
+        {
+        printf("xds_decode_begin() failed!\n");
+        return 1;
+        }
+    for (i = 0; i < sizeof (values) / sizeof (xds_float_t); ++i) {
+        xds_float_t val;
+        if (xds_decode(xds, "float", &val) != XDS_OK) {
+            printf("xds_decode(values[%d]) failed!\n", i);
+            return 1;
+        }
+        if (val != values[i]) {
+            printf("Decoding the %dth value failed!\n", i);
+            return 1;
+        }
+    }
+    if (xds_decode(xds, "end") != XDS_OK)
+        {
+        printf("xds_decode_end() failed!\n");
+        return 1;
+        }
+    xds_destroy(xds);
+
+    /* Everything went fine. */
+
+    return 0;
+}
+
+#endif /* XDS_TEST_XML_FLOAT */
+
 #ifdef XDS_TEST_XML_STRING
 
 int main(int argc, char *argv[])
@@ -720,4 +848,3 @@
 }
 
 #endif /* XDS_TEST_XML_OCTETSTREAM_EMPTY */
-

CVSTrac 2.0.1