Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
TestCase.cpp
Package: SwordOnline.rar [view]
Upload User: dzyhzl
Upload Date: 2019-04-29
Package Size: 56270k
Code Size: 3k
Category:
Game Server Simulator
Development Platform:
C/C++
- #include <stdexcept>
- #include <cmath>
- #include "TestCase.h"
- #include "TestResult.h"
- #include "estring.h"
- // Create a default TestResult
- TestResult *TestCase::defaultResult ()
- { return new TestResult; }
- // Check for a failed general assertion
- void TestCase::assertImplementation (bool condition,
- std::string conditionExpression,
- long lineNumber,
- std::string fileName)
- {
- if (!condition)
- throw CppUnitException (conditionExpression, lineNumber, fileName);
- }
- // Check for a failed equality assertion
- void TestCase::assertEquals (long expected,
- long actual,
- long lineNumber,
- std::string fileName)
- {
- if (expected != actual)
- assertImplementation (false, notEqualsMessage(expected, actual), lineNumber, fileName);
- }
- // Check for a failed equality assertion
- void TestCase::assertEquals (double expected,
- double actual,
- double delta,
- long lineNumber,
- std::string fileName)
- {
- if (fabs (expected - actual) > delta)
- assertImplementation (false, notEqualsMessage(expected, actual), lineNumber, fileName);
- }
- // Run the test and catch any exceptions that are triggered by it
- void TestCase::run (TestResult *result)
- {
- result->startTest (this);
- setUp ();
- try {
- runTest ();
- }
- catch (CppUnitException e) {
- CppUnitException *copy = new CppUnitException (e);
- result->addFailure (this, copy);
- }
- catch (exception e) {
- result->addError (this, new CppUnitException (e.what ()));
- }
- catch (...) {
- CppUnitException *e = new CppUnitException ("unknown exception");
- result->addError (this, e);
- }
- tearDown ();
- result->endTest (this);
- }
- // A default run method
- TestResult *TestCase::run ()
- {
- TestResult *result = defaultResult ();
- run (result);
- return result;
- }
- // All the work for runTest is deferred to subclasses
- void TestCase::runTest ()
- {
- }
- // Build a message about a failed equality check
- std::string TestCase::notEqualsMessage (long expected, long actual)
- {
- return "expected: " + estring (expected) + " but was: " + estring (actual);
- }
- // Build a message about a failed equality check
- std::string TestCase::notEqualsMessage (double expected, double actual)
- {
- return "expected: " + estring (expected) + " but was: " + estring (actual);
- }