?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download

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