ossp-pkg/sa/sa_test.c
1.8
/*
** SA - OSSP Socket Abstraction Library
** Copyright (c) 2001 Ralf S. Engelschall <rse@engelschall.com>
** Copyright (c) 2001 The OSSP Project <http://www.ossp.org/>
** Copyright (c) 2001 Cable & Wireless Deutschland <http://www.cw.com/de/>
**
** This file is part of OSSP SA, a socket abstraction library which
** can be found at http://www.ossp.org/pkg/sa/.
**
** Permission to use, copy, modify, and distribute this software for
** any purpose with or without fee is hereby granted, provided that
** the above copyright notice and this permission notice appear in all
** copies.
**
** THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
** WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
** IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
** USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
** OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
** SUCH DAMAGE.
**
** sa_test.c: socket abstraction library test suite
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <time.h>
#include <sys/utsname.h>
#include <unistd.h>
#include "ts.h"
#include "sa.h"
TST_FUNC(test_sa)
{
}
TST_FUNC(test_saa)
{
sa_addr_t *saa;
sa_rc_t rv;
char *cp1;
char *cp2;
tst_check(TST, "sa_addr_create");
if ((rv = sa_addr_create(&saa)) != SA_OK)
tst_fail(tst, "rv=%d (%s)", rv, sa_error(rv));
tst_check(TST, "sa_addr_u2a");
cp1 = "inet://127.0.0.1:12345";
if ((rv = sa_addr_u2a(saa, cp1)) != SA_OK)
tst_fail(TST, "rv=%d (%s)", rv, sa_error(rv));
tst_check(TST, "sa_addr_a2u");
if ((rv = sa_addr_a2u(saa, &cp2)) != SA_OK)
tst_fail(TST, "rv=%d (%s)", rv, sa_error(rv));
if (strcmp(cp1, cp2) != 0)
tst_fail(TST, "import \"%s\" <-> export \"%s\"", cp1, cp2);
tst_check(tst, "sa_addr_destroy");
if ((rv = sa_addr_destroy(saa)) != SA_OK)
tst_fail(TST, "rv=%d (%s)", rv, sa_error(rv));
}
int main(int argc, char *argv[])
{
ts_t *ts;
int n;
ts = ts_new("OSSP SA (Socket Abstraction Library)");
ts_test(ts, test_saa, "socket address abstraction");
ts_test(ts, test_sa, "socket abstraction");
n = ts_run(ts);
ts_free(ts);
return n;
}