1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/glib/tsrc/BC/src/log_test.c Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,86 @@
1.4 +/*
1.5 +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
1.6 +*
1.7 +* This library is free software; you can redistribute it and/or
1.8 +* modify it under the terms of the GNU Lesser General Public
1.9 +* License as published by the Free Software Foundation; either
1.10 +* version 2 of the License, or (at your option) any later version.
1.11 +*
1.12 +* This library is distributed in the hope that it will be useful,
1.13 +* but WITHOUT ANY WARRANTY; without even the implied warranty of
1.14 +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1.15 +* Lesser General Public License for more details.
1.16 +*
1.17 +* You should have received a copy of the GNU Lesser General Public
1.18 +* License along with this library; if not, write to the
1.19 +* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
1.20 +* Boston, MA 02111-1307, USA.
1.21 +*
1.22 +* Description:
1.23 +*
1.24 +*/
1.25 +
1.26 +
1.27 +
1.28 +// This test case is part automated and part manual. On running the test case
1.29 +// an output is expected on the screen. All the other APIs which are tested,
1.30 +// if they fail will write in the log file.
1.31 +
1.32 +#undef G_DISABLE_ASSERT
1.33 +#undef G_LOG_DOMAIN
1.34 +
1.35 +#include <stdio.h>
1.36 +#include <string.h>
1.37 +#include "glib.h"
1.38 +
1.39 +#ifdef SYMBIAN
1.40 +#include "mrt2_glib2_test.h"
1.41 +#endif /*SYMBIAN*/
1.42 +
1.43 +void myLogHandler(const gchar *log_domain,GLogLevelFlags log_level,const gchar *message,gpointer user_data)
1.44 +{
1.45 + char *data = (char *)user_data;
1.46 + sprintf(data,"%s",message);
1.47 +}
1.48 +
1.49 +int main (int argc,char *argv[])
1.50 +{
1.51 + gchar message[100],message1[100];
1.52 + int id = -1;
1.53 + GLogFunc log_func;
1.54 +
1.55 + #ifdef SYMBIAN
1.56 +
1.57 + #endif /*SYMBIAN*/
1.58 +
1.59 + log_func = g_log_set_default_handler(myLogHandler,message);
1.60 + g_log(NULL,G_LOG_LEVEL_MESSAGE,"test message");
1.61 +
1.62 + // checks g_log_set_default_handler. The new handler
1.63 + // will put the message in the message array and the
1.64 + // same is tested using the assert below.
1.65 + g_assert(!strcmp(message,"test message"));
1.66 +
1.67 + log_func = g_log_set_default_handler(log_func,message);
1.68 +
1.69 + g_assert(log_func == myLogHandler);
1.70 +
1.71 + id = g_log_set_handler ("test domain",G_LOG_LEVEL_MESSAGE, &myLogHandler, message1);
1.72 +
1.73 + g_log("test domain",G_LOG_LEVEL_MESSAGE,"test message2");
1.74 +
1.75 + // checks g_log_set_handler. The new handler
1.76 + // will put the message in the message1 array and the
1.77 + // same is tested using the assert below.
1.78 + g_assert(id != -1 && !strcmp(message1,"test message2"));
1.79 +
1.80 + g_log_remove_handler("test domain",id);
1.81 +
1.82 + // This log message should print on stdout
1.83 + // as the handler is removed.
1.84 + g_log("test domain",G_LOG_LEVEL_MESSAGE,"test message printed \nsuccessfully\n");
1.85 + printf("Press any key to exit");
1.86 +
1.87 + getchar();
1.88 +
1.89 +}
1.90 \ No newline at end of file