Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 编程语言 > C/C++ > a perl script automatic make a cppunit test case
【标  题】:a perl script automatic make a cppunit test case
【关键字】:perl,script,automatic,make,cppunit,test,case
【来  源】:http://www.cublog.cn/u/7391/showart.php?id=100486

a perl script automatic make a cppunit test case

Your Ad Here

a perl script automatic make a cppunit test case file


还比较粗糙,最近不用cpp,暂时不改进了。
#! /usr/bin/env perl
use warnings;
use strict;
my $DEBUG = 1;
my @methods;
my $fileName = shift;
unless ($fileName)
{
&Usage;
exit;
}
open F, $fileName or die "can not open file: $fileName: $!\n";


my $className = $fileName;
$className =~ s/\.\w+//;
warn "class name is $className" if $DEBUG;

&getMethods;
if (-e "T$className.H")
{
print "T$className.H exists\n";
exit;
}
open T, ">T$className.H" or die "can not create T$className:$!\n";
select T;
my $ucClassName = uc($className);
print "#ifndef T$ {ucClassName}_H\n";
print "#define T$ {ucClassName}_H\n";
print "\n";
print "\n";
print "#include \"$className.H\"\n";
print "#include \n";
print "#include \n";
print "#include \n";
print "#include \n";
print "#include \n";
print "\n";
print "class T$className : public CppUnit::TestFixture { \n";
print "private:\n";
print " //TODO: Define test target here:\n";
print "public: \n";
print "\n";
print " void setUp(){\n";
print "//TODO: initialize test target here: \n";
print " }\n";
print " \n";
print " void tearDown(){\n";
print "//TODO: release test resource here:\n";
print " }\n";
print "\n";


foreach (@methods)
{
print " void test_$_(){\n";
print " // TODO: implement test here:\n";
print " }\n";
}

print " static CppUnit::Test *suite(){\n";
print " CppUnit::TestSuite *suiteOfTests = new CppUnit::TestSuite(\"T${className}\");\n";

foreach (@methods)
{

print " suiteOfTests->addTest(new CppUnit::TestCaller\n";
print " (\"test_$_\",
&T$ {className}::test_$_));\n";
}

print " return suiteOfTests;\n";
print " }\n";
print "};\n";
print "#endif\n";
close T;

open MAIN, ">Main.C" or die "can not create Main.C:$!\n";
select MAIN;
print "#include \n";
print "#include \"T$ {className}.H\"\n";
print "int main()\n";
print "{\n";
print " CppUnit::TextUi::TestRunner runner;\n";
print " runner.addTest(T$ {className}::suite());\n";
print " runner.run();\n";
print " return 0;\n";
print "}\n";
close MAIN;

open MAKEFILE, ">Makefile" or die "can not create Makefile:$!\n";
select MAKEFILE;
print "SUFFIXES= .C .o\n";
print "\n";
print ".SUFFIXES:\n";
print ".SUFFIXES: .C .o\n";
print "\n";
print "LIB=-L/home/tiw/lib -lcppunit -ldl\n";
print "INCLUDE=-I/home/tiw/include\n";
print "CC=g++\n";
print "OBJECTS= Main.o T$ {className}.o $ {className}.o\n";
print "\n";
print "all: Main\n";
print "\n";
print ".C.o:\n";
print " \$(CC) -c \$(INCLUDE) \$<\n";
print "\n";
print "Main: \$(OBJECTS)\n";
print " \$(CC) -o Main \$(LIB) \$(OBJECTS)\n";
print "\n";
print "clean:\n";
print " rm -f Main *.o\n";
print "\n";
close MAKEFILE;

sub getMethods
{
print "class name : $className\n";
while ()
{
my $line = $_;
if ($line =~ m/$className\:\:(\w+)\(/)
{
push @methods, $1;
}
}
} # end getMethods
sub Usage{
print "Usage:\n";
print " makeTest.pl ClassName\n";
print " in the file ClassName target methods are defined\n";
print " test file is saved into TclassName.H\n";
print "Example:\n";
print " makeTest.pl ModellAgent.C\n";
print " test file is saved into TModellAgent.C\n";
}
IBM DB2 日常维护汇总(基础):【上一篇】
静态链接库:【下一篇】
【相关文章】
  • eclips和active perl建立perl开发环境
  • javascript数组运用-解决多个单选框状态检查
  • Makefile Introduction
  • javascript代码收集
  • 如何用javascript来实现autocomplete
  • test 181 要点
  • Makefile的编写
  • 侃侃JavaScript Template
  • SVG + Javascript + ASP.NET + WebService开发楼宇管理系统(六)
  • javascript触发事件汇总
  • 【随机文章】
  • 理想的10-Gbit/sec接口标准简化元件互连
  • JAVA优质代码编写的30条可行建议
  • MIDP2.0中对图片象素级处理(1)
  • 传奇 我打魔龙教主的一点经验
  • 使用PWM得到精密的输出电压
  • 附录 A PHP 函数索引 二
  • [java]RMI客户端在服务器双网卡或者多网卡情况下无法连接问题
  • Delete不了(SQL)
  • 將資料直接輸出到檔案
  • FreeBSD下网络备份Net Backup System的实现
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 bbb软讯网络 All Rigths Reserved.