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