//- Copyright (c) 2008-2020 James Grenning --- All rights reserved
//- For exclusive use by participants in Wingman Software training courses.
//- Cannot be used by attendees to train others without written permission.
//- www.wingman-sw.com james@wingman-sw.com

#include "CppUTest/TestHarness.h"

extern "C"
{
#include "CircularBuffer.h"
#include "FormatOutputSpy.h"
}

TEST_GROUP(CircularBufferPrint)
{
    CircularBuffer * buffer;
    const char * expectedOutput;
    const int default_value = -1;

    void setup()
    {
        buffer = CircularBuffer_Create(5, default_value);
    }

    void teardown()
    {
         CircularBuffer_Destroy(buffer);
    }

    void fillTheQueue(int seed, unsigned int howMany)
    {
        for (unsigned int i = 0; i < howMany; i++)
            CircularBuffer_Put(buffer, (int)i+seed);
    }
};

#define PRINTED_OUTPUT_IS(expected)\
    STRCMP_EQUAL(expected, FormatOutputSpy_GetOutput());

IGNORE_TEST(CircularBufferPrint, PrintEmpty)
{
    //    FAIL("Start here");
    //Remove IGNORE_ from IGNORE_TEST
    //Finish writing this test.
    // Start by uncommenting the last line of the test
    //Setup FormatOutputSpy. See FormatOutputSpyTest for examples
    //Implement the CircularBuffer_Print, calling it like this:
    //CircularBuffer_Print(buffer);

    PRINTED_OUTPUT_IS("Circular buffer content:\n<>\n");
}

#ifdef move_this_line_down_one_test_at_a_time

/*
 * In the prior test should have only printed the heading.  This next test
 * drives you to get the format of a single element.  Did you implement any of
 * the element looping logic already?  Delete it if you did.
 */

TEST(CircularBufferPrint, PrintAfterOneIsPutIntoBuffer)
{
    // Finish writing this test, adding just enough production code.

    PRINTED_OUTPUT_IS("Circular buffer content:\n<42>\n");
}

/*
 * The next test requires the loop to print all items, and logic to
 * get the commas in the right places.  Do not concern yourself with
 * wrapping yet.  Oh, you have write the whole test, I just showed
 * you the example output.
 */

TEST(CircularBufferPrint, PrintNotYetWrappedOrFull)
{
    PRINTED_OUTPUT_IS("Circular buffer content:\n<42, 43, 44>\n");
}

/*
 * Fill, but do not over fill a five element CircularBuffer, print it.
 */

TEST(CircularBufferPrint, PrintNotYetWrappedAndIsFull)
{
    PRINTED_OUTPUT_IS("Circular buffer content:\n<200, 201, 202, 203, 204>\n");
}

/*
 * If you used CircularBuffer_Get in your print function, take
 * a look at the 'requirements'. Print should not modify the
 * contents of the CircularBuffer.
 */
TEST(CircularBufferPrint, PrintDoesNotModifyTheCircularBuffer)
{

}

/*
 * Print does not need to handle wrapping until this next test.  I am
 * glad to hear you resisted the temptation to code ahead of your tests.
 *
 * In this test you will create a 5 element buffer, fill it, pull one out
 * and add another.
 */

TEST(CircularBufferPrint, PrintWrappedAndIsFullOldestToNewest)
{
    PRINTED_OUTPUT_IS("Circular buffer content:\n<201, 202, 203, 204, 999>\n");
}


TEST(CircularBufferPrint, FillThenEmptyThenPrint)
{
    PRINTED_OUTPUT_IS("Circular buffer content:\n<>\n");
}

/*
 * After the code review, one of the engineers argued that library code,
 * like the CircularBuffer, should not have side effects. Printing
 * using some global is a side effect.  He suggests the caller should
 * pass in the print function.  Refactor your code and tests for this
 * design improvement.
 */
#endif


