title: Unit testing a function that returns a pointer (C++)
body: <p>I have the following function:</p>
  
  <pre><code>unsigned* b_row_to_array(b_row r) {
      unsigned a[] = {(r &gt;&gt; 8) &amp; 3,
          (r &gt;&gt; 6) &amp; 3,
          (r &gt;&gt; 4) &amp; 3,
          (r &gt;&gt; 2) &amp; 3,
          r &amp; 3};
      return a;
  }
  </code></pre>
  
  <p>That I wrote the following test function for:</p>
  
  <pre><code>TEST_METHOD(BRowToArrayTest) {
      unsigned expected[] = { 0, 0, 0, 0, 0 };
      unsigned* computed = b_row_to_array(0);
      for (int i = 0; i &lt; 1; i++) {
          Assert::AreEqual(expected[i], computed[i]);
      }
  }
  </code></pre>
  
  <p>But the test fails, saying "Expected:&lt;0>, Actual:&lt;42348989>", where the value for Actual is different with every test, so it must be reading in the wrong address. Am I using pointers wrong or does it read out-of-bounds because the test function is not in the same project? How can I solve this?</p>