Click here to Skip to main content
15,896,726 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.4K   246   28  
A unit testing framework for eVC++ applications, and its usage.
/******************************************************************************
 * File Name:		WCEUnitMacros.h
 * Description:		This file contains the macros used in WCEUnit.
 * Date:			12/8/2004
 * Author:			AbdulMunaf Chhatra
 * E-Mail:			a.chhatra@popnet.co.in
 *
 * Warning:
 * This code is provided as is without any guarantee or warranty, implicit or 
 * explicit. If this code damages your system then the author is not 
 * responsible for it. This code is free to use with the permission of author. 
 * If you want to use this code then please send me an email at 
 * a.chhatra@popnet.co.in for permission, I will gladly give the permission. 
 * If you make any changes in this code, then feel free to add your name here, 
 * but this notice should appear in this code.
 ******************************************************************************
 * ------------------------------
 * Version History
 * ------------------------------
 * Version	:  1.0
 * Author	:  AbdulMunaf Chhatra
 * Date    	:  12/8/2004
 * Comment 	:  Initial release
 * ------------------------------
 *****************************************************************************/
 
#ifndef __WCEUNIT_HELPER_MACROS__
#define __WCEUNIT_HELPER_MACROS__

//*************************************************************
//Macros for the creating test suite.

//Initialization of test suite.
#define WCEUNIT_TESTSUITE_INIT(testSuite)							\
void CreateTestSuite()												\
{																	\
    SetTestSuiteName(#testSuite);
	
//End of test suite.
#define WCEUNIT_TESTSUITE_END()										\
	return;															\
}
	

//Adding test case to test suite.
#define WCEUNIT_ADD_TESTCASE(testCase)				                \
	AddTestCase((FPTR)testCase,#testCase);



#define WCEUNIT_ADD_TESTCASE_EXCEPTION( testCase,testException)     \
	AddTestCase((FPTR)testCase, #testCase, TRUE, #testException);



//*************************************************************

/*
 *	Macros for WCEUnit assertion.
 */

#define WCEUNIT_ASSERT(condition)									\
    m_bAssert = (condition);                                        \
    if(!m_bAssert)                                                  \
    {                                                               \
        m_dLineNumber= __LINE__;									\
	    m_strFileName = __FILE__;									\
        m_strExpression = #condition;                               \
        return;                                                     \
    }


#define WCEUNIT_ASSERT_FAIL(condition)							    \
    m_bAssert = !(condition);                                       \
    if(!m_bAssert)                                                  \
    {                                                               \
        m_dLineNumber= __LINE__;									\
	    m_strFileName = __FILE__;									\
        m_strExpression = #condition;                               \
        return;                                                     \
    }


#define WCEUNIT_ASSERT_EQUALS(testValue, compValue)                 \
	m_bAssert = ((testValue) == (compValue));                       \
    if(!m_bAssert)                                                  \
    {                                                               \
        m_dLineNumber = __LINE__;                                   \
	    m_strFileName = __FILE__;                                   \
        m_strExpression = #testValue;                               \
        m_strExpression = m_strExpression + _T(", ");               \
        m_strExpression = m_strExpression + #compValue;             \
        return;                                                     \
    }


#define WCEUNIT_DOUBLE_EQUALS(testValue, compValue)                 \
	m_bAssert = ((double)(testValue) == (double)(compValue));       \
    if(!m_bAssert)                                                  \
    {                                                               \
        m_dLineNumber = __LINE__;                                   \
	    m_strFileName = __FILE__;                                   \
        m_strExpression = #testValue;                               \
        m_strExpression = m_strExpression + _T(", ");               \
        m_strExpression = m_strExpression + #compValue;             \
        return;                                                     \
    }


#define WCEUNIT_DOUBLE_BETWEEN(testValue, minValue, maxValue)       \
	m_bAssert = ((double)(testValue) >=                             \
                 (double)(minValue)  &&                             \
                 (double)(testValue) <=                             \
                 (double)(maxValue));                               \
    if(!m_bAssert)                                                  \
    {                                                               \
        m_dLineNumber = __LINE__;                                   \
	    m_strFileName = __FILE__;                                   \
        m_strExpression = #testValue;                               \
        m_strExpression = m_strExpression + _T(", ");               \
        m_strExpression = m_strExpression + #minValue;              \
        m_strExpression = m_strExpression + _T(", ");               \
        m_strExpression = m_strExpression + #maxValue;              \
        return;                                                     \
    }


#endif //__WCEUNIT_HELPER_MACROS__

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