Checklist CppUnit and VC 6.0

CppUnit GUI 在 VC6.0 中的使用指南
本文档详细介绍了如何在Microsoft Visual Studio 6.0中配置C++项目以使用CppUnit GUI进行单元测试。主要内容包括设置项目环境、修改Visual Studio选项、使测试运行器GUI在编译后工作以及创建测试用例类。

 

Axel Pospischil, apos@gmx.de, october 2002

Hello to alls lowers of extreme programming and stable code,

 
Download this document:
CppUnit_GUI_under_VC6_0.zip

Introduction
I am a real beginner in coding C++ and XP, so don't ask me big questions.
In a couple of years we can deal with that.

This document describes preparing an MS VS 6.0 C++ project to run with CppUnit.

After searching the internet several days, there is no easy step by step description on how to use the GUI of CppUnit in an project.
So i decided to make one and here it is.

Important before going on:
If you are familiar with unit testing like JUnit:
Read and consider carefully ALL(!) instructions of the „INSTALL-WIN32.txt“ of the cppunit - distribution! You should plan a few hours, a pot of coffee or probably a whole day for this undertaking.
If jou are NOT familiar with unit tests:
Please do yourself a favor and give yourself time to read about it. Very good information you can get on the internet - pages of "JUnit" ( search at http://www.cetus-links.org ) or extreme programming ( http://c2.com/cgi/wiki ).
If you are a real freak and don't need that stuff:
I think you don't need XP, 'cause your code must be perfectly running without any bugs :)
In any case:
Study carefully the ( doxygen generated - ) helpfile of CppUnit. It is not that easy to get the GUI running with an MFC program. Withour an deeply understanding of the CppUnit class hierarchie it is almost impossible. IMO thats the reason, it did not become very usual yet to use unit tests in a c++ environment.


Now have a lot of fun and effort using CppUnit :) and talk to your programming friends and tell them, that it is worth unit testing.

Axel Pospischil


apos@gmx.de
www.apos.de
worms, germany september 2002



Recources:





Preparation

Put cppunit/lib/testrunner.dll an testrunnerd.dll into the /debug folder.

If you don't do this, the testrunner won't start!



1. Changing the project-settings ( c++ & link -tab)

1.1 Fill in the right include-path for the preprocessor tab

preprocessor_tab

1.2. Check the RTTI  at c++ tab

cpp_tab

1.3. Link to the appropriate cppunit and testrunner libs

link_tab

MyPaths ( pay attention: have a WHITESPACE between the paths !):
E:/Programmiersprachen/cppunit/cppunit/lib/cppunitd.lib E:/Programmiersprachen/cppunit/cppunit/lib/testrunnerd.lib




2. Change the visual studio options (path)

2.1 Apply the right include path to the options-dialog

paths_include

MyPath: E:/Programmiersprachen/cppunit/cppunit/include

2.2. Do the same withthe lib path


paths_lib

MyPath: E:/Programmiersprachen/cppunit/cppunit/lib

2.3. Do the same withthe src path

paths_src

MyPath: E:/Programmiersprachen/cppunit/cppunit/src/cppunit

 

2.4. Code Generation
code_genaration

2.5. There has to be a copy of "../lib/testrunnerd.dll" in the actual path

This is done eather by...
  • ...copying it manually to the debug path 
copy path_to_cppunit/lib/testrunnerd.dll path_to_debug_of_your_program

  • or letting the visual studio environment do the work for you after compilation ( don't ignore the "point" at the end of the command ! ).
copy path_to_cppunit/lib/testrunnerd.dll .

copy_testrunnerd.dll

MyPath:  E:/Programmiersprachen/cppunit/cppunit/lib/testrunnerd.dll

That's it for the vs 6.0 environment.

Now lets go to the program code in the testclasses and MFC...




3. Getting the testrunner-GUI working after compilation

Now go foreward and have a look in the „HostApp“ workspace. It describes how to invoke the testrunner-GUI. Add the code between „//++++“ to your MFC-Code.

_____________________________________________
1. MainApp.h:

class CMainApp : public CWinApp
{

[...]

// +++++++++++++++++++++++++
    private:
      void RunUnitTests();
// +++++++++++++++++++++++++

};  /// END of main header file class definition
 
_____________________________________________
2. MainApp.cpp:

#include "stdafx.h"
#include "MainApp.h"

[...] // other includes

// +++++++++++++++++++++++++
    // CppUnit: MFC TestRunner
    #include <cppunit/ui/mfc/TestRunner.h>
   
    // CppUnit: TestFactoryRegistry to retreive the top test
    // suite that contains all registered tests.
    #include <cppunit/extensions/TestFactoryRegistry.h>
// +++++++++++++++++++++++++

[...] // Debug #defines

// +++++++++++++++++++++++++
    static AFX_EXTENSION_MODULE extTestRunner;
// +++++++++++++++++++++++++

[...] // Message-Maps and main construction of "theApp"

BOOL CMainApp::InitInstance()
{

[...]  // Standard init

#ifdef _AFXDLL
    Enable3dControls();            ///  Diese Funktion bei Verwendung von MFC in gemeinsam genutzten DLLs aufrufen
#else
    Enable3dControlsStatic();    ///  Diese Funktion bei statischen MFC-Anbindungen aufrufen
#endif


// +++++++++++++++++++++++++
    RunUnitTests();
// +++++++++++++++++++++++++

CMainDlg dlg;
    m_pMainWnd = &dlg;
    int nResponse = dlg.DoModal();
    if (nResponse == IDOK)

[...]  // Show the main window

} // END of InitInstance()

// +++++++++++++++++++++++++
void CHostAppApp::RunUnitTests()
{
    CppUnit::MfcUi::TestRunner runner;
    runner.addTest( CppUnit::TestFactoryRegistry::getRegistry().makeTest() );
    runner.run();
}
// +++++++++++++++++++++++++




4. Making a test case class

4.1. Just make an ordinary class with the class wizard and devire it from „TestCase“

You can use thef following code as a template ( just find and change „CSomeClass“ to the name of the class you would write a test to.

4.1.1 Header


// CSomeClassTest.h: interface of class CSomeClassTest.
//////////////////////////////////////////////////////////////////////

#ifndef _CSOMECLASSTEST_H_
#define _CSOMECLASSTEST_H_

#include <cppunit/extensions/HelperMacros.h>

/// cppunit test class, main doc text
///
/// more documentation text
class CSomeClassTest : public CppUnit::TestFixture
{
    ///////////////////////////////////////////////
    CPPUNIT_TEST_SUITE( CSomeClassTest );
    /// place here the add_test macros
        // f.e. CPPUNIT_TEST ( test_1 );


    /// END test_suite macros
    CPPUNIT_TEST_SUITE_END();
    ///////////////////////////////////////////////


    ///////////////////////////////////////////////
    /// place here the protected variables for testing
    protected:   


    /// END protected variables for testing   
    ///////////////////////////////////////////////


    ///////////////////////////////////////////////
    /// fixture
    public:
        void tearDown();
        void setUp();

    /// END public methods
    ///////////////////////////////////////////////


    ///////////////////////////////////////////////
    /// protected test methods
    protected:
        // f.e. void test_1();



    /// END test methods
    ///////////////////////////////////////////////

};

#endif // !defined _CSOMECLASSTEST_H_


4.1.2 Implementation


// CSomeClassTest.cpp: implementation of class CSomeClassTest.
//////////////////////////////////////////////////////////////////////


#include "stdafx.h"
#include "CSomeClassTest.h"

//////////////////////////////////////////////////////
/// do the registry of the test_fixture
// #include <cppunit/extensions/HelperMacros.h>
CPPUNIT_TEST_SUITE_REGISTRATION( CSomeClassTest );
//////////////////////////////////////////////////////

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

//////////////////////////////////////////////////////////////////////
// test fixture
//////////////////////////////////////////////////////////////////////

void CSomeClassTest::setUp()
{

}

void CSomeClassTest::tearDown()
{

}

//////////////////////////////////////////////////////////////////////
// test methods
//////////////////////////////////////////////////////////////////////





















提供了基于BP(Back Propagation)神经网络结合PID(比例-积分-微分)控制策略的Simulink仿真模型。该模型旨在实现对杨艺所著论文《基于S函数的BP神经网络PID控制器及Simulink仿真》中的理论进行实践验证。在Matlab 2016b环境下开发,经过测试,确保能够正常运行,适合学习和研究神经网络在控制系统中的应用。 特点 集成BP神经网络:模型中集成了BP神经网络用于提升PID控制器的性能,使之能更好地适应复杂控制环境。 PID控制优化:利用神经网络的自学习能力,对传统的PID控制算法进行了智能调整,提高控制精度和稳定性。 S函数应用:展示了如何在Simulink中通过S函数嵌入MATLAB代码,实现BP神经网络的定制化逻辑。 兼容性说明:虽然开发于Matlab 2016b,但理论上兼容后续版本,可能会需要调整少量配置以适配不同版本的Matlab。 使用指南 环境要求:确保你的电脑上安装有Matlab 2016b或更高版本。 模型加载: 下载本仓库到本地。 在Matlab中打开.slx文件。 运行仿真: 调整模型参数前,请先熟悉各模块功能和输入输出设置。 运行整个模型,观察控制效果。 参数调整: 用户可以自由调节神经网络的层数、节点数以及PID控制器的参数,探索不同的控制性能。 学习和修改: 通过阅读模型中的注释和查阅相关文献,加深对BP神经网络与PID控制结合的理解。 如需修改S函数内的MATLAB代码,建议有一定的MATLAB编程基础。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值