os/ossrv/glib/tsrc/BC/inc/mrt2_glib2_test.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
     3 *
     4 * This library is free software; you can redistribute it and/or
     5 * modify it under the terms of the GNU Lesser General Public
     6 * License as published by the Free Software Foundation; either
     7 * version 2 of the License, or (at your option) any later version.
     8 *
     9 * This library is distributed in the hope that it will be useful,
    10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
    11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    12 * Lesser General Public License for more details.
    13 *
    14 * You should have received a copy of the GNU Lesser General Public
    15 * License along with this library; if not, write to the
    16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    17 * Boston, MA 02111-1307, USA.
    18 *
    19 * Description:
    20 *
    21 */
    22 
    23 
    24 
    25 #ifndef __G_LOG_MRT2_GLIB2_TEST
    26 #define __G_LOG_MRT2_GLIB2_TEST
    27 #include <stdio.h>
    28 #include <time.h>
    29 #include <string.h>
    30 #include <dirent.h>
    31 #include <sys/stat.h>
    32 
    33 gboolean assert_failed = FALSE;
    34 
    35 #undef g_assert
    36 #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
    37 
    38 	
    39 void mrtLogHandler(const gchar* log_domain, GLogLevelFlags log_level,
    40 					const gchar* message, gpointer user_data)
    41 {
    42 	FILE *fp;
    43 	fp = fopen("c:\\logtests.txt","a");
    44 	
    45 	if(fp)
    46 	{
    47 		fprintf(fp,message);
    48 		fprintf(fp,"\n");
    49 		fclose(fp);
    50 	}
    51 }
    52 
    53 void mrtPrintHandler(const gchar *message)
    54 {
    55 	FILE *fp;
    56 	fp = fopen("c:\\logtests.txt","a");
    57 	
    58 	if(fp)
    59 	{
    60 		fprintf(fp,message);
    61 		fprintf(fp,"\n");
    62 		fclose(fp);
    63 	}
    64 }
    65 
    66 
    67 // This function is used to generate the xml file used bt ATS
    68 void testResultXml(char *filename)
    69 {
    70 	char time_buf[50];
    71 	
    72 	char result[10];
    73 	
    74 	char xmlfilename[256];
    75 		
    76 	time_t t = time(NULL);
    77 	
    78 	struct tm *tm1 = localtime(&t);
    79 	
    80 	char *atsinitmsg 	= 	"<test-report>\n\t<test-batch>";
    81 	
    82 	char *atsbatchinit1	=   \
    83 							"\n\t\t<batch-init>\
    84 							\n\t\t\t<description></description>\
    85 							\n\t\t\t<date>";						
    86 							
    87 	char *atsbatchinit2 =	"</date>\
    88 							\n\t\t\t<factory>NA</factory>\
    89 							\n\t\t\t<component>\
    90 							\n\t\t\t\t<name>NA</name>\
    91 							\n\t\t\t\t<version>NA</version>\
    92 							\n\t\t\t</component>\
    93 							\n\t\t</batch-init>";
    94 							
    95 	char *atsbatchresult=	\
    96 							"\n\t\t<batch-result>\
    97 							\n\t\t\t<run-time>00:00:00</run-time>\
    98 							\n\t\t</batch-result>";
    99 							
   100 	char *atsclosemsg	=   \
   101 							"\n\t</test-batch>\
   102 							\n</test-report>\n ";
   103 
   104 	char *atstestinit	=	"\n\t\t<test-case time-stamp=\"00:00:00\">";
   105 
   106 	
   107 	char *atscaseinit1	=	\
   108 							"\n\t\t\t<case-init>\
   109 							\n\t\t\t\t<version></version>\
   110 							\n\t\t\t\t<id>";
   111 												
   112 	char *atscaseinit2 = 	"</id>\
   113 							\n\t\t\t\t<expected-result description=\"\">0</expected-result>\
   114 							\n\t\t\t</case-init>";
   115 							
   116 	char *atscaseresult1=	\
   117 							"\n\t\t\t<case-result status=\"";
   118 							
   119 	char *atscaseresult2=	"\">\
   120 							\n\t\t\t\t<actual-result>0</actual-result>\
   121 							\n\t\t\t\t<run-time>00:00:00</run-time>\
   122 							\n\t\t\t</case-result>";
   123 
   124 	char *atstestclose	=	"\n\t\t</test-case>";
   125 	
   126 	/* Check and see if spd_logs/xml is existent or not. If not present create it */
   127 	DIR *dir;
   128 	FILE *fp;
   129 	
   130 	dir = opendir("c:\\spd_logs");
   131 	if(!dir)
   132 		mkdir("c:\\spd_logs",0777);
   133 	
   134 	dir = opendir("c:\\spd_logs\\xml");
   135 	if(!dir)
   136 		mkdir("c:\\spd_logs\\xml",0777);
   137 	
   138 	// create the xml file name
   139 	strcpy(xmlfilename,"c:/spd_logs/xml/");
   140 	strcat(xmlfilename,filename);
   141 	strcat(xmlfilename,".xml");
   142 	
   143 	strftime(time_buf,50,"%c",tm1);
   144 	
   145 	if(assert_failed )
   146 		strcpy(result,"FAILED");
   147 	else
   148 		strcpy(result,"PASSED");
   149 	
   150 	fp = fopen(xmlfilename,"w");
   151 	
   152 	if(fp)
   153 	{
   154 		fprintf(fp,"%s%s%s%s%s%s%s%s%s%s%s%s%s%s",atsinitmsg,atsbatchinit1,time_buf,atsbatchinit2,atstestinit,
   155 			atscaseinit1,filename,atscaseinit2,atscaseresult1,result,atscaseresult2,
   156 			atstestclose,atsbatchresult,atsclosemsg);
   157 			
   158 		fclose(fp);	
   159 	}
   160 	else
   161 	{
   162 		g_assert(FALSE && "Failed to create the xml file");
   163 	}
   164 }
   165 
   166 #endif