Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/examples/100-Fix-Section.cpp
diff options
context:
space:
mode:
authorMartin Moene2017-10-13 09:43:50 +0200
committerMartin Hořeňovský2017-11-15 15:37:39 +0100
commit4ecb2e112e0565451c14fc42d63f438cb9ecb7dd (patch)
treea096a4aa62856f6b71c4358c697630f346434e7d /examples/100-Fix-Section.cpp
parent97a8640cbf10a8ff3d6f06f0293f5c37b263144a (diff)
downloadcatch3-4ecb2e112e0565451c14fc42d63f438cb9ecb7dd.tar.gz
Add examples folder with initial examples
Diffstat (limited to 'examples/100-Fix-Section.cpp')
-rw-r--r--examples/100-Fix-Section.cpp69
1 files changed, 69 insertions, 0 deletions
diff --git a/examples/100-Fix-Section.cpp b/examples/100-Fix-Section.cpp
new file mode 100644
index 00000000..8cb94bff
--- /dev/null
+++ b/examples/100-Fix-Section.cpp
@@ -0,0 +1,69 @@
+// 100-Fix-Section.cpp
+
+// Catch has two ways to express fixtures:
+// - Sections (this file)
+// - Traditional class-based fixtures
+
+// main() provided in 000-CatchMain.cpp
+
+#include "catch.hpp"
+
+TEST_CASE( "vectors can be sized and resized", "[vector]" ) {
+
+ // For each section, vector v is anew:
+
+ std::vector<int> v( 5 );
+
+ REQUIRE( v.size() == 5 );
+ REQUIRE( v.capacity() >= 5 );
+
+ SECTION( "resizing bigger changes size and capacity" ) {
+ v.resize( 10 );
+
+ REQUIRE( v.size() == 10 );
+ REQUIRE( v.capacity() >= 10 );
+ }
+ SECTION( "resizing smaller changes size but not capacity" ) {
+ v.resize( 0 );
+
+ REQUIRE( v.size() == 0 );
+ REQUIRE( v.capacity() >= 5 );
+ }
+ SECTION( "reserving bigger changes capacity but not size" ) {
+ v.reserve( 10 );
+
+ REQUIRE( v.size() == 5 );
+ REQUIRE( v.capacity() >= 10 );
+ }
+ SECTION( "reserving smaller does not change size or capacity" ) {
+ v.reserve( 0 );
+
+ REQUIRE( v.size() == 5 );
+ REQUIRE( v.capacity() >= 5 );
+ }
+}
+
+// Compile & run:
+// - g++ -std=c++11 -Wall -I$(CATCH_SINGLE_INCLUDE) -o 100-Fix-Section 100-Fix-Section.cpp 000-CatchMain.o && 100-Fix-Section --success
+// - cl -EHsc -I%CATCH_SINGLE_INCLUDE% 100-Fix-Section.cpp 000-CatchMain.obj && 100-Fix-Section --success
+
+// Expected compact output (all assertions):
+//
+// prompt> 100-Fix-Section.exe --reporter compact --success
+// 100-Fix-Section.cpp:17: passed: v.size() == 5 for: 5 == 5
+// 100-Fix-Section.cpp:18: passed: v.capacity() >= 5 for: 5 >= 5
+// 100-Fix-Section.cpp:23: passed: v.size() == 10 for: 10 == 10
+// 100-Fix-Section.cpp:24: passed: v.capacity() >= 10 for: 10 >= 10
+// 100-Fix-Section.cpp:17: passed: v.size() == 5 for: 5 == 5
+// 100-Fix-Section.cpp:18: passed: v.capacity() >= 5 for: 5 >= 5
+// 100-Fix-Section.cpp:29: passed: v.size() == 0 for: 0 == 0
+// 100-Fix-Section.cpp:30: passed: v.capacity() >= 5 for: 5 >= 5
+// 100-Fix-Section.cpp:17: passed: v.size() == 5 for: 5 == 5
+// 100-Fix-Section.cpp:18: passed: v.capacity() >= 5 for: 5 >= 5
+// 100-Fix-Section.cpp:35: passed: v.size() == 5 for: 5 == 5
+// 100-Fix-Section.cpp:36: passed: v.capacity() >= 10 for: 10 >= 10
+// 100-Fix-Section.cpp:17: passed: v.size() == 5 for: 5 == 5
+// 100-Fix-Section.cpp:18: passed: v.capacity() >= 5 for: 5 >= 5
+// 100-Fix-Section.cpp:41: passed: v.size() == 5 for: 5 == 5
+// 100-Fix-Section.cpp:42: passed: v.capacity() >= 5 for: 5 >= 5
+// Passed 1 test case with 16 assertions.