title: How to test C++ classes when header files contain explicit paths?
body: <p>I have classes that look like this:</p>
  <p>Header (.h):</p>
  <pre><code>class DatabaseX ; //forward declare
  class DeepClass
  { 
  public:
    void DeepClass(DatabaseX* db);
    void doStuff();
  private:
    DatabaseX *m_db;
  
  };
  </code></pre>
  <p>Definition (.cpp)</p>
  <pre><code>#include &quot;some/path/that/stretches/into/a/rather/deep/structure/DeepClass.h&quot;
  #include &quot;another/somewhat/disturbing/long/path/to/somewhere/distant/DatabaseX.h&quot;
  
  void DeepClass::DeepClass(DatabaseX* db):m_db(db){ m_db-&gt;open() }
  void DeepClass::~DeepClass(){ m_db-&gt;close(); delete m_db; }
  
  void DeepClass::doStuff(){ // &lt;complicated stuff here&gt; }
  
  </code></pre>
  <p>Now I want a <em>test</em> that checks that <code>doStuff()</code> does the right kind of stuff.</p>
  <p>So I write my own mock <code>DatabaseX</code>.
  But I have a problem, my own mock database lives in the test directory, it has no place in production code, and what's worse, <code>DatabaseX</code> was never written to be inherited and overloaded.
  It's a concrete class, and isn't anything like an interface.</p>
  <p>So my question is, how do I write a test, with all these hard-coded include paths everywhere?
  Do I for example:</p>
  <ol>
  <li>create another duplicate file structure that matches the include paths, and put my  mock <code>DatabaseX</code> there in this duplicate file structure?</li>
  <li>Somehow rewite each cpp file before the compiler accesses it by some indirection magic or other?</li>
  <li>Add macros to eat up the paths?</li>
  <li>Write a python/perl/bash script to temporarily remove the include paths prior to compiling my tests?</li>
  <li>Just include everything, accept the dependencies of <code>DatabaseX</code>, and just compile the real thing, and all it's dependencies and then replace at link time?</li>
  <li>Accept defeat; don't write any tests, and bury my head in the sand.</li>
  <li>OR ... ?</li>
  </ol>
  <p>I should say there are well over a million lines of code, so changing the source code isn't an option.
  Is there a very simple way to overcome this nightmare via a nice simple compiler option or other?</p>
  <p>(Perhaps it's not relevant but I'm using Qt's QTest &amp; QtCreator. Maybe there is some magical switch that makes all these gruesome paths go away!).</p>
  <p>I am using GCC 4.8.5</p>