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 33,175 of 33,346    |
|    DeMarcus to All    |
|    Is it a bad idea to define private: as p    |
|    25 Aug 13 06:43:28    |
   
   From: demarcus_at_hotmail_com@tellus.orb.dotsrc.org   
      
   Hi,   
      
   In books about TDD I've seen various solutions to do White-Box   
   testing, i.e. test the protected and private parts of classes.   
      
   I came up with an idea that if you do the following it would be easy   
   to test the internal parts of a class.   
      
   #define protected public   
   #define private public   
      
   Here's an example that compiles with gcc 4.7.2.   
      
   // PrintClass.h   
   #include    
      
   class PrintClass   
   {   
   public:   
    std::string print() { return "Printing"; }   
   private:   
    std::string privatePrinting() { return "Printing private"; }   
   };   
      
      
   // main.cpp   
   #include    
      
   #define protected public   
   #define private public   
      
   #include "PrintClass.h"   
      
   void whiteBoxTest()   
   {   
    PrintClass pc;   
    std::cout << pc.privatePrinting() << std::endl;   
   }   
      
   int main()   
   {   
    whiteBoxTest();   
    return 0;   
   }   
      
   My question is: is this a bad idea?   
      
   I can't really see the bad consequences but I guess things like SFINAE   
   could break.   
      
      
   Thanks,   
   Daniel   
      
      
   --   
    [ 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