安装
将cppunit的include拷贝到你的include目录下; 编译cppunit, cppunit_dll, 最后应该包含4个.lib, 两个.dll 将lib文件拷贝到你的lib目录下 将dll文件拷贝到你的bin目录下,这个目录应该在环境变量PATH中。 如果使用MFC进行GUI的testrunner,还需要编译testrunner项目,然后 将对应的4个lib文件拷贝到你的lib目录 将对应的4个dll文件拷贝到你的bin目录下 安装 AddingUnitTestMethod.dsm 到你的 msdev 6.0下面是AddingUnitTestMethod.dsm 的代码,我修改了一下,添加了一个addSuiteMethod的方法。
'Made by bloodchen
'add by [email protected]
sub AddTestSuiteClass()
On Error Resume Next
dim proj_path,ext,pos,proj_dir,MyCppFile,MyCppName,MyHFile,MyHName,ClassName,HText,CPPText
proj_path = ActiveProject.fullname
ext = ""
pos = len (proj_path)
Do While ext <> "\"
ext = Mid(proj_path, pos, 1)
pos = pos -1
Loop
proj_dir = left(proj_path, pos+1)
ClassName=InputBox("Enter the Suite name[not include Suite]:", "Suite Name")
if ActiveProject.Type <> "Build" then
MsgBox "This project is not valid. Ending macro."
Exit Sub
end if
if (len(ClassName) <= 0) then
MsgBox "Invalid suite name. Ending macro."
Exit Sub
end if
' ClassName="CTest"
MyCppName=proj_dir+ClassName+"Suite.cpp"
MyHName=proj_dir+ClassName+"Suite.h"
ActiveProject.AddFile MyCppName
ActiveProject.AddFile MyHName
Documents.Add "Text"
ActiveDocument.Selection.StartOfDocument
HText= "#ifndef _"+ClassName+"_SUITE_INCLUDE_H_"+VbCrLf& _
"#define _"+ClassName+"_SUITE_INCLUDE_H_"+VbCrLf& _
""+VbCrLf& _
"#include <cppunit\testSuite.h>"+VbCrLf& _
"#include <string>"+VbCrLf& _
"namespace "+ClassName+"Suite"+VbCrLf& _
"{"+VbCrLf& _
" inline std::string name()"+VbCrLf& _
" {"+VbCrLf& _
" return "+chr(34)+ClassName+chr(34)+";"+VbCrLf& _
" }"+VbCrLf& _
""+VbCrLf& _
" CppUnit::Test *suite();"+VbCrLf& _
""+VbCrLf& _
"};"+VbCrLf& _
"#endif"+VbCrLf
ActiveDocument.Selection = HText
ActiveDocument.Save MyHName
' WriteFile MyHName,HText
Documents.Add "Text"
ActiveDocument.Selection.StartOfDocument
CPPText = "#include "+chr(34)+"stdafx.h"+chr(34)+VbCrLf& _
"#include <cppunit/extensions/TestFactoryRegistry.h>"+VbCrLf& _
"#include "+chr(34)+ClassName+"Suite.h" +chr(34)+VbCrLf& _
""+VbCrLf& _
"namespace "+ClassName+"Suite"+VbCrLf& _
"{"+VbCrLf& _
" CppUnit::Test* suite()"+VbCrLf& _
" {"+VbCrLf& _
" CppUnit::TestFactoryRegistry ®istry = "+VbCrLf& _
" CppUnit::TestFactoryRegistry::getRegistry(name());"+VbCrLf& _
""+VbCrLf& _
" return registry.makeTest();"+VbCrLf& _
" }"+VbCrLf& _
"}"
' WriteFile MyCppName,CPPText
ActiveDocument.Selection = CPPText
ActiveDocument.Save MyCppName
End sub
Sub AddTestClass()
On Error Resume Next
dim proj_path,ext,pos,proj_dir,MyCppFile,MyCppName,MyHFile,MyHName,ClassName,HText,CPPText
proj_path = ActiveProject.fullname
ext = ""
pos = len (proj_path)
Do While ext <> "\"
ext = Mid(proj_path, pos, 1)
pos = pos -1
Loop
proj_dir = left(proj_path, pos+1)
ClassName=InputBox("Enter the class name:", "Class Name")
if ActiveProject.Type <> "Build" then
MsgBox "This project is not valid. Ending macro."
Exit Sub
end if
if (len(ClassName) <= 0) then
MsgBox "Invalid class name. Ending macro."
Exit Sub
end if
' ClassName="CTest"
MyCppName=proj_dir+ClassName+".cpp"
MyHName=proj_dir+ClassName+".h"
ActiveProject.AddFile MyCppName
ActiveProject.AddFile MyHName
Documents.Add "Text"
ActiveDocument.Selection.StartOfDocument
HText= "#ifndef _"+ClassName+"_TEST_INCLUDE_H_"+VbCrLf& _
"#define _"+ClassName+"_TEST_INCLUDE_H_"+VbCrLf& _
""+VbCrLf& _
"#include <cppunit\testcase.h>"+VbCrLf& _
"#include <cppunit\extensions\HelperMacros.h>"+VbCrLf& _
"class "+ClassName+":public CppUnit::TestCase"+VbCrLf& _
"{"+VbCrLf& _
" CPPUNIT_TEST_SUITE( "+ClassName+" );"+VbCrLf& _
" CPPUNIT_TEST_SUITE_END();"+VbCrLf& _
"public:"+VbCrLf& _
" "+ClassName+"();"+VbCrLf& _
" virtual ~"+ClassName+"();"+VbCrLf& _
"};"+VbCrLf& _
"#endif"+VbCrLf
ActiveDocument.Selection = HText
ActiveDocument.Save MyHName
' WriteFile MyHName,HText
Documents.Add "Text"
ActiveDocument.Selection.StartOfDocument
CPPText = "#include "+chr(34)+"stdafx.h"+chr(34)+VbCrLf& _
"#include "+chr(34)+ClassName+".h"+chr(34)+VbCrLf& _
"#include "+chr(34)+"xxxSuite.h"+chr(34)+VbCrLf& _
""+VbCrLf& _
""+VbCrLf& _
"CPPUNIT_TEST_SUITE_NAMED_REGISTRATION("+ClassName+ ", xxxSuite::name() );"+VbCrLf& _
""+VbCrLf& _
""+VbCrLf& _
ClassName+"::"+ClassName+"()"+VbCrLf& _
"{"+VbCrLf& _
"}"+VbCrLf& _
""+VbCrLf& _
""+VbCrLf& _
ClassName+"::~"+ClassName+"()"+VbCrLf& _
"{"+VbCrLf& _
"}"
' WriteFile MyCppName,CPPText
ActiveDocument.Selection = CPPText
ActiveDocument.Save MyCppName
End Sub
Sub ToggleHandCPP()
'DESCRIPTION: Opens the .cpp or .h file for the current document.
'Toggles between the .cpp & .h file
ext = ActiveDocument.FullName
If ext = "" Then
msgbox ("Error, not a .cpp or .h file")
exit sub
End If
DocName = UCase(ext)
If Right(DocName,4) = ".CPP" Then
fn = left(DocName, Len(DocName)-3) & "h"
ElseIf Right(DocName,2) = ".H" Then
fn = Left(DocName, Len(DocName)-1) & "cpp"
Else
msgbox ("Error, not a .cpp or a .h file")
exit sub
End If
'msgbox (fn)
on error resume next
Documents.Open (fn)
End Sub
Sub AddTestMethod()
strHpt = ActiveDocument.FullName
if right(strHpt,3) = "CPP" Or right (strHpt,3) = "cpp" Then
ActiveDocument.Selection.SelectLine
strText = ActiveDocument.Selection.Text
if (Instr(strText, "::" ) = 0) Then
MsgBox("Line not valid !!")
Exit Sub
End If
else
exit sub
end if
pos = Instr(strText, "::")
strName = Right(strText, (Len(strText) - (pos+1)))
pos = Instr(strName,"(")
strName = Left(strName,pos-1)
strClass = Left(strText,pos - 1)
while (instr(strClass, " ") > 0)
pos = instr(strClass, " ")
strTyp = strTyp & Left(strClass, pos)
strClass = Right(strClass, Len(strClass) - (pos) )
wend
ToggleHandCPP
ActiveDocument.Selection.SelectAll
strHead = ActiveDocument.Selection.Text
if (instr(strHead,strClass) = 0) Then
MsgBox(" Can't find class " & strClass & " !!")
ToggleHandCPP
Exit Sub
End If
ActiveDocument.Selection.EndOfDocument
lineBottom = ActiveDocument.Selection.CurrentLine
ActiveDocument.Selection.StartOfDocument
ActiveDocument.Selection.StartOfLine
ActiveDocument.Selection.SelectLine
strLine = ActiveDocument.Selection.Text
while (instr(strLine, strName) = 0 And ActiveDocument.Selection.CurrentLine <> lineBottom)
ActiveDocument.Selection.StartOfLine
ActiveDocument.Selection.LineDown dsMove
ActiveDocument.Selection.SelectLine
strLine = ActiveDocument.Selection.Text
Wend
if (ActiveDocument.Selection.CurrentLine < lineBottom) Then
if( instr(strLine, "CPPUNIT_TEST" ) <> 0 )Then
ToggleHandCPP
Exit Sub
end if
End If
ActiveDocument.Selection.StartOfDocument
ActiveDocument.Selection.StartOfLine
ActiveDocument.Selection.SelectLine
strLine = ActiveDocument.Selection.Text
while (instr(strLine, "CPPUNIT_TEST_SUITE_END();" ) = 0 And ActiveDocument.Selection.CurrentLine <> lineBottom)
ActiveDocument.Selection.StartOfLine
ActiveDocument.Selection.LineDown dsMove
ActiveDocument.Selection.SelectLine
strLine = ActiveDocument.Selection.Text
Wend
if (ActiveDocument.Selection.CurrentLine < lineBottom) Then
ActiveDocument.Selection.EndOfLine
ActiveDocument.Selection.LineUp
ActiveDocument.Selection.EndOfLine
ActiveDocument.Selection.NewLine
ActiveDocument.Selection = "CPPUNIT_TEST( "&strName&" );"
else
MsgBox("CPPUNIT_TEST_SUITE_END not found")
end if
ToggleHandCPP
End Sub
本文地址:http://com.8s8s.com/it/it25882.htm