glib/tsrc/glib_nonstif/src/log_test.c
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // This test case is part automated and part manual. On running the test case 
       
    22 // an output is expected on the screen. All the other APIs which are tested, 
       
    23 // if they fail will write in the log file.
       
    24 
       
    25 #undef G_DISABLE_ASSERT
       
    26 #undef G_LOG_DOMAIN
       
    27 
       
    28 #include <stdio.h>
       
    29 #include <string.h>
       
    30 #include "glib.h"
       
    31 
       
    32 #ifdef __SYMBIAN32__
       
    33 #include "mrt2_glib2_test.h"
       
    34 #endif /*__SYMBIAN32__*/
       
    35 
       
    36 void myLogHandler(const gchar *log_domain,GLogLevelFlags log_level,const gchar *message,gpointer user_data)
       
    37 {
       
    38 	char *data = (char *)user_data;
       
    39 	sprintf(data,"%s",message);
       
    40 }
       
    41 
       
    42 int main (int argc,char *argv[])
       
    43 {
       
    44 	gchar message[100],message1[100];
       
    45 	int id = -1;
       
    46 	GLogFunc log_func;
       
    47 	
       
    48 	#ifdef __SYMBIAN32__
       
    49 
       
    50 	#endif /*__SYMBIAN32__*/
       
    51 	
       
    52 	log_func = g_log_set_default_handler(myLogHandler,message);
       
    53 	g_log(NULL,G_LOG_LEVEL_MESSAGE,"test message");
       
    54 	
       
    55 	// checks g_log_set_default_handler. The new handler
       
    56 	// will put the message in the message array and the 
       
    57 	// same is tested using the assert below.
       
    58 	g_assert(!strcmp(message,"test message"));
       
    59 	
       
    60 	log_func = g_log_set_default_handler(log_func,message);
       
    61 	
       
    62 	g_assert(log_func == myLogHandler);
       
    63 	
       
    64 	id = g_log_set_handler ("test domain",G_LOG_LEVEL_MESSAGE, &myLogHandler, message1);
       
    65 	
       
    66 	g_log("test domain",G_LOG_LEVEL_MESSAGE,"test message2");
       
    67 	
       
    68 	// checks g_log_set_handler. The new handler
       
    69 	// will put the message in the message1 array and the 
       
    70 	// same is tested using the assert below.
       
    71 	g_assert(id != -1 && !strcmp(message1,"test message2"));
       
    72 	
       
    73 	g_log_remove_handler("test domain",id);
       
    74 	
       
    75 	// This log message should print on stdout
       
    76 	// as the handler is removed.
       
    77 	g_log("test domain",G_LOG_LEVEL_MESSAGE,"test message printed \nsuccessfully\n");
       
    78 	printf("Press any key to exit");
       
    79 	
       
    80 	getchar();
       
    81 	
       
    82 }