1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/glib/tsrc/BC/inc/mrt2_glib2_test.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,166 @@
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 +#ifndef __G_LOG_MRT2_GLIB2_TEST
1.29 +#define __G_LOG_MRT2_GLIB2_TEST
1.30 +#include <stdio.h>
1.31 +#include <time.h>
1.32 +#include <string.h>
1.33 +#include <dirent.h>
1.34 +#include <sys/stat.h>
1.35 +
1.36 +gboolean assert_failed = FALSE;
1.37 +
1.38 +#undef g_assert
1.39 +#define g_assert(expr) G_STMT_START{ if (expr) { } else {g_log (G_LOG_DOMAIN,G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG, "file %s: line %d: assertion failed: (%s)", __FILE__, __LINE__, #expr);assert_failed = TRUE; }}G_STMT_END
1.40 +
1.41 +
1.42 +void mrtLogHandler(const gchar* log_domain, GLogLevelFlags log_level,
1.43 + const gchar* message, gpointer user_data)
1.44 +{
1.45 + FILE *fp;
1.46 + fp = fopen("c:\\logtests.txt","a");
1.47 +
1.48 + if(fp)
1.49 + {
1.50 + fprintf(fp,message);
1.51 + fprintf(fp,"\n");
1.52 + fclose(fp);
1.53 + }
1.54 +}
1.55 +
1.56 +void mrtPrintHandler(const gchar *message)
1.57 +{
1.58 + FILE *fp;
1.59 + fp = fopen("c:\\logtests.txt","a");
1.60 +
1.61 + if(fp)
1.62 + {
1.63 + fprintf(fp,message);
1.64 + fprintf(fp,"\n");
1.65 + fclose(fp);
1.66 + }
1.67 +}
1.68 +
1.69 +
1.70 +// This function is used to generate the xml file used bt ATS
1.71 +void testResultXml(char *filename)
1.72 +{
1.73 + char time_buf[50];
1.74 +
1.75 + char result[10];
1.76 +
1.77 + char xmlfilename[256];
1.78 +
1.79 + time_t t = time(NULL);
1.80 +
1.81 + struct tm *tm1 = localtime(&t);
1.82 +
1.83 + char *atsinitmsg = "<test-report>\n\t<test-batch>";
1.84 +
1.85 + char *atsbatchinit1 = \
1.86 + "\n\t\t<batch-init>\
1.87 + \n\t\t\t<description></description>\
1.88 + \n\t\t\t<date>";
1.89 +
1.90 + char *atsbatchinit2 = "</date>\
1.91 + \n\t\t\t<factory>NA</factory>\
1.92 + \n\t\t\t<component>\
1.93 + \n\t\t\t\t<name>NA</name>\
1.94 + \n\t\t\t\t<version>NA</version>\
1.95 + \n\t\t\t</component>\
1.96 + \n\t\t</batch-init>";
1.97 +
1.98 + char *atsbatchresult= \
1.99 + "\n\t\t<batch-result>\
1.100 + \n\t\t\t<run-time>00:00:00</run-time>\
1.101 + \n\t\t</batch-result>";
1.102 +
1.103 + char *atsclosemsg = \
1.104 + "\n\t</test-batch>\
1.105 + \n</test-report>\n ";
1.106 +
1.107 + char *atstestinit = "\n\t\t<test-case time-stamp=\"00:00:00\">";
1.108 +
1.109 +
1.110 + char *atscaseinit1 = \
1.111 + "\n\t\t\t<case-init>\
1.112 + \n\t\t\t\t<version></version>\
1.113 + \n\t\t\t\t<id>";
1.114 +
1.115 + char *atscaseinit2 = "</id>\
1.116 + \n\t\t\t\t<expected-result description=\"\">0</expected-result>\
1.117 + \n\t\t\t</case-init>";
1.118 +
1.119 + char *atscaseresult1= \
1.120 + "\n\t\t\t<case-result status=\"";
1.121 +
1.122 + char *atscaseresult2= "\">\
1.123 + \n\t\t\t\t<actual-result>0</actual-result>\
1.124 + \n\t\t\t\t<run-time>00:00:00</run-time>\
1.125 + \n\t\t\t</case-result>";
1.126 +
1.127 + char *atstestclose = "\n\t\t</test-case>";
1.128 +
1.129 + /* Check and see if spd_logs/xml is existent or not. If not present create it */
1.130 + DIR *dir;
1.131 + FILE *fp;
1.132 +
1.133 + dir = opendir("c:\\spd_logs");
1.134 + if(!dir)
1.135 + mkdir("c:\\spd_logs",0777);
1.136 +
1.137 + dir = opendir("c:\\spd_logs\\xml");
1.138 + if(!dir)
1.139 + mkdir("c:\\spd_logs\\xml",0777);
1.140 +
1.141 + // create the xml file name
1.142 + strcpy(xmlfilename,"c:/spd_logs/xml/");
1.143 + strcat(xmlfilename,filename);
1.144 + strcat(xmlfilename,".xml");
1.145 +
1.146 + strftime(time_buf,50,"%c",tm1);
1.147 +
1.148 + if(assert_failed )
1.149 + strcpy(result,"FAILED");
1.150 + else
1.151 + strcpy(result,"PASSED");
1.152 +
1.153 + fp = fopen(xmlfilename,"w");
1.154 +
1.155 + if(fp)
1.156 + {
1.157 + fprintf(fp,"%s%s%s%s%s%s%s%s%s%s%s%s%s%s",atsinitmsg,atsbatchinit1,time_buf,atsbatchinit2,atstestinit,
1.158 + atscaseinit1,filename,atscaseinit2,atscaseresult1,result,atscaseresult2,
1.159 + atstestclose,atsbatchresult,atsclosemsg);
1.160 +
1.161 + fclose(fp);
1.162 + }
1.163 + else
1.164 + {
1.165 + g_assert(FALSE && "Failed to create the xml file");
1.166 + }
1.167 +}
1.168 +
1.169 +#endif