//----------------------------------------------------------------------------
///
/// \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"
#include "formaterCpp.h"

#define TEST_ALL
#define STOP_ON_FAIL

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

struct SBoardApp
{
   QString board;
   QString app;
};

QList<SBoardApp> list=
{
   {SOURCE_DIR "/../arena/boards/stm32l031f6.json",
    CURRENT_SOURCE_DIR "/tests/apps/miniminutnik.json"},
   {SOURCE_DIR "/../arena/boards/stm32g441kb.json",
    CURRENT_SOURCE_DIR "/tests/apps/candis.json"},
};

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

   SECTION( "Resolve" )
   {
      for( const auto &boardApp: list)
      {
         app.clear();
         board.clear();
         app.setBoardId("app");

         app.loadFile( boardApp.app );
         board.loadFile( boardApp.board );
         pinmux.setBoardApp(board, app);

         int status=0;
         try
         {
            pinmux.resolveApp( );
         }
         catch(...)
         {
            status=1;
         }
         REQUIRE ( status == 0);
      }
   }
}

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