t_xdr.c revision 1.1
11.1Spgoyette/* $NetBSD: t_xdr.c,v 1.1 2011/01/08 06:59:37 pgoyette Exp $ */ 21.1Spgoyette 31.1Spgoyette/* 41.1Spgoyette * Copyright (c) 2008 The NetBSD Foundation, Inc. 51.1Spgoyette * All rights reserved. 61.1Spgoyette * 71.1Spgoyette * This code is derived from software contributed to The NetBSD Foundation 81.1Spgoyette * by Ben Harris. 91.1Spgoyette * 101.1Spgoyette * Redistribution and use in source and binary forms, with or without 111.1Spgoyette * modification, are permitted provided that the following conditions 121.1Spgoyette * are met: 131.1Spgoyette * 1. Redistributions of source code must retain the above copyright 141.1Spgoyette * notice, this list of conditions and the following disclaimer. 151.1Spgoyette * 2. Redistributions in binary form must reproduce the above copyright 161.1Spgoyette * notice, this list of conditions and the following disclaimer in the 171.1Spgoyette * documentation and/or other materials provided with the distribution. 181.1Spgoyette * 191.1Spgoyette * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 201.1Spgoyette * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 211.1Spgoyette * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 221.1Spgoyette * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 231.1Spgoyette * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 241.1Spgoyette * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 251.1Spgoyette * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 261.1Spgoyette * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 271.1Spgoyette * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 281.1Spgoyette * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 291.1Spgoyette * POSSIBILITY OF SUCH DAMAGE. 301.1Spgoyette */ 311.1Spgoyette 321.1Spgoyette/*- 331.1Spgoyette * Copyright (c) 2001 Ben Harris 341.1Spgoyette * All rights reserved. 351.1Spgoyette * 361.1Spgoyette * Redistribution and use in source and binary forms, with or without 371.1Spgoyette * modification, are permitted provided that the following conditions 381.1Spgoyette * are met: 391.1Spgoyette * 1. Redistributions of source code must retain the above copyright 401.1Spgoyette * notice, this list of conditions and the following disclaimer. 411.1Spgoyette * 2. Redistributions in binary form must reproduce the above copyright 421.1Spgoyette * notice, this list of conditions and the following disclaimer in the 431.1Spgoyette * documentation and/or other materials provided with the distribution. 441.1Spgoyette * 3. The name of the author may not be used to endorse or promote products 451.1Spgoyette * derived from this software without specific prior written permission. 461.1Spgoyette * 471.1Spgoyette * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 481.1Spgoyette * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 491.1Spgoyette * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 501.1Spgoyette * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 511.1Spgoyette * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 521.1Spgoyette * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 531.1Spgoyette * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 541.1Spgoyette * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 551.1Spgoyette * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 561.1Spgoyette * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 571.1Spgoyette */ 581.1Spgoyette 591.1Spgoyette#include <sys/cdefs.h> 601.1Spgoyette__COPYRIGHT("@(#) Copyright (c) 2008\ 611.1Spgoyette The NetBSD Foundation, inc. All rights reserved."); 621.1Spgoyette__RCSID("$NetBSD: t_xdr.c,v 1.1 2011/01/08 06:59:37 pgoyette Exp $"); 631.1Spgoyette 641.1Spgoyette#include <rpc/types.h> 651.1Spgoyette#include <rpc/xdr.h> 661.1Spgoyette 671.1Spgoyette#include <string.h> 681.1Spgoyette 691.1Spgoyette#include <atf-c.h> 701.1Spgoyette 711.1Spgoyette#include "h_testbits.h" 721.1Spgoyette 731.1Spgoyettechar xdrdata[] = { 741.1Spgoyette 0x3f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* double 1.0 */ 751.1Spgoyette 0x00, 0x00, 0x00, 0x01, /* enum smallenum SE_ONE */ 761.1Spgoyette 0xff, 0xff, 0xfb, 0x2e, /* enum medenum ME_NEG */ 771.1Spgoyette 0x00, 0x12, 0xd6, 0x87, /* enum bigenum BE_LOTS */ 781.1Spgoyette}; 791.1Spgoyette 801.1SpgoyetteATF_TC(xdr); 811.1SpgoyetteATF_TC_HEAD(xdr, tc) 821.1Spgoyette{ 831.1Spgoyette atf_tc_set_md_var(tc, "descr", 841.1Spgoyette "Checks encoding/decoding of doubles and enumerations"); 851.1Spgoyette} 861.1SpgoyetteATF_TC_BODY(xdr, tc) 871.1Spgoyette{ 881.1Spgoyette XDR x; 891.1Spgoyette double d; 901.1Spgoyette smallenum s; 911.1Spgoyette medenum m; 921.1Spgoyette bigenum b; 931.1Spgoyette char newdata[sizeof(xdrdata)]; 941.1Spgoyette 951.1Spgoyette xdrmem_create(&x, xdrdata, sizeof(xdrdata), XDR_DECODE); 961.1Spgoyette 971.1Spgoyette ATF_REQUIRE_MSG(xdr_double(&x, &d), "xdr_double DECODE failed"); 981.1Spgoyette ATF_REQUIRE_EQ_MSG(d, 1.0, "double 1.0 decoded as %g", d); 991.1Spgoyette 1001.1Spgoyette ATF_REQUIRE_MSG(xdr_smallenum(&x, &s), "xdr_smallenum DECODE failed"); 1011.1Spgoyette ATF_REQUIRE_EQ_MSG(s, SE_ONE, "SE_ONE decoded as %d", s); 1021.1Spgoyette 1031.1Spgoyette ATF_REQUIRE_MSG(xdr_medenum(&x, &m), "xdr_medenum DECODE failed"); 1041.1Spgoyette ATF_REQUIRE_EQ_MSG(m, ME_NEG, "ME_NEG decoded as %d", m); 1051.1Spgoyette 1061.1Spgoyette ATF_REQUIRE_MSG(xdr_bigenum(&x, &b), "xdr_bigenum DECODE failed"); 1071.1Spgoyette ATF_REQUIRE_EQ_MSG(b, BE_LOTS, "BE_LOTS decoded as %d", b); 1081.1Spgoyette 1091.1Spgoyette xdr_destroy(&x); 1101.1Spgoyette 1111.1Spgoyette 1121.1Spgoyette xdrmem_create(&x, newdata, sizeof(newdata), XDR_ENCODE); 1131.1Spgoyette 1141.1Spgoyette ATF_REQUIRE_MSG(xdr_double(&x, &d), "xdr_double ENCODE failed"); 1151.1Spgoyette ATF_REQUIRE_MSG(xdr_smallenum(&x, &s), "xdr_smallenum ENCODE failed"); 1161.1Spgoyette ATF_REQUIRE_MSG(xdr_medenum(&x, &m), "xdr_medenum ENCODE failed"); 1171.1Spgoyette ATF_REQUIRE_MSG(xdr_bigenum(&x, &b), "xdr_bigenum ENCODE failed"); 1181.1Spgoyette ATF_REQUIRE_MSG(memcmp(newdata, xdrdata, sizeof(xdrdata)) == 0, 1191.1Spgoyette "xdr ENCODE result differs"); 1201.1Spgoyette 1211.1Spgoyette xdr_destroy(&x); 1221.1Spgoyette} 1231.1Spgoyette 1241.1SpgoyetteATF_TP_ADD_TCS(tp) 1251.1Spgoyette{ 1261.1Spgoyette ATF_TP_ADD_TC(tp, xdr); 1271.1Spgoyette 1281.1Spgoyette return atf_no_error(); 1291.1Spgoyette} 130