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


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


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


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

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

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

#include "../src/board.h"
#include "../src/app.h"
#include "../src/pinmux.h"
#include "writerPlatform.h"

#define TEST_ALL
#define STOP_ON_FAIL

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


TEST_CASE( "Like", "[default]" ) {
   CPinmux pinmux;
   CApp app;
   CBoard board;

   SECTION( "periphery with 'like' syntax" )
   {
      const char *boardString=
      R"JSON(
      {
          "name": "myboard_like",
          "version": "1",
          "peripheries": [
                  { "type": "GPIO",   "periphery": "PA12", "pin": "D1", "irq": "EXTI9_5_IRQHandler" },
                  { "type": "GPIO",   "periphery": "PA11", "pin": "D0", "irq": "EXTI15_10_IRQHandler" },
                  {
                     "type": "CANFD", "periphery": "CAN1.PA11", "irqs": "CAN_IRQHandler",
                     "consumes": [
                         { "periphery": "PA12",   "name": "TX", "mode": "skip" },
                         { "periphery": "PA11",   "name": "RX", "mode": "skip" }
                     ],
                     "attributes": {
                         "configBlock": "SPI1_PA12_PA11",
                         "implementation": "10Khz",
                         "like": "CAN"
                     }
                  }
         ],
         "constructors": [
                 {
                     "type": "CANFD",
                     "arguments": [
                             { "type": "fixed", "value": "spiConfig_<attribute:configBlock>" },
                             { "type": "fixed", "value": "spiConfig_<attribute:speedo>" }
                     ]
                 }
         ],
         "final": "yes"
      }
      )JSON";

      app.clear();
      board.clear();
      app.setBoardId("myboard");
      board.loadByteArray( QByteArray(boardString), "CAN" );
      app.loadByteArray(
               QByteArray(R"JSON(
               {
                   "name": "canio",
                   "periphery": [
                      { "type": "CAN", "name": "1",
                           "attributes": {
                               "speedo": "24Mhz"
                           }
                      }
                    ]
               }
      )JSON" ), "intern" );

      pinmux.setBoardApp(board, app);
      pinmux.resolveApp();

      REQUIRE( true == true );


   }

}


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