如何编译google test的例子?

原创 2011年01月16日 00:13:00
本博客http://blog.csdn.net/livelylittlefish 贴出作者(三二一@小鱼)相关研究、学习内容所做的笔记,欢迎广大朋友指正!

How to build samples of Google Test?

 

In the source of google test, it provides some samples to show how to use google test. In this article, we describe how to build these samples.

 

1. an example to build a sample

 

The source of google test provides a sample to build its exmaple. It is in ../make.

This example is to build sample1_unittest, it is in ../samples.

The source code to be tested is in file sample1.cc & sample1.h.

The unit test code is in file sample1_unittest.cc.

# /usr/src/gtest-1.5.0

# cd make

# make

# ./sample1_unittest

The result of build is in ../make, then, we can run sample1_unittest, as follows.

root@yu29:/usr/src/gtest-1.5.0/make# ./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 (0 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. (0 ms total)

[  PASSED  ] 6 tests.

2. how to build all samples by using cmake?

 

Cmake generates native build scripts. 先建立mybuild目录

# cd /usr/src/gtest-1.5.0

# mddir mybuild

# cd mybuild

(1) only generate gtest_unittest

# cmake /usr/src/gtest-1.5.0  //generate Makefile

# make                        //generate executable file gtest_unittest

(2) generate gtest_unittest and all samples

//generate Makefile with Google Test's samples to be compiled

# cmake -Dbuild_gtest_samples=ON /usr/src/gtest-1.5.0


//generate executable files gtest_unittest, sample1_unittest, sample2_unittest, ...

# make

Reference

http://code.google.com/p/googletest

../readme

 

 

Appendix. 使用CMake编译gtest_unittestsamples

 

//生成Makefile文件

root@yu29:/usr/src/gtest-1.5.0/mybuild# cmake -Dbuild_gtest_samples=ON /usr/src/gtest-1.5.0

-- The CXX compiler identification is GNU

-- The C compiler identification is GNU

-- Check for working CXX compiler: /usr/bin/c++

-- Check for working CXX compiler: /usr/bin/c++ -- works

-- Detecting CXX compiler ABI info

-- Detecting CXX compiler ABI info - done

-- Check for working C compiler: /usr/bin/gcc

-- Check for working C compiler: /usr/bin/gcc -- works

-- Detecting C compiler ABI info

-- Detecting C compiler ABI info - done

-- Looking for include files CMAKE_HAVE_PTHREAD_H

-- Looking for include files CMAKE_HAVE_PTHREAD_H - found

-- Looking for pthread_create in pthreads

-- Looking for pthread_create in pthreads - not found

-- Looking for pthread_create in pthread

-- Looking for pthread_create in pthread - found

-- Found Threads: TRUE

-- Found PythonInterp: /usr/bin/python2.6

-- Configuring done

-- Generating done

-- Build files have been written to: /usr/src/gtest-1.5.0/mybuild

root@yu29:/usr/src/gtest-1.5.0/mybuild# ls

CMakeCache.txt  CMakeFiles  cmake_install.cmake  CTestTestfile.cmake  Makefile

//编译

root@yu29:/usr/src/gtest-1.5.0/mybuild# make

Scanning dependencies of target gtest

[  5%] Building CXX object CMakeFiles/gtest.dir/src/gtest-all.cc.o

Linking CXX static library libgtest.a

[  5%] Built target gtest

Scanning dependencies of target gtest_main

[ 11%] Building CXX object CMakeFiles/gtest_main.dir/src/gtest_main.cc.o

...

//生成了所有samples的可执行程序

root@yu29:/usr/src/gtest-1.5.0/mybuild# ls

CMakeCache.txt       libgtest.a         sample2_unittest  sample7_unittest

CMakeFiles           libgtest_main.a    sample3_unittest  sample8_unittest

cmake_install.cmake  Makefile           sample4_unittest  sample9_unittest

CTestTestfile.cmake  sample10_unittest  sample5_unittest

gtest_unittest       sample1_unittest   sample6_unittest

//看看sample2的执行结果

root@yu29:/usr/src/gtest-1.5.0/mybuild# ./sample2_unittest

Running main() from gtest_main.cc

[==========] Running 4 tests from 1 test case.

[----------] Global test environment set-up.

[----------] 4 tests from MyString

[ RUN      ] MyString.DefaultConstructor

[       OK ] MyString.DefaultConstructor (0 ms)

[ RUN      ] MyString.ConstructorFromCString

[       OK ] MyString.ConstructorFromCString (0 ms)

[ RUN      ] MyString.CopyConstructor

[       OK ] MyString.CopyConstructor (0 ms)

[ RUN      ] MyString.Set

[       OK ] MyString.Set (0 ms)

[----------] 4 tests from MyString (0 ms total)

 

[----------] Global test environment tear-down

[==========] 4 tests from 1 test case ran. (1 ms total)

[  PASSED  ] 4 tests.

//gtest_unittest的执行结果较长,此处不再显示。





版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

单元测试 Google Test 使用

gtest 用法 1 将gtest-1.5.0解压,拷贝gtest-1.5.0.zip\gtest-1.5.0\include下的gtest 到 include 目录下 添加...

使用Google Test的一个简单例子

本博客http://blog.csdn.net/livelylittlefish 贴出作者(三二一@小鱼)相关研究、学习内容所做的笔记,欢迎广大朋友指正! 0. 引子   本例是从gtest-1....

Linux下Google Test测试环境安装和使用,实战总结

google test(libgtes)是由谷歌开发的一款基于xunit框架的跨平台单元测试框架,C#上的NUnit,Java的JUnit写单元测试非常容易,也不乏可视化工具与IDE集成插件,深受喜欢...

Windows Visual Studio下安装和使用google test(gtest)

http://blog.csdn.net/officercat/article/details/39299553

Linux平台如何编译使用Google test写的单元测试?

本博客http://blog.csdn.net/livelylittlefish 贴出作者(三二一@小鱼)相关研究、学习内容所做的笔记,欢迎广大朋友指正! 在Linux平台如何编译单元测试的代码?(请...

linux下epoll如何实现高效处理百万句柄的

开发高性能网络程序时,windows开发者们言必称iocp,linux开发者们则言必称epoll。大家都明白epoll是一种IO多路复用技术,可以非常高效的处理数以百万计的socket句柄,比起以前的...

Google Test(GTest)使用方法和源码解析——死亡测试技术分析和应用

本文介绍了GTest的死亡测试技术的实现。

Google Test(GTest)使用方法和源码解析——概况

本文将以GTest的1.7版本为参照,讲解GTest测试框架的简单使用和特性。

比特币源码学习笔记(一)

前言 从事区块链的开发,不了解其底层核心技术是不够的。许多人在看了比特币白皮书之后仍然不清楚比特币是怎样实现的,因为比特币的源码设计精巧,有许多设计白皮书未曾提及,加上本身比特币的文档稀少,加大了新手...
  • g2com
  • g2com
  • 2017-03-21 05:03
  • 2704
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)