Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.c++.moderated    |    Moderated discussion of C++ superhackery    |    33,346 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 32,745 of 33,346    |
|    Ian Collins to Balog Pal    |
|    Re: Singletons    |
|    17 Dec 12 00:48:38    |
   
   From: ian-news@this.is.invalid   
      
   Balog Pal wrote:   
   > On 12/14/2012 1:21 AM, Öö Tiib wrote:   
   >> First ... about your idea in general. Making unit tests is difficult   
   >> when singular state on what your unit depends is behind free functions   
   >> and you use some mocking framework that does not help turning free   
   >> functions into mock versions.   
   >   
   > Can you give a C++ example for this? IME you just use its regular   
   > header, then the linker obviously will miss the function body, and you   
   > provide an implementation.   
   >   
   > And you can help with the preprocessor too defining a macro for the   
   > function name that hijacks it. (the singleton accessor function shall   
   > have a unique name, right?)   
      
   That is pretty close to the my mocking frameworks works. Behind the   
   scenes the framework replaces free functions with function objects.   
   These function objects have a set of static member functions that can be   
   used to control the function's behaviour in each suite or test. For   
   example if there was a Database type and a free function:   
      
   DatabaseInterface& database();   
      
   I could write   
      
    struct MockDatabase : DatabaseInterface { ... };   
      
    MockDatabase testDb;   
      
    database::willReturn( testDb );   
      
   --   
   Ian Collins   
      
      
    [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
    [ comp.lang.c++.moderated. First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca