?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. #include "UnitTest++/UnitTestPP.h"
  2. #include "UnitTest++/CurrentTest.h"
  3. #include "RecordingReporter.h"
  4. #include "ScopedCurrentTest.h"
  5.  
  6. using namespace std;
  7.  
  8. #ifndef UNITTEST_NO_EXCEPTIONS
  9.  
  10. namespace {
  11.  
  12.    TEST(RequireCheckSucceedsOnTrue)
  13.    {
  14.       bool failure = true;
  15.       bool exception = false;
  16.       {
  17.          RecordingReporter reporter;
  18.          UnitTest::TestResults testResults(&reporter);
  19.  
  20.          ScopedCurrentTest scopedResults(testResults);
  21.  
  22.          try
  23.          {
  24.             REQUIRE CHECK(true);
  25.          }
  26.          catch(const UnitTest::RequiredCheckException&)
  27.          {
  28.             exception = true;
  29.          }
  30.  
  31.          failure = (testResults.GetFailureCount() > 0);
  32.       }
  33.  
  34.       CHECK(!failure);
  35.       CHECK(!exception);
  36.    }
  37.  
  38.    TEST(RequiredCheckFailsOnFalse)
  39.    {
  40.       bool failure = false;
  41.       bool exception = false;
  42.       {
  43.          RecordingReporter reporter;
  44.          UnitTest::TestResults testResults(&reporter);
  45.          ScopedCurrentTest scopedResults(testResults);
  46.  
  47.          try
  48.          {
  49.             REQUIRE CHECK(false);
  50.          }
  51.          catch (const UnitTest::RequiredCheckException&)
  52.          {
  53.             exception = true;
  54.          }
  55.  
  56.          failure = (testResults.GetFailureCount() > 0);
  57.       }
  58.  
  59.       CHECK(failure);
  60.       CHECK(exception);
  61.    }
  62.  
  63.  
  64.    TEST(RequireMacroSupportsMultipleChecks)
  65.    {
  66.       bool failure = false;
  67.       bool exception = false;
  68.       {
  69.          RecordingReporter reporter;
  70.          UnitTest::TestResults testResults(&reporter);
  71.          ScopedCurrentTest scopedResults(testResults);
  72.  
  73.          try{
  74.             REQUIRE
  75.             {
  76.                CHECK(true);
  77.                CHECK_EQUAL(1,1);
  78.             }
  79.          }
  80.          catch (const UnitTest::RequiredCheckException&)
  81.          {
  82.             exception = true;
  83.          }
  84.  
  85.          failure = (testResults.GetFailureCount() > 0);
  86.       }
  87.  
  88.       CHECK(!failure);
  89.       CHECK(!exception);
  90.    }
  91.  
  92.  
  93.    TEST(RequireMacroSupportsMultipleChecksWithFailingChecks)
  94.    {
  95.       bool failure = false;
  96.       bool exception = false;
  97.       {
  98.          RecordingReporter reporter;
  99.          UnitTest::TestResults testResults(&reporter);
  100.          ScopedCurrentTest scopedResults(testResults);
  101.  
  102.          try{
  103.             REQUIRE
  104.             {
  105.                CHECK(true);
  106.                CHECK_EQUAL(1,2);
  107.             }
  108.          }
  109.          catch (const UnitTest::RequiredCheckException&)
  110.          {
  111.             exception = true;
  112.          }
  113.  
  114.          failure = (testResults.GetFailureCount() > 0);
  115.       }
  116.  
  117.       CHECK(failure);
  118.       CHECK(exception);
  119.    }
  120.  
  121.    TEST(RequireMacroDoesntExecuteCodeAfterAFailingCheck)
  122.    {
  123.       bool failure = false;
  124.       bool exception = false;
  125.       bool run = false;
  126.       {
  127.          RecordingReporter reporter;
  128.          UnitTest::TestResults testResults(&reporter);
  129.          ScopedCurrentTest scopedResults(testResults);
  130.  
  131.          try{
  132.             REQUIRE
  133.             {
  134.                CHECK(false);
  135.                run = true;     // this shouldn't get executed.
  136.             }
  137.          }
  138.          catch (const UnitTest::RequiredCheckException&)
  139.          {
  140.             exception = true;
  141.          }
  142.  
  143.          failure = (testResults.GetFailureCount() > 0);
  144.       }
  145.  
  146.       CHECK(failure);
  147.       CHECK(exception);
  148.       CHECK(!run);
  149.    }
  150.  
  151.    TEST(FailureReportsCorrectTestName)
  152.    {
  153.       RecordingReporter reporter;
  154.       {
  155.          UnitTest::TestResults testResults(&reporter);
  156.          ScopedCurrentTest scopedResults(testResults);
  157.  
  158.          try
  159.          {
  160.             REQUIRE CHECK(false);
  161.          }
  162.          catch (const UnitTest::RequiredCheckException&)
  163.          {}
  164.       }
  165.  
  166.       CHECK_EQUAL(m_details.testName, reporter.lastFailedTest);
  167.    }
  168.  
  169.    TEST(RequiredCheckFailureIncludesCheckContents)
  170.    {
  171.       RecordingReporter reporter;
  172.       {
  173.          UnitTest::TestResults testResults(&reporter);
  174.          ScopedCurrentTest scopedResults(testResults);
  175.          const bool yaddayadda = false;
  176.  
  177.          try
  178.          {
  179.             REQUIRE CHECK(yaddayadda);
  180.          }
  181.          catch (const UnitTest::RequiredCheckException&)
  182.          {}
  183.       }
  184.  
  185.       CHECK(strstr(reporter.lastFailedMessage, "yaddayadda"));
  186.    }
  187.  
  188.    TEST(RequiredCheckEqualSucceedsOnEqual)
  189.    {
  190.       bool failure = true;
  191.       bool exception = false;
  192.       {
  193.          RecordingReporter reporter;
  194.          UnitTest::TestResults testResults(&reporter);
  195.          ScopedCurrentTest scopedResults(testResults);
  196.  
  197.          try
  198.          {
  199.             REQUIRE CHECK_EQUAL(1,1);
  200.          }
  201.          catch (const UnitTest::RequiredCheckException&)
  202.          {
  203.             exception = true;
  204.          }
  205.  
  206.          failure = (testResults.GetFailureCount() > 0);
  207.       }
  208.  
  209.       CHECK(!failure);
  210.       CHECK(!exception);
  211.    }
  212.  
  213.    TEST(RequiredCheckEqualFailsOnNotEqual)
  214.    {
  215.       bool failure = false;
  216.       bool exception = false;
  217.       {
  218.          RecordingReporter reporter;
  219.          UnitTest::TestResults testResults(&reporter);
  220.          ScopedCurrentTest scopedResults(testResults);
  221.  
  222.          try
  223.          {
  224.             REQUIRE CHECK_EQUAL(1, 2);
  225.          }
  226.          catch (const UnitTest::RequiredCheckException&)
  227.          {
  228.             exception = true;
  229.          }
  230.  
  231.          failure = (testResults.GetFailureCount() > 0);
  232.       }
  233.  
  234.       CHECK(failure);
  235.       CHECK(exception);
  236.    }
  237.  
  238.    TEST(RequiredCheckEqualFailureContainsCorrectDetails)
  239.    {
  240.       int line = 0;
  241.       RecordingReporter reporter;
  242.       {
  243.          UnitTest::TestResults testResults(&reporter);
  244.          UnitTest::TestDetails const testDetails("testName", "suiteName", "filename", -1);
  245.          ScopedCurrentTest scopedResults(testResults, &testDetails);
  246.  
  247.          try
  248.          {
  249.             line = __LINE__; REQUIRE CHECK_EQUAL(1, 123);
  250.          }
  251.          catch (const UnitTest::RequiredCheckException&)
  252.          {}
  253.       }
  254.  
  255.       CHECK_EQUAL("testName", reporter.lastFailedTest);
  256.       CHECK_EQUAL("suiteName", reporter.lastFailedSuite);
  257.       CHECK_EQUAL("filename", reporter.lastFailedFile);
  258.       CHECK_EQUAL(line, reporter.lastFailedLine);
  259.    }
  260.  
  261.    int g_sideEffect = 0;
  262.    int FunctionWithSideEffects()
  263.    {
  264.       ++g_sideEffect;
  265.       return 1;
  266.    }
  267.  
  268.    TEST(RequiredCheckEqualDoesNotHaveSideEffectsWhenPassing)
  269.    {
  270.       g_sideEffect = 0;
  271.       {
  272.          UnitTest::TestResults testResults;
  273.          ScopedCurrentTest scopedResults(testResults);
  274.  
  275.          try
  276.          {
  277.             REQUIRE CHECK_EQUAL(1, FunctionWithSideEffects());
  278.          }
  279.          catch (const UnitTest::RequiredCheckException&)
  280.          {}
  281.       }
  282.       CHECK_EQUAL(1, g_sideEffect);
  283.    }
  284.  
  285.    TEST(RequiredCheckEqualDoesNotHaveSideEffectsWhenFailing)
  286.    {
  287.       g_sideEffect = 0;
  288.       {
  289.          UnitTest::TestResults testResults;
  290.          ScopedCurrentTest scopedResults(testResults);
  291.  
  292.          try
  293.          {
  294.             REQUIRE CHECK_EQUAL(2, FunctionWithSideEffects());
  295.          }
  296.          catch (const UnitTest::RequiredCheckException&)
  297.          {}
  298.       }
  299.       CHECK_EQUAL(1, g_sideEffect);
  300.    }
  301.  
  302.  
  303.    TEST(RequiredCheckCloseSucceedsOnEqual)
  304.    {
  305.       bool failure = true;
  306.       bool exception = false;
  307.       {
  308.          RecordingReporter reporter;
  309.          UnitTest::TestResults testResults(&reporter);
  310.          ScopedCurrentTest scopedResults(testResults);
  311.  
  312.          try
  313.          {
  314.             REQUIRE CHECK_CLOSE(1.0f, 1.001f, 0.01f);
  315.          }
  316.          catch (const UnitTest::RequiredCheckException&)
  317.          {
  318.             exception = true;
  319.          }
  320.  
  321.          failure = (testResults.GetFailureCount() > 0);
  322.       }
  323.  
  324.       CHECK(!failure);
  325.       CHECK(!exception);
  326.    }
  327.  
  328.    TEST(RequiredCheckCloseFailsOnNotEqual)
  329.    {
  330.       bool failure = false;
  331.       bool exception = false;
  332.       {
  333.          RecordingReporter reporter;
  334.          UnitTest::TestResults testResults(&reporter);
  335.          ScopedCurrentTest scopedResults(testResults);
  336.  
  337.          try
  338.          {
  339.             REQUIRE CHECK_CLOSE (1.0f, 1.1f, 0.01f);
  340.          }
  341.          catch (const UnitTest::RequiredCheckException&)
  342.          {
  343.             exception = true;
  344.          }
  345.  
  346.          failure = (testResults.GetFailureCount() > 0);
  347.       }
  348.  
  349.       CHECK(failure);
  350.       CHECK(exception);
  351.    }
  352.  
  353.    TEST(RequiredCheckCloseFailureContainsCorrectDetails)
  354.    {
  355.       int line = 0;
  356.       RecordingReporter reporter;
  357.       {
  358.          UnitTest::TestResults testResults(&reporter);
  359.          UnitTest::TestDetails testDetails("test", "suite", "filename", -1);
  360.          ScopedCurrentTest scopedResults(testResults, &testDetails);
  361.  
  362.          try
  363.          {
  364.             line = __LINE__; REQUIRE CHECK_CLOSE(1.0f, 1.1f, 0.01f);
  365.             CHECK(false);
  366.          }
  367.          catch (const UnitTest::RequiredCheckException&)
  368.          {}
  369.       }
  370.  
  371.       CHECK_EQUAL("test", reporter.lastFailedTest);
  372.       CHECK_EQUAL("suite", reporter.lastFailedSuite);
  373.       CHECK_EQUAL("filename", reporter.lastFailedFile);
  374.       CHECK_EQUAL(line, reporter.lastFailedLine);
  375.    }
  376.  
  377.    TEST(RequiredCheckCloseDoesNotHaveSideEffectsWhenPassing)
  378.    {
  379.       g_sideEffect = 0;
  380.       {
  381.          UnitTest::TestResults testResults;
  382.          ScopedCurrentTest scopedResults(testResults);
  383.  
  384.          try
  385.          {
  386.             REQUIRE CHECK_CLOSE (1, FunctionWithSideEffects(), 0.1f);
  387.          }
  388.          catch (const UnitTest::RequiredCheckException&)
  389.          {}
  390.       }
  391.       CHECK_EQUAL(1, g_sideEffect);
  392.    }
  393.  
  394.    TEST(RequiredCheckCloseDoesNotHaveSideEffectsWhenFailing)
  395.    {
  396.       g_sideEffect = 0;
  397.       {
  398.          UnitTest::TestResults testResults;
  399.          ScopedCurrentTest scopedResults(testResults);
  400.  
  401.          try
  402.          {
  403.             REQUIRE CHECK_CLOSE(2, FunctionWithSideEffects(), 0.1f);
  404.          }
  405.          catch (const UnitTest::RequiredCheckException&)
  406.          {}
  407.       }
  408.       CHECK_EQUAL(1, g_sideEffect);
  409.    }
  410.  
  411.    TEST(RequiredCheckArrayCloseSucceedsOnEqual)
  412.    {
  413.       bool failure = true;
  414.       bool exception = false;
  415.       {
  416.          RecordingReporter reporter;
  417.          UnitTest::TestResults testResults(&reporter);
  418.          ScopedCurrentTest scopedResults(testResults);
  419.          const float data[4] = { 0, 1, 2, 3 };
  420.  
  421.          try
  422.          {
  423.             REQUIRE CHECK_ARRAY_CLOSE (data, data, 4, 0.01f);
  424.          }
  425.          catch (const UnitTest::RequiredCheckException&)
  426.          {
  427.             exception = true;
  428.          }
  429.  
  430.          failure = (testResults.GetFailureCount() > 0);
  431.       }
  432.  
  433.       CHECK(!failure);
  434.       CHECK(!exception);
  435.    }
  436.  
  437.    TEST(RequiredCheckArrayCloseFailsOnNotEqual)
  438.    {
  439.       bool failure = false;
  440.       bool exception = false;
  441.       {
  442.          RecordingReporter reporter;
  443.          UnitTest::TestResults testResults(&reporter);
  444.          ScopedCurrentTest scopedResults(testResults);
  445.  
  446.          int const data1[4] = { 0, 1, 2, 3 };
  447.          int const data2[4] = { 0, 1, 3, 3 };
  448.  
  449.          try
  450.          {
  451.             REQUIRE CHECK_ARRAY_CLOSE (data1, data2, 4, 0.01f);
  452.          }
  453.          catch (const UnitTest::RequiredCheckException&)
  454.          {
  455.             exception = true;
  456.          }
  457.  
  458.          failure = (testResults.GetFailureCount() > 0);
  459.       }
  460.  
  461.       CHECK(failure);
  462.       CHECK(exception);
  463.    }
  464.  
  465.    TEST(RequiredCheckArrayCloseFailureIncludesCheckExpectedAndActual)
  466.    {
  467.       RecordingReporter reporter;
  468.       {
  469.          UnitTest::TestResults testResults(&reporter);
  470.          ScopedCurrentTest scopedResults(testResults);
  471.  
  472.          int const data1[4] = { 0, 1, 2, 3 };
  473.          int const data2[4] = { 0, 1, 3, 3 };
  474.  
  475.          try
  476.          {
  477.             REQUIRE CHECK_ARRAY_CLOSE(data1, data2, 4, 0.01f);
  478.          }
  479.          catch (const UnitTest::RequiredCheckException&)
  480.          {}
  481.       }
  482.  
  483.       CHECK(strstr(reporter.lastFailedMessage, "xpected [ 0 1 2 3 ]"));
  484.       CHECK(strstr(reporter.lastFailedMessage, "was [ 0 1 3 3 ]"));
  485.    }
  486.  
  487.    TEST(RequiredCheckArrayCloseFailureContainsCorrectDetails)
  488.    {
  489.       int line = 0;
  490.       RecordingReporter reporter;
  491.       {
  492.          UnitTest::TestResults testResults(&reporter);
  493.          UnitTest::TestDetails testDetails("arrayCloseTest", "arrayCloseSuite", "filename", -1);
  494.          ScopedCurrentTest scopedResults(testResults, &testDetails);
  495.  
  496.          int const data1[4] = { 0, 1, 2, 3 };
  497.          int const data2[4] = { 0, 1, 3, 3 };
  498.  
  499.          try
  500.          {
  501.             line = __LINE__; REQUIRE CHECK_ARRAY_CLOSE (data1, data2, 4, 0.01f);
  502.          }
  503.          catch (const UnitTest::RequiredCheckException&)
  504.          {}
  505.       }
  506.  
  507.       CHECK_EQUAL("arrayCloseTest", reporter.lastFailedTest);
  508.       CHECK_EQUAL("arrayCloseSuite", reporter.lastFailedSuite);
  509.       CHECK_EQUAL("filename", reporter.lastFailedFile);
  510.       CHECK_EQUAL(line, reporter.lastFailedLine);
  511.    }
  512.  
  513.    TEST(RequiredCheckArrayCloseFailureIncludesTolerance)
  514.    {
  515.       RecordingReporter reporter;
  516.       {
  517.          UnitTest::TestResults testResults(&reporter);
  518.          ScopedCurrentTest scopedResults(testResults);
  519.  
  520.          float const data1[4] = { 0, 1, 2, 3 };
  521.          float const data2[4] = { 0, 1, 3, 3 };
  522.  
  523.          try
  524.          {
  525.             REQUIRE CHECK_ARRAY_CLOSE (data1, data2, 4, 0.01f);
  526.          }
  527.          catch (const UnitTest::RequiredCheckException&)
  528.          {}
  529.       }
  530.  
  531.       CHECK(strstr(reporter.lastFailedMessage, "0.01"));
  532.    }
  533.  
  534.    TEST(RequiredCheckArrayEqualSuceedsOnEqual)
  535.    {
  536.       bool failure = true;
  537.       bool exception = false;
  538.       {
  539.          RecordingReporter reporter;
  540.          UnitTest::TestResults testResults(&reporter);
  541.          ScopedCurrentTest scopedResults(testResults);
  542.  
  543.          const float data[4] = { 0, 1, 2, 3 };
  544.  
  545.          try
  546.          {
  547.             REQUIRE CHECK_ARRAY_EQUAL (data, data, 4);
  548.          }
  549.          catch (const UnitTest::RequiredCheckException&)
  550.          {
  551.             exception = true;
  552.          }
  553.  
  554.          failure = (testResults.GetFailureCount() > 0);
  555.       }
  556.  
  557.       CHECK(!failure);
  558.       CHECK(!exception);
  559.    }
  560.  
  561.    TEST(RequiredCheckArrayEqualFailsOnNotEqual)
  562.    {
  563.       bool failure = false;
  564.       bool exception = false;
  565.       {
  566.          RecordingReporter reporter;
  567.          UnitTest::TestResults testResults(&reporter);
  568.          ScopedCurrentTest scopedResults(testResults);
  569.  
  570.          int const data1[4] = { 0, 1, 2, 3 };
  571.          int const data2[4] = { 0, 1, 3, 3 };
  572.  
  573.          try
  574.          {
  575.             REQUIRE CHECK_ARRAY_EQUAL (data1, data2, 4);
  576.          }
  577.          catch (const UnitTest::RequiredCheckException&)
  578.          {
  579.             exception = true;
  580.          }
  581.  
  582.          failure = (testResults.GetFailureCount() > 0);
  583.       }
  584.  
  585.       CHECK(failure);
  586.       CHECK(exception);
  587.    }
  588.  
  589.    TEST(RequiredCheckArrayEqualFailureIncludesCheckExpectedAndActual)
  590.    {
  591.       RecordingReporter reporter;
  592.       {
  593.          UnitTest::TestResults testResults(&reporter);
  594.          ScopedCurrentTest scopedResults(testResults);
  595.  
  596.          int const data1[4] = { 0, 1, 2, 3 };
  597.          int const data2[4] = { 0, 1, 3, 3 };
  598.  
  599.          try
  600.          {
  601.             REQUIRE CHECK_ARRAY_EQUAL (data1, data2, 4);
  602.          }
  603.          catch (const UnitTest::RequiredCheckException&)
  604.          {}
  605.       }
  606.  
  607.       CHECK(strstr(reporter.lastFailedMessage, "xpected [ 0 1 2 3 ]"));
  608.       CHECK(strstr(reporter.lastFailedMessage, "was [ 0 1 3 3 ]"));
  609.    }
  610.  
  611.    TEST(RequiredCheckArrayEqualFailureContainsCorrectInfo)
  612.    {
  613.       int line = 0;
  614.       RecordingReporter reporter;
  615.       {
  616.          UnitTest::TestResults testResults(&reporter);
  617.          ScopedCurrentTest scopedResults(testResults);
  618.  
  619.          int const data1[4] = { 0, 1, 2, 3 };
  620.          int const data2[4] = { 0, 1, 3, 3 };
  621.  
  622.          try
  623.          {
  624.             line = __LINE__; REQUIRE CHECK_ARRAY_EQUAL (data1, data2, 4);
  625.          }
  626.          catch (const UnitTest::RequiredCheckException&)
  627.          {}
  628.       }
  629.  
  630.       CHECK_EQUAL("RequiredCheckArrayEqualFailureContainsCorrectInfo", reporter.lastFailedTest);
  631.       CHECK_EQUAL(__FILE__, reporter.lastFailedFile);
  632.       CHECK_EQUAL(line, reporter.lastFailedLine);
  633.    }
  634.  
  635.    float const* FunctionWithSideEffects2()
  636.    {
  637.       ++g_sideEffect;
  638.       static float const data[] = {1,2,3,4};
  639.       return data;
  640.    }
  641.  
  642.    TEST(RequiredCheckArrayCloseDoesNotHaveSideEffectsWhenPassing)
  643.    {
  644.       g_sideEffect = 0;
  645.       {
  646.          UnitTest::TestResults testResults;
  647.          ScopedCurrentTest scopedResults(testResults);
  648.  
  649.          const float data[] = { 1, 2, 3, 4 };
  650.  
  651.          REQUIRE CHECK_ARRAY_CLOSE (data, FunctionWithSideEffects2(), 4, 0.01f);
  652.       }
  653.       CHECK_EQUAL(1, g_sideEffect);
  654.    }
  655.  
  656.    TEST(RequiredCheckArrayCloseDoesNotHaveSideEffectsWhenFailing)
  657.    {
  658.       g_sideEffect = 0;
  659.       {
  660.          UnitTest::TestResults testResults;
  661.          ScopedCurrentTest scopedResults(testResults);
  662.  
  663.          const float data[] = { 0, 1, 3, 3 };
  664.  
  665.          try
  666.          {
  667.             REQUIRE CHECK_ARRAY_CLOSE (data, FunctionWithSideEffects2(), 4, 0.01f);
  668.          }
  669.          catch (const UnitTest::RequiredCheckException&)
  670.          {}
  671.       }
  672.  
  673.       CHECK_EQUAL(1, g_sideEffect);
  674.    }
  675.  
  676.    TEST(RequiredCheckArray2DCloseSucceedsOnEqual)
  677.    {
  678.       bool failure = true;
  679.       bool exception = false;
  680.       {
  681.          RecordingReporter reporter;
  682.          UnitTest::TestResults testResults(&reporter);
  683.          ScopedCurrentTest scopedResults(testResults);
  684.  
  685.          const float data[2][2] = { {0, 1}, {2, 3} };
  686.  
  687.          try
  688.          {
  689.             REQUIRE CHECK_ARRAY2D_CLOSE(data, data, 2, 2, 0.01f);
  690.          }
  691.          catch (const UnitTest::RequiredCheckException&)
  692.          {
  693.             exception = true;
  694.          }
  695.  
  696.          failure = (testResults.GetFailureCount() > 0);
  697.       }
  698.  
  699.       CHECK(!failure);
  700.       CHECK(!exception);
  701.    }
  702.  
  703.    TEST(RequiredCheckArray2DCloseFailsOnNotEqual)
  704.    {
  705.       bool failure = false;
  706.       bool exception = false;
  707.       {
  708.          RecordingReporter reporter;
  709.          UnitTest::TestResults testResults(&reporter);
  710.          ScopedCurrentTest scopedResults(testResults);
  711.  
  712.          int const data1[2][2] = { {0, 1}, {2, 3} };
  713.          int const data2[2][2] = { {0, 1}, {3, 3} };
  714.  
  715.          try
  716.          {
  717.             REQUIRE CHECK_ARRAY2D_CLOSE (data1, data2, 2, 2, 0.01f);
  718.          }
  719.          catch (const UnitTest::RequiredCheckException&)
  720.          {
  721.             exception = true;
  722.          }
  723.  
  724.          failure = (testResults.GetFailureCount() > 0);
  725.       }
  726.  
  727.       CHECK(failure);
  728.       CHECK(exception);
  729.    }
  730.  
  731.    TEST(RequiredCheckArray2DCloseFailureIncludesCheckExpectedAndActual)
  732.    {
  733.       RecordingReporter reporter;
  734.       {
  735.          UnitTest::TestResults testResults(&reporter);
  736.          ScopedCurrentTest scopedResults(testResults);
  737.  
  738.          int const data1[2][2] = { {0, 1}, {2, 3} };
  739.          int const data2[2][2] = { {0, 1}, {3, 3} };
  740.  
  741.          try
  742.          {
  743.             REQUIRE CHECK_ARRAY2D_CLOSE (data1, data2, 2, 2, 0.01f);
  744.          }
  745.          catch (const UnitTest::RequiredCheckException&)
  746.          {}
  747.       }
  748.  
  749.       CHECK(strstr(reporter.lastFailedMessage, "xpected [ [ 0 1 ] [ 2 3 ] ]"));
  750.       CHECK(strstr(reporter.lastFailedMessage, "was [ [ 0 1 ] [ 3 3 ] ]"));
  751.    }
  752.  
  753.    TEST(RequiredCheckArray2DCloseFailureContainsCorrectDetails)
  754.    {
  755.       int line = 0;
  756.       RecordingReporter reporter;
  757.       {
  758.          UnitTest::TestResults testResults(&reporter);
  759.          UnitTest::TestDetails testDetails("array2DCloseTest", "array2DCloseSuite", "filename", -1);
  760.          ScopedCurrentTest scopedResults(testResults, &testDetails);
  761.  
  762.          int const data1[2][2] = { {0, 1}, {2, 3} };
  763.          int const data2[2][2] = { {0, 1}, {3, 3} };
  764.  
  765.          try
  766.          {
  767.             line = __LINE__; REQUIRE CHECK_ARRAY2D_CLOSE (data1, data2, 2, 2, 0.01f);
  768.          }
  769.          catch (const UnitTest::RequiredCheckException&)
  770.          {}
  771.       }
  772.  
  773.       CHECK_EQUAL("array2DCloseTest", reporter.lastFailedTest);
  774.       CHECK_EQUAL("array2DCloseSuite", reporter.lastFailedSuite);
  775.       CHECK_EQUAL("filename", reporter.lastFailedFile);
  776.       CHECK_EQUAL(line, reporter.lastFailedLine);
  777.    }
  778.  
  779.    TEST(RequiredCheckArray2DCloseFailureIncludesTolerance)
  780.    {
  781.       RecordingReporter reporter;
  782.       {
  783.          UnitTest::TestResults testResults(&reporter);
  784.          ScopedCurrentTest scopedResults(testResults);
  785.  
  786.          float const data1[2][2] = { {0, 1}, {2, 3} };
  787.          float const data2[2][2] = { {0, 1}, {3, 3} };
  788.  
  789.          try
  790.          {
  791.             REQUIRE CHECK_ARRAY2D_CLOSE (data1, data2, 2, 2, 0.01f);
  792.          }
  793.          catch (const UnitTest::RequiredCheckException&)
  794.          {}
  795.       }
  796.  
  797.       CHECK(strstr(reporter.lastFailedMessage, "0.01"));
  798.    }
  799.  
  800.    float const* const* FunctionWithSideEffects3()
  801.    {
  802.       ++g_sideEffect;
  803.       static float const data1[] = {0,1};
  804.       static float const data2[] = {2,3};
  805.       static const float* const data[] = {data1, data2};
  806.       return data;
  807.    }
  808.  
  809.    TEST(RequiredCheckArray2DCloseDoesNotHaveSideEffectsWhenPassing)
  810.    {
  811.       g_sideEffect = 0;
  812.       {
  813.          UnitTest::TestResults testResults;
  814.          ScopedCurrentTest scopedResults(testResults);
  815.  
  816.          const float data[2][2] = { {0, 1}, {2, 3} };
  817.  
  818.          try
  819.          {
  820.             REQUIRE CHECK_ARRAY2D_CLOSE (data, FunctionWithSideEffects3(), 2, 2, 0.01f);
  821.          }
  822.          catch (const UnitTest::RequiredCheckException&)
  823.          {}
  824.       }
  825.       CHECK_EQUAL(1, g_sideEffect);
  826.    }
  827.  
  828.    TEST(RequiredCheckArray2DCloseDoesNotHaveSideEffectsWhenFailing)
  829.    {
  830.       g_sideEffect = 0;
  831.       {
  832.          UnitTest::TestResults testResults;
  833.          ScopedCurrentTest scopedResults(testResults);
  834.  
  835.          const float data[2][2] = { {0, 1}, {3, 3} };
  836.  
  837.          try
  838.          {
  839.             REQUIRE CHECK_ARRAY2D_CLOSE (data, FunctionWithSideEffects3(), 2, 2, 0.01f);
  840.          }
  841.          catch (const UnitTest::RequiredCheckException&)
  842.          {}
  843.       }
  844.       CHECK_EQUAL(1, g_sideEffect);
  845.    }
  846.  
  847. }
  848.  
  849. #endif
  850.