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