//----------------------------------------------------------------------------
///
/// \file   main.cpp
///
/// \brief  main file for pinmux
///
/// \date   20220619
/// \author Maximilian Seesslen <mes@seesslen.net>
///
//----------------------------------------------------------------------------


//---Documentation------------------------------------------------------------


//---Includes -----------------------------------------------------------------


//---General--------------------------

#define CATCH_CONFIG_MAIN

#if defined ( CATCH_V3 )
   #include <catch2/catch_test_macros.hpp>
#elif defined ( CATCH_V2 )
   #include <catch2/catch.hpp>
#elif defined ( CATCH_V1 )
   #include <catch/catch.hpp>
#else
   #error "Either 'catch' or 'catch2' has to be installed"
#endif

#include <lepto/ring.h>
#include <lepto/bufferRing.hpp>

//--- Own ----------------------------

#define TEST_ALL
#define STOP_ON_FAIL

//---Implementation------------------------------------------------------------


TEST_CASE( "Ring", "[default]" )
{

   SECTION( "Ring" )
   {
      CRing< int > ring(3);
      //ring.setFatal(false);
      bool sta;

      // Just the plain start value
      REQUIRE ( ring.bottomEntry() == nullptr );
      REQUIRE ( ring.putEntry(0x10) == true );
      REQUIRE ( ring.putEntry(0x20) == true );
      REQUIRE ( ring.putEntry(0x30) == false );
      REQUIRE ( *ring.bottomEntry() == 0x10 );
      ring.dropEntry();
      REQUIRE ( *ring.bottomEntry() == 0x20 );
      ring.dropEntry();
      REQUIRE ( ring.bottomEntry() == nullptr );
      //ring.release();
   }
   SECTION( "Overlap" )
   {
      CRing< int > ring(4);
      bool sta;

      // Just the plain start value
      REQUIRE ( ring.bottomEntry() == nullptr );
      REQUIRE ( ring.putEntry(0x10) == true );
      REQUIRE ( ring.putEntry(0x20) == true );
      ring.dropEntry();
      REQUIRE ( ring.putEntry(0x30) == true );
      REQUIRE ( ring.putEntry(0x40) == true );

      REQUIRE ( *ring.bottomEntry() == 0x20 );
      ring.dropEntry();
      REQUIRE ( *ring.bottomEntry() == 0x30 );
      ring.dropEntry();
      REQUIRE ( *ring.bottomEntry() == 0x40 );
      ring.dropEntry();
      REQUIRE ( ring.bottomEntry() == nullptr );
      //ring.release();
   }

   SECTION( "Next" )
   {
      CRing< int > ring(4);
      bool sta;

      // Just the plain start value
      ring.putEntry(0x10);
      *ring.topEntry()=0x20;
      ring.pushEntry();
      *ring.topEntry()=0x30;
      ring.pushEntry();

      REQUIRE ( ring.topEntry() != nullptr );
      REQUIRE ( ring.pushable() == false );

      REQUIRE ( ring.popEntry() == 0x10 );
      REQUIRE ( ring.popEntry() == 0x20 );
      REQUIRE ( ring.popEntry() == 0x30 );
      REQUIRE ( ring.isDataAvailable() == false );
   }

   SECTION( "Buffer" )
   {
      CBufferRing ring(10,3);
      bool sta;

      // Just the plain start value
      //ring.pushBuffer(0x10);
      //ring.pushBuffer(0x10);
      //ring.pushBuffer(0x10);

      //REQUIRE ( ring.getTopData() == nullptr );
      REQUIRE ( nullptr == nullptr );
   }
}


//---fin-----------------------------------------------------------------------
