Click here to Skip to main content
15,886,783 members
Articles / Mobile Apps

Unit Testing Framework for eVC++ Applications

Rate me:
Please Sign up or sign in to vote.
4.63/5 (13 votes)
17 Oct 2004CPOL6 min read 85.2K   246   28  
A unit testing framework for eVC++ applications, and its usage.
// TestComplex1.cpp: implementation of the CTestComplex class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "TestComplex.h"
#include "TestComplex1.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CTestComplex::CTestComplex()
{

}

CTestComplex::~CTestComplex()
{

}

void CTestComplex::testAdd()
{
	CComplex temp;
	temp = *m_p1 + *m_p2;
	WCEUNIT_ASSERT(CComplex(30, 70) == temp);
}

void CTestComplex::testEqual()
{
	CComplex temp2;			//Below test should fail.
	WCEUNIT_ASSERT_FAIL(temp2 == *m_p3);

	CComplex temp1;			//Below test should pass.
	temp1 = *m_p1 + *m_p2;
	WCEUNIT_ASSERT_EQUALS(temp1, *m_p3);

	//To check the equality of the real and imaginary members.
	WCEUNIT_DOUBLE_EQUALS(temp1.GetReal(), m_p3->GetReal());
	WCEUNIT_DOUBLE_EQUALS(temp1.GetImaginary(), m_p3->GetImaginary());	
}

void CTestComplex::testException()
{
	//This fuction is only to demonstrate the exception test.
	//It throws CUserException. This test will fail as the expected exception
	//is CFileException.

	CUserException e;
	THROW(&e);
}

void CTestComplex::InitializeTest()
{
	m_p1 = new CComplex(10, 20);
	m_p2 = new CComplex(20, 50);
	m_p3 = new CComplex(30, 70);
}

void CTestComplex::CleanUpTest()
{
	delete m_p1;
	delete m_p2;
	delete m_p3;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
India India
A person who like to know about new things, peolple and make frineds. I strarted programming in 2000 with fortran but my first love in programming is C++. Also programmed in VB, MFC and for Windows CE.

Graduated in Physics and done masteres in Computer application. Physics and astronomy are my area of intrest. Karate is also one of my hobbies, BTW I am a Black Belt in Karate.

Comments and Discussions