sigmait.pl
Open in
urlscan Pro
162.159.135.42
Public Scan
Submitted URL: http://sigmait.pl/blog/implementing-and-testing-callbacks-in-c-and-gmock/
Effective URL: https://sigmait.pl/blog/implementing-and-testing-callbacks-in-c-and-gmock/
Submission: On April 06 via api from US — Scanned from US
Effective URL: https://sigmait.pl/blog/implementing-and-testing-callbacks-in-c-and-gmock/
Submission: On April 06 via api from US — Scanned from US
Form analysis
3 forms found in the DOM/
<form class="nexer-search__wrapper" action="/" autocomplete="off"> <button class="nexer-search__search-btn" aria-label="Search"> <svg width="22" height="22" viewBox="0 0 22 22" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M18.6883 9.83157C18.6883 14.6473 14.7576 18.5631 9.89417 18.5631C5.03069 18.5631 1.1 14.6473 1.1 9.83157C1.1 5.01583 5.03069 1.1 9.89417 1.1C14.7576 1.1 18.6883 5.01583 18.6883 9.83157Z" stroke="black" stroke-width="2.2"></path>
<rect width="7.43859" height="2.16984" transform="matrix(0.709347 0.704859 -0.709347 0.704859 16.7227 15.2266)" fill="black"></rect>
</svg> </button> <label id="nexer-search__label" class="sr-only" for="nexer-search__input">Search</label> <input id="nexer-search__input" type="text" placeholder="Search" class="nexer-search__input" aria-labelledby="nexer-search__label"
autocomplete="off"> <button class="nexer-search__close-btn" type="button" aria-label=" Close search"> <svg width="26" height="22" viewBox="0 0 26 22" fill="none" xmlns="http://www.w3.org/2000/svg">
<rect x="3" y="19.3848" width="26" height="2.29412" transform="rotate(-45 3 19.3848)" fill="black"></rect>
<rect x="4.62305" y="1.14453" width="26" height="2.29412" transform="rotate(45 4.62305 1.14453)" fill="black"></rect>
</svg> </button></form>
<form autocomplete="off">
<h3 class="p-h2">Functionality</h3>
<hr>
<p> These cookies are required as we need to save your consent of your choices of cookies.</p>
<div class="nexer-cookie-bar-choices__row"> <label class="switch" for="nexer-cookie-functionality-checkbox"> <input type="checkbox" checked="" disabled="" id="nexer-cookie-functionality-checkbox" autocomplete="off"> <span
class="slider round"></span> <span style="display:none">Functionality cookies are mandatory</span> </label></div> <br>
<h3 class="p-h2">Tracking and Performance</h3>
<hr>
<p>These cookies are used for gathering data on how our visitors use our website.</p>
<div class="nexer-cookie-bar-choices__row"> <label class="switch" for="nexer-cookie-tracking-checkbox"> <input type="checkbox" id="nexer-cookie-tracking-checkbox" autocomplete="off"> <span class="slider round"></span> <span
style="display:none">Toggle Tracking and Performance cookies</span> </label></div> <br>
<h3 class="p-h2">Targeting and Advertising</h3>
<hr>
<p>These cookies are used for gathering information from you on your device to display advertisements to you based on relevant topics that interests you.</p>
<div class="nexer-cookie-bar-choices__row"> <label class="switch" for="nexer-cookie-targeting-checkbox"> <input type="checkbox" id="nexer-cookie-targeting-checkbox" autocomplete="off"> <span class="slider round"></span> <span
style="display:none">Toggle Targeting and Advertising cookies</span> </label></div> <br>
<hr>
<div class="nexer-cookie-bar-choices__row"> <button class="nexer-button allow-all"> ALLOW ALL </button> <button class="nexer-button reject-all"> REJECT ALL </button> <button class="nexer-button save-options primary"> SAVE OPTIONS </button></div>
</form>
POST https://forms.hsforms.com/submissions/v3/public/submit/formsnext/multipart/3391768/23902bc5-9184-4067-a54b-ba22d36117fe
<form id="hsForm_23902bc5-9184-4067-a54b-ba22d36117fe" method="POST" accept-charset="UTF-8" enctype="multipart/form-data" novalidate=""
action="https://forms.hsforms.com/submissions/v3/public/submit/formsnext/multipart/3391768/23902bc5-9184-4067-a54b-ba22d36117fe"
class="hs-form-private hsForm_23902bc5-9184-4067-a54b-ba22d36117fe hs-form-23902bc5-9184-4067-a54b-ba22d36117fe hs-form-23902bc5-9184-4067-a54b-ba22d36117fe_2ddf6d18-1319-425b-98ad-aa45a2b54fbd hs-form stacked"
target="target_iframe_23902bc5-9184-4067-a54b-ba22d36117fe" data-instance-id="2ddf6d18-1319-425b-98ad-aa45a2b54fbd" data-form-id="23902bc5-9184-4067-a54b-ba22d36117fe" data-portal-id="3391768"
data-test-id="hsForm_23902bc5-9184-4067-a54b-ba22d36117fe" autocomplete="off">
<div class="hs_email hs-email hs-fieldtype-text field hs-form-field"><label id="label-email-23902bc5-9184-4067-a54b-ba22d36117fe" class="" placeholder="Enter your Email" for="email-23902bc5-9184-4067-a54b-ba22d36117fe"><span>Email</span><span
class="hs-form-required">*</span></label>
<legend class="hs-field-desc" style="display: none;"></legend>
<div class="input"><input id="email-23902bc5-9184-4067-a54b-ba22d36117fe" name="email" required="" placeholder="" type="email" class="hs-input" inputmode="email" autocomplete="off" value=""></div>
</div>
<div class="hs_checklang hs-checklang hs-fieldtype-text field hs-form-field" style="display: none;"><label id="label-checklang-23902bc5-9184-4067-a54b-ba22d36117fe" class="" placeholder="Enter your checkLang"
for="checklang-23902bc5-9184-4067-a54b-ba22d36117fe"><span>checkLang</span></label>
<legend class="hs-field-desc" style="display: none;"></legend>
<div class="input"><input name="checklang" class="hs-input" type="hidden" value="en" autocomplete="off"></div>
</div>
<div class="hs_submit hs-submit">
<div class="hs-field-desc" style="display: none;"></div>
<div class="actions"><input type="submit" class="hs-button primary large" value="Registrera" autocomplete="off" style="display: none;"></div>
</div><input name="hs_context" type="hidden"
value="{"embedAtTimestamp":"1712444536090","formDefinitionUpdatedAt":"1632792288922","userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36","pageTitle":"implementing and testing callbacks in C++ and gmock - Sigma IT","pageUrl":"https://sigmait.pl/blog/implementing-and-testing-callbacks-in-c-and-gmock/","isHubSpotCmsGeneratedPage":false,"formTarget":"#hubspot-newsletter-23902bc5-9184-4067-a54b-ba22d36117fe","rumScriptExecuteTime":1762.2000045776367,"rumTotalRequestTime":2085.900001525879,"rumTotalRenderTime":2132.800003051758,"rumServiceResponseTime":323.6999969482422,"rumFormRenderTime":46.900001525878906,"connectionType":"4g","firstContentfulPaint":0,"largestContentfulPaint":0,"locale":"en","timestamp":1712444536242,"originalEmbedContext":{"portalId":"3391768","formId":"23902bc5-9184-4067-a54b-ba22d36117fe","region":"na1","target":"#hubspot-newsletter-23902bc5-9184-4067-a54b-ba22d36117fe","isBuilder":false,"isTestPage":false,"isPreview":false,"css":"","isMobileResponsive":true},"correlationId":"2ddf6d18-1319-425b-98ad-aa45a2b54fbd","renderedFieldsIds":["email","checklang"],"captchaStatus":"NOT_APPLICABLE","emailResubscribeStatus":"NOT_APPLICABLE","isInsideCrossOriginFrame":false,"source":"forms-embed-1.5064","sourceName":"forms-embed","sourceVersion":"1.5064","sourceVersionMajor":"1","sourceVersionMinor":"5064","allPageIds":{},"_debug_embedLogLines":[{"clientTimestamp":1712444536189,"level":"INFO","message":"Retrieved customer callbacks used on embed context: [\"onFormReady\",\"onFormSubmit\",\"onFormSubmitted\"]"},{"clientTimestamp":1712444536189,"level":"INFO","message":"Retrieved pageContext values which may be overriden by the embed context: {\"pageTitle\":\"implementing and testing callbacks in C++ and gmock - Sigma IT\",\"pageUrl\":\"https://sigmait.pl/blog/implementing-and-testing-callbacks-in-c-and-gmock/\",\"userAgent\":\"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36\",\"isHubSpotCmsGeneratedPage\":false}"},{"clientTimestamp":1712444536191,"level":"INFO","message":"Retrieved countryCode property from normalized embed definition response: \"US\""}]}"
autocomplete="off"><iframe name="target_iframe_23902bc5-9184-4067-a54b-ba22d36117fe" style="display: none;"></iframe>
</form>
Text Content
implementing and testing callbacks in C++ and gmock - Sigma IT Skip to content MENU * DevOps * Data Management Business services * Web development * Mobile development * Discovery Workshops * PoC and MVP R&D Projects * Connectivity Center * Mixed Reality * Embedded software development Cloud services * DevOps * Data Management MENU * Services * Industries * Projects * Blog * Careers * About us LANGUAGE ENGLISH Services Business services R&D Projects Cloud services Industries Life sciences Automotive HealthTech & Welfare About us Who we are Contacts Business services * Web development * Mobile development * Discovery Workshops * PoC and MVP R&D Projects * Connectivity Center * Mixed Reality * Embedded software development Cloud services * DevOps * Data Management CLOSE MENU * Services * Industries * Projects * Blog * Careers * About us LANGUAGE ENG * Services BUSINESS SERVICES Web development Mobile development Discovery Workshops PoC and MVP R&D PROJECTS Connectivity Center Mixed Reality Embedded software development CLOUD SERVICES DevOps Data Management * Industries Life sciences Automotive HealthTech & Welfare * Projects * Blog * Careers * About us Who we are Contacts Global Search Search Latest results 6 of 6 Type All results SELECT LANGUAGE ENGLISH SELECT COUNTRY Brasil Česká republika Colombia India Portugal Sverige United kingdom United States NEXER GLOBAL Start / News / implementing and testing callbacks in C++ and gmock TECHNICAL INSIGHTS SOFTWARE DEVELOPMENT A PRACTICAL GUIDE TO IMPLEMENTING AND TESTING CALLBACKS IN C++ AND GMOCK In this article, we implement the concept of callback in C++ and also use gmock as a way to test our code. OVERVIEW Callbacks exist in real life: you call someone, and they can not answer at that moment for any reason, you request a callback so that they call you at a later time. C++ has some Callables: functions, lambda expressions, bind expressions, function objects, and function pointers. There is also a class template std::function which is a general-purpose function wrapper that can store, copy and invoke any Callable. CASE STUDY There are two types of callbacks, blocking ones (synchronous) and deferred ones (asynchronous). The difference is blocking ones are called before the caller function returns so the caller actually waits for them to finish their job. A simple example of std::fucntion below: As an example of blocking/synchronous callback: Now, let’s look into how std::function can be tested using gmock. To mock std::function in tests, gmock provides MockFunction. First you need to create MockFunction object, obtain a std::fucntion proxy to Call from AsStdFucntion(), then set up expectations on its Call method and pass the obtained proxy to the test. Below there is an example of the std::funciton and MockFunction in a unit test: #include <gtest/gtest.h> #include <gmock/gmock.h> using ::testing::_; using ::testing::MockFunction; This simple example shows how MockFunction can be used in a handy way to mock std::function for testing purposes. REFERENCES [1] https://en.wikipedia.org/wiki/Callback_(computer_programming) [2] https://en.cppreference.com/w/cpp/utility/functional/function [3] http://google.github.io/googletest/gmock_cook_book.html#MockFunction Author: Cathayoun Ghotbi C++ Developer at Sigma IT RELATED ARTICLES: What Makes C++ one of the Top PrograMMING lANGUAGES? eMBEDDED sOFTWARE dEVELOPERS: dESIRED sKILLS aNd mAIN cHALLENGES tO fACE. wI-fi lAB: sECURE sOLUTION fOR rEMOTE eMBEDDED sOFTWARE dEVELOPMENT. This site uses cookies to provide you with a great user experience. By using this website, you accept the privacy policy. ALLOW ALL MANAGE OPTIONS Close cookie bar choices modal COOKIE SETTINGS -------------------------------------------------------------------------------- This site uses cookies to provide you with a great user experience. By using nexergroup.com, you accept the privacy policy. FUNCTIONALITY -------------------------------------------------------------------------------- These cookies are required as we need to save your consent of your choices of cookies. Functionality cookies are mandatory TRACKING AND PERFORMANCE -------------------------------------------------------------------------------- These cookies are used for gathering data on how our visitors use our website. Toggle Tracking and Performance cookies TARGETING AND ADVERTISING -------------------------------------------------------------------------------- These cookies are used for gathering information from you on your device to display advertisements to you based on relevant topics that interests you. Toggle Targeting and Advertising cookies -------------------------------------------------------------------------------- ALLOW ALL REJECT ALL SAVE OPTIONS Never miss a thing With Sigma IT´s newsletter you get all the latest updates on everything we do. With Sigma IT´s newsletter you get all the latest updates on everything we do. Email* checkLang CONTACT Sigma IT Poland Sp. z o.o. Fabryczna 6,53-609 Wroclaw Poland BUSINESS SERVICES: - Web Development - Mobile Development - Discovery Workshops - POC and MVP RESEARCH AND DEVELOPMENT PROJECTS: - Connectivity Center - Mixed Reality - Embedded Software Development CLOUD SERVICES: - DevOps - Data Management INDUSTRIES: - Life sciences - HealthTech & Welfare - Automotive linkedin Privacy policy Cookies policy 2024 SIGMA 2024 SIGMA