1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/cstdlib/TSTLIB/tsock.c Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,99 @@
1.4 +/*
1.5 +* Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +* Test of the unsupported option values in setsockopt
1.19 +*
1.20 +*
1.21 +*/
1.22 +
1.23 +
1.24 +
1.25 +#include <stdio.h>
1.26 +#include <errno.h>
1.27 +#include <stdlib.h>
1.28 +#include <string.h>
1.29 +#include <unistd.h>
1.30 +#include <sys/types.h>
1.31 +#include <sys/socket.h>
1.32 +#include <sys/ioctl.h>
1.33 +#include <libc/netinet/in.h>
1.34 +#include <libc/arpa/inet.h>
1.35 +#include <netdb.h>
1.36 +#include <reent.h>
1.37 +
1.38 +#include "CTEST.H" /* includes C interface to EPOC32 threads, and SpawnPosixServer */
1.39 +
1.40 +test_Data;
1.41 +
1.42 +struct sockaddr_in testaddr;
1.43 +
1.44 +//The structure _reent contains *all* globals needed by the library.
1.45 +struct _reent* p;
1.46 +
1.47 +unsigned short int port = 2001;
1.48 +
1.49 +/**
1.50 +@SYMTestCaseID SYSLIB-STDLIB-CT-1119
1.51 +@SYMTestCaseDesc Tests for the unsupported option values in setsockopt
1.52 +@SYMTestPriority High
1.53 +@SYMTestActions Tests for creation of a socket and setting unsupported options on a socket
1.54 +@SYMTestExpectedResults Test must not fail
1.55 +@SYMREQ REQ0000
1.56 +*/
1.57 +void testSimple()
1.58 + {
1.59 + int fd1;
1.60 + int err;
1.61 + int optionbuf[20];
1.62 + size_t optionsize;
1.63 +
1.64 + //Creating stream sockets to be used in the test
1.65 + test_Next("Create stream sockets");
1.66 + fd1=socket(AF_INET, SOCK_STREAM, 0);
1.67 + test_ok(fd1>=0);
1.68 +
1.69 + optionbuf[0]=7*1024;
1.70 + optionsize=sizeof(optionbuf[0]);
1.71 +
1.72 + //valid option e.g SO_SNDBUF(positive value 3)
1.73 + err=setsockopt(fd1,SOL_SOCKET,SO_SNDBUF,optionbuf,optionsize);
1.74 + p=_REENT;
1.75 + //No error in setsockopt with returned value in p->_errno=0
1.76 + test(err==0);
1.77 + test(p->_errno==0);
1.78 +
1.79 +
1.80 + //invalid(not supported) option e.g IP_ADD_MEMBERSHIP(negative value -8)
1.81 + err=setsockopt(fd1,SOL_SOCKET,IP_ADD_MEMBERSHIP,optionbuf,optionsize);
1.82 + p=_REENT;
1.83 + //Error in setsockopt with returned value in p->_errno=ENOSYS(88)
1.84 + test(err==-1);
1.85 + test(p->_errno==ENOSYS);
1.86 +
1.87 + }
1.88 +
1.89 +int main()
1.90 + {
1.91 + int err;
1.92 + test_Title("AF_INET Streams");
1.93 +
1.94 + err=CommInit(0); /* ensure a workable comms environment */
1.95 + test(err==0);
1.96 + IN_SET_LOOPBACK_ADDR(&testaddr);
1.97 +
1.98 + testSimple();
1.99 +
1.100 + test_Close();
1.101 + return 0;
1.102 + }