sl@0: /* sl@0: * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: sl@0: #ifndef _STD_LOG_FILE_H__ sl@0: #define _STD_LOG_FILE_H__ sl@0: sl@0: #include <stdio.h> sl@0: #include <time.h> sl@0: #include <string.h> sl@0: #include <stdarg.h> sl@0: #include <dirent.h> sl@0: #ifdef __SYMBIAN32__ sl@0: //#define LOG_FILE "c:\\logs\\std_test_log.txt" sl@0: #define LOG_DIR "c:\\logs\\" sl@0: #define LOG_FILE_EXT "xml" sl@0: int assert_failed = 0; sl@0: #else sl@0: #define LOG_DIR "" sl@0: #define LOG_FILE_EXT "xml" sl@0: #define LOG_FILE "std_test_log.txt" sl@0: int assert_failed = 0; sl@0: #endif sl@0: FILE *fp; sl@0: sl@0: int gnutest = 1; sl@0: sl@0: # define VERIFY(fn) gnutest &= (fn) sl@0: sl@0: sl@0: void std_log(const char *filename,const int lineno,const char* aformat,...) sl@0: { sl@0: va_list va; sl@0: if(fp==NULL) sl@0: { sl@0: fp = fopen(LOG_FILE,"a"); sl@0: } sl@0: sl@0: va_start(va,aformat); sl@0: { sl@0: fprintf(fp,"%s - [%d] : ",filename,lineno); sl@0: vfprintf(fp,aformat,va); sl@0: fprintf(fp,"\n"); sl@0: } sl@0: va_end(va); sl@0: fflush(fp); sl@0: } sl@0: sl@0: sl@0: void init_log_file() sl@0: { sl@0: if(fp == NULL) sl@0: { sl@0: fp = fopen(LOG_FILE, "a"); sl@0: } sl@0: } sl@0: sl@0: void close_log_file() sl@0: { sl@0: fclose(fp); sl@0: } sl@0: sl@0: // This function is used to generate the xml file used bt ATS sl@0: void testResultXml(char *filename) sl@0: { sl@0: char time_buf[50]; sl@0: sl@0: char result[10]; sl@0: sl@0: char xmlfilename[256]; sl@0: sl@0: time_t t = time(NULL); sl@0: sl@0: struct tm *tm1 = localtime(&t); sl@0: sl@0: char *atsinitmsg = "<test-report>\n\t<test-batch>"; sl@0: sl@0: char *atsbatchinit1 = \ sl@0: "\n\t\t<batch-init>\ sl@0: \n\t\t\t<description></description>\ sl@0: \n\t\t\t<date>"; sl@0: sl@0: char *atsbatchinit2 = "</date>\ sl@0: \n\t\t\t<factory>NA</factory>\ sl@0: \n\t\t\t<component>\ sl@0: \n\t\t\t\t<name>NA</name>\ sl@0: \n\t\t\t\t<version>NA</version>\ sl@0: \n\t\t\t</component>\ sl@0: \n\t\t</batch-init>"; sl@0: sl@0: char *atsbatchresult= \ sl@0: "\n\t\t<batch-result>\ sl@0: \n\t\t\t<run-time>00:00:00</run-time>\ sl@0: \n\t\t</batch-result>"; sl@0: sl@0: char *atsclosemsg = \ sl@0: "\n\t</test-batch>\ sl@0: \n</test-report>\n "; sl@0: sl@0: char *atstestinit = "\n\t\t<test-case time-stamp=\"00:00:00\">"; sl@0: sl@0: sl@0: char *atscaseinit1 = \ sl@0: "\n\t\t\t<case-init>\ sl@0: \n\t\t\t\t<version></version>\ sl@0: \n\t\t\t\t<id>"; sl@0: sl@0: char *atscaseinit2 = "</id>\ sl@0: \n\t\t\t\t<expected-result description=\"\">0</expected-result>\ sl@0: \n\t\t\t</case-init>"; sl@0: sl@0: char *atscaseresult1= \ sl@0: "\n\t\t\t<case-result status=\""; sl@0: sl@0: char *atscaseresult2= "\">\ sl@0: \n\t\t\t\t<actual-result>0</actual-result>\ sl@0: \n\t\t\t\t<run-time>00:00:00</run-time>\ sl@0: \n\t\t\t</case-result>"; sl@0: sl@0: char *atstestclose = "\n\t\t</test-case>"; sl@0: sl@0: /* Check and see if spd_logs/xml is existent or not. If not present create it */ sl@0: DIR *dir; sl@0: FILE *fp; sl@0: sl@0: dir = opendir("c:\\spd_logs"); sl@0: if(!dir) sl@0: mkdir("c:\\spd_logs",0777); sl@0: sl@0: dir = opendir("c:\\spd_logs\\xml"); sl@0: if(!dir) sl@0: mkdir("c:\\spd_logs\\xml",0777); sl@0: sl@0: // create the xml file name sl@0: strcpy(xmlfilename,"c:/spd_logs/xml/"); sl@0: strcat(xmlfilename,filename); sl@0: strcat(xmlfilename,".xml"); sl@0: sl@0: strftime(time_buf,50,"%c",tm1); sl@0: sl@0: if(assert_failed ) sl@0: strcpy(result,"FAILED"); sl@0: else sl@0: strcpy(result,"PASSED"); sl@0: sl@0: fp = fopen(xmlfilename,"w"); sl@0: sl@0: if(fp) sl@0: { sl@0: fprintf(fp,"%s%s%s%s%s%s%s%s%s%s%s%s%s%s",atsinitmsg,atsbatchinit1,time_buf,atsbatchinit2,atstestinit, sl@0: atscaseinit1,filename,atscaseinit2,atscaseresult1,result,atscaseresult2, sl@0: atstestclose,atsbatchresult,atsclosemsg); sl@0: sl@0: fclose(fp); sl@0: } sl@0: else sl@0: { sl@0: g_assert(FALSE && "Failed to create the xml file"); sl@0: } sl@0: } sl@0: sl@0: #endif sl@0: