Compilation and simple test of gtest-1.60.zip in Linux

Source: Internet
Author: User

Operating System: fedora15-x86_64

1. Download and decompress the package to/home/HLF,

Music gtest-1.60 gtest

CD gtest

2, G ++-I./include-I./-C./src/gtest-all.cc (note,-I after no space, directly Add ./)

3. ar-RV libgtest. A gtest-all.o

Note:

Although there are configure in the directory or makefile files in the make directory, they are all blind.

Simple test:

Let's test a max function in Foo. H (calculate a larger one of the two numbers)
The Foo. h file is as follows:

# Ifndef _ foo_h __# DEFINE _ foo_h _ intmax (INTA, intb) {returna> B? A: B;} # endif

Write the test program foo_test.cpp to test FOO:
The foo_test.cpp file is as follows:

# Include "gtest/gtest. H "# include" foo. H "test (Foo, max) {expect_eq (2, max (2,-1); expect_eq (3, max (2, 3);} intmain (intargc, char ** argv) {: Testing: initgoogletest (& argc, argv); returnrun_all_tests ();}

Compile foo_test.cpp with the following command:

G ++-G foo_test.cpp-O foo_test-I/home/HLF/gtest/include-L/home/HLF/-lgtest-lpthread

Note that you need to link the pthread library.

Test results:

[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from foo
[Run] Foo. Max
[OK] Foo. Max (0 MS)
[----------] 1 test From Foo (1 MS total)

[----------] Global test environment tear-down
[===========] 1 test from 1 test case ran. (3 MS total)
[Passed] 1 test.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.