--- xds_test_xdr.c 2001/08/22 20:22:41 1.6
+++ xds_test_xdr.c 2001/08/30 08:55:41 1.7
@@ -834,3 +834,104 @@
}
#endif /* XDS_TEST_XDR_FLOAT */
+
+#ifdef XDS_TEST_XDR_DOUBLE
+
+int main(int argc, char *argv[])
+{
+ XDR xdrs;
+ char xdr_buf[1024];
+ size_t xdr_buf_size;
+
+ xds_t *xds;
+ char *xds_buf;
+ size_t xds_buf_size;
+
+ double values[] =
+ {
+ 0,
+ 3.14,
+ -3.14,
+ 0.14,
+ -0.14,
+ 123456.789,
+ -123456.789
+ };
+
+ size_t i;
+
+ /* Encode the values array using the RPC-XDR implementation. */
+ xdrmem_create(&xdrs, xdr_buf, sizeof (xdr_buf), XDR_ENCODE);
+ for (i = 0; i < sizeof (values) / sizeof (double); ++i)
+ xdr_double(&xdrs, &values[i]);
+ xdr_buf_size = xdr_getpos(&xdrs);
+ xdr_destroy(&xdrs);
+
+ /* Encode the values array using the XDS implementation. */
+ xds = xds_init(XDS_ENCODE);
+ if (xds == NULL) {
+ printf("Failed to initialize XDS context.\n");
+ return 1;
+ }
+ if (xds_register(xds, "double", &xdr_encode_double, NULL) != XDS_OK) {
+ printf("Failed to register my encoding engines.\n");
+ return 1;
+ }
+ for (i = 0; i < sizeof (values) / sizeof (double); ++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 **)&xds_buf, &xds_buf_size) !=
+ XDS_OK) {
+ printf("getbuffer() failed.\n");
+ return 1;
+ }
+ xds_destroy(xds);
+
+ /* Both buffers must be equal now. */
+ if (xdr_buf_size != xds_buf_size) {
+ printf("The buffer sizes don't match: %d != %d.\n", xdr_buf_size,
+ xds_buf_size);
+ return 1;
+ }
+ if (memcmp(xds_buf, xdr_buf, xds_buf_size) != 0) {
+ printf("The buffers' contents is not identical!\n");
+ return 1;
+ }
+
+ /* Now we decode the values again using the XDS implementation and
+ compare them to our original values. Obviously, they should not
+ differ. */
+ xds = xds_init(XDS_DECODE);
+ if (xds == NULL) {
+ printf("Failed to initialize XDS context.\n");
+ return 1;
+ }
+ if (xds_register(xds, "double", &xdr_decode_double, NULL) != XDS_OK) {
+ printf("Failed to register my decoding engines.\n");
+ return 1;
+ }
+ if (xds_setbuffer(xds, XDS_GIFT, xds_buf, xds_buf_size) != XDS_OK) {
+ printf("setbuffer() failed.\n");
+ return 1;
+ }
+ for (i = 0; i < sizeof (values) / sizeof (double); ++i) {
+ double tmp;
+ if (xds_decode(xds, "double", &tmp) != XDS_OK) {
+ printf("xds_decode() failed for the %d value!\n", i);
+ return 1;
+ }
+ if (values[i] != tmp) {
+ printf("The %dth value has not been decoded correctly!\n", i);
+ return 1;
+ }
+ }
+ xds_destroy(xds);
+
+ /* Everything went fine. */
+ return 0;
+}
+
+#endif /* XDS_TEST_XDR_DOUBLE */
|