C++课程设计《酒店客人课程管理系统统》的框架是怎么样写的?

你必须非常努力,才能看起来毫不费力!——共勉
精彩在线课程 >>
gtest,英文全称是Google C++ Testing Framework,即谷歌C++测试框架。是从谷歌内部诞生并受到业界追捧的一个非常优秀的测试框架,支持如自动发现测试、自定义断言、死亡测试、自动报告等诸多功能。
本文就来详细介绍gtest的使用。
一、gtest源码下载
/p/googletest/downloads/list
目前有两个版本的gtest源代码。
二、Linux下安装并使用gtest
1)使用unzip命令解压完后,在linux上通过如下命令执行编译安装
./configure
sudo make install
./configuremakesudo make install
但在执行sudo make install时,会提示类似如下错误:
echo “‘make install’ is dangerous and not supported. Instead, see README for how to integrate Google Test into your build system.” ‘make install’ is dangerous and not supported. Instead, see README for how to integrate Google Test into your build system. false
也就是提醒我们去安装README里面的提示进行安装。
事实上,我们使用make install,会在机器上安装一份编译好的gtest库,以后测试时只需要链接该库就可以了(linux下的library大多数都采用这种方式)。这样虽然方便,但会带来一个问题:每个人使用gtest时,可能需要不同的编译选项,如果使用别人预先编译好的gtest库,可能会造成混乱。所以每个人在编译自己的测试工程时,需要自己编译自己需要的gtest库。因此现在并不提供make install。
README文档有点长,如果你觉得麻烦,请继续往下看。
三、google C++测试框架gtest使用实例
事实上,将安装包解压后,我们就能看到里面有一个samples的文件夹和make文件夹,而这两个文件夹,给出来如何使用gtest的具体实例。进入make文件夹后,你能看到里面有一个Makefile文件,这个Makefile文件将gtest的具体用法说明的清清楚楚。Makefile具体文件如下:
# A sample Makefile for building Google Test and using it in user
Please tweak it to suit your environment and project.
# may want to move it to your project's root directory.
# SYNOPSIS:
make [all]
- makes everything.
make TARGET - makes the given target.
make clean
- removes all files generated by make.
# Please tweak the following variable definitions as needed by your
# project, except GTEST_HEADERS, which you can use in your own targets
# but shouldn't modify.
# Points to the root of Google Test, relative to where this file is.
# Remember to tweak this if you move this file.
GTEST_DIR = ..
# Where to find user code.
USER_DIR = ../samples
# Flags passed to the preprocessor.
# Set Google Test's header directory as a system directory, such that
# the compiler doesn't generate warnings in Google Test headers.
CPPFLAGS += -isystem $(GTEST_DIR)/include
# Flags passed to the C++ compiler.
CXXFLAGS += -g -Wall -Wextra -pthread
# All tests produced by this Makefile.
Remember to add new tests you
# created to the list.
TESTS = sample1_unittest
# All Google Test headers.
Usually you shouldn't change this
# definition.
GTEST_HEADERS = $(GTEST_DIR)/include/gtest/*.h \
$(GTEST_DIR)/include/gtest/internal/*.h
# House-keeping build targets.
all : $(TESTS)
rm -f $(TESTS) gtest.a gtest_main.a *.o
# Builds gtest.a and gtest_main.a.
# Usually you shouldn't tweak such internal variables, indicated by a
# trailing _.
GTEST_SRCS_ = $(GTEST_DIR)/src/*.cc $(GTEST_DIR)/src/*.h $(GTEST_HEADERS)
# For simplicity and to avoid depending on Google Test's
# implementation details, the dependencies specified below are
# conservative and not optimized.
This is fine as Google Test
# compiles fast and for ordinary users its source rarely changes.
gtest-all.o : $(GTEST_SRCS_)
$(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c \
$(GTEST_DIR)/src/gtest-all.cc
gtest_main.o : $(GTEST_SRCS_)
$(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c \
$(GTEST_DIR)/src/gtest_main.cc
gtest.a : gtest-all.o
$(AR) $(ARFLAGS) $@ $^
gtest_main.a : gtest-all.o gtest_main.o
$(AR) $(ARFLAGS) $@ $^
# Builds a sample test.
A test should link with either gtest.a or
# gtest_main.a, depending on whether it defines its own main()
# function.
sample1.o : $(USER_DIR)/sample1.cc $(USER_DIR)/sample1.h $(GTEST_HEADERS)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/sample1.cc
sample1_unittest.o : $(USER_DIR)/sample1_unittest.cc \
$(USER_DIR)/sample1.h $(GTEST_HEADERS)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/sample1_unittest.cc
sample1_unittest : sample1.o sample1_unittest.o gtest_main.a
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
# A sample Makefile for building Google Test and using it in user# tests.&&Please tweak it to suit your environment and project.&&You# may want to move it to your project's root directory.## SYNOPSIS:##&& make [all]&&- makes everything.#&& make TARGET - makes the given target.#&& make clean&&- removes all files generated by make.&# Please tweak the following variable definitions as needed by your# project, except GTEST_HEADERS, which you can use in your own targets# but shouldn't modify.&# Points to the root of Google Test, relative to where this file is.# Remember to tweak this if you move this file.GTEST_DIR = ..&# Where to find user code.USER_DIR = ../samples&# Flags passed to the preprocessor.# Set Google Test's header directory as a system directory, such that# the compiler doesn't generate warnings in Google Test headers.CPPFLAGS += -isystem $(GTEST_DIR)/include&# Flags passed to the C++ compiler.CXXFLAGS += -g -Wall -Wextra -pthread&# All tests produced by this Makefile.&&Remember to add new tests you# created to the list.TESTS = sample1_unittest&# All Google Test headers.&&Usually you shouldn't change this# definition.GTEST_HEADERS = $(GTEST_DIR)/include/gtest/*.h \&&&&&&&&&&&&&&&&$(GTEST_DIR)/include/gtest/internal/*.h&# House-keeping build targets.&all : $(TESTS)&clean :&&&&rm -f $(TESTS) gtest.a gtest_main.a *.o&# Builds gtest.a and gtest_main.a.&# Usually you shouldn't tweak such internal variables, indicated by a# trailing _.GTEST_SRCS_ = $(GTEST_DIR)/src/*.cc $(GTEST_DIR)/src/*.h $(GTEST_HEADERS)&# For simplicity and to avoid depending on Google Test's# implementation details, the dependencies specified below are# conservative and not optimized.&&This is fine as Google Test# compiles fast and for ordinary users its source rarely changes.gtest-all.o : $(GTEST_SRCS_)&&&&$(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c \&&&&&&&&&&&&$(GTEST_DIR)/src/gtest-all.cc&gtest_main.o : $(GTEST_SRCS_)&&&&$(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c \&&&&&&&&&&&&$(GTEST_DIR)/src/gtest_main.cc&gtest.a : gtest-all.o&&&&$(AR) $(ARFLAGS) $@ $^&gtest_main.a : gtest-all.o gtest_main.o&&&&$(AR) $(ARFLAGS) $@ $^&# Builds a sample test.&&A test should link with either gtest.a or# gtest_main.a, depending on whether it defines its own main()# function.&sample1.o : $(USER_DIR)/sample1.cc $(USER_DIR)/sample1.h $(GTEST_HEADERS)&&&&$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/sample1.cc&sample1_unittest.o : $(USER_DIR)/sample1_unittest.cc \&&&&&&&&&&&&&&&&&&&& $(USER_DIR)/sample1.h $(GTEST_HEADERS)&&&&$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/sample1_unittest.cc&sample1_unittest : sample1.o sample1_unittest.o gtest_main.a&&&&$(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@
这个Makefile是samplies文件夹下源代码的自动化编译脚本。因此,我们需要做的事情是执行如下命令:首先切换到make目录下,然后执行make命令。
Code123.cc$ cd make
Code123.cc$ make
Code123.cc$ cd makeCode123.cc$ make
执行完后,就会自动编译出单元测试可执行程序sample1_unittest。
gtest官方给出的示例程序的运行结果如下:
Code123.cc$ls
gtest-all.o
gtest_main.a
gtest_main.o
sample1_unittest
sample1_unittest.o
Code123.cc$./sample1_unittest
Running main() from gtest_main.cc
[==========] Running 6 tests from 2 test cases.
[----------] Global test environment set-up.
[----------] 3 tests from FactorialTest
] FactorialTest.Negative
OK ] FactorialTest.Negative (0 ms)
] FactorialTest.Zero
OK ] FactorialTest.Zero (0 ms)
] FactorialTest.Positive
OK ] FactorialTest.Positive (0 ms)
[----------] 3 tests from FactorialTest (1 ms total)
[----------] 3 tests from IsPrimeTest
] IsPrimeTest.Negative
OK ] IsPrimeTest.Negative (0 ms)
] IsPrimeTest.Trivial
OK ] IsPrimeTest.Trivial (0 ms)
] IsPrimeTest.Positive
OK ] IsPrimeTest.Positive (0 ms)
[----------] 3 tests from IsPrimeTest (0 ms total)
[----------] Global test environment tear-down
[==========] 6 tests from 2 test cases ran. (2 ms total)
] 6 tests.
123456789101112131415161718192021222324252627
Code123.cc$lsgtest-all.o&&gtest_main.a&&gtest_main.o&&Makefile&&sample1.o&&sample1_unittest&&sample1_unittest.oCode123.cc$./sample1_unittest Running main() from gtest_main.cc[==========] Running 6 tests from 2 test cases.[----------] Global test environment set-up.[----------] 3 tests from FactorialTest[ RUN&&&&&&] FactorialTest.Negative[&&&&&& OK ] FactorialTest.Negative (0 ms)[ RUN&&&&&&] FactorialTest.Zero[&&&&&& OK ] FactorialTest.Zero (0 ms)[ RUN&&&&&&] FactorialTest.Positive[&&&&&& OK ] FactorialTest.Positive (0 ms)[----------] 3 tests from FactorialTest (1 ms total)&[----------] 3 tests from IsPrimeTest[ RUN&&&&&&] IsPrimeTest.Negative[&&&&&& OK ] IsPrimeTest.Negative (0 ms)[ RUN&&&&&&] IsPrimeTest.Trivial[&&&&&& OK ] IsPrimeTest.Trivial (0 ms)[ RUN&&&&&&] IsPrimeTest.Positive[&&&&&& OK ] IsPrimeTest.Positive (0 ms)[----------] 3 tests from IsPrimeTest (0 ms total)&[----------] Global test environment tear-down[==========] 6 tests from 2 test cases ran. (2 ms total)[&&PASSED&&] 6 tests.
四、如何使用gtest对自己的程序进行单元测试?
有了第三步的样例,我们只需要仿照samples文件夹中的样例,编写我们自己的单元测试用例便可。(注意第三步中Makefile文件与你要测试的源文件没在同一个文件夹下,如果你的源代码存放位置有变化,请修改如下语句中USER_DIR的值。
# Where to find user code.
USER_DIR = ../samples
# Where to find user code.USER_DIR = ../samples
总结:从上面的使用可以看出,我们使用谷歌C++单元测试框架gtest时,并不需要预先编译gtest框架,只需要在测试代码中通过引用gtest源文件来使用gtest进行单元测试。
or分享 (0)c++课程设计(参考文档----公司人员管理系统)_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
评价文档:
喜欢此文档的还喜欢
c++课程设计(参考文档----公司人员管理系统)
C​+​+​课​程​设​计​ ​ ​公​司​人​员​管​理​系​统
阅读已结束,如果下载本文需要使用
想免费下载本文?
把文档贴到Blog、BBS或个人站等:
普通尺寸(450*500pix)
较大尺寸(630*500pix)
你可能喜欢扫扫二维码,随身浏览文档
手机或平板扫扫即可继续访问
c++课程设计
举报该文档为侵权文档。
举报该文档含有违规或不良信息。
反馈该文档无法正常浏览。
举报该文档为重复文档。
推荐理由:
将文档分享至:
分享完整地址
文档地址:
粘贴到BBS或博客
flash地址:
支持嵌入FLASH地址的网站使用
html代码:
&embed src='/DocinViewer-4.swf' width='100%' height='600' type=application/x-shockwave-flash ALLOWFULLSCREEN='true' ALLOWSCRIPTACCESS='always'&&/embed&
450px*300px480px*400px650px*490px
支持嵌入HTML代码的网站使用
您的内容已经提交成功
您所提交的内容需要审核后才能发布,请您等待!
3秒自动关闭窗口大规模C++程序设计.pdf
带目录书签 - 下载频道 - CSDN.NET
&&&&大规模C++程序设计.pdf
带目录书签
&大规模C++程序设计.pdf
带目录书签
大规模C++程序设计.pdf
带目录书签
这是一本为所有从事软件开发工作(例如数据库、操作系统、编译程序及框架)的C++软件专业人员而写的权威著作。它是第一本实际演示如何开发大型C++系统的书,并且是一本少有的面向对象设计的书,尤其侧重于C++编程语言的实践方面。
在本书中,Lakos介绍了将大型系统分解成较小且较好管理的组件层次结构(不是继承)的过程。这种具有非循环物理依赖的系统的维护、测试和重用从根本上比相互紧密依赖的系统更容易且更经济。此外,本书还说明了遵从好的物理设计和逻辑设计规划的动机。Lakos给读者提供了一系列用来消除循环依赖、编译时依赖和连接时(物理)依赖的特殊技术。
第0章 引言
第1部分 基础知识
第1章 预备知识
第2章 基本规则
第2部分 物理设计概念
第3章 组件
第4章 物理层次结构
第5章 层次化
第6章 绝缘
第3部分 逻辑设计问题
第8章 构建一个组件
第9章 设计一个函数
第10章 实现一个对象
附录A 协议层次结构设计模式
附录B 实现一个与ANSI C兼容的C++接口
附录C 一个依赖提取器/分析器包
若举报审核通过,可奖励20下载分
被举报人:
举报的资源分:
请选择类型
资源无法下载
资源无法使用
标题与实际内容不符
含有危害国家安全内容
含有反动色情等内容
含广告内容
版权问题,侵犯个人或公司的版权
*详细原因:
您可能还需要
Q.为什么我点的下载下不了,但积分却被扣了
A. 由于下载人数众多,下载服务器做了并发的限制。若发现下载不了,请稍后再试,多次下载是不会重复扣分的。
Q.我的积分不多了,如何获取积分?
A. 获得积分,详细见。
完成任务获取积分。
评价资源返积分。
论坛可用分兑换下载积分。
第一次绑定手机,将获得5个C币,C币可。
下载资源意味着您已经同意遵守以下协议
资源的所有权益归上传用户所有
未经权益所有人同意,不得将资源中的内容挪作商业或盈利用途
CSDN下载频道仅提供交流平台,并不能对任何下载资源负责
下载资源中如有侵权或不适当内容,
本站不保证本站提供的资源的准确性,安全性和完整性,同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
课程资源下载排行
你下载资源过于频繁,请输入验证码
如何快速获得积分?
你已经下载过该资源,再次下载不需要扣除积分
大规模C++程序设计.pdf
带目录书签
所需积分:1
剩余积分:
VIP会员,免积分下载
会员到期时间:日
剩余下载次数:1000
VIP服务公告:}

我要回帖

更多关于 课程管理系统 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信