### Reveal.js Project Setup and Serve Source: https://github.com/cpp-testing/gunit/blob/master/docs/cppcon-2018/reveal.js/README.md Steps to clone the reveal.js repository, install Node.js dependencies, and start the local development server. This enables live preview and monitoring of source file changes. ```shell git clone https://github.com/hakimel/reveal.js.git cd reveal.js npm install npm start ``` ```shell npm start -- --port=8001 ``` -------------------------------- ### Socket.io Server Setup Commands Source: https://github.com/cpp-testing/gunit/blob/master/docs/cppcon-2018/reveal.js/README.md Commands to install dependencies and run a local socket.io server for the Reveal.js multiplex plugin. Also includes deployment command using 'now'. ```shell npm install node plugin/multiplex now plugin/multiplex ``` -------------------------------- ### Socket.io Server Setup and Presentation Commands Source: https://github.com/cpp-testing/gunit/blob/master/docs/cppnow-2017/README.md Commands for setting up a socket.io server for Reveal.js multiplexing and serving presentations. Includes installing dependencies and running the server, as well as commands for serving the master presentation locally. ```bash # For master presentation (local static file server) npm install node-static static ``` ```bash # For master presentation with speaker notes plugin node plugin/notes-server ``` ```bash # For socket.io server npm install node plugin/multiplex ``` -------------------------------- ### Initialize reveal.js Presentation Source: https://github.com/cpp-testing/gunit/blob/master/docs/cppnow-2017/test/examples/barebones.html This snippet initializes the reveal.js presentation framework. It's a core function required to start any reveal.js slideshow. No specific parameters are shown in this minimal example, but it typically takes an options object. ```javascript Reveal.initialize(); ``` -------------------------------- ### Initialize reveal.js Presentation Source: https://github.com/cpp-testing/gunit/blob/master/docs/cppcon-2018/reveal.js/test/examples/barebones.html This snippet initializes the reveal.js presentation framework. It's a core function required to start any reveal.js slideshow. No specific parameters are shown in this minimal example, but it typically takes an options object. ```javascript Reveal.initialize(); ``` -------------------------------- ### Boost.DI Basic Setup Source: https://github.com/cpp-testing/gunit/blob/master/docs/cppnow-2017/index.html Includes the necessary Boost.DI header and defines the namespace alias for convenience. This is the foundational setup for using Boost.DI in C++ projects. ```cpp #include namespace di = boost::di; ``` -------------------------------- ### Reveal.js Initialization Example Source: https://github.com/cpp-testing/gunit/blob/master/docs/cppnow-2017/test/examples/slide-transitions.html This JavaScript snippet demonstrates how to initialize the reveal.js presentation framework. It includes common configuration options such as centering slides, enabling history, and commented-out examples for transition effects and speed. ```javascript Reveal.initialize({ center: true, history: true, // transition: 'slide', // transitionSpeed: 'slow', // backgroundTransition: 'slide' }); ``` -------------------------------- ### C++ Wiring Mess Example (Main) Source: https://github.com/cpp-testing/gunit/blob/master/docs/cppnow-2017/index.html This C++ code snippet demonstrates the 'wiring mess' in a `main` function, representing the composition root. It shows the manual instantiation and setup of concrete dependencies (`FileReader`, `Printer`) and their wiring into the `App` class. This manual composition can become complex and hard to maintain. ```cpp int main() { auto file = std::fstream{"input.txt"}; // WIRING! auto reader = std::make_unique(file); // WIRING! auto printer = std::make_shared(std::cout); // WIRING! App app{reader, printer}; // WIRING! } ``` -------------------------------- ### GUnit.GMake Tutorial: C++ Test Fixture (V4) Source: https://github.com/cpp-testing/gunit/blob/master/docs/GMake.md Presents a modern C++ test fixture using `testing::Test` (V4) with GUnit.GMake. The `SetUp` method automatically initializes the SUT and mocks using `testing::make`, preparing them for multiple test cases and eliminating setup repetition. ```cpp class Test : public testing::Test { public: void SetUp() override { std::tie(sut, mocks) = testing::make, NaggyMock>(); } }; TEST(Test, ShouldPrintTextWhenUpdate) { using namespace testing; EXPECT_CALL(mock(), (is_dumpable)()).WillOnce(Return(true)); EXPECT_CALL(mock(), (print)("text")); sut->update(); } ``` -------------------------------- ### GUnit Example Test Invocations Source: https://github.com/cpp-testing/gunit/blob/master/CMakeLists.txt Examples of calling the 'test' function to build and run specific GUnit examples, including setting feature file paths for Gherkin-based tests. ```cmake if(GUNIT_BUILD_EXAMPLES) test(example/GAssert SCENARIO=) test(example/GMock SCENARIO=) test(example/GTest SCENARIO=) test(example/GTest-Lite SCENARIO=) test(example/GSteps SCENARIO=${CMAKE_CURRENT_SOURCE_DIR}/example/GSteps.feature) endif() ``` -------------------------------- ### Reveal.js Initialization Example Source: https://github.com/cpp-testing/gunit/blob/master/docs/cppcon-2018/reveal.js/test/examples/slide-transitions.html This JavaScript snippet demonstrates how to initialize the reveal.js presentation framework. It includes common configuration options such as centering slides, enabling history, and commented-out examples for transition effects and speed. ```javascript Reveal.initialize({ center: true, history: true, // transition: 'slide', // transitionSpeed: 'slow', // backgroundTransition: 'slide' }); ``` -------------------------------- ### Master Presentation Setup Commands Source: https://github.com/cpp-testing/gunit/blob/master/docs/cppcon-2018/reveal.js/README.md Commands to set up a local static file server for the master presentation and to run the speaker notes server. ```shell npm install node-static static node plugin/notes-server ``` -------------------------------- ### GUnit.GTest-Lite with Lambda Example Source: https://github.com/cpp-testing/gunit/blob/master/docs/cppnow-2017/index.html Demonstrates using GUnit.GTest-Lite with a lambda function to define a test suite. This approach allows for encapsulating setup, test logic, and teardown within a single block, enhancing organization. ```cpp "Calculator"_test = [] { Calculator calc{}; // set-up SHOULD("add 2 numbers") { // 1. set-up EXPECT(4 == calc.add(2, 2)); // 2. should add 2 numbers } // 3. tear-down SHOULD("sub 2 numbers") { // 1. set-up EXPECT(0 == calc.sub(2, 2)); // 2. should sub 2 numbers } // 3. tear-down // tear-down }; ``` -------------------------------- ### Probability of Heads Source: https://github.com/cpp-testing/gunit/blob/master/docs/cppcon-2018/reveal.js/test/examples/math.html Example of the probability of getting k heads when flipping n coins, rendered using LaTeX. This illustrates the plugin's support for binomial probability formulas. ```latex P(E) = {n \choose k} p^k (1-p)^{ n-k} ``` -------------------------------- ### GUnit.GMock Example Classes Source: https://github.com/cpp-testing/gunit/blob/master/docs/GMock.md Defines the interface classes `iconfig` and `iprinter`, and an implementation class `example` that depends on these interfaces. These classes are used to demonstrate the functionality of GUnit.GMock in test scenarios. ```cpp class iconfig { public: virtual bool is_dumpable() const = 0; virtual ~iconfig() = default; }; ``` ```cpp class iprinter { public: virtual ~iprinter() = default; virtual void print(const std::string& text) = 0; }; ``` ```cpp class example { public: example(const iconfig& config, const std::shraed_ptr& printer) : config(config), printer(printer) { } void update() { if (config.is_dumpable()) { printer->print("text"); } } private: const iconfig& config; std::shared_ptr printer; }; ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/cpp-testing/gunit/blob/master/docs/cppnow-2017/README.md Installs all necessary Node.js dependencies for reveal.js using npm. This command reads the 'package.json' file to download required packages. ```sh npm install ``` -------------------------------- ### Initialize Reveal.js Source: https://github.com/cpp-testing/gunit/blob/master/docs/cppnow-2017/test/examples/embedded-media.html Initializes the reveal.js presentation framework with specified configuration options. This example sets the transition effect to 'linear'. ```javascript Reveal.initialize({ transition: 'linear' }); ``` -------------------------------- ### GUnit.GMake Tutorial: C++14 Test Example Source: https://github.com/cpp-testing/gunit/blob/master/docs/GMake.md Illustrates using `testing::make` in a C++14 test case with `std::tie` to create a System Under Test (SUT) requiring StrictMock. This example shows the syntax for older C++ standards and the explicit declaration of SUT and mocks. ```cpp TEST(Test, ShouldPrintTextWhenUpdate) { using namespace testing; std::unique_ptr sut; mocks_t mocks; std::tie(sut, mocks) = make, StrictMock>(); // create StrictMock when required EXPECT_CALL(mocks.mock(), (is_dumpable)()).WillOnce(Return(true)); EXPECT_CALL(mocks.mock(), (print)("text")); sut->update(); } ``` -------------------------------- ### Serve Presentation and Monitor Changes Source: https://github.com/cpp-testing/gunit/blob/master/docs/cppnow-2017/README.md Starts the Grunt development server, which serves the reveal.js presentation locally and watches for changes in source files to automatically reload. ```sh grunt serve ``` -------------------------------- ### GTest: Refactor - DRY Setup for Trading System Tests Source: https://github.com/cpp-testing/gunit/blob/master/docs/cppnow-2017/index.html Demonstrates refactoring GTest code to remove duplication by creating a common setup block for multiple tests within the same test suite, improving readability and maintainability. ```cpp "Trading System [Parse Feeds]"_test = [] { auto [ts, mocks] = testing::make(); // DRY, setup SHOULD("connect to the market data on startup") { EXPECT_CALL(mocks(), connect); ts.start(); } SHOULD("not disconnect on stop if it wasn't connected") { EXPECT_CALL(mocks(), disconnect).Times(0); ts.stop(); }; }; ``` -------------------------------- ### reveal.js Initialization Configuration Source: https://github.com/cpp-testing/gunit/blob/master/docs/cppcon-2018/reveal.js/test/examples/slide-backgrounds.html Shows a common JavaScript configuration object for initializing reveal.js. This example includes settings for centering slides, transition effects, and background transitions. ```javascript Reveal.initialize({ center: true, // rtl: true, transition: 'linear', // transitionSpeed: 'slow', // backgroundTransition: 'slide' }); ``` -------------------------------- ### Initialize Reveal.js Source: https://github.com/cpp-testing/gunit/blob/master/docs/cppcon-2018/reveal.js/test/examples/embedded-media.html Initializes the reveal.js presentation framework with specified configuration options. This example sets the transition effect to 'linear'. ```javascript Reveal.initialize({ transition: 'linear' }); ``` -------------------------------- ### GUnit CMake Project Setup Source: https://github.com/cpp-testing/gunit/blob/master/CMakeLists.txt Initializes the CMake project, sets the minimum version, defines project name, and configures master project status based on the current directory. ```cmake cmake_minimum_required(VERSION 3.12) project(GUnit CXX) set(MASTER_PROJECT OFF) if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) set(MASTER_PROJECT ON) endif() ``` -------------------------------- ### Code Syntax Highlighting Example Source: https://github.com/cpp-testing/gunit/blob/master/docs/cppnow-2017/README.md Demonstrates Reveal.js's integration with highlight.js for code syntax highlighting. The example shows an HTML structure containing Clojure code, with the `data-trim` attribute used to remove surrounding whitespace. ```html

(def lazy-fib
  (concat
   [0 1]
   ((fn rfib [a b]
        (lazy-cons (+ a b) (rfib b (+ a b)))) 0 1)))
	
``` ```clojure (def lazy-fib (concat [0 1] ((fn rfib [a b] (lazy-cons (+ a b) (rfib b (+ a b)))) 0 1))) ``` -------------------------------- ### reveal.js Initialization Configuration Source: https://github.com/cpp-testing/gunit/blob/master/docs/cppnow-2017/test/examples/slide-backgrounds.html Shows a common JavaScript configuration object for initializing reveal.js. This example includes settings for centering slides, transition effects, and background transitions. ```javascript Reveal.initialize({ center: true, // rtl: true, transition: 'linear', // transitionSpeed: 'slow', // backgroundTransition: 'slide' }); ``` -------------------------------- ### Reveal.js Code Syntax Highlighting Setup Source: https://github.com/cpp-testing/gunit/blob/master/docs/cppcon-2018/reveal.js/README.md Configure reveal.js to use highlight.js for code syntax highlighting. This involves loading the highlight plugin and initializing it on page load. ```javascript Reveal.initialize({ // More info https://github.com/hakimel/reveal.js#dependencies dependencies: [ { src: 'plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } }, ] }); ``` -------------------------------- ### GUnit Benchmark Test Invocations Source: https://github.com/cpp-testing/gunit/blob/master/CMakeLists.txt Examples of calling the 'test' function to build and run GUnit benchmarks, targeting specific benchmark suites. ```cmake if(GUNIT_BUILD_BENCHMARKS) include_directories(benchmark) test(benchmark/GUnit/test SCENARIO=) test(benchmark/gtest/test SCENARIO=) endif() ``` -------------------------------- ### Configure Reveal.js Initialization with Plugins (JavaScript) Source: https://github.com/cpp-testing/gunit/blob/master/docs/cppcon-2018/reveal.js/index.html This snippet demonstrates how to initialize the reveal.js presentation framework. It configures the presentation with an array of dependencies, specifying plugins for Markdown parsing, notes display, and code highlighting, ensuring they load asynchronously and execute callbacks. ```javascript Reveal.initialize({ dependencies: [ { src: 'plugin/markdown/marked.js' }, { src: 'plugin/markdown/markdown.js' }, { src: 'plugin/notes/notes.js', async: true }, { src: 'plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } } ] }); ``` -------------------------------- ### Reveal.js Initialization with Dependencies Source: https://github.com/cpp-testing/gunit/blob/master/docs/cppnow-2017/README.md Demonstrates how to initialize Reveal.js and load external scripts as dependencies. Dependencies can have optional conditions, asynchronous loading, and callbacks. ```javascript Reveal.initialize({ dependencies: [ // Cross-browser shim that fully implements classList - https://github.com/eligrey/classList.js/ { src: 'lib/js/classList.js', condition: function() { return !document.body.classList; } }, // Interpret Markdown in
elements { src: 'plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } }, { src: 'plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } }, // Syntax highlight for elements { src: 'plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } }, // Zoom in and out with Alt+click { src: 'plugin/zoom-js/zoom.js', async: true }, // Speaker notes { src: 'plugin/notes/notes.js', async: true }, // MathJax { src: 'plugin/math/math.js', async: true } ] }); ``` -------------------------------- ### GUnit.GMake Tutorial: C++17 Test Example Source: https://github.com/cpp-testing/gunit/blob/master/docs/GMake.md Demonstrates using `testing::make` in a C++17 test case to create a System Under Test (SUT) with NaggyMocks. It shows how to set expectations on mocks and call a method on the SUT, highlighting the automatic mock creation and constructor flexibility. ```cpp TEST(Test, ShouldPrintTextWhenUpdate) { using namespace testing; auto [sut, mocks] = make(); // create NaggyMocks when required EXPECT_CALL(mocks.mock(), (is_dumpable)()).WillOnce(Return(true)); EXPECT_CALL(mocks.mock(), (print)("text")); sut->update(); } ``` -------------------------------- ### PHP Function Example Source: https://github.com/cpp-testing/gunit/blob/master/docs/cppnow-2017/plugin/markdown/example.html A basic PHP function demonstrating array creation and assignment. This snippet is a standalone example of PHP syntax. ```php public function foo() { $foo = array( 'bar' => 'bar' ); } ``` -------------------------------- ### Quick Start: Fetch GUnit with CMake Source: https://github.com/cpp-testing/gunit/blob/master/README.md Demonstrates how to add GUnit to your project using CMake's FetchContent module. This method fetches the GUnit repository directly from GitHub and makes it available for use in your build. ```cmake include(FetchContent) FetchContent_Declare( gunit GIT_REPOSITORY https://github.com/cpp-testing/GUnit.git GIT_TAG master ) FETCHCONTENT_MAKEAVAILABLE(gunit) ``` -------------------------------- ### GUnit.GTest-Lite Example Source: https://github.com/cpp-testing/gunit/blob/master/docs/cppnow-2017/index.html An example of a test case using the GUnit.GTest-Lite framework. This lightweight version uses string literals for test names and operator overloading for assertions, simplifying test writing. ```cpp "should add 2 numbers"_test { // -gnu-string-literal EXPECT(4 == add(2, 2)); // -operator-template } ``` -------------------------------- ### GoogleTest Example Source: https://github.com/cpp-testing/gunit/blob/master/docs/cppnow-2017/index.html An example of a test case written using the GoogleTest framework. It employs `TEST` macros for defining test suites and cases, and `EXPECT_EQ` for assertions, offering robust testing capabilities. ```cpp TEST(AddTest, should_add_2_numbers) { EXPECT_EQ(4, add(2, 2)); } ``` -------------------------------- ### Reveal.js Initialization Configuration Source: https://github.com/cpp-testing/gunit/blob/master/docs/cppnow-2017/index.html This snippet demonstrates the primary configuration object for Reveal.js. It includes settings for display controls, progress bars, slide numbers, navigation history, keyboard shortcuts, overview mode, slide centering, touch support, looping, RTL direction, fragments, embedded mode, help overlays, speaker notes, auto-sliding, mouse wheel navigation, address bar hiding, link previews, transition styles and speeds, background transitions, view distance, and parallax backgrounds. It also includes an array of plugin dependencies. ```javascript Reveal.initialize({ // Display controls in the bottom right corner controls: true, // Display a presentation progress bar progress: true, // Display the page number of the current slide slideNumber: true, // Push each slide change to the browser history history: true, // Enable keyboard shortcuts for navigation keyboard: true, // Enable the slide overview mode overview: true, // Vertical centering of slides center: true, // Enables touch navigation on devices with touch input touch: true, // Loop the presentation loop: false, // Change the presentation direction to be RTL rtl: false, // Turns fragments on and off globally fragments: false, // Flags if the presentation is running in an embedded mode, // i.e. contained within a limited portion of the screen embedded: false, // Flags if we should show a help overlay when the questionmark // key is pressed help: true, // Flags if speaker notes should be visible to all viewers showNotes: false, // Number of milliseconds between automatically proceeding to the // next slide, disabled when set to 0, this value can be overwritten // by using a data-autoslide attribute on your slides autoSlide: 0, // Stop auto-sliding after user input autoSlideStoppable: true, // Enable slide navigation via mouse wheel mouseWheel: true, // Hides the address bar on mobile devices hideAddressBar: true, // Opens links in an iframe preview overlay previewLinks: false, // Transition style transition: 'convex', // none/fade/slide/convex/concave/zoom // Transition speed transitionSpeed: 'default', // default/fast/slow // Transition style for full page slide backgrounds backgroundTransition: 'default', // none/fade/slide/convex/concave/zoom // Number of slides away from the current that are visible viewDistance: 3, // Parallax background image parallaxBackgroundImage: '', // e.g. "https://s3.amazonaws.com/hakim-static/reveal-js/reveal-parallax-1.jpg" // Parallax background size parallaxBackgroundSize: '', // CSS syntax, e.g. "2100px 900px" // Number of pixels to move the parallax background per slide // - Calculated automatically unless specified // - Set to 0 to disable movement along an axis parallaxBackgroundHorizontal: null, parallaxBackgroundVertical: null, // Optional reveal.js plugins dependencies: [ { src: 'lib/js/classList.js', condition: function() { return !document.body.classList; } }, { src: 'plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } }, { src: 'plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } }, { src: 'plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } }, { src: 'plugin/zoom-js/zoom.js', async: true }, { src: 'plugin/notes/notes.js', async: true } ] }); ``` -------------------------------- ### Boost.DI: Creating an App Object Source: https://github.com/cpp-testing/gunit/blob/master/docs/cppnow-2017/index.html Demonstrates how to create an instance of the 'App' class using Boost.DI's `make` function. Boost.DI automatically deduces constructor parameters and their scopes, simplifying object creation. ```cpp class App { public: App(const Reader&, Printer&); // Boost.DI deduces constructors parameters // deduces required scope for them private: // create dependencies and inject them Reader& reader; Printer& printer; }; int main() { auto app = di::make(); app.run(); } ``` -------------------------------- ### Boost.Test Example Source: https://github.com/cpp-testing/gunit/blob/master/docs/cppnow-2017/index.html An example of a test case using the Boost.Test framework. It utilizes `BOOST_AUTO_TEST_CASE` for test case definition and `BOOST_CHECK_EQUAL` for assertions, providing better output and structure than standard C++ assertions. ```cpp BOOST_AUTO_TEST_CASE(should_add_2_numbers) { BOOST_CHECK_EQUAL(4, add(2, 2)); } ``` -------------------------------- ### Reveal.js HTML Code Example with Attributes Source: https://github.com/cpp-testing/gunit/blob/master/docs/cppcon-2018/reveal.js/README.md An example of an HTML slide section containing a preformatted code block. It demonstrates the use of `data-trim` to remove surrounding whitespace and `data-noescape` to prevent HTML escaping. ```html

(def lazy-fib
  (concat
   [0 1]
   ((fn rfib [a b]
        (lazy-cons (+ a b) (rfib b (+ a b)))) 0 1)))
	
``` -------------------------------- ### Reveal.js Client Presentation Configuration Source: https://github.com/cpp-testing/gunit/blob/master/docs/cppcon-2018/reveal.js/README.md Configuration for setting up a client Reveal.js presentation to connect to a master. Includes socket.io connection details and dependencies for multiplexing. ```javascript Reveal.initialize({ // other options... multiplex: { // Example values. To generate your own, see the socket.io server instructions. secret: null, // null so the clients do not have control of the master presentation id: '1ea875674b17ca76', // id, obtained from socket.io server url: 'https://reveal-js-multiplex-ccjbegmaii.now.sh' // Location of socket.io server }, // Don't forget to add the dependencies dependencies: [ { src: '//cdn.socket.io/socket.io-1.3.5.js', async: true }, { src: 'plugin/multiplex/client.js', async: true } // other dependencies... ] }); ``` -------------------------------- ### C++ Integration Test with GMock and Boost.DI Source: https://github.com/cpp-testing/gunit/blob/master/docs/FAQ.md Demonstrates setting up integration tests for a system under test (SUT) using Google Mock (GMock) for mocking dependencies and Boost.DI for dependency injection. It shows how to bind mock interfaces to the injector and configure expectations on the mocks. ```cpp class example; // System Under Test GTEST(example) { namespace di = boost::di; SHOULD("create example") { const auto injector = di::make_injector( di::bind.to(di::NiceGMock{mocks}) , di::bind.to(di::StrictGMock{mocks}) ); sut = testing::make(injector); EXPECT_CALL(mock(), (get)(_)).WillOnce(Return(123)); EXPECT_CALL(mock(), (f2)(123)); sut->update(); } } ``` -------------------------------- ### Reveal.js Initialization with Syntax Highlighting Source: https://github.com/cpp-testing/gunit/blob/master/docs/cppcon-2018/index.html Initializes the reveal.js presentation framework, setting up a callback for syntax highlighting using highlight.js and loading various plugins for enhanced functionality like zoom, notes, and line numbers. ```javascript Reveal.initialize({ callback: function() { hljs.initHighlightingOnLoad(); } }, { src: 'reveal.js/plugin/zoom-js/zoom.js', async: true }, { src: 'reveal.js/plugin/notes/notes.js', async: true }, { src: 'extensions/plugin/line-numbers/line-numbers.js' }); ``` -------------------------------- ### Reveal.js Code Highlighting Example Source: https://github.com/cpp-testing/gunit/blob/master/docs/cppcon-2018/reveal.js/demo.html A JavaScript function example within reveal.js that demonstrates applying a 'roll' class to elements, likely for visual effects or integration with code highlighting libraries. ```javascript function linkify( selector ) { if( supports3DTransforms ) { var nodes = document.querySelectorAll( selector ); for( var i = 0, len = nodes.length; i < len; i++ ) { var node = nodes[i]; if( !node.className ) { node.className += ' roll'; } } } } ``` -------------------------------- ### Reveal.js Initialization Configuration Source: https://github.com/cpp-testing/gunit/blob/master/docs/cppcon-2018/reveal.js/plugin/markdown/example.html Configuration object for initializing reveal.js, including options for controls, progress, history, centering, and loading optional libraries like markdown support and syntax highlighting. ```javascript Reveal.initialize({ controls: true, progress: true, history: true, center: true, // Optional libraries used to extend on reveal.js dependencies: [ { src: '../../lib/js/classList.js', condition: function() { return !document.body.classList; } }, { src: 'marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } }, { src: 'markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } }, { src: '../highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } }, { src: '../notes/notes.js' } ] }); ``` -------------------------------- ### BDD Acceptance Criteria Example (Trading System) Source: https://github.com/cpp-testing/gunit/blob/master/docs/cppnow-2017/index.html An example of BDD acceptance criteria written in Gherkin for an Automated Trading System. It defines scenarios for buying and selling shares based on stock price movements. ```gherkin Feature: Automated Trading System Scenario 1: Trading System requests to buy shares Given The Trading System is up and running When GOOGL stock is rising (last 1000 transactions) Then A buy order for 100 shares of APPL should have been executed And The TS should own 100 shares of APPL Scenario 2: Trading System requests to sell shares Given The Trading System is up and running And The TS owns 50 shares of APPL stock When GOOGL stock is falling ( ``` -------------------------------- ### BDD C++ Test Example (Gherkin Syntax) Source: https://github.com/cpp-testing/gunit/blob/master/docs/cppnow-2017/index.html An example demonstrating Behaviour Driven Development (BDD) using C++ with a syntax inspired by Gherkin/Cucumber. It shows how to define tests with 'Given', 'When', and 'Then' steps. ```cpp "[TDD] add numbers"_test = [] { "[BDD] should add 2 numbers" = [] { EXPECT_CALL(sum, add(2, 2)).WillOnce(Return(4)); GIVEN(sum, add(2, 2)).WillOnce(Return(4)); c.add(2, 2); WHEN(calc.add(2, 2)); EXPECT(count == 4); THEN(count).should_be(4); }; }; ``` -------------------------------- ### Initialize Reveal.js with Default Configuration Source: https://github.com/cpp-testing/gunit/blob/master/docs/cppnow-2017/README.md This snippet demonstrates initializing the Reveal.js presentation framework with a comprehensive set of default configuration options. It covers display controls, navigation, history, keyboard shortcuts, and various visual and functional settings for the presentation. ```javascript Reveal.initialize({ // Display controls in the bottom right corner controls: true, // Display a presentation progress bar progress: true, // Display the page number of the current slide slideNumber: false, // Push each slide change to the browser history history: false, // Enable keyboard shortcuts for navigation keyboard: true, // Enable the slide overview mode overview: true, // Vertical centering of slides center: true, // Enables touch navigation on devices with touch input touch: true, // Loop the presentation loop: false, // Change the presentation direction to be RTL rtl: false, // Turns fragments on and off globally fragments: true, // Flags if the presentation is running in an embedded mode, // i.e. contained within a limited portion of the screen embedded: false, // Flags if we should show a help overlay when the questionmark // key is pressed help: true, // Flags if speaker notes should be visible to all viewers showNotes: false, // Number of milliseconds between automatically proceeding to the // next slide, disabled when set to 0, this value can be overwritten // by using a data-autoslide attribute on your slides autoSlide: 0, // Stop auto-sliding after user input autoSlideStoppable: true, // Enable slide navigation via mouse wheel mouseWheel: false, // Hides the address bar on mobile devices hideAddressBar: true, // Opens links in an iframe preview overlay previewLinks: false, // Transition style transition: 'default', // none/fade/slide/convex/concave/zoom // Transition speed transitionSpeed: 'default', // default/fast/slow // Transition style for full page slide backgrounds backgroundTransition: 'default', // none/fade/slide/convex/concave/zoom // Number of slides away from the current that are visible viewDistance: 3, // Parallax background image parallaxBackgroundImage: '', // e.g. "'https://s3.amazonaws.com/hakim-static/reveal-js/reveal-parallax-1.jpg'" // Parallax background size parallaxBackgroundSize: '', // CSS syntax, e.g. "2100px 900px" // Amount to move parallax background (horizontal and vertical) on slide change // Number, e.g. 100 parallaxBackgroundHorizontal: '', parallaxBackgroundVertical: '' }); ``` -------------------------------- ### Reveal.js Initialization Configuration Source: https://github.com/cpp-testing/gunit/blob/master/docs/cppnow-2017/plugin/markdown/example.html JavaScript code to initialize the reveal.js presentation framework. It includes common configuration options and specifies dependencies for optional libraries like marked.js and markdown.js for Markdown support, and highlight.js for code highlighting. ```javascript Reveal.initialize({ controls: true, progress: true, history: true, center: true, // Optional libraries used to extend on reveal.js dependencies: [ { src: '../../lib/js/classList.js', condition: function() { return !document.body.classList; } }, { src: 'marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } }, { src: 'markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } }, { src: '../highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } }, { src: '../notes/notes.js' } ] }); ``` -------------------------------- ### Configure Reveal.js Initialization Source: https://github.com/cpp-testing/gunit/blob/master/docs/cppcon-2018/reveal.js/demo.html Shows how to initialize reveal.js with various configuration options. This includes enabling controls, progress bars, history, centering slides, setting transitions, and loading necessary dependencies like plugins. ```javascript // More info https://github.com/hakimel/reveal.js#configuration Reveal.initialize({ controls: true, progress: true, history: true, center: true, transition: 'slide', // none/fade/slide/convex/concave/zoom // More info https://github.com/hakimel/reveal.js#dependencies dependencies: [ { src: 'lib/js/classList.js', condition: function() { return !document.body.classList; } }, { src: 'plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } }, { src: 'plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } }, { src: 'plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } }, { src: 'plugin/search/search.js', async: true }, { src: 'plugin/zoom-js/zoom.js', async: true }, { src: 'plugin/notes/notes.js', async: true } ] }); ``` -------------------------------- ### JavaScript Variable Declaration Source: https://github.com/cpp-testing/gunit/blob/master/docs/cppcon-2018/reveal.js/test/simple.md A basic example demonstrating how to declare a variable using 'var' in JavaScript. ```js var a = 1; ``` -------------------------------- ### GUnit GSteps Basic Usage Source: https://github.com/cpp-testing/gunit/blob/master/docs/GSteps.md Example of how to register Given, When, and Then steps using the GSTEPS macro and lambda expressions. ```cpp /** * @param args default-constructible types to be injected */ GSTEPS("*" ) { // * - any feature Given("Step...") = [] { /* action */ }; When("Step...") = [] { /* action */ }; Then("Step...") = [] { /* action */ }; } ``` -------------------------------- ### GUnit Library and Dependency Setup Source: https://github.com/cpp-testing/gunit/blob/master/CMakeLists.txt Configures the main GUnit library as an INTERFACE library, sets include directories for GUnit, googletest, gmock, and nlohmann/json, and links against necessary libraries like gtest_main, gmock_main, and gherkin-cpp. ```cmake enable_testing() add_subdirectory(libs/googletest) add_library(gunit INTERFACE) target_include_directories(gunit INTERFACE include) target_include_directories(gunit INTERFACE ${gtest_SOURCE_DIR}/include ${gmock_SOURCE_DIR}/include libs/json/single_include/nlohmann ) target_link_libraries(gunit INTERFACE gtest_main INTERFACE gmock_main INTERFACE gherkin-cpp ) set(BUILD_GMOCK) set(BUILD_GTEST) add_subdirectory(libs/gherkin-cpp) ``` -------------------------------- ### Stupid vs SOLID: App Class Example Source: https://github.com/cpp-testing/gunit/blob/master/docs/cppnow-2017/index.html Presents a C++ `App` class that tightly couples with a `Manager` instance, leading to untestability. It demonstrates issues like tight coupling, untestability, premature optimization, and singleton usage via `Logger::instance()`. ```cpp class App { public: App() : manager(std::make_unique()) // Untestability { } // Tight Coupling __attribute__((always_inline)) void run() { // Premature Optimization Logger::instance() // Singleton << "run:" << manager()->readValue() << '\n'; manager->printValue( manager->readValue() // Duplication ) } private: std::unique_ptr manager; }; ``` -------------------------------- ### GUnit GSteps Implementation Example Source: https://github.com/cpp-testing/gunit/blob/master/docs/GSteps.md Detailed implementation of Gherkin steps for a calculator feature, including parameter matching and nested steps. ```cpp GSTEPS("Calc*") { using namespace testing; double result{}; Given("I created a calculator with initial value equals {n}"_step) = [&](double n) { Calculator calc{n}; Given("I have entered {n} into the calculator") = [&](double n) { calc.push(n); }; When("I press add") = [&] { result = calc.add(); }; When("I press divide") = [&] { result = calc.divide(); }; Then("the result should be {expected} on the screen") = [&](double expected) { EXPECT_EQ(expected, result); }; }; } ``` -------------------------------- ### Socket.IO Connection and State Handling Source: https://github.com/cpp-testing/gunit/blob/master/docs/cppnow-2017/plugin/notes-server/notes.html Establishes a Socket.IO connection to the server to receive presentation state changes. It ignores messages from other clients and initializes the presentation setup once connected. It also handles incoming state messages, updating the speaker notes and synchronizing the presentation slides. ```javascript (function() { var notes, notesValue, currentState, currentSlide, upcomingSlide, connected = false; var socket = io.connect( window.location.origin ), socketId = '{{socketId}}'; socket.on( 'statechanged', function( data ) { // ignore data from sockets that aren't ours if( data.socketId !== socketId ) { return; } if( connected === false ) { connected = true; setupKeyboard(); setupNotes(); setupTimer(); } handleStateMessage( data ); } ); // Load our presentation iframes setupIframes(); // Once the iframes have loaded, emit a signal saying there's // a new subscriber which will trigger a 'statechanged' // message to be sent back window.addEventListener( 'message', function( event ) { var data = JSON.parse( event.data ); if( data && data.namespace === 'reveal' ) { if( /ready/.test( data.eventName ) ) { socket.emit( 'new-subscriber', { socketId: socketId } ); } } // Messages sent by reveal.js inside of the current slide preview if( data && data.namespace === 'reveal' ) { if( /slidechanged|fragmentshown|fragmenthidden|overviewshown|overviewhidden|paused|resumed/.test( data.eventName ) && currentState !== JSON.stringify( data.state ) ) { socket.emit( 'statechanged-speaker', { state: data.state } ); } } } ); /** * Called when the main window sends an updated state. */ function handleStateMessage( data ) { // Store the most recently set state to avoid circular loops // applying the same state currentState = JSON.stringify( data.state ); // No need for updating the notes in case of fragment changes if ( data.notes ) { notes.classList.remove( 'hidden' ); if( data.markdown ) { notesValue.innerHTML = marked( data.notes ); } else { notesValue.innerHTML = data.notes; } } else { notes.classList.add( 'hidden' ); } // Update the note slides currentSlide.contentWindow.postMessage( JSON.stringify({ method: 'setState', args: [ data.state ] }), '*'); upcomingSlide.contentWindow.postMessage( JSON.stringify({ method: 'setState', args: [ data.state ] }), '*'); upcomingSlide.contentWindow.postMessage( JSON.stringify({ method: 'next' }), '*'); } // Limit to max one state update per X ms handleStateMessage = debounce( handleStateMessage, 200 ); /** * Forward keyboard events to the current slide window. * This enables keyboard events to work even if focus * isn't set on the current slide iframe. */ function setupKeyboard() { document.addEventListener( 'keydown', function( event ) { currentSlide.contentWindow.postMessage( JSON.stringify({ method: 'triggerKey', args: [ event.keyCode ] }), '*'); } ); } /** * Creates the preview iframes. */ function setupIframes() { var params = [ 'receiver', 'progress=false', 'history=false', 'transition=none', 'backgroundTransition=none' ].join('&'); var currentURL = '/?' + params + '&postMessageEvents=true'; var upcomingURL = '/?' + params + '&controls=false'; currentSlide = document.createElement( 'iframe' ); currentSlide.setAttribute( 'width', 1280 ); currentSlide.setAttribute( 'height', 1024 ); currentSlide.setAttribute( 'src', currentURL ); document.querySelector( '#current-slide' ).appendChild( currentSlide ); upcomingSlide = document.createElement( 'iframe' ); upcomingSlide.setAttribute( 'width', 640 ); upcomingSlide.setAttribute( 'height', 512 ); upcomingSlide.setAttribute( 'src', upcomingURL ); document.querySelector( '#upcoming-slide' ).appendChild( upcomingSlide ); } /** * Setup the notes UI. */ function setupNotes() { notes = document.querySelector( '.speaker-controls-notes' ); notesValue = document.querySelector( '.speaker-controls-notes .value' ); } /** * Create the timer and clock and start updating them * at an interval. */ function setupTimer() { var start = new Date(), timeEl = document.querySelector( '.speaker-controls-time' ), clockEl = timeEl.querySelector( '.clock-value' ), hoursEl = timeEl.querySelector( '.hours-value' ), minutesEl = timeEl.querySelector( '.minutes-value' ), secondsEl = timeEl.querySelector( '.seconds-value' ); function _updateTimer() { var diff, hours, minutes, seconds, now = new Date(); diff = now.getTime() - start.getTime(); hours = Math.floor( diff / ( 1000 * 60 * 60 ) ); minutes = Math.floor( ( diff / ( 1000 * 60 ) ) % 60 ); seconds = Math.floor( ( diff / 1000 ) % 60 ); clockEl.innerHTML = now.toLocaleTimeString( 'en-US', { hour12: true, hour: '2-digit', minute:'2-digit' } ); hoursEl.innerHTML = zeroPadInteger( hours ); hoursEl.className = hours > 0 ? '' : 'mute'; minutesEl.innerHTML = ':' + zeroPadInteger( minutes ); minutesEl.className = minutes > 0 ? '' : 'mute'; secondsEl.innerHTML = ':' + zeroPadInteger( seconds ); } // Update once directly _updateTimer(); // Then update every second setInterval( _updateTimer, 1000 ); timeEl.addEventListener( 'click', function() { start = new Date(); _updateTimer(); return false; } ); } function zeroPadInteger( num ) { var str = '00' + parseInt( num ); return str.substring( str.length - 2 ); } /** * Limits the frequency at which a function can be called. */ function debounce(func, wait, immediate) { var timeout, result; return function() { var context = this, args = arguments; var later = function() { timeout = null; if (!immediate) result = func.apply(context, args); }; var callNow = immediate && !timeout; clearTimeout(timeout); timeout = setTimeout(later, wait); if (callNow) result = func.apply(context, args); return result; }; } })(); ``` -------------------------------- ### Rogers-Ramanujan Identity Source: https://github.com/cpp-testing/gunit/blob/master/docs/cppcon-2018/reveal.js/test/examples/math.html Example of a Rogers-Ramanujan Identity rendered using LaTeX. This demonstrates the plugin's support for infinite series and product notations. ```latex 1 + \frac{q^2}{(1-q)}+\frac{q^6}{(1-q)(1-q^2)}+\cdots = \prod_{j=0}^{\infty}\frac{1}{(1-q^{5j+2})(1-q^{5j+3})} ```