sl@0: /* sl@0: * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. sl@0: * sl@0: * This library is free software; you can redistribute it and/or sl@0: * modify it under the terms of the GNU Lesser General Public sl@0: * License as published by the Free Software Foundation; either sl@0: * version 2 of the License, or (at your option) any later version. sl@0: * sl@0: * This library is distributed in the hope that it will be useful, sl@0: * but WITHOUT ANY WARRANTY; without even the implied warranty of sl@0: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU sl@0: * Lesser General Public License for more details. sl@0: * sl@0: * You should have received a copy of the GNU Lesser General Public sl@0: * License along with this library; if not, write to the sl@0: * Free Software Foundation, Inc., 59 Temple Place - Suite 330, sl@0: * Boston, MA 02111-1307, USA. sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: sl@0: // This test case is part automated and part manual. On running the test case sl@0: // an output is expected on the screen. All the other APIs which are tested, sl@0: // if they fail will write in the log file. sl@0: sl@0: #undef G_DISABLE_ASSERT sl@0: #undef G_LOG_DOMAIN sl@0: sl@0: #include sl@0: #include sl@0: #include "glib.h" sl@0: sl@0: #ifdef SYMBIAN sl@0: #include "mrt2_glib2_test.h" sl@0: #endif /*SYMBIAN*/ sl@0: sl@0: void myLogHandler(const gchar *log_domain,GLogLevelFlags log_level,const gchar *message,gpointer user_data) sl@0: { sl@0: char *data = (char *)user_data; sl@0: sprintf(data,"%s",message); sl@0: } sl@0: sl@0: int main (int argc,char *argv[]) sl@0: { sl@0: gchar message[100],message1[100]; sl@0: int id = -1; sl@0: GLogFunc log_func; sl@0: sl@0: #ifdef SYMBIAN sl@0: sl@0: #endif /*SYMBIAN*/ sl@0: sl@0: log_func = g_log_set_default_handler(myLogHandler,message); sl@0: g_log(NULL,G_LOG_LEVEL_MESSAGE,"test message"); sl@0: sl@0: // checks g_log_set_default_handler. The new handler sl@0: // will put the message in the message array and the sl@0: // same is tested using the assert below. sl@0: g_assert(!strcmp(message,"test message")); sl@0: sl@0: log_func = g_log_set_default_handler(log_func,message); sl@0: sl@0: g_assert(log_func == myLogHandler); sl@0: sl@0: id = g_log_set_handler ("test domain",G_LOG_LEVEL_MESSAGE, &myLogHandler, message1); sl@0: sl@0: g_log("test domain",G_LOG_LEVEL_MESSAGE,"test message2"); sl@0: sl@0: // checks g_log_set_handler. The new handler sl@0: // will put the message in the message1 array and the sl@0: // same is tested using the assert below. sl@0: g_assert(id != -1 && !strcmp(message1,"test message2")); sl@0: sl@0: g_log_remove_handler("test domain",id); sl@0: sl@0: // This log message should print on stdout sl@0: // as the handler is removed. sl@0: g_log("test domain",G_LOG_LEVEL_MESSAGE,"test message printed \nsuccessfully\n"); sl@0: printf("Press any key to exit"); sl@0: sl@0: getchar(); sl@0: sl@0: }