Boost &googletest  Will Shen2011/10/17
OutlineBoost    •   Smart pointer    •   Assign    •   oreach    •   bindgoogletest    • Simple tests    • Assertions2
Hundred of boost libraries              hpp               hpp                                   hpp + lib                 ...
Memory Leaking    Cause of Evil - new/delete4
boost – Smart pointer    Cause of Evil - new/delete    Managing memory in a smart way    • std::auto_ptr  Ownership    • ...
Stack and Heap    Using Stack variable to manage Heap    memory               p1       Proxy   fun()               …      ...
Different smart pointers    Ownership, Non-copyable, Reference counting      ap1                    ap1      ap2          ...
Used in STL Container    Both auto_ptr and scoped_ptr can not    be used in STL container.       vec[0         vec[0      ...
scoped_array and shared_array    operator[]9
boost::assign – filling containers with data operator+=(), operator,() operator()()10
boost::assign list_of - to initialize a container repeat, repeat_fun, range11
boost::foreach BOOST_FOREACH, BOOST_REVERSE_FOREACH Supported Sequence Type     •   STL containers     •   arrays     •   ...
boost::foreach + typeof BOOST_TYPEOF13
boost::bind A generalization of the standard functions std::bind1st and std::bind2nd. Supports: function objects, function...
boost::bind - place holders _1, _2, …, _915
Use boost::bind() in STL algorithm                         binding member function16
googletest - Unit Testing Framework                                     Execute test cases through the GUI Google test fra...
gtest is more lightweight than cppunitCppunit                              gtest1. Write a test class derived from   TestF...
Basic concepts Start by writing ASSERTIONS     • statements that check whether a condition is true.     • success, nonfata...
Assertions Basic Assertions, Binary Comparison, String Comparison20
To Write Simple Tests               Subject to be tested21
Test Fixture - Using the Same Data             Configuration for Multiple Tests  SUTTestFixture                           ...
gtest folder in GMapShop project                      Tests23
Recommended Books24
Recommended Books25
Recommended Books26
Recommended Books27
More to talk Code Smell Refactoring method Principles of Object-oriented Design     • SRP, OCP, LSP, DSP, DIP28
Upcoming SlideShare
Loading in...5
×

20111018 boost and gtest

702

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
702
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

20111018 boost and gtest

  1. 1. Boost &googletest Will Shen2011/10/17
  2. 2. OutlineBoost • Smart pointer • Assign • oreach • bindgoogletest • Simple tests • Assertions2
  3. 3. Hundred of boost libraries hpp hpp hpp + lib hpp + lib (.h+.cpp) (.h+.cpp) up to 90% without linking date_time filesystem regex program_otpions test thread python3
  4. 4. Memory Leaking Cause of Evil - new/delete4
  5. 5. boost – Smart pointer Cause of Evil - new/delete Managing memory in a smart way • std::auto_ptr  Ownership • boost::scoped_ptr  Non-copyable • boost:: shared_ptr  Reference counting5
  6. 6. Stack and Heap Using Stack variable to manage Heap memory p1 Proxy fun() … stack heap6
  7. 7. Different smart pointers Ownership, Non-copyable, Reference counting ap1 ap1 ap2 ap2 shp1 shp1 shp2 shp27
  8. 8. Used in STL Container Both auto_ptr and scoped_ptr can not be used in STL container. vec[0 vec[0 ] e ] vec[1 vec[1 ] ] vec[2 vec[2 ] ]8
  9. 9. scoped_array and shared_array operator[]9
  10. 10. boost::assign – filling containers with data operator+=(), operator,() operator()()10
  11. 11. boost::assign list_of - to initialize a container repeat, repeat_fun, range11
  12. 12. boost::foreach BOOST_FOREACH, BOOST_REVERSE_FOREACH Supported Sequence Type • STL containers • arrays • Null-terminated strings (char and wchar_t) • std::pair of iterators12
  13. 13. boost::foreach + typeof BOOST_TYPEOF13
  14. 14. boost::bind A generalization of the standard functions std::bind1st and std::bind2nd. Supports: function objects, functions, function pointers, and member function pointers Able to bind any argument to a specific value or route input arguments into arbitrary positions. Function object14
  15. 15. boost::bind - place holders _1, _2, …, _915
  16. 16. Use boost::bind() in STL algorithm binding member function16
  17. 17. googletest - Unit Testing Framework Execute test cases through the GUI Google test framework (gtest) • Easy to execute • Easy to implement test cases“Unicode Debug-test” configuration Execute test cases in console17
  18. 18. gtest is more lightweight than cppunitCppunit gtest1. Write a test class derived from TestFixture 1. One TEST macro2. Write setup3. Write teardown4. Write test method5. Define test suite6. Context-switch between .h/.cpp files18
  19. 19. Basic concepts Start by writing ASSERTIONS • statements that check whether a condition is true. • success, nonfatal failure, or fatal failure. A test case contains one or many tests. A test program can contain multiple test cases.19
  20. 20. Assertions Basic Assertions, Binary Comparison, String Comparison20
  21. 21. To Write Simple Tests Subject to be tested21
  22. 22. Test Fixture - Using the Same Data Configuration for Multiple Tests SUTTestFixture Tests 22
  23. 23. gtest folder in GMapShop project Tests23
  24. 24. Recommended Books24
  25. 25. Recommended Books25
  26. 26. Recommended Books26
  27. 27. Recommended Books27
  28. 28. More to talk Code Smell Refactoring method Principles of Object-oriented Design • SRP, OCP, LSP, DSP, DIP28

×