Skip to content
Snippets Groups Projects
Commit bc5629a8 authored by Tim Wickberg's avatar Tim Wickberg Committed by Morris Jette
Browse files

[PATCH 1/2] update dejagnu header file from latest upstream

parent e7ba69c5
No related branches found
No related tags found
No related merge requests found
/* /* DejaGnu unit testing header.
* Copyright (C) 2000, 2001 Free Software Foundation, Inc. Copyright (C) 2000, 2001, 2002, 2004, 2006 Free Software
* Foundation, Inc.
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by This file is part of DejaGnu.
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version. DejaGnu is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* This program is distributed in the hope that it will be useful, the Free Software Foundation; either version 3 of the License, or
* but WITHOUT ANY WARRANTY; without even the implied warranty of (at your option) any later version.
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. DejaGnu is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
* You should have received a copy of the GNU General Public License MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* along with this program; if not, write to the Free Software General Public License for more details.
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ You should have received a copy of the GNU General Public License
along with DejaGnu; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
#ifndef __DEJAGNU_H__ #ifndef __DEJAGNU_H__
#define __DEJAGNU_H__ #define __DEJAGNU_H__
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#include <string.h> #include <string.h>
#define _BUFFER_SIZE_ 512 /* If you have problems with DejaGnu dropping failed, untested, or
* unresolved messages generated by a unit testcase, then: */
/* #define _DEJAGNU_WAIT_ */
static int passed = 0; #ifdef _DEJAGNU_WAIT_
static int failed = 0; #include <sys/time.h>
static int untest = 0; #include <sys/types.h>
static int unresolve = 0; #include <unistd.h>
static int tests = 0; #endif
static char buffer[ _BUFFER_SIZE_ ]; static int passed;
static int failed;
static int untest;
static int unresolve;
static int xfailed;
static int xpassed;
static char buffer[512];
inline void void
pass (const char* fmt, ... ) __attribute__ ((format (printf, 1, 2))); wait (void)
inline void {
pass (const char* fmt, ... ) { #ifdef _DEJAGNU_WAIT_
va_list ap; fd_set rfds;
struct timeval tv;
tests++; FD_ZERO (&rfds);
passed++; tv.tv_sec = 0;
va_start( ap, fmt ); tv.tv_usec = 1;
vsnprintf( buffer, _BUFFER_SIZE_, fmt, ap );
va_end( ap ); select (0, &rfds, NULL, NULL, &tv);
printf ("\tPASSED: #%d %s\n", tests, buffer ); #endif
fflush( stdout );
} }
inline void static inline void
fail (const char* fmt, ... ) __attribute__ ((format (printf, 1, 2))); pass (const char* fmt, ...)
inline void {
fail (const char* fmt, ... ) { va_list ap;
va_list ap;
passed++;
va_start (ap, fmt);
vsnprintf (buffer, sizeof (buffer), fmt, ap);
va_end (ap);
printf ("\tPASSED: %s\n", buffer);
wait ();
}
tests++; static inline void
failed++; xpass (const char* fmt, ...)
va_start( ap, fmt ); {
vsnprintf( buffer, _BUFFER_SIZE_, fmt, ap ); va_list ap;
va_end( ap );
printf ("\tFAILED: #%d %s\n", tests, buffer ); passed++;
fflush( stdout ); va_start (ap, fmt);
vsnprintf (buffer, sizeof (buffer), fmt, ap);
va_end (ap);
printf ("\tXPASSED: %s\n", buffer);
wait ();
} }
inline void static inline void
untested (const char* fmt, ... ) __attribute__ ((format (printf, 1, 2))); fail (const char* fmt, ...)
inline void {
untested (const char* fmt, ... ) { va_list ap;
va_list ap;
failed++;
va_start (ap, fmt);
vsnprintf (buffer, sizeof (buffer), fmt, ap);
va_end (ap);
printf ("\tFAILED: %s\n", buffer);
wait ();
}
tests++; static inline void
untest++; xfail (const char* fmt, ...)
va_start( ap, fmt ); {
vsnprintf( buffer, _BUFFER_SIZE_, fmt, ap ); va_list ap;
va_end( ap );
printf ("\tUNTESTED: #%d %s\n", tests, buffer ); failed++;
fflush( stdout ); va_start (ap, fmt);
vsnprintf (buffer, sizeof (buffer), fmt, ap);
va_end (ap);
printf ("\tXFAILED: %s\n", buffer);
wait ();
} }
inline void static inline void
unresolved (const char* fmt, ... ) __attribute__ ((format (printf, 1, 2))); untested (const char* fmt, ...)
inline void {
unresolved (const char* fmt, ... ) { va_list ap;
va_list ap;
untest++;
va_start (ap, fmt);
vsnprintf (buffer, sizeof (buffer), fmt, ap);
va_end (ap);
printf ("\tUNTESTED: %s\n", buffer);
wait ();
}
tests++; static inline void
unresolve++; unresolved (const char* fmt, ...)
va_start( ap, fmt ); {
vsnprintf( buffer, _BUFFER_SIZE_, fmt, ap ); va_list ap;
va_end( ap );
printf ("\tUNRESOLVED: #%d %s\n", tests, buffer ); unresolve++;
fflush( stdout ); va_start (ap, fmt);
vsnprintf (buffer, sizeof (buffer), fmt, ap);
va_end (ap);
printf ("\tUNRESOLVED: %s\n", buffer);
wait ();
} }
inline void static inline void
note (const char* fmt, ... ) __attribute__ ((format (printf, 1, 2))); note (const char* fmt, ...)
inline void {
note (const char* fmt, ... ) { va_list ap;
va_list ap;
va_start (ap, fmt);
va_start( ap, fmt ); vsnprintf (buffer, sizeof (buffer), fmt, ap);
vsnprintf( buffer, _BUFFER_SIZE_, fmt, ap ); va_end (ap);
va_end( ap ); printf ("\tNOTE: %s\n", buffer);
printf ("\tNOTE: %s\n", buffer ); wait ();
fflush( stdout );
} }
inline void static inline void
totals (void) { totals (void)
printf ("\nTotals:\n"); {
printf ("\t#passed:\t\t%d\n", passed); printf ("\nTotals:\n");
printf ("\t#failed:\t\t%d\n", failed); printf ("\t#passed:\t\t%d\n", passed);
if (untest) printf ("\t#real failed:\t\t%d\n", failed);
printf ("\t#untested:\t\t%d\n", untest); if (xfailed)
if (unresolve) printf ("\t#expected failures:\t\t%d\n", xfailed);
printf ("\t#unresolved:\t\t%d\n", unresolve); if (untest)
printf ("\t#untested:\t\t%d\n", untest);
if (unresolve)
printf ("\t#unresolved:\t\t%d\n", unresolve);
} }
#ifdef __cplusplus #ifdef __cplusplus
#include <iostream> #include <iostream>
#include <iomanip> #include <iomanip>
#include <fstream> #include <fstream>
#include <string> #include <string>
#if 0
#if HAVE_STL3
#include <sstream>
#else
#include <strstream>
#endif
#endif
const char *outstate_list[] = { const char *outstate_list[] = {
"FAILED: ", "FAILED: ", "PASSED: ", "UNTESTED: ", "UNRESOLVED: ", "XFAILED: ", "XPASSED: "
"PASSED: ",
"UNTESTED: ",
"UNRESOLVED: "
}; };
const char ** outstate = outstate_list; const char ** outstate = outstate_list;
#if 0 enum teststate { FAILED, PASSED, UNTESTED, UNRESOLVED, XFAILED, XPASSED} laststate;
extern ios& __iomanip_testout (ios&, int);
inline smanip<int> testout (int n) {
return smanip<int> (__iomanip_testout, n);
}
ios & __iomanip_testout (ios& i, int x) {
return i;
}
template<class T>
class OMANIP {
private:
T i;
ostream &(*f)(ostream&, T);
public:
OMANIP(ostream& (*ff)(ostream&, T), T ii) : f(ff), i(ii) {
}
friend ostream operator<<(ostream& us, OMANIP& m) {
return m.f(os,m.i);
}
};
ostream&
freakout(ostream& os, int x) {
return os << "FREAKOUT" ;
// return x << "TESTOUT " << x ;
}
OMANIP<int> testout(int i) {
return OMANIP<int>(&freakout,i);
}
#endif
enum teststate {FAILED, PASSED,UNTESTED,UNRESOLVED} laststate;
class TestState { class TestState {
private: private:
teststate laststate; teststate laststate;
std::string lastmsg; std::string lastmsg;
public: public:
TestState(void) { TestState (void)
passed = 0; {
failed = 0; passed = 0;
untest = 0; failed = 0;
unresolve = 0; untest = 0;
} xpassed = 0;
~TestState(void) { xfailed = 0;
totals(); unresolve = 0;
}; }
void testrun (bool b, std::string s) { ~TestState (void) { totals(); }
if (b)
pass (s); void testrun (bool b, std::string s)
else {
fail (s); if (b)
} pass (s);
else
void pass (std::string s) { fail (s);
passed++; }
laststate = PASSED;
lastmsg = s; void pass (std::string s)
std::cout << "\t" << outstate[PASSED] << s << std::endl; {
} passed++;
void pass (const char *c) { laststate = PASSED;
std::string s = c; lastmsg = s;
pass (s); std::cout << "\t" << outstate[PASSED] << s << std::endl;
} }
void fail (std::string s) { void pass (const char *c)
failed++; {
laststate = FAILED; std::string s = c;
lastmsg = s; pass (s);
std::cout << "\t" << outstate[FAILED] << s << std::endl; }
}
void fail (const char *c) { void xpass (std::string s)
std::string s = c; {
fail (s); xpassed++;
} laststate = PASSED;
lastmsg = s;
void untested (std::string s) { std::cout << "\t" << outstate[XPASSED] << s << std::endl;
untest++; }
laststate = UNTESTED;
lastmsg = s; void xpass (const char *c)
std::cout << "\t" << outstate[UNTESTED] << s << std::endl; {
} std::string s = c;
void untested (const char *c) { xpass (s);
std::string s = c; }
untested (s);
} void fail (std::string s)
{
void unresolved (std::string s) { failed++;
unresolve++; laststate = FAILED;
laststate = UNRESOLVED; lastmsg = s;
lastmsg = s; std::cout << "\t" << outstate[FAILED] << s << std::endl;
std::cout << "\t" << outstate[UNRESOLVED] << s << std::endl; }
}
void unresolved (const char *c) { void fail (const char *c)
std::string s = c; {
unresolved (s); std::string s = c;
} fail (s);
}
void totals (void) {
std::cout << "\t#passed:\t\t" << passed << std::endl; void xfail (std::string s)
std::cout << "\t#failed:\t\t" << failed << std::endl; {
if (untest) xfailed++;
std::cout << "\t#untested:\t\t" << untest << std::endl; laststate = XFAILED;
if (unresolve) lastmsg = s;
std::cout << "\t#unresolved:\t\t" << unresolve << std::endl; std::cout << "\t" << outstate[XFAILED] << s << std::endl;
} }
// This is so this class can be printed in an ostream. void xfail (const char *c)
friend std::ostream & operator << (std::ostream &os, TestState& t) { {
return os << "\t" << outstate[t.laststate] << t.lastmsg ; std::string s = c;
} xfail (s);
}
int GetState(void) {
return laststate; void untested (std::string s)
} {
std::string GetMsg(void) { untest++;
return lastmsg; laststate = UNTESTED;
} lastmsg = s;
}; std::cout << "\t" << outstate[UNTESTED] << s << std::endl;
}
void untested (const char *c)
{
std::string s = c;
untested (s);
}
void unresolved (std::string s)
{
unresolve++;
laststate = UNRESOLVED;
lastmsg = s;
std::cout << "\t" << outstate[UNRESOLVED] << s << std::endl;
}
void unresolved (const char *c)
{
std::string s = c;
unresolved (s);
}
void totals (void)
{
std::cout << "\t#passed:\t\t" << passed << std::endl;
std::cout << "\t#real failed:\t\t" << failed << std::endl;
if (xfailed)
std::cout << "\t#expected failures:\t\t" << xfailed << std::endl;
if (xpassed)
std::cout << "\t#unexpected passes:\t\t" << xpassed << std::endl;
if (untest)
std::cout << "\t#untested:\t\t" << untest << std::endl;
if (unresolve)
std::cout << "\t#unresolved:\t\t" << unresolve << std::endl;
}
#endif // __cplusplus // This is so this class can be printed in an ostream.
#endif // _DEJAGNU_H_ friend std::ostream & operator << (std::ostream &os, TestState& t)
{
return os << "\t" << outstate[t.laststate] << t.lastmsg ;
}
int GetState (void) { return laststate; }
std::string GetMsg (void) { return lastmsg; }
};
#endif /* __cplusplus */
#endif /* _DEJAGNU_H_ */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment