2009-09-23 16:25:52 +04:00
# include <config.h>
2013-04-16 17:41:44 +04:00
# include "testutils.h"
2009-09-23 16:25:52 +04:00
# ifdef WITH_ESX
2010-03-09 21:22:22 +03:00
# include <unistd.h>
2009-09-23 16:25:52 +04:00
2010-03-09 21:22:22 +03:00
# include "internal.h"
2012-12-12 22:06:53 +04:00
# include "viralloc.h"
2010-12-22 00:39:55 +03:00
# include "vmx / vmx.h"
2010-03-09 21:22:22 +03:00
# include "esx / esx_util.h"
2010-04-07 13:23:53 +04:00
# include "esx / esx_vi_types.h"
2009-09-23 16:25:52 +04:00
2009-09-23 16:52:36 +04:00
struct testPath {
2010-08-01 21:53:00 +04:00
const char * datastorePath ;
2009-09-23 16:52:36 +04:00
int result ;
const char * datastoreName ;
const char * directoryName ;
2010-08-25 13:44:57 +04:00
const char * directoryAndFileName ;
2009-09-23 16:52:36 +04:00
} ;
static struct testPath paths [ ] = {
2010-08-25 13:44:57 +04:00
{ " [datastore] directory/file " , 0 , " datastore " , " directory " ,
" directory/file " } ,
{ " [datastore] directory1/directory2/file " , 0 , " datastore " ,
" directory1/directory2 " , " directory1/directory2/file " } ,
{ " [datastore] file " , 0 , " datastore " , " file " , " file " } ,
{ " [datastore] directory/ " , 0 , " datastore " , " directory " , " directory/ " } ,
{ " [datastore] " , 0 , " datastore " , " " , " " } ,
2009-09-23 16:52:36 +04:00
{ " [] directory/file " , - 1 , NULL , NULL , NULL } ,
{ " directory/file " , - 1 , NULL , NULL , NULL } ,
} ;
static int
2019-10-14 15:45:03 +03:00
testParseDatastorePath ( const void * data G_GNUC_UNUSED )
2009-09-23 16:52:36 +04:00
{
Convert 'int i' to 'size_t i' in tests/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 18:09:33 +04:00
int result = 0 ;
size_t i ;
2009-09-23 16:52:36 +04:00
char * datastoreName = NULL ;
char * directoryName = NULL ;
2010-08-25 13:44:57 +04:00
char * directoryAndFileName = NULL ;
2009-09-23 16:52:36 +04:00
2019-10-15 14:55:26 +03:00
for ( i = 0 ; i < G_N_ELEMENTS ( paths ) ; + + i ) {
2009-09-23 16:52:36 +04:00
VIR_FREE ( datastoreName ) ;
VIR_FREE ( directoryName ) ;
2010-08-25 13:44:57 +04:00
VIR_FREE ( directoryAndFileName ) ;
2009-09-23 16:52:36 +04:00
2010-08-25 13:44:57 +04:00
if ( esxUtil_ParseDatastorePath
( paths [ i ] . datastorePath , & datastoreName , & directoryName ,
& directoryAndFileName ) ! = paths [ i ] . result ) {
2009-09-23 16:52:36 +04:00
goto failure ;
}
2014-11-13 17:20:43 +03:00
if ( paths [ i ] . result < 0 )
2009-09-23 16:52:36 +04:00
continue ;
if ( STRNEQ ( paths [ i ] . datastoreName , datastoreName ) ) {
2016-05-26 18:01:51 +03:00
virTestDifference ( stderr , paths [ i ] . datastoreName , datastoreName ) ;
2009-09-23 16:52:36 +04:00
goto failure ;
}
2010-08-25 13:44:57 +04:00
if ( STRNEQ ( paths [ i ] . directoryName , directoryName ) ) {
2016-05-26 18:01:51 +03:00
virTestDifference ( stderr , paths [ i ] . directoryName , directoryName ) ;
2009-09-23 16:52:36 +04:00
goto failure ;
}
2010-08-25 13:44:57 +04:00
if ( STRNEQ ( paths [ i ] . directoryAndFileName , directoryAndFileName ) ) {
2016-05-26 18:01:51 +03:00
virTestDifference ( stderr , paths [ i ] . directoryAndFileName ,
directoryAndFileName ) ;
2009-09-23 16:52:36 +04:00
goto failure ;
}
}
2014-03-25 10:53:44 +04:00
cleanup :
2009-09-23 16:52:36 +04:00
VIR_FREE ( datastoreName ) ;
VIR_FREE ( directoryName ) ;
2010-08-25 13:44:57 +04:00
VIR_FREE ( directoryAndFileName ) ;
2009-09-23 16:52:36 +04:00
return result ;
2014-03-25 10:53:44 +04:00
failure :
2009-09-23 16:52:36 +04:00
result = - 1 ;
goto cleanup ;
}
2010-04-07 13:23:53 +04:00
struct testDateTime {
const char * dateTime ;
2011-05-13 09:07:13 +04:00
long long calendarTime ;
2010-04-07 13:23:53 +04:00
} ;
static struct testDateTime times [ ] = {
/* different timezones */
{ " 2010-04-08T05:45:11-07:00 " , 1270730711 } ,
{ " 2010-04-08T07:45:11-05:00 " , 1270730711 } ,
{ " 2010-04-08T12:45:11+00:00 " , 1270730711 } ,
{ " 2010-04-08T14:45:11+02:00 " , 1270730711 } ,
{ " 2010-04-08T22:15:11+09:30 " , 1270730711 } ,
{ " 2010-04-09T01:30:11+12:45 " , 1270730711 } ,
/* optional parts */
{ " 2010-04-08T12:45:11Z " , 1270730711 } ,
{ " 2010-04-08T12:45:11 " , 1270730711 } ,
{ " -2010-04-08T14:45:11+02:00 " , 0 } ,
{ " 2010-04-08T14:45:11.529576+02:00 " , 1270730711 } ,
/* borders */
{ " 1970-01-01T00:00:00+00:00 " , 0 } ,
{ " 2038-01-19T03:14:07+00:00 " , 2147483647 } ,
/* random */
{ " 1999-08-02T01:19:55+02:00 " , 933549595 } ,
{ " 2004-03-07T23:23:55+02:00 " , 1078694635 } ,
{ " 1984-10-27T14:33:45+02:00 " , 467728425 } ,
{ " 1970-01-12T16:11:04+02:00 " , 1001464 } ,
{ " 2014-07-20T13:35:38+02:00 " , 1405856138 } ,
{ " 2032-06-24T17:04:49+02:00 " , 1971702289 } ,
} ;
static int
2019-10-14 15:45:03 +03:00
testConvertDateTimeToCalendarTime ( const void * data G_GNUC_UNUSED )
2010-04-07 13:23:53 +04:00
{
Convert 'int i' to 'size_t i' in tests/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 18:09:33 +04:00
size_t i ;
2010-04-07 13:23:53 +04:00
esxVI_DateTime dateTime ;
2011-05-13 09:07:13 +04:00
long long calendarTime ;
2010-04-07 13:23:53 +04:00
2019-10-15 14:55:26 +03:00
for ( i = 0 ; i < G_N_ELEMENTS ( times ) ; + + i ) {
2010-04-07 13:23:53 +04:00
dateTime . value = ( char * ) times [ i ] . dateTime ;
if ( esxVI_DateTime_ConvertToCalendarTime ( & dateTime ,
& calendarTime ) < 0 ) {
return - 1 ;
}
2014-11-13 17:20:43 +03:00
if ( times [ i ] . calendarTime ! = calendarTime )
2010-04-07 13:23:53 +04:00
return - 1 ;
}
return 0 ;
}
2010-10-12 21:37:39 +04:00
struct testDatastoreItem {
const char * string ;
const char * escaped ;
} ;
static struct testDatastoreItem datastoreItems [ ] = {
{ " normal " , " normal " } ,
{ /* "Aä1ö2ü3ß4#5~6!7§8/9%Z" */
" A \303 \244 1 \303 \266 2 \303 \274 3 \303 \237 4#5~6!7 \302 \247 8/9%Z " ,
" A+w6Q-1+w7Y-2+w7w-3+w58-4+Iw-5+fg-6+IQ-7+wqc-8+JQ-2f9+JQ-25Z " } ,
{ /* "Z~6!7§8/9%0#1\"2'3`4&A" */ " Z~6!7 \302 \247 8/9%0#1 \" 2'3`4&A " ,
" Z+fg-6+IQ-7+wqc-8+JQ-2f9+JQ-250+Iw-1_2'3+YA-4+Jg-A " } ,
{ /* "標準語" */ " \346 \250 \231 \346 \272 \226 \350 \252 \236 " , " +5qiZ5rqW6Kqe " } ,
{ " ! \" #$%&'()*+,-./0123456789:;<=>? " ,
" +IQ-_+IyQl-25+Jg-'()_+Kw-,-.+JQ-2f0123456789_+Ow-_+PQ-__ " } ,
{ " A Z[ \\ ]^_B " , " A Z+WyU-5c+XV4-_B " } ,
{ " A`B@{|}~DEL " , " A+YA-B+QHs-_+fX4-DEL " } ,
{ /* "hÀÁÂÃÄÅH" */ " h \303 \200 \303 \201 \303 \202 \303 \203 \303 \204 \303 \205 H " ,
" h+w4DDgcOCw4PDhMOF-H " } ,
{ /* "A쿀Z" */ " A \354 \277 \200 Z " , " A+7L+A-Z " } ,
{ /* "!쿀A" */ " ! \354 \277 \200 A " , " +Iey,gA-A " } ,
{ " ~~~ " , " +fn5+ " } ,
{ " ~~~A " , " +fn5+-A " } ,
{ " K%U/H \\ Z " , " K+JQ-25U+JQ-2fH+JQ-5cZ " } ,
{ " vvv<A \" B \" C>zzz " , " vvv_A_B_C_zzz " } ,
} ;
static int
2019-10-14 15:45:03 +03:00
testEscapeDatastoreItem ( const void * data G_GNUC_UNUSED )
2010-10-12 21:37:39 +04:00
{
Convert 'int i' to 'size_t i' in tests/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 18:09:33 +04:00
size_t i ;
2010-10-12 21:37:39 +04:00
char * escaped = NULL ;
2019-10-15 14:55:26 +03:00
for ( i = 0 ; i < G_N_ELEMENTS ( datastoreItems ) ; + + i ) {
2010-10-12 21:37:39 +04:00
VIR_FREE ( escaped ) ;
escaped = esxUtil_EscapeDatastoreItem ( datastoreItems [ i ] . string ) ;
2014-11-13 17:20:43 +03:00
if ( escaped = = NULL )
2010-10-12 21:37:39 +04:00
return - 1 ;
if ( STRNEQ ( datastoreItems [ i ] . escaped , escaped ) ) {
VIR_FREE ( escaped ) ;
return - 1 ;
}
}
2011-04-25 02:25:10 +04:00
VIR_FREE ( escaped ) ;
2010-10-12 21:37:39 +04:00
return 0 ;
}
2010-10-15 19:50:23 +04:00
struct testWindows1252ToUTF8 {
const char * windows1252 ;
const char * utf8 ;
} ;
static struct testWindows1252ToUTF8 windows1252ToUTF8 [ ] = {
{ " normal " , " normal " } ,
{ /* "A€Z" */ " A \200 Z " , " A \342 \202 \254 Z " } ,
{ /* "Aä1ö2ü3ß4#5~6!7§8/9%Z" */ " A \344 1 \366 2 \374 3 \337 4#5~6!7 \247 8/9%Z " ,
" A \303 \244 1 \303 \266 2 \303 \274 3 \303 \237 4#5~6!7 \302 \247 8/9%Z " } ,
{ /* "hÀÁÂÃÄÅH" */ " h \300 \301 \302 \303 \304 \305 H " ,
" h \303 \200 \303 \201 \303 \202 \303 \203 \303 \204 \303 \205 H " } ,
} ;
static int
2019-10-14 15:45:03 +03:00
testConvertWindows1252ToUTF8 ( const void * data G_GNUC_UNUSED )
2010-10-15 19:50:23 +04:00
{
Convert 'int i' to 'size_t i' in tests/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 18:09:33 +04:00
size_t i ;
2010-10-15 19:50:23 +04:00
char * utf8 = NULL ;
2019-10-15 14:55:26 +03:00
for ( i = 0 ; i < G_N_ELEMENTS ( windows1252ToUTF8 ) ; + + i ) {
2010-10-15 19:50:23 +04:00
VIR_FREE ( utf8 ) ;
2010-12-22 00:39:55 +03:00
utf8 = virVMXConvertToUTF8 ( " Windows-1252 " ,
windows1252ToUTF8 [ i ] . windows1252 ) ;
2010-10-15 19:50:23 +04:00
2014-11-13 17:20:43 +03:00
if ( utf8 = = NULL )
2010-10-15 19:50:23 +04:00
return - 1 ;
if ( STRNEQ ( windows1252ToUTF8 [ i ] . utf8 , utf8 ) ) {
VIR_FREE ( utf8 ) ;
return - 1 ;
}
}
2011-04-25 02:25:10 +04:00
VIR_FREE ( utf8 ) ;
2010-10-15 19:50:23 +04:00
return 0 ;
}
2009-09-23 16:25:52 +04:00
static int
2011-04-29 20:21:20 +04:00
mymain ( void )
2009-09-23 16:25:52 +04:00
{
int result = 0 ;
2016-05-26 18:02:00 +03:00
virTestQuiesceLibvirtErrors ( true ) ;
2009-09-23 16:52:36 +04:00
2017-11-03 15:09:47 +03:00
# define DO_TEST(_name) \
do { \
if ( virTestRun ( " VMware " # _name , test # # _name , \
NULL ) < 0 ) { \
result = - 1 ; \
} \
2009-09-23 16:52:36 +04:00
} while ( 0 )
2010-08-01 21:53:00 +04:00
DO_TEST ( ParseDatastorePath ) ;
2010-04-07 13:23:53 +04:00
DO_TEST ( ConvertDateTimeToCalendarTime ) ;
2010-10-12 21:37:39 +04:00
DO_TEST ( EscapeDatastoreItem ) ;
2010-10-15 19:50:23 +04:00
DO_TEST ( ConvertWindows1252ToUTF8 ) ;
2009-09-23 16:25:52 +04:00
return result = = 0 ? EXIT_SUCCESS : EXIT_FAILURE ;
}
2017-03-29 17:45:42 +03:00
VIR_TEST_MAIN ( mymain )
2009-09-23 16:25:52 +04:00
# else
2011-07-09 03:24:44 +04:00
int main ( void )
2009-09-23 16:25:52 +04:00
{
2011-07-09 03:24:44 +04:00
return EXIT_AM_SKIP ;
2009-09-23 16:25:52 +04:00
}
# endif /* WITH_ESX */