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