utilitylibraries/libutils/tsrc/nft/inc/std_log_result.h
changeset 31 ce057bb09d0b
parent 0 e4d67989cc36
equal deleted inserted replaced
30:e20de85af2ee 31:ce057bb09d0b
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 /*This material, including documentation and any related
       
    18  :*  computer programs, is protected by copyright controlled by
       
    19  *  Nokia Corporation. All rights are reserved. Copying,
       
    20  *  including reproducing, storing, adapting or translating, any
       
    21  *  or all of this material requires the prior written consent of
       
    22  *  Nokia Corporation. This material also contains confidential
       
    23  *  information which may not be disclosed to others without the
       
    24  *  prior written consent of Nokia Corporation.
       
    25  * ============================================================================
       
    26  */
       
    27 
       
    28 
       
    29 #ifndef _STD_LOG_FILE_H__
       
    30 #define _STD_LOG_FILE_H__
       
    31 
       
    32 #include <stdio.h>
       
    33 #include <time.h>
       
    34 #include <string.h>
       
    35 #include <stdarg.h>
       
    36 #ifdef __SYMBIAN32__
       
    37 #define LOG_FILE "c:\\logs\\std_test_log.txt"
       
    38 #define LOG_DIR "c:\\logs\\"
       
    39 #define LOG_FILE_EXT "xml"
       
    40 bool assert_failed = false;
       
    41 #else
       
    42 #define LOG_DIR ""
       
    43 #define LOG_FILE_EXT "xml"
       
    44 #define LOG_FILE "std_test_log.txt"
       
    45 bool assert_failed = false;
       
    46 #endif
       
    47 FILE *fp;
       
    48 
       
    49 bool gnutest = true;
       
    50 
       
    51 # define VERIFY(fn) gnutest &= (fn)
       
    52 
       
    53 
       
    54 void std_log(const char *filename,const int lineno,const char* aformat,...)
       
    55 {
       
    56 	if(fp==NULL)
       
    57 	{
       
    58 		fp = fopen(LOG_FILE,"a");
       
    59 	}
       
    60 	va_list va;
       
    61 	va_start(va,aformat);    
       
    62     {
       
    63 		fprintf(fp,"%s - [%d] : ",filename,lineno);
       
    64 		vfprintf(fp,aformat,va);
       
    65 		fprintf(fp,"\n");
       
    66 	}
       
    67 	va_end(va);
       
    68 }
       
    69 
       
    70 
       
    71 void init_log_file()
       
    72 {
       
    73 	if(fp == NULL)
       
    74 	{
       
    75 		fp = fopen(LOG_FILE, "a");
       
    76 	}
       
    77 }
       
    78 
       
    79 void close_log_file()
       
    80 {
       
    81    fclose(fp);
       
    82 }
       
    83 
       
    84 // This function is used to generate the xml file used bt ATS
       
    85 void testResultXml(char *filename)
       
    86 {
       
    87 	char time_buf[50];
       
    88 
       
    89 	char result[10];
       
    90 
       
    91 	char xmlfilename[256];
       
    92 
       
    93 	time_t t = time(NULL);
       
    94 
       
    95 	struct tm *tm1 = localtime(&t);
       
    96 
       
    97 	char *atsinitmsg        =   "<test-report>\n\t<test-batch>";
       
    98 
       
    99 	char *atsbatchinit1     =   \
       
   100 								"\n\t\t<batch-init>\
       
   101 								\n\t\t\t<description></description>\
       
   102 								\n\t\t\t<date>";
       
   103 	char *atsbatchinit2 =   "</date>\
       
   104 							 \n\t\t\t<factory>NA</factory>\
       
   105 							 \n\t\t\t<component>\
       
   106 							 \n\t\t\t\t<name>NA</name>\
       
   107 							 \n\t\t\t\t<version>NA</version>\
       
   108 							 \n\t\t\t</component>\
       
   109 							 \n\t\t</batch-init>";
       
   110 
       
   111 	char *atsbatchresult=   \
       
   112 							"\n\t\t<batch-result>\
       
   113 							\n\t\t\t<run-time>00:00:00</run-time>\
       
   114 							\n\t\t</batch-result>";
       
   115 
       
   116 	char *atsclosemsg       =   \
       
   117 								"\n\t</test-batch>\
       
   118 								\n</test-report>\n ";
       
   119 
       
   120 	char *atstestinit       =       "\n\t\t<test-case time-stamp=\"00:00:00\">";
       
   121 
       
   122 
       
   123 	char *atscaseinit1      =       \
       
   124 									"\n\t\t\t<case-init>\
       
   125 									\n\t\t\t\t<version></version>\
       
   126 									\n\t\t\t\t<id>";
       
   127 
       
   128 	char *atscaseinit2 =    "</id>\
       
   129 							 \n\t\t\t\t<expected-result description=\"\">0</expected-result>\
       
   130 							 \n\t\t\t</case-init>";
       
   131 
       
   132 	char *atscaseresult1=   \
       
   133 							"\n\t\t\t<case-result status=\"";
       
   134 
       
   135 	char *atscaseresult2=   "\">\
       
   136 							 \n\t\t\t\t<actual-result>0</actual-result>\
       
   137 							 \n\t\t\t\t<run-time>00:00:00</run-time>\
       
   138 							 \n\t\t\t</case-result>";
       
   139 
       
   140 	char *atstestclose      =       "\n\t\t</test-case>";
       
   141 
       
   142 	// create the xml file name
       
   143 	FILE *fp_result;
       
   144 	sprintf(xmlfilename, "%s%s.%s", LOG_DIR, filename, LOG_FILE_EXT);
       
   145 	strftime(time_buf,50,"%c",tm1);
       
   146 
       
   147 	if(assert_failed )
       
   148 		strcpy(result,"FAILED");
       
   149 	else
       
   150 		strcpy(result,"PASSED");
       
   151 
       
   152 	fp_result = fopen(xmlfilename,"w");
       
   153 
       
   154 	if(fp_result)
       
   155 	{
       
   156 		fprintf(fp_result,"%s%s%s%s%s%s%s%s%s%s%s%s%s%s",atsinitmsg,atsbatchinit1,time_buf,atsbatchinit2,atstestinit,
       
   157 				atscaseinit1,filename,atscaseinit2,atscaseresult1,result,atscaseresult2,
       
   158 				atstestclose,atsbatchresult,atsclosemsg);
       
   159 
       
   160 		fclose(fp_result);
       
   161 	}
       
   162 }
       
   163 
       
   164 #endif
       
   165