[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Camino-devel] camino/src/common PhilAsserts.h PhilAsserts.cpp...
From: |
Philippe Fremy |
Subject: |
[Camino-devel] camino/src/common PhilAsserts.h PhilAsserts.cpp... |
Date: |
Mon, 03 Mar 2003 17:12:05 -0500 |
CVSROOT: /cvsroot/camino
Module name: camino
Changes by: Philippe Fremy <address@hidden> 03/03/03 17:12:05
Modified files:
src/common : PhilAsserts.h PhilAsserts.cpp
PhilTestRunner.cpp
Log message:
- add pointer equalitychecking
- add non assertion
- add gcc-like output
Patches:
Index: camino/src/common/PhilAsserts.cpp
diff -u camino/src/common/PhilAsserts.cpp:1.2
camino/src/common/PhilAsserts.cpp:1.3
--- camino/src/common/PhilAsserts.cpp:1.2 Tue Jan 21 17:28:13 2003
+++ camino/src/common/PhilAsserts.cpp Mon Mar 3 17:12:05 2003
@@ -18,6 +18,16 @@
}
+void philNotAssert( std::string actualExpr, bool unassertion,
+ long lineNumber, std::string fileName ) {
+ if (unassertion == false) return;
+ std::string s;
+ s = "'" + actualExpr + "' was not false!";
+ throw CppUnit::Exception (s, CppUnit::SourceLine(fileName, lineNumber));
+
+}
+
+
// --------------------------- numbers
@@ -71,6 +81,37 @@
throw CppUnit::Exception (s, CppUnit::SourceLine(fileName, lineNumber));
}
+// ------------------- pointers
+//
+void philAssertEquals( std::string actualExpr, void * actual, void * expected,
+ long lineNumber, std::string
fileName )
+{
+ if (expected == actual) return;
+
+ char tmp[TMP_SIZE];
+ std::string s;
+ s = "'" + actualExpr + "' is ";
+ sprintf( tmp, "%p", actual );
+ s += tmp;
+ s += " instead of expected ";
+ sprintf( tmp, "%p\n\n", expected );
+ s += tmp;
+ throw CppUnit::Exception (s, CppUnit::SourceLine(fileName, lineNumber));
+
+}
+void philAssertNotEquals( std::string actualExpr, void * actual, void *
notExpected,
+ long lineNumber, std::string
fileName )
+{
+ if (notExpected != actual) return;
+
+ char tmp[TMP_SIZE];
+ std::string s;
+ s = "'" + actualExpr + "' should not be ";
+ sprintf( tmp, "%p\n\n", actual );
+ s += tmp;
+ throw CppUnit::Exception (s, CppUnit::SourceLine(fileName, lineNumber));
+
+}
// ------------------- std::string
Index: camino/src/common/PhilAsserts.h
diff -u camino/src/common/PhilAsserts.h:1.3 camino/src/common/PhilAsserts.h:1.4
--- camino/src/common/PhilAsserts.h:1.3 Tue Jan 28 16:54:27 2003
+++ camino/src/common/PhilAsserts.h Mon Mar 3 17:12:05 2003
@@ -82,6 +82,9 @@
void philAssert( std::string actualExpr, bool assertion,
long lineNumber, std::string fileName );
+void philNotAssert( std::string actualExpr, bool assertion,
+ long lineNumber, std::string fileName );
+
// numbers
void philAssertEquals( std::string actualExpr, long actual, long expected,
@@ -91,6 +94,12 @@
void philAssertNotEquals( std::string actualExpr, long actual, long
notExpected,
long lineNumber, std::string
fileName );
+// pointers
+void philAssertEquals( std::string actualExpr, void * actual, void * expected,
+ long lineNumber, std::string
fileName );
+void philAssertNotEquals( std::string actualExpr, void * actual, void *
notExpected,
+ long lineNumber, std::string
fileName );
+
// std::string
void philAssertEquals( std::string actualExpr, std::string actual, std::string
expected,
@@ -155,7 +164,8 @@
#endif // Qt
-#define check( actual ) (philAssert( (#actual),
(actual),__LINE__,__FILE__))
+#define checkAssert( actual ) (philAssert( (#actual),
(actual),__LINE__,__FILE__))
+#define checkNotAssert( actual )(philNotAssert( (#actual),
((actual)),__LINE__,__FILE__))
#define checkEquals( actual, expected ) \
(philAssertEquals ( (#actual), (actual),\
Index: camino/src/common/PhilTestRunner.cpp
diff -u camino/src/common/PhilTestRunner.cpp:1.3
camino/src/common/PhilTestRunner.cpp:1.4
--- camino/src/common/PhilTestRunner.cpp:1.3 Tue Feb 18 13:43:20 2003
+++ camino/src/common/PhilTestRunner.cpp Mon Mar 3 17:12:05 2003
@@ -3,6 +3,8 @@
#include <windows.h>
#endif
+#include <stdio.h>
+
#include <iostream>
#include <cppunit/TestResult.h>
@@ -81,12 +83,20 @@
CppUnit::SourceLine sl = failure.thrownException()->sourceLine();
char s[1024];
+ char errorFormat[1024];
+
+#ifdef WIN32
+ sprintf( errorFormat, "%s", "%s(%d) : %s: " );
+#else
+ sprintf( errorFormat, "%s", "%s:%d: %s: " );
+#endif
+
strcpy( s, "" );
if( sl.isValid() ) {
- sprintf( s, "%s(%d) : %s!\n", sl.fileName().c_str(),
sl.lineNumber(),
+ sprintf( s, errorFormat, sl.fileName().c_str(),
sl.lineNumber(),
failure.isError() ? "Error" : "Failure" );
}
- std::cerr << s << failure.thrownException()->what();
+ std::cerr << s << failure.thrownException()->what() << std::endl;
#ifdef WIN32
OutputDebugStringA( s );
@@ -110,6 +120,8 @@
std::cerr << "Failures : " << m_resultCollector->testFailures()
<< std::endl;
std::cerr << "Errors : " << m_resultCollector->testErrors()
<< std::endl;
}
+ std::cerr << std::endl;
+ exit(0);
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Camino-devel] camino/src/common PhilAsserts.h PhilAsserts.cpp...,
Philippe Fremy <=