os/ossrv/utilitylibraries/libutils/tsrc/inc/std_log_result.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/utilitylibraries/libutils/tsrc/inc/std_log_result.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,165 @@
     1.4 +/*
     1.5 +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description:
    1.18 +*
    1.19 +*/
    1.20 +/*This material, including documentation and any related
    1.21 + :*  computer programs, is protected by copyright controlled by
    1.22 + *  Nokia Corporation. All rights are reserved. Copying,
    1.23 + *  including reproducing, storing, adapting or translating, any
    1.24 + *  or all of this material requires the prior written consent of
    1.25 + *  Nokia Corporation. This material also contains confidential
    1.26 + *  information which may not be disclosed to others without the
    1.27 + *  prior written consent of Nokia Corporation.
    1.28 + * ============================================================================
    1.29 + */
    1.30 +
    1.31 +
    1.32 +#ifndef _STD_LOG_FILE_H__
    1.33 +#define _STD_LOG_FILE_H__
    1.34 +
    1.35 +#include <stdio.h>
    1.36 +#include <time.h>
    1.37 +#include <string.h>
    1.38 +#include <stdarg.h>
    1.39 +#ifdef __SYMBIAN32__
    1.40 +#define LOG_FILE "c:\\logs\\std_test_log.txt"
    1.41 +#define LOG_DIR "c:\\logs\\"
    1.42 +#define LOG_FILE_EXT "xml"
    1.43 +bool assert_failed = false;
    1.44 +#else
    1.45 +#define LOG_DIR ""
    1.46 +#define LOG_FILE_EXT "xml"
    1.47 +#define LOG_FILE "std_test_log.txt"
    1.48 +bool assert_failed = false;
    1.49 +#endif
    1.50 +FILE *fp;
    1.51 +
    1.52 +bool gnutest = true;
    1.53 +
    1.54 +# define VERIFY(fn) gnutest &= (fn)
    1.55 +
    1.56 +
    1.57 +void std_log(const char *filename,const int lineno,const char* aformat,...)
    1.58 +{
    1.59 +	if(fp==NULL)
    1.60 +	{
    1.61 +		fp = fopen(LOG_FILE,"a");
    1.62 +	}
    1.63 +	va_list va;
    1.64 +	va_start(va,aformat);    
    1.65 +    {
    1.66 +		fprintf(fp,"%s - [%d] : ",filename,lineno);
    1.67 +		vfprintf(fp,aformat,va);
    1.68 +		fprintf(fp,"\n");
    1.69 +	}
    1.70 +	va_end(va);
    1.71 +}
    1.72 +
    1.73 +
    1.74 +void init_log_file()
    1.75 +{
    1.76 +	if(fp == NULL)
    1.77 +	{
    1.78 +		fp = fopen(LOG_FILE, "a");
    1.79 +	}
    1.80 +}
    1.81 +
    1.82 +void close_log_file()
    1.83 +{
    1.84 +   fclose(fp);
    1.85 +}
    1.86 +
    1.87 +// This function is used to generate the xml file used bt ATS
    1.88 +void testResultXml(char *filename)
    1.89 +{
    1.90 +	char time_buf[50];
    1.91 +
    1.92 +	char result[10];
    1.93 +
    1.94 +	char xmlfilename[256];
    1.95 +
    1.96 +	time_t t = time(NULL);
    1.97 +
    1.98 +	struct tm *tm1 = localtime(&t);
    1.99 +
   1.100 +	char *atsinitmsg        =   "<test-report>\n\t<test-batch>";
   1.101 +
   1.102 +	char *atsbatchinit1     =   \
   1.103 +								"\n\t\t<batch-init>\
   1.104 +								\n\t\t\t<description></description>\
   1.105 +								\n\t\t\t<date>";
   1.106 +	char *atsbatchinit2 =   "</date>\
   1.107 +							 \n\t\t\t<factory>NA</factory>\
   1.108 +							 \n\t\t\t<component>\
   1.109 +							 \n\t\t\t\t<name>NA</name>\
   1.110 +							 \n\t\t\t\t<version>NA</version>\
   1.111 +							 \n\t\t\t</component>\
   1.112 +							 \n\t\t</batch-init>";
   1.113 +
   1.114 +	char *atsbatchresult=   \
   1.115 +							"\n\t\t<batch-result>\
   1.116 +							\n\t\t\t<run-time>00:00:00</run-time>\
   1.117 +							\n\t\t</batch-result>";
   1.118 +
   1.119 +	char *atsclosemsg       =   \
   1.120 +								"\n\t</test-batch>\
   1.121 +								\n</test-report>\n ";
   1.122 +
   1.123 +	char *atstestinit       =       "\n\t\t<test-case time-stamp=\"00:00:00\">";
   1.124 +
   1.125 +
   1.126 +	char *atscaseinit1      =       \
   1.127 +									"\n\t\t\t<case-init>\
   1.128 +									\n\t\t\t\t<version></version>\
   1.129 +									\n\t\t\t\t<id>";
   1.130 +
   1.131 +	char *atscaseinit2 =    "</id>\
   1.132 +							 \n\t\t\t\t<expected-result description=\"\">0</expected-result>\
   1.133 +							 \n\t\t\t</case-init>";
   1.134 +
   1.135 +	char *atscaseresult1=   \
   1.136 +							"\n\t\t\t<case-result status=\"";
   1.137 +
   1.138 +	char *atscaseresult2=   "\">\
   1.139 +							 \n\t\t\t\t<actual-result>0</actual-result>\
   1.140 +							 \n\t\t\t\t<run-time>00:00:00</run-time>\
   1.141 +							 \n\t\t\t</case-result>";
   1.142 +
   1.143 +	char *atstestclose      =       "\n\t\t</test-case>";
   1.144 +
   1.145 +	// create the xml file name
   1.146 +	FILE *fp_result;
   1.147 +	sprintf(xmlfilename, "%s%s.%s", LOG_DIR, filename, LOG_FILE_EXT);
   1.148 +	strftime(time_buf,50,"%c",tm1);
   1.149 +
   1.150 +	if(assert_failed )
   1.151 +		strcpy(result,"FAILED");
   1.152 +	else
   1.153 +		strcpy(result,"PASSED");
   1.154 +
   1.155 +	fp_result = fopen(xmlfilename,"w");
   1.156 +
   1.157 +	if(fp_result)
   1.158 +	{
   1.159 +		fprintf(fp_result,"%s%s%s%s%s%s%s%s%s%s%s%s%s%s",atsinitmsg,atsbatchinit1,time_buf,atsbatchinit2,atstestinit,
   1.160 +				atscaseinit1,filename,atscaseinit2,atscaseresult1,result,atscaseresult2,
   1.161 +				atstestclose,atsbatchresult,atsclosemsg);
   1.162 +
   1.163 +		fclose(fp_result);
   1.164 +	}
   1.165 +}
   1.166 +
   1.167 +#endif
   1.168 +