2019-02-07 20:07:16 +03:00
/*
* Copyright ( C ) Red Hat , Inc . 2019
*
* This library is free software ; you can redistribute it and / or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation ; either
* version 2.1 of the License , or ( at your option ) any later version .
*
* This library is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the GNU
* Lesser General Public License for more details .
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library . If not , see
* < http : //www.gnu.org/licenses/>.
*/
# include <config.h>
# include "testutils.h"
# include "storage_conf.h"
# include "storage_capabilities.h"
# define VIR_FROM_THIS VIR_FROM_NONE
struct test_virStoragePoolCapsFormatData {
const char * filename ;
2021-03-11 10:16:13 +03:00
virCaps * driverCaps ;
2019-02-07 20:07:16 +03:00
} ;
static void
2021-03-11 10:16:13 +03:00
test_virCapabilitiesAddFullStoragePool ( virCaps * caps )
2019-02-07 20:07:16 +03:00
{
size_t i ;
for ( i = 0 ; i < VIR_STORAGE_POOL_LAST ; i + + )
virCapabilitiesAddStoragePool ( caps , i ) ;
}
static void
2021-03-11 10:16:13 +03:00
test_virCapabilitiesAddFSStoragePool ( virCaps * caps )
2019-02-07 20:07:16 +03:00
{
virCapabilitiesAddStoragePool ( caps , VIR_STORAGE_POOL_FS ) ;
}
static int
test_virStoragePoolCapsFormat ( const void * opaque )
{
struct test_virStoragePoolCapsFormatData * data =
( struct test_virStoragePoolCapsFormatData * ) opaque ;
2021-03-11 10:16:13 +03:00
virCaps * driverCaps = data - > driverCaps ;
2019-10-15 15:47:50 +03:00
g_autoptr ( virStoragePoolCaps ) poolCaps = NULL ;
2019-10-15 16:16:31 +03:00
g_autofree char * path = NULL ;
g_autofree char * poolCapsXML = NULL ;
2019-02-07 20:07:16 +03:00
if ( ! ( poolCaps = virStoragePoolCapsNew ( driverCaps ) ) )
2019-03-07 14:12:11 +03:00
return - 1 ;
2019-02-07 20:07:16 +03:00
2019-10-22 16:26:14 +03:00
path = g_strdup_printf ( " %s/storagepoolcapsschemadata/poolcaps-%s.xml " ,
abs_srcdir , data - > filename ) ;
2019-02-07 20:07:16 +03:00
if ( ! ( poolCapsXML = virStoragePoolCapsFormat ( poolCaps ) ) )
2019-03-07 14:12:11 +03:00
return - 1 ;
2019-02-07 20:07:16 +03:00
2019-03-06 21:02:08 +03:00
if ( virTestCompareToFile ( poolCapsXML , path ) < 0 )
2019-03-07 14:12:11 +03:00
return - 1 ;
2019-02-07 20:07:16 +03:00
2019-03-07 14:12:11 +03:00
return 0 ;
2019-02-07 20:07:16 +03:00
}
static int
mymain ( void )
{
2019-03-06 21:14:16 +03:00
int ret = 0 ;
2019-10-15 15:47:50 +03:00
g_autoptr ( virCaps ) fullCaps = NULL ;
g_autoptr ( virCaps ) fsCaps = NULL ;
2019-02-07 20:07:16 +03:00
# define DO_TEST(Filename, DriverCaps) \
do { \
struct test_virStoragePoolCapsFormatData data = \
{ . filename = Filename , . driverCaps = DriverCaps } ; \
if ( virTestRun ( Filename , test_virStoragePoolCapsFormat , & data ) < 0 ) \
2019-03-06 21:14:16 +03:00
ret = - 1 ; \
2019-02-07 20:07:16 +03:00
} while ( 0 )
if ( ! ( fullCaps = virCapabilitiesNew ( VIR_ARCH_NONE , false , false ) ) | |
2019-03-06 21:14:16 +03:00
! ( fsCaps = virCapabilitiesNew ( VIR_ARCH_NONE , false , false ) ) ) {
2019-03-07 14:12:11 +03:00
return - 1 ;
2019-03-06 21:14:16 +03:00
}
2019-02-07 20:07:16 +03:00
test_virCapabilitiesAddFullStoragePool ( fullCaps ) ;
test_virCapabilitiesAddFSStoragePool ( fsCaps ) ;
DO_TEST ( " full " , fullCaps ) ;
DO_TEST ( " fs " , fsCaps ) ;
2021-05-16 19:14:53 +03:00
return ret = = 0 ? EXIT_SUCCESS : EXIT_FAILURE ;
2019-02-07 20:07:16 +03:00
}
VIR_TEST_MAIN ( mymain )