2004-01-13 05:55:26 +03:00
/*
2005-11-05 22:57:48 +03:00
* Copyright ( c ) 2004 - 2005 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation . All rights reserved .
* Copyright ( c ) 2004 - 2005 The University of Tennessee and The University
* of Tennessee Research Foundation . All rights
* reserved .
2015-06-24 06:59:57 +03:00
* Copyright ( c ) 2004 - 2005 High Performance Computing Center Stuttgart ,
2004-11-28 23:09:25 +03:00
* University of Stuttgart . All rights reserved .
2005-03-24 15:43:37 +03:00
* Copyright ( c ) 2004 - 2005 The Regents of the University of California .
* All rights reserved .
2004-11-22 04:38:40 +03:00
* $ COPYRIGHT $
2015-06-24 06:59:57 +03:00
*
2004-11-22 04:38:40 +03:00
* Additional copyrights may follow
2015-06-24 06:59:57 +03:00
*
2004-01-13 05:55:26 +03:00
* $ HEADER $
*/
2004-10-20 05:03:09 +04:00
# include "ompi_config.h"
2004-01-13 05:55:26 +03:00
# include <stdio.h>
# include <string.h>
# include <stdlib.h>
2004-08-10 01:07:24 +04:00
# include "support.h"
2006-02-12 22:51:24 +03:00
# include "opal/constants.h"
2005-07-04 04:13:44 +04:00
# include "opal/util/argv.h"
2004-01-13 05:55:26 +03:00
static bool test1 ( void ) ;
static bool test2 ( void ) ;
static bool test3 ( void ) ;
static bool test4 ( void ) ;
static bool test5 ( void ) ;
static bool test6 ( void ) ;
static bool test7 ( void ) ;
static bool test8 ( void ) ;
2004-10-01 22:38:16 +04:00
static bool test9 ( void ) ;
static bool test10 ( void ) ;
2004-01-13 05:55:26 +03:00
int main ( int argc , char * argv [ ] )
{
2005-07-04 04:13:44 +04:00
test_init ( " opal_argv_t " ) ;
2004-08-10 01:07:24 +04:00
if ( test1 ( ) ) test_success ( ) ;
else test_failure ( " test1 argv test failed " ) ;
if ( test2 ( ) ) test_success ( ) ;
else test_failure ( " test2 argv test failed " ) ;
if ( test3 ( ) ) test_success ( ) ;
else test_failure ( " test3 argv test failed " ) ;
if ( test4 ( ) ) test_success ( ) ;
else test_failure ( " test4 argv test failed " ) ;
if ( test5 ( ) ) test_success ( ) ;
else test_failure ( " test5 argv test failed " ) ;
if ( test6 ( ) ) test_success ( ) ;
else test_failure ( " test6 argv test failed " ) ;
if ( test7 ( ) ) test_success ( ) ;
else test_failure ( " test7 argv test failed " ) ;
if ( test8 ( ) ) test_success ( ) ;
else test_failure ( " test8 argv test failed " ) ;
2004-10-01 22:38:16 +04:00
if ( test9 ( ) ) {
test_success ( ) ;
} else {
test_failure ( " test9 argv test failed " ) ;
}
2015-06-24 06:59:57 +03:00
2004-10-01 22:38:16 +04:00
if ( test10 ( ) ) {
test_success ( ) ;
} else {
test_failure ( " test10 argv test failed " ) ;
}
2015-06-24 06:59:57 +03:00
2004-08-10 01:07:24 +04:00
/* All done */
2005-03-22 17:41:45 +03:00
return test_finalize ( ) ;
2004-01-13 05:55:26 +03:00
}
static bool test1 ( void )
{
char * a [ ] = { " argv1 " , " argv2 " , " argv3 " , NULL } ;
char * * argv = NULL ;
int i , j , argc = 28 ;
/* Test basic functionality. Start with a NULL argv and add the
2015-06-24 06:59:57 +03:00
contents of the a array .
2004-01-13 05:55:26 +03:00
2005-07-04 04:13:44 +04:00
Set argc to be an initiall bogus number - - opal_argv_add ( ) should
2004-01-13 05:55:26 +03:00
reset it back to zero after the first iteration .
After adding the a [ i ] , ensure that argv [ 0 - ( i - 1 ) ] are the same
as a [ 0 - ( i - 1 ) ] .
Also ensure that a [ i + 1 ] = = NULL and that argc is the proper
value . */
for ( i = 0 ; a [ i ] ! = NULL ; + + i ) {
2005-08-21 23:21:09 +04:00
if ( opal_argv_append ( & argc , & argv , a [ i ] ) ! = OPAL_SUCCESS ) {
2004-01-13 05:55:26 +03:00
return false ;
}
for ( j = 0 ; j < = i ; + + j ) {
if ( strcmp ( argv [ j ] , a [ j ] ) ! = 0 ) {
return false ;
}
}
if ( NULL ! = argv [ i + 1 ] ) {
return false ;
}
if ( argc ! = i + 1 ) {
return false ;
}
}
2005-07-04 04:13:44 +04:00
opal_argv_free ( argv ) ;
2004-01-13 05:55:26 +03:00
return true ;
}
static bool test2 ( void )
{
int i , j ;
char * * argv = NULL ;
int argc ;
char * a [ ] = { " aaa " , " bbb " , " ccc " , NULL } ;
char * b [ 4 ] ;
2005-07-04 04:13:44 +04:00
/* Similar test to above, but ensure that opal_argv_add is actually
2004-01-13 05:55:26 +03:00
* copying * the string by value , not by reference . So copy the a
2005-07-04 04:13:44 +04:00
array into b , and then opal_argv_add ( ) from b . After that ,
2004-01-13 05:55:26 +03:00
scribble in the first character of the b [ ] string that we just
added , and compare all entries in a to argv - - they should be
identical ( even though b is now corrupted ) . */
for ( i = 0 ; a [ i ] ! = NULL ; + + i ) {
b [ i ] = strdup ( a [ i ] ) ;
}
b [ i ] = NULL ;
for ( i = 0 ; b [ i ] ! = NULL ; + + i ) {
2005-08-21 23:21:09 +04:00
if ( opal_argv_append ( & argc , & argv , b [ i ] ) ! = OPAL_SUCCESS ) {
2004-01-13 05:55:26 +03:00
return false ;
}
+ + b [ i ] [ 0 ] ;
for ( j = 0 ; j < = i ; + + j ) {
if ( strcmp ( argv [ j ] , a [ j ] ) ! = 0 ) {
return false ;
}
}
if ( NULL ! = argv [ i + 1 ] ) {
return false ;
}
if ( argc ! = i + 1 ) {
return false ;
}
}
2005-07-04 04:13:44 +04:00
opal_argv_free ( argv ) ;
2004-10-01 22:38:16 +04:00
for ( i = 0 ; b [ i ] ! = NULL ; + + i ) {
free ( b [ i ] ) ;
}
2004-01-13 05:55:26 +03:00
return true ;
}
static bool test3 ( void )
{
int i ;
int argc ;
char * * argv = NULL ;
char * a [ ] = { " aaa " , " bbb " , " ccc " , NULL } ;
char * b [ 4 ] ;
/* Try to free a null argv -- should be harmless (we'll seg fault if
it ' s not ! ) */
2005-07-04 04:13:44 +04:00
opal_argv_free ( argv ) ;
2004-01-13 05:55:26 +03:00
/* Now add some stuff and try to free it. We'll seg fault if
anything goes wrong . a is on the stack , so if it mistakenly
tries to free it , we should get a seg fault . */
for ( i = 0 ; a [ i ] ! = NULL ; + + i ) {
2005-08-21 23:21:09 +04:00
if ( opal_argv_append ( & argc , & argv , a [ i ] ) ! = OPAL_SUCCESS ) {
2004-01-13 05:55:26 +03:00
return false ;
}
}
2005-07-04 04:13:44 +04:00
opal_argv_free ( argv ) ;
2004-01-13 05:55:26 +03:00
/* Do the same thing but guarantee that the copied array was from
2005-07-04 04:13:44 +04:00
the heap and was freed before we call opal_argv_free ( ) . */
2004-01-13 05:55:26 +03:00
2004-10-01 22:38:16 +04:00
argc = 0 ;
argv = NULL ;
2004-01-13 05:55:26 +03:00
for ( i = 0 ; a [ i ] ! = NULL ; + + i ) {
b [ i ] = strdup ( a [ i ] ) ;
}
2004-10-01 22:38:16 +04:00
b [ i ] = NULL ;
2004-01-13 05:55:26 +03:00
for ( i = 0 ; b [ i ] ! = NULL ; + + i ) {
2005-08-21 23:21:09 +04:00
if ( opal_argv_append ( & argc , & argv , b [ i ] ) ! = OPAL_SUCCESS ) {
2004-01-13 05:55:26 +03:00
return false ;
}
}
for ( i = 0 ; b [ i ] ! = NULL ; + + i ) {
free ( b [ i ] ) ;
}
2005-07-04 04:13:44 +04:00
opal_argv_free ( argv ) ;
2004-01-13 05:55:26 +03:00
/* All done */
return true ;
}
static bool test4 ( void )
{
2005-04-01 17:35:57 +04:00
size_t i , count ;
2004-01-13 05:55:26 +03:00
char * a = strdup ( " the quick brown fox jumped over the lazy dog a_really_long_argument_to_force_a_long_copy_zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz " ) ;
char * * b ;
char * start ;
/* split a string into an argv, and compare it against the original
2005-07-04 04:13:44 +04:00
string . Add double spaces into the string ; opal_argv_split ( )
2004-01-13 05:55:26 +03:00
should skip them . */
2005-07-04 04:13:44 +04:00
b = opal_argv_split ( a , ' ' ) ;
2004-01-13 05:55:26 +03:00
for ( count = i = 1 ; i < strlen ( a ) ; + + i ) {
if ( a [ i ] ! = ' ' & & a [ i - 1 ] = = ' ' ) {
+ + count ;
}
}
for ( i = 0 ; b [ i ] ! = NULL ; + + i ) {
continue ;
}
if ( i ! = count ) {
return false ;
}
/* now do the same thing and compare each token in b */
for ( start = a , count = i = 0 ; i < strlen ( a ) ; + + i ) {
if ( a [ i ] = = ' ' & & a [ i - 1 ] ! = ' ' ) {
a [ i ] = ' \0 ' ;
if ( strcmp ( start , b [ count ] ) ! = 0 ) {
return false ;
}
+ + count ;
a [ i ] = ' ' ;
}
if ( a [ i ] = = ' ' & & a [ i + 1 ] ! = ' ' ) {
start = a + i + 1 ;
}
}
if ( strcmp ( start , b [ count ] ) ! = 0 ) {
return false ;
}
/* all done */
2005-07-04 04:13:44 +04:00
opal_argv_free ( b ) ;
2004-01-13 05:55:26 +03:00
free ( a ) ;
return true ;
}
static bool test5 ( void )
{
char * a [ ] = { " aaa " , " bbb " , " ccc " , NULL } ;
2005-07-04 04:13:44 +04:00
return ( opal_argv_count ( NULL ) = = 0 & & opal_argv_count ( a ) = = 3 ) ;
2004-01-13 05:55:26 +03:00
}
static bool test6 ( void )
{
char * a = " the quick brown fox jumped over the lazy dog a_really_long_argument_to_force_a_long_copy_zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz " ;
char * * b ;
char * c ;
/* split the string above and then join it -- the joined version
should be just like the original */
2005-07-04 04:13:44 +04:00
b = opal_argv_split ( a , ' ' ) ;
c = opal_argv_join ( b , ' ' ) ;
2004-01-13 05:55:26 +03:00
if ( strcmp ( a , c ) ! = 0 ) {
return false ;
}
/* All done */
free ( c ) ;
2005-07-04 04:13:44 +04:00
opal_argv_free ( b ) ;
2004-01-13 05:55:26 +03:00
return true ;
}
static bool test7 ( void )
{
char * a [ ] = { " a " , " b " , " c " , NULL } ;
size_t a_len = ( 1 + 1 + sizeof ( char * ) ) * 3 + sizeof ( char * * ) ;
/* check a NULL pointer first -- should return 0 */
2005-07-04 04:13:44 +04:00
if ( opal_argv_len ( NULL ) ! = ( size_t ) 0 ) {
2004-01-13 05:55:26 +03:00
return false ;
2004-01-13 05:57:17 +03:00
}
2004-01-13 05:55:26 +03:00
/* now check a real string */
/* size should be (sizeof(char **) + (sizeof(char) + sizeof('\0') +
sizeof ( char * ) ) * 3 ) */
2005-07-04 04:13:44 +04:00
if ( opal_argv_len ( a ) ! = a_len ) {
2004-01-13 05:55:26 +03:00
return false ;
2004-01-13 05:57:17 +03:00
}
2004-01-13 05:55:26 +03:00
/* All done */
return true ;
}
static bool test8 ( void )
{
char * a [ ] = { " aaa " , " bbbbbbbb " , " cccccccccc " , NULL } ;
int i ;
char * * b ;
/* bozo case */
2005-07-04 04:13:44 +04:00
if ( NULL ! = opal_argv_copy ( NULL ) ) {
2004-01-13 05:55:26 +03:00
return false ;
2004-01-13 05:57:17 +03:00
}
2004-01-13 05:55:26 +03:00
/* dup the a array and compare it (array length, contents, etc.) */
2005-07-04 04:13:44 +04:00
b = opal_argv_copy ( a ) ;
2004-01-13 05:55:26 +03:00
2005-07-04 04:13:44 +04:00
if ( opal_argv_count ( a ) ! = opal_argv_count ( b ) ) {
2004-01-13 05:55:26 +03:00
return false ;
2004-01-13 05:57:17 +03:00
}
for ( i = 0 ; a [ i ] ! = NULL ; + + i ) {
if ( 0 ! = strcmp ( a [ i ] , b [ i ] ) ) {
2004-01-13 05:55:26 +03:00
return false ;
2004-01-13 05:57:17 +03:00
}
}
2004-01-13 05:55:26 +03:00
/* All done */
2005-07-04 04:13:44 +04:00
opal_argv_free ( b ) ;
2004-01-13 05:55:26 +03:00
return true ;
}
2004-10-01 22:38:16 +04:00
static bool test9 ( void )
{
char * * a = NULL ;
int argc ;
/* bozo cases */
2015-06-24 06:59:57 +03:00
2005-08-21 23:21:09 +04:00
if ( OPAL_SUCCESS ! = opal_argv_delete ( NULL , NULL , 0 , 0 ) ) {
2004-10-01 22:38:16 +04:00
return false ;
2015-06-24 06:59:57 +03:00
}
2004-10-01 22:38:16 +04:00
a = NULL ;
argc = 0 ;
2005-07-04 04:13:44 +04:00
opal_argv_append ( & argc , & a , " foo " ) ;
2005-08-21 23:21:09 +04:00
if ( OPAL_SUCCESS ! = opal_argv_delete ( & argc , & a , 7 , 1 ) | |
2005-07-04 04:13:44 +04:00
1 ! = opal_argv_count ( a ) ) {
2004-10-01 22:38:16 +04:00
return false ;
2015-06-24 06:59:57 +03:00
}
2005-07-04 04:13:44 +04:00
opal_argv_free ( a ) ;
2004-10-01 22:38:16 +04:00
a = NULL ;
argc = 0 ;
2005-07-04 04:13:44 +04:00
opal_argv_append ( & argc , & a , " foo " ) ;
2005-08-21 23:21:09 +04:00
if ( OPAL_SUCCESS ! = opal_argv_delete ( & argc , & a , 0 , 0 ) | |
2005-07-04 04:13:44 +04:00
1 ! = opal_argv_count ( a ) ) {
2004-10-01 22:38:16 +04:00
return false ;
}
2005-07-04 04:13:44 +04:00
opal_argv_free ( a ) ;
2004-10-01 22:38:16 +04:00
/* now some real tests */
/* delete 1 off the top */
a = NULL ;
argc = 0 ;
2005-07-04 04:13:44 +04:00
opal_argv_append ( & argc , & a , " a " ) ;
opal_argv_append ( & argc , & a , " b " ) ;
opal_argv_append ( & argc , & a , " c " ) ;
opal_argv_append ( & argc , & a , " d " ) ;
opal_argv_append ( & argc , & a , " e " ) ;
opal_argv_append ( & argc , & a , " f " ) ;
2005-08-21 23:21:09 +04:00
if ( OPAL_SUCCESS ! = opal_argv_delete ( & argc , & a , 0 , 1 ) | |
2005-07-04 04:13:44 +04:00
5 ! = opal_argv_count ( a ) | |
2004-10-01 22:38:16 +04:00
0 ! = strcmp ( a [ 0 ] , " b " ) | |
0 ! = strcmp ( a [ 1 ] , " c " ) | |
0 ! = strcmp ( a [ 2 ] , " d " ) | |
0 ! = strcmp ( a [ 3 ] , " e " ) | |
0 ! = strcmp ( a [ 4 ] , " f " ) ) {
return false ;
}
2005-07-04 04:13:44 +04:00
opal_argv_free ( a ) ;
2004-10-01 22:38:16 +04:00
/* delete 2 off the top */
a = NULL ;
argc = 0 ;
2005-07-04 04:13:44 +04:00
opal_argv_append ( & argc , & a , " a " ) ;
opal_argv_append ( & argc , & a , " b " ) ;
opal_argv_append ( & argc , & a , " c " ) ;
opal_argv_append ( & argc , & a , " d " ) ;
opal_argv_append ( & argc , & a , " e " ) ;
opal_argv_append ( & argc , & a , " f " ) ;
2005-08-21 23:21:09 +04:00
if ( OPAL_SUCCESS ! = opal_argv_delete ( & argc , & a , 0 , 2 ) | |
2005-07-04 04:13:44 +04:00
4 ! = opal_argv_count ( a ) | |
2004-10-01 22:38:16 +04:00
0 ! = strcmp ( a [ 0 ] , " c " ) | |
0 ! = strcmp ( a [ 1 ] , " d " ) | |
0 ! = strcmp ( a [ 2 ] , " e " ) | |
0 ! = strcmp ( a [ 3 ] , " f " ) ) {
return false ;
}
2005-07-04 04:13:44 +04:00
opal_argv_free ( a ) ;
2004-10-01 22:38:16 +04:00
/* delete 1 in the middle */
a = NULL ;
argc = 0 ;
2005-07-04 04:13:44 +04:00
opal_argv_append ( & argc , & a , " a " ) ;
opal_argv_append ( & argc , & a , " b " ) ;
opal_argv_append ( & argc , & a , " c " ) ;
opal_argv_append ( & argc , & a , " d " ) ;
opal_argv_append ( & argc , & a , " e " ) ;
opal_argv_append ( & argc , & a , " f " ) ;
2005-08-21 23:21:09 +04:00
if ( OPAL_SUCCESS ! = opal_argv_delete ( & argc , & a , 1 , 1 ) | |
2005-07-04 04:13:44 +04:00
5 ! = opal_argv_count ( a ) | |
2004-10-01 22:38:16 +04:00
0 ! = strcmp ( a [ 0 ] , " a " ) | |
0 ! = strcmp ( a [ 1 ] , " c " ) | |
0 ! = strcmp ( a [ 2 ] , " d " ) | |
0 ! = strcmp ( a [ 3 ] , " e " ) | |
0 ! = strcmp ( a [ 4 ] , " f " ) ) {
return false ;
}
2005-07-04 04:13:44 +04:00
opal_argv_free ( a ) ;
2004-10-01 22:38:16 +04:00
/* delete 2 in the middle */
a = NULL ;
argc = 0 ;
2005-07-04 04:13:44 +04:00
opal_argv_append ( & argc , & a , " a " ) ;
opal_argv_append ( & argc , & a , " b " ) ;
opal_argv_append ( & argc , & a , " c " ) ;
opal_argv_append ( & argc , & a , " d " ) ;
opal_argv_append ( & argc , & a , " e " ) ;
opal_argv_append ( & argc , & a , " f " ) ;
2005-08-21 23:21:09 +04:00
if ( OPAL_SUCCESS ! = opal_argv_delete ( & argc , & a , 1 , 2 ) | |
2005-07-04 04:13:44 +04:00
4 ! = opal_argv_count ( a ) | |
2004-10-01 22:38:16 +04:00
0 ! = strcmp ( a [ 0 ] , " a " ) | |
0 ! = strcmp ( a [ 1 ] , " d " ) | |
0 ! = strcmp ( a [ 2 ] , " e " ) | |
0 ! = strcmp ( a [ 3 ] , " f " ) ) {
return false ;
}
2005-07-04 04:13:44 +04:00
opal_argv_free ( a ) ;
2004-10-01 22:38:16 +04:00
/* delete everything from the top */
a = NULL ;
argc = 0 ;
2005-07-04 04:13:44 +04:00
opal_argv_append ( & argc , & a , " a " ) ;
opal_argv_append ( & argc , & a , " b " ) ;
2005-08-21 23:21:09 +04:00
if ( OPAL_SUCCESS ! = opal_argv_delete ( & argc , & a , 0 , 99 ) | |
2005-07-04 04:13:44 +04:00
0 ! = opal_argv_count ( a ) ) {
2004-10-01 22:38:16 +04:00
return false ;
}
2005-07-04 04:13:44 +04:00
opal_argv_free ( a ) ;
2004-10-01 22:38:16 +04:00
/* delete everything from the middle */
a = NULL ;
argc = 0 ;
2005-07-04 04:13:44 +04:00
opal_argv_append ( & argc , & a , " a " ) ;
opal_argv_append ( & argc , & a , " b " ) ;
2005-08-21 23:21:09 +04:00
if ( OPAL_SUCCESS ! = opal_argv_delete ( & argc , & a , 1 , 99 ) | |
2005-07-04 04:13:44 +04:00
1 ! = opal_argv_count ( a ) | |
2004-10-01 22:38:16 +04:00
0 ! = strcmp ( a [ 0 ] , " a " ) ) {
return false ;
}
2005-07-04 04:13:44 +04:00
opal_argv_free ( a ) ;
2004-10-01 22:38:16 +04:00
/* All done */
return true ;
}
static bool test10 ( void )
{
char * * orig ;
char * * insert ;
int o , i ;
/* bozo cases */
2015-06-24 06:59:57 +03:00
2004-10-01 22:38:16 +04:00
orig = NULL ;
o = 0 ;
insert = NULL ;
i = 0 ;
2005-07-04 04:13:44 +04:00
opal_argv_append ( & i , & insert , " insert a " ) ;
2005-08-21 23:21:09 +04:00
if ( OPAL_SUCCESS = = opal_argv_insert ( NULL , 0 , insert ) ) {
2004-10-01 22:38:16 +04:00
return false ;
2015-06-24 06:59:57 +03:00
}
2005-07-04 04:13:44 +04:00
opal_argv_append ( & o , & orig , " orig a " ) ;
2005-08-21 23:21:09 +04:00
if ( OPAL_SUCCESS ! = opal_argv_insert ( & orig , 0 , NULL ) ) {
2004-10-01 22:38:16 +04:00
return false ;
2015-06-24 06:59:57 +03:00
}
2005-08-21 23:21:09 +04:00
if ( OPAL_SUCCESS = = opal_argv_insert ( & orig , - 1 , insert ) ) {
2004-10-01 22:38:16 +04:00
return false ;
2015-06-24 06:59:57 +03:00
}
2005-07-04 04:13:44 +04:00
opal_argv_free ( orig ) ;
opal_argv_free ( insert ) ;
2004-10-01 22:38:16 +04:00
/* append to the end */
orig = NULL ;
o = 0 ;
insert = NULL ;
i = 0 ;
2005-07-04 04:13:44 +04:00
opal_argv_append ( & i , & insert , " insert a " ) ;
opal_argv_append ( & i , & insert , " insert b " ) ;
opal_argv_append ( & i , & insert , " insert c " ) ;
opal_argv_append ( & o , & orig , " orig a " ) ;
opal_argv_append ( & o , & orig , " orig b " ) ;
opal_argv_append ( & o , & orig , " orig c " ) ;
2005-08-21 23:21:09 +04:00
if ( OPAL_SUCCESS ! = opal_argv_insert ( & orig , 99 , insert ) | |
2005-07-04 04:13:44 +04:00
6 ! = opal_argv_count ( orig ) | |
2004-10-01 22:38:16 +04:00
0 ! = strcmp ( orig [ 0 ] , " orig a " ) | |
0 ! = strcmp ( orig [ 1 ] , " orig b " ) | |
0 ! = strcmp ( orig [ 2 ] , " orig c " ) | |
0 ! = strcmp ( orig [ 3 ] , " insert a " ) | |
0 ! = strcmp ( orig [ 4 ] , " insert b " ) | |
0 ! = strcmp ( orig [ 5 ] , " insert c " ) ) {
return false ;
}
2005-07-04 04:13:44 +04:00
opal_argv_free ( orig ) ;
opal_argv_free ( insert ) ;
2004-10-01 22:38:16 +04:00
/* insert at the beginning */
orig = NULL ;
o = 0 ;
insert = NULL ;
i = 0 ;
2005-07-04 04:13:44 +04:00
opal_argv_append ( & i , & insert , " insert a " ) ;
opal_argv_append ( & i , & insert , " insert b " ) ;
opal_argv_append ( & i , & insert , " insert c " ) ;
opal_argv_append ( & o , & orig , " orig a " ) ;
opal_argv_append ( & o , & orig , " orig b " ) ;
opal_argv_append ( & o , & orig , " orig c " ) ;
2005-08-21 23:21:09 +04:00
if ( OPAL_SUCCESS ! = opal_argv_insert ( & orig , 0 , insert ) | |
2005-07-04 04:13:44 +04:00
6 ! = opal_argv_count ( orig ) | |
2004-10-01 22:38:16 +04:00
0 ! = strcmp ( orig [ 3 ] , " orig a " ) | |
0 ! = strcmp ( orig [ 4 ] , " orig b " ) | |
0 ! = strcmp ( orig [ 5 ] , " orig c " ) | |
0 ! = strcmp ( orig [ 0 ] , " insert a " ) | |
0 ! = strcmp ( orig [ 1 ] , " insert b " ) | |
0 ! = strcmp ( orig [ 2 ] , " insert c " ) ) {
return false ;
}
2005-07-04 04:13:44 +04:00
opal_argv_free ( orig ) ;
opal_argv_free ( insert ) ;
2004-10-01 22:38:16 +04:00
/* insert in the middle */
orig = NULL ;
o = 0 ;
insert = NULL ;
i = 0 ;
2005-07-04 04:13:44 +04:00
opal_argv_append ( & i , & insert , " insert a " ) ;
opal_argv_append ( & i , & insert , " insert b " ) ;
opal_argv_append ( & i , & insert , " insert c " ) ;
opal_argv_append ( & o , & orig , " orig a " ) ;
opal_argv_append ( & o , & orig , " orig b " ) ;
opal_argv_append ( & o , & orig , " orig c " ) ;
2005-08-21 23:21:09 +04:00
if ( OPAL_SUCCESS ! = opal_argv_insert ( & orig , 1 , insert ) | |
2005-07-04 04:13:44 +04:00
6 ! = opal_argv_count ( orig ) | |
2004-10-01 22:38:16 +04:00
0 ! = strcmp ( orig [ 0 ] , " orig a " ) | |
0 ! = strcmp ( orig [ 4 ] , " orig b " ) | |
0 ! = strcmp ( orig [ 5 ] , " orig c " ) | |
0 ! = strcmp ( orig [ 1 ] , " insert a " ) | |
0 ! = strcmp ( orig [ 2 ] , " insert b " ) | |
0 ! = strcmp ( orig [ 3 ] , " insert c " ) ) {
return false ;
}
2005-07-04 04:13:44 +04:00
opal_argv_free ( orig ) ;
opal_argv_free ( insert ) ;
2004-10-01 22:38:16 +04:00
/* insert in the middle */
orig = NULL ;
o = 0 ;
insert = NULL ;
i = 0 ;
2005-07-04 04:13:44 +04:00
opal_argv_append ( & i , & insert , " insert a " ) ;
opal_argv_append ( & i , & insert , " insert b " ) ;
opal_argv_append ( & i , & insert , " insert c " ) ;
opal_argv_append ( & o , & orig , " orig a " ) ;
opal_argv_append ( & o , & orig , " orig b " ) ;
opal_argv_append ( & o , & orig , " orig c " ) ;
opal_argv_append ( & o , & orig , " orig d " ) ;
opal_argv_append ( & o , & orig , " orig e " ) ;
opal_argv_append ( & o , & orig , " orig f " ) ;
2005-08-21 23:21:09 +04:00
if ( OPAL_SUCCESS ! = opal_argv_insert ( & orig , 1 , insert ) | |
2005-07-04 04:13:44 +04:00
9 ! = opal_argv_count ( orig ) | |
2004-10-01 22:38:16 +04:00
0 ! = strcmp ( orig [ 0 ] , " orig a " ) | |
0 ! = strcmp ( orig [ 4 ] , " orig b " ) | |
0 ! = strcmp ( orig [ 5 ] , " orig c " ) | |
0 ! = strcmp ( orig [ 6 ] , " orig d " ) | |
0 ! = strcmp ( orig [ 7 ] , " orig e " ) | |
0 ! = strcmp ( orig [ 8 ] , " orig f " ) | |
0 ! = strcmp ( orig [ 1 ] , " insert a " ) | |
0 ! = strcmp ( orig [ 2 ] , " insert b " ) | |
0 ! = strcmp ( orig [ 3 ] , " insert c " ) ) {
return false ;
}
2005-07-04 04:13:44 +04:00
opal_argv_free ( orig ) ;
opal_argv_free ( insert ) ;
2004-10-01 22:38:16 +04:00
/* All done */
return true ;
}