51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

查看: 3679|回复: 8
打印 上一主题 下一主题

关于CPPUNIT的一句话,我看不懂!

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2006-5-16 09:58:35 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
下面是一段改进代码,可是 有一句前面的话我看不懂,不知道怎么理解才好,而且我电脑上找不到这个文件夹的 :
  将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

bloodchen@hotmail.com

add by edsoncy@yahoo.com.cn
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 &registry = +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()
DEs criptION: 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( Cant 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

红子显示的就是了,他说的文件 我在电脑上找不到的啊,很郁闷,我的毕业设计就靠他了!
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

该用户从未签到

2#
发表于 2006-5-16 18:04:54 | 只看该作者
*.dsm 这个是VC60的宏文件。

1、把上面的代码保存为xxx.dsm文件,保存到 C:\Program Files\Microsoft Visual Studio\Common\MSDev98\Macro目录下。

2、Tools->Customize->Add-ins and Macro Files,选中上述文件就行了,正确的话应该出来一个新工具栏。
回复 支持 反对

使用道具 举报

该用户从未签到

3#
 楼主| 发表于 2006-5-16 18:56:25 | 只看该作者
太谢谢拉哦。。。。谢谢
回复 支持 反对

使用道具 举报

该用户从未签到

4#
 楼主| 发表于 2006-5-16 19:37:53 | 只看该作者
可是怎么保存啊我不会 啊 能不能麻烦帮助一下谢谢
回复 支持 反对

使用道具 举报

该用户从未签到

5#
 楼主| 发表于 2006-5-16 19:38:09 | 只看该作者
实在感谢实在感谢
回复 支持 反对

使用道具 举报

该用户从未签到

6#
发表于 2006-5-16 21:01:45 | 只看该作者
用EditPlus之类的文本编辑器都可以保存啊
不过,更简单的方法是:
Tools -> Macro 自己建一个宏文件,点击Edit,然后把代码贴过来就行了。
回复 支持 反对

使用道具 举报

该用户从未签到

7#
 楼主| 发表于 2006-5-17 20:13:15 | 只看该作者
郁闷啊 代码居然显示有错误  我靠
回复 支持 反对

使用道具 举报

该用户从未签到

8#
发表于 2006-5-17 21:24:53 | 只看该作者
这个就要慢慢调试了,我可没空帮你调试。

前面三行是注释,每行前面加上’

你这些宏代码应该只是在VC上加个工具栏,并不是必须的。


看你搞得那么麻烦,还是建议你用Visual Unit吧。VU 要简单易用得多,全中文的界面和帮助,免费的个人版功能也很好啊,仅仅自动生成测试代码这一项,就至少可以省下一半的单元测试时间。

[ 本帖最后由 VisualUnit 于 2006-5-17 21:35 编辑 ]
回复 支持 反对

使用道具 举报

该用户从未签到

9#
 楼主| 发表于 2006-5-19 14:35:10 | 只看该作者
Made by bloodchen

bloodchen@hotmail.com

add by edsoncy@yahoo.com.cn
??这些是注释? 谢谢哈 只是我的是毕业设计。。。只有做这个了呵呵 题目已经定了呵呵 你说的饿那个工具真的很好用很好用的
回复 支持 反对

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-5-6 11:18 , Processed in 0.083197 second(s), 25 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

快速回复 返回顶部 返回列表