genericopenlibs/cstdlib/TSTLIB/tsock.c
changeset 31 ce057bb09d0b
parent 0 e4d67989cc36
equal deleted inserted replaced
30:e20de85af2ee 31:ce057bb09d0b
       
     1 /*
       
     2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 * Test of the unsupported option values in setsockopt
       
    16 * 
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 
       
    22 #include <stdio.h>
       
    23 #include <errno.h>
       
    24 #include <stdlib.h>
       
    25 #include <string.h>
       
    26 #include <unistd.h>
       
    27 #include <sys/types.h>
       
    28 #include <sys/socket.h>
       
    29 #include <sys/ioctl.h>
       
    30 #include <libc/netinet/in.h>
       
    31 #include <libc/arpa/inet.h>
       
    32 #include <netdb.h>
       
    33 #include <reent.h>
       
    34 
       
    35 #include "CTEST.H"	/* includes C interface to EPOC32 threads, and SpawnPosixServer */
       
    36 
       
    37 test_Data;
       
    38 
       
    39 struct sockaddr_in testaddr;
       
    40 
       
    41 //The structure _reent contains *all* globals needed by the library.
       
    42 struct _reent* p;
       
    43 
       
    44 unsigned short int port = 2001;
       
    45 
       
    46 /**
       
    47 @SYMTestCaseID          SYSLIB-STDLIB-CT-1119
       
    48 @SYMTestCaseDesc	    Tests for the unsupported option values in setsockopt
       
    49 @SYMTestPriority 	    High
       
    50 @SYMTestActions  	    Tests for creation of a socket and setting unsupported options on a socket
       
    51 @SYMTestExpectedResults Test must not fail
       
    52 @SYMREQ                 REQ0000
       
    53 */					
       
    54 void testSimple()
       
    55 	{
       
    56 	int fd1;
       
    57 	int err;
       
    58 	int optionbuf[20];
       
    59 	size_t optionsize;
       
    60 
       
    61 	//Creating stream sockets to be used in the test
       
    62 	test_Next("Create stream sockets");
       
    63 	fd1=socket(AF_INET, SOCK_STREAM, 0);
       
    64 	test_ok(fd1>=0);
       
    65 
       
    66 	optionbuf[0]=7*1024;
       
    67 	optionsize=sizeof(optionbuf[0]);
       
    68 	
       
    69 	//valid option e.g SO_SNDBUF(positive value 3)
       
    70 	err=setsockopt(fd1,SOL_SOCKET,SO_SNDBUF,optionbuf,optionsize);
       
    71 	p=_REENT;
       
    72 	//No error in setsockopt with returned value in p->_errno=0
       
    73 	test(err==0);
       
    74 	test(p->_errno==0);
       
    75 
       
    76 
       
    77 	//invalid(not supported) option e.g IP_ADD_MEMBERSHIP(negative value -8)
       
    78 	err=setsockopt(fd1,SOL_SOCKET,IP_ADD_MEMBERSHIP,optionbuf,optionsize);
       
    79 	p=_REENT;
       
    80 	//Error in setsockopt with returned value in p->_errno=ENOSYS(88)
       
    81 	test(err==-1);
       
    82 	test(p->_errno==ENOSYS);
       
    83 	
       
    84 	}
       
    85 
       
    86 int main()
       
    87 	{
       
    88 	int err;
       
    89 	test_Title("AF_INET Streams");
       
    90 
       
    91 	err=CommInit(0);	/* ensure a workable comms environment */
       
    92 	test(err==0);
       
    93 	IN_SET_LOOPBACK_ADDR(&testaddr);
       
    94 
       
    95 	testSimple();
       
    96 
       
    97 	test_Close();
       
    98 	return 0;
       
    99 	}