当前位置: 首页 > news >正文

湛江专业建站免费咨询南京安居建设公司

湛江专业建站免费咨询,南京安居建设公司,WordPress集成插件到主题,wordpress主题导入DemoGoogleTest单元测试可用实现在每个测试用例结束后监控其内存使用情况#xff0c; 可以通过GoogleTest提供的事件侦听器EmptyTestEventListener 来实现#xff0c;下面通过官方提供的sample例子#xff0c;路径在samples文件夹下的sample10_unittest.cpp // Copyright 2009…GoogleTest单元测试可用实现在每个测试用例结束后监控其内存使用情况 可以通过GoogleTest提供的事件侦听器EmptyTestEventListener 来实现下面通过官方提供的sample例子路径在samples文件夹下的sample10_unittest.cpp // Copyright 2009 Google Inc. All Rights Reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // AS IS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.// This sample shows how to use Google Test listener API to implement // a primitive leak checker.#include stdio.h #include stdlib.h#include gtest/gtest.h using ::testing::EmptyTestEventListener; using ::testing::InitGoogleTest; using ::testing::Test; using ::testing::TestEventListeners; using ::testing::TestInfo; using ::testing::TestPartResult; using ::testing::UnitTest;namespace { // We will track memory used by this class. class Water {public:// Normal Water declarations go here.// operator new and operator delete help us control water allocation.void* operator new(size_t allocation_size) {allocated_;return malloc(allocation_size);}void operator delete(void* block, size_t /* allocation_size */) {allocated_--;free(block);}static int allocated() { return allocated_; }private:static int allocated_; };int Water::allocated_ 0;// This event listener monitors how many Water objects are created and // destroyed by each test, and reports a failure if a test leaks some Water // objects. It does this by comparing the number of live Water objects at // the beginning of a test and at the end of a test. class LeakChecker : public EmptyTestEventListener {private:// Called before a test starts.void OnTestStart(const TestInfo /* test_info */) override {initially_allocated_ Water::allocated();}// Called after a test ends.void OnTestEnd(const TestInfo /* test_info */) override {int difference Water::allocated() - initially_allocated_;// You can generate a failure in any event handler except// OnTestPartResult. Just use an appropriate Google Test assertion to do// it.EXPECT_LE(difference, 0) Leaked difference unit(s) of Water!;}int initially_allocated_; };TEST(ListenersTest, DoesNotLeak) {Water* water new Water;delete water; }// This should fail when the --check_for_leaks command line flag is // specified. TEST(ListenersTest, LeaksWater) {Water* water new Water;EXPECT_TRUE(water ! nullptr); } } // namespaceint main(int argc, char **argv) {InitGoogleTest(argc, argv);bool check_for_leaks false;if (argc 1 strcmp(argv[1], --check_for_leaks) 0 )check_for_leaks true;elseprintf(%s\n, Run this program with --check_for_leaks to enable custom leak checking in the tests.);// If we are given the --check_for_leaks command line flag, installs the// leak checker.if (check_for_leaks) {TestEventListeners listeners UnitTest::GetInstance()-listeners();// Adds the leak checker to the end of the test event listener list,// after the default text output printer and the default XML report// generator.//// The order is important - it ensures that failures generated in the// leak checkers OnTestEnd() method are processed by the text and XML// printers *before* their OnTestEnd() methods are called, such that// they are attributed to the right test. Remember that a listener// receives an OnXyzStart event *after* listeners preceding it in the// list received that event, and receives an OnXyzEnd event *before*// listeners preceding it.//// We dont need to worry about deleting the new listener later, as// Google Test will do it.listeners.Append(new LeakChecker);}return RUN_ALL_TESTS(); } 通过Water类来重写new和delete方法来实现记录内存分配/释放的情况另外通过LeakChecker 继承自EmptyTestEventListener 并实现OnTestStart测试用例开始前运行和OnTestEnd方法测试用例结束后运行 关于LeakChecker的使用是先获取系统提供的listeners 然后把自定义事件加入到系统中去即可。 TestEventListeners listeners UnitTest::GetInstance()-listeners(); listeners.Append(new LeakChecker);
http://www.dnsts.com.cn/news/36189.html

相关文章:

  • 网站访问流量怎么赚钱vue大型网站开发
  • 专业网站制作网站公司购物网站的策划
  • 报电子商务( 网站建设与运营)简单响应式网站
  • 资讯网站 整体ui电商运营培训
  • 网站在线开发网站建设人员招聘要求
  • 中英双语营销型网站重启 iis 中的网站
  • 潍坊网站建设哪里好北京企业
  • 潍坊建立企业网站公司自建网站国家审核要多久
  • 建设网站大概需要多少钱wordpress redirect.php
  • 网站seo报价从做系统找不到以前的网站
  • 网站 所有权阻止wordpress更新
  • 如何做家教网站asp网站打开速度慢
  • 网站建设公众号小程序属于什么城阳 网站建设
  • 网站开发技术与开发环境设计电影完整版视频在线
  • 织梦圈子如何调用网站默认模板视频软件
  • wordpress网站源码国内专业网站制作
  • 佛山高端网站设计专门做销售招聘网站
  • 自助建站工具深圳网站建设网络推广
  • 公司网站推广关于做好网站建设的通知
  • 个性化网站模板电脑怎么做最新系统下载网站
  • 常州做网站公司哪家好某商贸网站建设方案
  • asp access网站开发实例精讲推广网站怎么做能增加咨询
  • 做网站需要哪些技能兰州 网站建设公司
  • 征婚网站 女 做茶叶生意网站网页设计的公司
  • 哪个餐饮店微网站做的有特色网络营销的具体方法
  • 山东网站搭建有限公司深圳建网站 (报价)
  • 不锈钢网站哪家最专业约会软件app前十名
  • 高端网站建站商城小程序定制公司
  • 做微信投票的网站5广东省建设监理协会网站
  • 廊坊关键词优化服务如何优化关键词搜索排名