|
1 /* |
|
2 * Copyright (c) 2008 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 |
|
18 |
|
19 |
|
20 #ifndef _STD_LOG_FILE_H__ |
|
21 #define _STD_LOG_FILE_H__ |
|
22 |
|
23 #include <stdio.h> |
|
24 #include <time.h> |
|
25 #include <string.h> |
|
26 #include <stdarg.h> |
|
27 #include <dirent.h> |
|
28 #ifdef __SYMBIAN32__ |
|
29 //#define LOG_FILE "c:\\logs\\std_test_log.txt" |
|
30 #define LOG_DIR "c:\\logs\\" |
|
31 #define LOG_FILE_EXT "xml" |
|
32 int assert_failed = 0; |
|
33 #else |
|
34 #define LOG_DIR "" |
|
35 #define LOG_FILE_EXT "xml" |
|
36 #define LOG_FILE "std_test_log.txt" |
|
37 int assert_failed = 0; |
|
38 #endif |
|
39 FILE *fp; |
|
40 |
|
41 int gnutest = 1; |
|
42 |
|
43 # define VERIFY(fn) gnutest &= (fn) |
|
44 |
|
45 |
|
46 void std_log(const char *filename,const int lineno,const char* aformat,...) |
|
47 { |
|
48 va_list va; |
|
49 if(fp==NULL) |
|
50 { |
|
51 fp = fopen(LOG_FILE,"a"); |
|
52 } |
|
53 |
|
54 va_start(va,aformat); |
|
55 { |
|
56 fprintf(fp,"%s - [%d] : ",filename,lineno); |
|
57 vfprintf(fp,aformat,va); |
|
58 fprintf(fp,"\n"); |
|
59 } |
|
60 va_end(va); |
|
61 fflush(fp); |
|
62 } |
|
63 |
|
64 |
|
65 void init_log_file() |
|
66 { |
|
67 if(fp == NULL) |
|
68 { |
|
69 fp = fopen(LOG_FILE, "a"); |
|
70 } |
|
71 } |
|
72 |
|
73 void close_log_file() |
|
74 { |
|
75 fclose(fp); |
|
76 } |
|
77 |
|
78 // This function is used to generate the xml file used bt ATS |
|
79 void testResultXml(char *filename) |
|
80 { |
|
81 char time_buf[50]; |
|
82 |
|
83 char result[10]; |
|
84 |
|
85 char xmlfilename[256]; |
|
86 |
|
87 time_t t = time(NULL); |
|
88 |
|
89 struct tm *tm1 = localtime(&t); |
|
90 |
|
91 char *atsinitmsg = "<test-report>\n\t<test-batch>"; |
|
92 |
|
93 char *atsbatchinit1 = \ |
|
94 "\n\t\t<batch-init>\ |
|
95 \n\t\t\t<description></description>\ |
|
96 \n\t\t\t<date>"; |
|
97 |
|
98 char *atsbatchinit2 = "</date>\ |
|
99 \n\t\t\t<factory>NA</factory>\ |
|
100 \n\t\t\t<component>\ |
|
101 \n\t\t\t\t<name>NA</name>\ |
|
102 \n\t\t\t\t<version>NA</version>\ |
|
103 \n\t\t\t</component>\ |
|
104 \n\t\t</batch-init>"; |
|
105 |
|
106 char *atsbatchresult= \ |
|
107 "\n\t\t<batch-result>\ |
|
108 \n\t\t\t<run-time>00:00:00</run-time>\ |
|
109 \n\t\t</batch-result>"; |
|
110 |
|
111 char *atsclosemsg = \ |
|
112 "\n\t</test-batch>\ |
|
113 \n</test-report>\n "; |
|
114 |
|
115 char *atstestinit = "\n\t\t<test-case time-stamp=\"00:00:00\">"; |
|
116 |
|
117 |
|
118 char *atscaseinit1 = \ |
|
119 "\n\t\t\t<case-init>\ |
|
120 \n\t\t\t\t<version></version>\ |
|
121 \n\t\t\t\t<id>"; |
|
122 |
|
123 char *atscaseinit2 = "</id>\ |
|
124 \n\t\t\t\t<expected-result description=\"\">0</expected-result>\ |
|
125 \n\t\t\t</case-init>"; |
|
126 |
|
127 char *atscaseresult1= \ |
|
128 "\n\t\t\t<case-result status=\""; |
|
129 |
|
130 char *atscaseresult2= "\">\ |
|
131 \n\t\t\t\t<actual-result>0</actual-result>\ |
|
132 \n\t\t\t\t<run-time>00:00:00</run-time>\ |
|
133 \n\t\t\t</case-result>"; |
|
134 |
|
135 char *atstestclose = "\n\t\t</test-case>"; |
|
136 |
|
137 /* Check and see if spd_logs/xml is existent or not. If not present create it */ |
|
138 DIR *dir; |
|
139 FILE *fp; |
|
140 |
|
141 dir = opendir("c:\\spd_logs"); |
|
142 if(!dir) |
|
143 mkdir("c:\\spd_logs",0777); |
|
144 |
|
145 dir = opendir("c:\\spd_logs\\xml"); |
|
146 if(!dir) |
|
147 mkdir("c:\\spd_logs\\xml",0777); |
|
148 |
|
149 // create the xml file name |
|
150 strcpy(xmlfilename,"c:/spd_logs/xml/"); |
|
151 strcat(xmlfilename,filename); |
|
152 strcat(xmlfilename,".xml"); |
|
153 |
|
154 strftime(time_buf,50,"%c",tm1); |
|
155 |
|
156 if(assert_failed ) |
|
157 strcpy(result,"FAILED"); |
|
158 else |
|
159 strcpy(result,"PASSED"); |
|
160 |
|
161 fp = fopen(xmlfilename,"w"); |
|
162 |
|
163 if(fp) |
|
164 { |
|
165 fprintf(fp,"%s%s%s%s%s%s%s%s%s%s%s%s%s%s",atsinitmsg,atsbatchinit1,time_buf,atsbatchinit2,atstestinit, |
|
166 atscaseinit1,filename,atscaseinit2,atscaseresult1,result,atscaseresult2, |
|
167 atstestclose,atsbatchresult,atsclosemsg); |
|
168 |
|
169 fclose(fp); |
|
170 } |
|
171 else |
|
172 { |
|
173 g_assert(FALSE && "Failed to create the xml file"); |
|
174 } |
|
175 } |
|
176 |
|
177 #endif |
|
178 |