1272343Sngie/* $NetBSD: t_xdr.c,v 1.1 2011/01/08 06:59:37 pgoyette Exp $ */ 2272343Sngie 3272343Sngie/* 4272343Sngie * Copyright (c) 2008 The NetBSD Foundation, Inc. 5272343Sngie * All rights reserved. 6272343Sngie * 7272343Sngie * This code is derived from software contributed to The NetBSD Foundation 8272343Sngie * by Ben Harris. 9272343Sngie * 10272343Sngie * Redistribution and use in source and binary forms, with or without 11272343Sngie * modification, are permitted provided that the following conditions 12272343Sngie * are met: 13272343Sngie * 1. Redistributions of source code must retain the above copyright 14272343Sngie * notice, this list of conditions and the following disclaimer. 15272343Sngie * 2. Redistributions in binary form must reproduce the above copyright 16272343Sngie * notice, this list of conditions and the following disclaimer in the 17272343Sngie * documentation and/or other materials provided with the distribution. 18272343Sngie * 19272343Sngie * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20272343Sngie * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21272343Sngie * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22272343Sngie * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23272343Sngie * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24272343Sngie * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25272343Sngie * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26272343Sngie * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27272343Sngie * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28272343Sngie * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29272343Sngie * POSSIBILITY OF SUCH DAMAGE. 30272343Sngie */ 31272343Sngie 32272343Sngie/*- 33272343Sngie * Copyright (c) 2001 Ben Harris 34272343Sngie * All rights reserved. 35272343Sngie * 36272343Sngie * Redistribution and use in source and binary forms, with or without 37272343Sngie * modification, are permitted provided that the following conditions 38272343Sngie * are met: 39272343Sngie * 1. Redistributions of source code must retain the above copyright 40272343Sngie * notice, this list of conditions and the following disclaimer. 41272343Sngie * 2. Redistributions in binary form must reproduce the above copyright 42272343Sngie * notice, this list of conditions and the following disclaimer in the 43272343Sngie * documentation and/or other materials provided with the distribution. 44272343Sngie * 3. The name of the author may not be used to endorse or promote products 45272343Sngie * derived from this software without specific prior written permission. 46272343Sngie * 47272343Sngie * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 48272343Sngie * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 49272343Sngie * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 50272343Sngie * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 51272343Sngie * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 52272343Sngie * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 53272343Sngie * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 54272343Sngie * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 55272343Sngie * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 56272343Sngie * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 57272343Sngie */ 58272343Sngie 59272343Sngie#include <sys/cdefs.h> 60272343Sngie__COPYRIGHT("@(#) Copyright (c) 2008\ 61272343Sngie The NetBSD Foundation, inc. All rights reserved."); 62272343Sngie__RCSID("$NetBSD: t_xdr.c,v 1.1 2011/01/08 06:59:37 pgoyette Exp $"); 63272343Sngie 64272343Sngie#include <rpc/types.h> 65272343Sngie#include <rpc/xdr.h> 66272343Sngie 67272343Sngie#include <string.h> 68272343Sngie 69272343Sngie#include <atf-c.h> 70272343Sngie 71272343Sngie#include "h_testbits.h" 72272343Sngie 73272343Sngiechar xdrdata[] = { 74272343Sngie 0x3f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* double 1.0 */ 75272343Sngie 0x00, 0x00, 0x00, 0x01, /* enum smallenum SE_ONE */ 76272343Sngie 0xff, 0xff, 0xfb, 0x2e, /* enum medenum ME_NEG */ 77272343Sngie 0x00, 0x12, 0xd6, 0x87, /* enum bigenum BE_LOTS */ 78272343Sngie}; 79272343Sngie 80272343SngieATF_TC(xdr); 81272343SngieATF_TC_HEAD(xdr, tc) 82272343Sngie{ 83272343Sngie atf_tc_set_md_var(tc, "descr", 84272343Sngie "Checks encoding/decoding of doubles and enumerations"); 85272343Sngie} 86272343SngieATF_TC_BODY(xdr, tc) 87272343Sngie{ 88272343Sngie XDR x; 89272343Sngie double d; 90272343Sngie smallenum s; 91272343Sngie medenum m; 92272343Sngie bigenum b; 93272343Sngie char newdata[sizeof(xdrdata)]; 94272343Sngie 95272343Sngie xdrmem_create(&x, xdrdata, sizeof(xdrdata), XDR_DECODE); 96272343Sngie 97272343Sngie ATF_REQUIRE_MSG(xdr_double(&x, &d), "xdr_double DECODE failed"); 98272343Sngie ATF_REQUIRE_EQ_MSG(d, 1.0, "double 1.0 decoded as %g", d); 99272343Sngie 100272343Sngie ATF_REQUIRE_MSG(xdr_smallenum(&x, &s), "xdr_smallenum DECODE failed"); 101272343Sngie ATF_REQUIRE_EQ_MSG(s, SE_ONE, "SE_ONE decoded as %d", s); 102272343Sngie 103272343Sngie ATF_REQUIRE_MSG(xdr_medenum(&x, &m), "xdr_medenum DECODE failed"); 104272343Sngie ATF_REQUIRE_EQ_MSG(m, ME_NEG, "ME_NEG decoded as %d", m); 105272343Sngie 106272343Sngie ATF_REQUIRE_MSG(xdr_bigenum(&x, &b), "xdr_bigenum DECODE failed"); 107272343Sngie ATF_REQUIRE_EQ_MSG(b, BE_LOTS, "BE_LOTS decoded as %d", b); 108272343Sngie 109272343Sngie xdr_destroy(&x); 110272343Sngie 111272343Sngie 112272343Sngie xdrmem_create(&x, newdata, sizeof(newdata), XDR_ENCODE); 113272343Sngie 114272343Sngie ATF_REQUIRE_MSG(xdr_double(&x, &d), "xdr_double ENCODE failed"); 115272343Sngie ATF_REQUIRE_MSG(xdr_smallenum(&x, &s), "xdr_smallenum ENCODE failed"); 116272343Sngie ATF_REQUIRE_MSG(xdr_medenum(&x, &m), "xdr_medenum ENCODE failed"); 117272343Sngie ATF_REQUIRE_MSG(xdr_bigenum(&x, &b), "xdr_bigenum ENCODE failed"); 118272343Sngie ATF_REQUIRE_MSG(memcmp(newdata, xdrdata, sizeof(xdrdata)) == 0, 119272343Sngie "xdr ENCODE result differs"); 120272343Sngie 121272343Sngie xdr_destroy(&x); 122272343Sngie} 123272343Sngie 124272343SngieATF_TP_ADD_TCS(tp) 125272343Sngie{ 126272343Sngie ATF_TP_ADD_TC(tp, xdr); 127272343Sngie 128272343Sngie return atf_no_error(); 129272343Sngie} 130