2017-09-21 22:26:06 +03:00
/*
2015-03-06 13:38:13 +03:00
* Copyright ( C ) 2015 Red Hat , Inc .
*
2018-01-30 22:26:26 +03:00
* SPDX - License - Identifier : LGPL - 2.0 +
*
2015-03-06 13:38:13 +03:00
* 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 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
2021-12-07 04:20:55 +03:00
* License along with this library . If not , see < https : //www.gnu.org/licenses/>.
2015-03-06 13:38:13 +03:00
*/
# include "config.h"
2023-05-01 21:24:29 +03:00
# include "libglnx.h"
2015-03-06 13:38:13 +03:00
# include "ostree-mutable-tree.h"
2023-05-01 21:24:29 +03:00
# include "ot-opt-utils.h"
# include <gio/gio.h>
2015-03-06 13:38:13 +03:00
# include <glib.h>
# include <stdlib.h>
# include <string.h>
static GString * printerr_str = NULL ;
static void
util_usage_error_printerr ( const gchar * string )
{
if ( printerr_str = = NULL )
printerr_str = g_string_new ( NULL ) ;
g_string_append ( printerr_str , string ) ;
}
static void
test_ot_util_usage_error ( void )
{
2023-05-01 21:24:29 +03:00
g_autoptr ( GError ) error = NULL ;
g_autoptr ( GOptionContext ) context = g_option_context_new ( " [TEST] " ) ;
2015-03-06 13:38:13 +03:00
GPrintFunc old_printerr = g_set_printerr_handler ( util_usage_error_printerr ) ;
ot_util_usage_error ( context , " find_me " , & error ) ;
g_assert_nonnull ( strstr ( printerr_str - > str , " [TEST] " ) ) ;
g_assert_nonnull ( strstr ( error - > message , " find_me " ) ) ;
2016-12-02 21:45:04 +03:00
g_clear_error ( & error ) ;
2015-03-06 13:38:13 +03:00
g_set_printerr_handler ( old_printerr ) ;
g_string_free ( printerr_str , TRUE ) ;
printerr_str = NULL ;
}
2023-05-01 21:24:29 +03:00
int
main ( int argc , char * * argv )
2015-03-06 13:38:13 +03:00
{
g_test_init ( & argc , & argv , NULL ) ;
g_test_add_func ( " /ot-opt-utils/ot-util-usage-error " , test_ot_util_usage_error ) ;
2023-05-01 21:24:29 +03:00
return g_test_run ( ) ;
2015-03-06 13:38:13 +03:00
}