sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
|
sl@0
|
3 |
*
|
sl@0
|
4 |
* This library is free software; you can redistribute it and/or
|
sl@0
|
5 |
* modify it under the terms of the GNU Lesser General Public
|
sl@0
|
6 |
* License as published by the Free Software Foundation; either
|
sl@0
|
7 |
* version 2 of the License, or (at your option) any later version.
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* This library is distributed in the hope that it will be useful,
|
sl@0
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
sl@0
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
sl@0
|
12 |
* Lesser General Public License for more details.
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* You should have received a copy of the GNU Lesser General Public
|
sl@0
|
15 |
* License along with this library; if not, write to the
|
sl@0
|
16 |
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
sl@0
|
17 |
* Boston, MA 02111-1307, USA.
|
sl@0
|
18 |
*
|
sl@0
|
19 |
* Description:
|
sl@0
|
20 |
*
|
sl@0
|
21 |
*/
|
sl@0
|
22 |
|
sl@0
|
23 |
|
sl@0
|
24 |
|
sl@0
|
25 |
#ifndef __G_LOG_MRT2_GLIB2_TEST
|
sl@0
|
26 |
#define __G_LOG_MRT2_GLIB2_TEST
|
sl@0
|
27 |
#include <stdio.h>
|
sl@0
|
28 |
#include <time.h>
|
sl@0
|
29 |
#include <string.h>
|
sl@0
|
30 |
#include <dirent.h>
|
sl@0
|
31 |
#include <sys/stat.h>
|
sl@0
|
32 |
|
sl@0
|
33 |
gboolean assert_failed = FALSE;
|
sl@0
|
34 |
|
sl@0
|
35 |
#undef g_assert
|
sl@0
|
36 |
#define g_assert(expr) G_STMT_START{ if (expr) { } else {g_log (G_LOG_DOMAIN,G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG, "file %s: line %d: assertion failed: (%s)", __FILE__, __LINE__, #expr);assert_failed = TRUE; }}G_STMT_END
|
sl@0
|
37 |
|
sl@0
|
38 |
|
sl@0
|
39 |
void mrtLogHandler(const gchar* log_domain, GLogLevelFlags log_level,
|
sl@0
|
40 |
const gchar* message, gpointer user_data)
|
sl@0
|
41 |
{
|
sl@0
|
42 |
FILE *fp;
|
sl@0
|
43 |
fp = fopen("c:\\logtests.txt","a");
|
sl@0
|
44 |
|
sl@0
|
45 |
if(fp)
|
sl@0
|
46 |
{
|
sl@0
|
47 |
fprintf(fp,message);
|
sl@0
|
48 |
fprintf(fp,"\n");
|
sl@0
|
49 |
fclose(fp);
|
sl@0
|
50 |
}
|
sl@0
|
51 |
}
|
sl@0
|
52 |
|
sl@0
|
53 |
void mrtPrintHandler(const gchar *message)
|
sl@0
|
54 |
{
|
sl@0
|
55 |
FILE *fp;
|
sl@0
|
56 |
fp = fopen("c:\\logtests.txt","a");
|
sl@0
|
57 |
|
sl@0
|
58 |
if(fp)
|
sl@0
|
59 |
{
|
sl@0
|
60 |
fprintf(fp,message);
|
sl@0
|
61 |
fprintf(fp,"\n");
|
sl@0
|
62 |
fclose(fp);
|
sl@0
|
63 |
}
|
sl@0
|
64 |
}
|
sl@0
|
65 |
|
sl@0
|
66 |
|
sl@0
|
67 |
// This function is used to generate the xml file used bt ATS
|
sl@0
|
68 |
void testResultXml(char *filename)
|
sl@0
|
69 |
{
|
sl@0
|
70 |
char time_buf[50];
|
sl@0
|
71 |
|
sl@0
|
72 |
char result[10];
|
sl@0
|
73 |
|
sl@0
|
74 |
char xmlfilename[256];
|
sl@0
|
75 |
|
sl@0
|
76 |
time_t t = time(NULL);
|
sl@0
|
77 |
|
sl@0
|
78 |
struct tm *tm1 = localtime(&t);
|
sl@0
|
79 |
|
sl@0
|
80 |
char *atsinitmsg = "<test-report>\n\t<test-batch>";
|
sl@0
|
81 |
|
sl@0
|
82 |
char *atsbatchinit1 = \
|
sl@0
|
83 |
"\n\t\t<batch-init>\
|
sl@0
|
84 |
\n\t\t\t<description></description>\
|
sl@0
|
85 |
\n\t\t\t<date>";
|
sl@0
|
86 |
|
sl@0
|
87 |
char *atsbatchinit2 = "</date>\
|
sl@0
|
88 |
\n\t\t\t<factory>NA</factory>\
|
sl@0
|
89 |
\n\t\t\t<component>\
|
sl@0
|
90 |
\n\t\t\t\t<name>NA</name>\
|
sl@0
|
91 |
\n\t\t\t\t<version>NA</version>\
|
sl@0
|
92 |
\n\t\t\t</component>\
|
sl@0
|
93 |
\n\t\t</batch-init>";
|
sl@0
|
94 |
|
sl@0
|
95 |
char *atsbatchresult= \
|
sl@0
|
96 |
"\n\t\t<batch-result>\
|
sl@0
|
97 |
\n\t\t\t<run-time>00:00:00</run-time>\
|
sl@0
|
98 |
\n\t\t</batch-result>";
|
sl@0
|
99 |
|
sl@0
|
100 |
char *atsclosemsg = \
|
sl@0
|
101 |
"\n\t</test-batch>\
|
sl@0
|
102 |
\n</test-report>\n ";
|
sl@0
|
103 |
|
sl@0
|
104 |
char *atstestinit = "\n\t\t<test-case time-stamp=\"00:00:00\">";
|
sl@0
|
105 |
|
sl@0
|
106 |
|
sl@0
|
107 |
char *atscaseinit1 = \
|
sl@0
|
108 |
"\n\t\t\t<case-init>\
|
sl@0
|
109 |
\n\t\t\t\t<version></version>\
|
sl@0
|
110 |
\n\t\t\t\t<id>";
|
sl@0
|
111 |
|
sl@0
|
112 |
char *atscaseinit2 = "</id>\
|
sl@0
|
113 |
\n\t\t\t\t<expected-result description=\"\">0</expected-result>\
|
sl@0
|
114 |
\n\t\t\t</case-init>";
|
sl@0
|
115 |
|
sl@0
|
116 |
char *atscaseresult1= \
|
sl@0
|
117 |
"\n\t\t\t<case-result status=\"";
|
sl@0
|
118 |
|
sl@0
|
119 |
char *atscaseresult2= "\">\
|
sl@0
|
120 |
\n\t\t\t\t<actual-result>0</actual-result>\
|
sl@0
|
121 |
\n\t\t\t\t<run-time>00:00:00</run-time>\
|
sl@0
|
122 |
\n\t\t\t</case-result>";
|
sl@0
|
123 |
|
sl@0
|
124 |
char *atstestclose = "\n\t\t</test-case>";
|
sl@0
|
125 |
|
sl@0
|
126 |
/* Check and see if spd_logs/xml is existent or not. If not present create it */
|
sl@0
|
127 |
DIR *dir;
|
sl@0
|
128 |
FILE *fp;
|
sl@0
|
129 |
|
sl@0
|
130 |
dir = opendir("c:\\spd_logs");
|
sl@0
|
131 |
if(!dir)
|
sl@0
|
132 |
mkdir("c:\\spd_logs",0777);
|
sl@0
|
133 |
|
sl@0
|
134 |
dir = opendir("c:\\spd_logs\\xml");
|
sl@0
|
135 |
if(!dir)
|
sl@0
|
136 |
mkdir("c:\\spd_logs\\xml",0777);
|
sl@0
|
137 |
|
sl@0
|
138 |
// create the xml file name
|
sl@0
|
139 |
strcpy(xmlfilename,"c:/spd_logs/xml/");
|
sl@0
|
140 |
strcat(xmlfilename,filename);
|
sl@0
|
141 |
strcat(xmlfilename,".xml");
|
sl@0
|
142 |
|
sl@0
|
143 |
strftime(time_buf,50,"%c",tm1);
|
sl@0
|
144 |
|
sl@0
|
145 |
if(assert_failed )
|
sl@0
|
146 |
strcpy(result,"FAILED");
|
sl@0
|
147 |
else
|
sl@0
|
148 |
strcpy(result,"PASSED");
|
sl@0
|
149 |
|
sl@0
|
150 |
fp = fopen(xmlfilename,"w");
|
sl@0
|
151 |
|
sl@0
|
152 |
if(fp)
|
sl@0
|
153 |
{
|
sl@0
|
154 |
fprintf(fp,"%s%s%s%s%s%s%s%s%s%s%s%s%s%s",atsinitmsg,atsbatchinit1,time_buf,atsbatchinit2,atstestinit,
|
sl@0
|
155 |
atscaseinit1,filename,atscaseinit2,atscaseresult1,result,atscaseresult2,
|
sl@0
|
156 |
atstestclose,atsbatchresult,atsclosemsg);
|
sl@0
|
157 |
|
sl@0
|
158 |
fclose(fp);
|
sl@0
|
159 |
}
|
sl@0
|
160 |
else
|
sl@0
|
161 |
{
|
sl@0
|
162 |
g_assert(FALSE && "Failed to create the xml file");
|
sl@0
|
163 |
}
|
sl@0
|
164 |
}
|
sl@0
|
165 |
|
sl@0
|
166 |
#endif
|