os/ossrv/glib/tsrc/BC/src/log_test.c
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
     3 *
     4 * This library is free software; you can redistribute it and/or
     5 * modify it under the terms of the GNU Lesser General Public
     6 * License as published by the Free Software Foundation; either
     7 * version 2 of the License, or (at your option) any later version.
     8 *
     9 * This library is distributed in the hope that it will be useful,
    10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
    11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    12 * Lesser General Public License for more details.
    13 *
    14 * You should have received a copy of the GNU Lesser General Public
    15 * License along with this library; if not, write to the
    16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    17 * Boston, MA 02111-1307, USA.
    18 *
    19 * Description:
    20 *
    21 */
    22 
    23 
    24 
    25 // This test case is part automated and part manual. On running the test case 
    26 // an output is expected on the screen. All the other APIs which are tested, 
    27 // if they fail will write in the log file.
    28 
    29 #undef G_DISABLE_ASSERT
    30 #undef G_LOG_DOMAIN
    31 
    32 #include <stdio.h>
    33 #include <string.h>
    34 #include "glib.h"
    35 
    36 #ifdef SYMBIAN
    37 #include "mrt2_glib2_test.h"
    38 #endif /*SYMBIAN*/
    39 
    40 void myLogHandler(const gchar *log_domain,GLogLevelFlags log_level,const gchar *message,gpointer user_data)
    41 {
    42 	char *data = (char *)user_data;
    43 	sprintf(data,"%s",message);
    44 }
    45 
    46 int main (int argc,char *argv[])
    47 {
    48 	gchar message[100],message1[100];
    49 	int id = -1;
    50 	GLogFunc log_func;
    51 	
    52 	#ifdef SYMBIAN
    53 
    54 	#endif /*SYMBIAN*/
    55 	
    56 	log_func = g_log_set_default_handler(myLogHandler,message);
    57 	g_log(NULL,G_LOG_LEVEL_MESSAGE,"test message");
    58 	
    59 	// checks g_log_set_default_handler. The new handler
    60 	// will put the message in the message array and the 
    61 	// same is tested using the assert below.
    62 	g_assert(!strcmp(message,"test message"));
    63 	
    64 	log_func = g_log_set_default_handler(log_func,message);
    65 	
    66 	g_assert(log_func == myLogHandler);
    67 	
    68 	id = g_log_set_handler ("test domain",G_LOG_LEVEL_MESSAGE, &myLogHandler, message1);
    69 	
    70 	g_log("test domain",G_LOG_LEVEL_MESSAGE,"test message2");
    71 	
    72 	// checks g_log_set_handler. The new handler
    73 	// will put the message in the message1 array and the 
    74 	// same is tested using the assert below.
    75 	g_assert(id != -1 && !strcmp(message1,"test message2"));
    76 	
    77 	g_log_remove_handler("test domain",id);
    78 	
    79 	// This log message should print on stdout
    80 	// as the handler is removed.
    81 	g_log("test domain",G_LOG_LEVEL_MESSAGE,"test message printed \nsuccessfully\n");
    82 	printf("Press any key to exit");
    83 	
    84 	getchar();
    85 	
    86 }