//----------------------------------------------------------------------------
///
/// \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

#include <QFile>
#include <QJsonParseError>
#include <QJsonDocument>
#include <QDebug>
#include <QCommandLineParser>
#include <QFileInfo>
#include <QDir>
#include <QString>

//--- 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------------------------------------------------------------


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

   SECTION( "find periphery with required feature" )
   {
      const char *boardString=
      R"JSON(
      {
          "name": "board_alternate_function",
          "version": "1",
          "peripheries": [
               { "type": "GPIO", "periphery": "PA0" },
               { "type": "GPIO", "periphery": "PA1" },
               { "type": "GPIO", "periphery": "PA2" },
               { "type": "GPIO", "periphery": "PA3", "physicalLed": "yes" },
               { "type": "GPIO", "periphery": "PA4" },
               { "type": "GPIO", "periphery": "PA5" },
               {
                  "type": "LED",
                  "name": "ledFab",
                  "periphery": "ledFab1",
                  "consumes":
                  [
                     { "type": "GPIO" }
                  ]
               }
          ],
          "final": "yes"
      }
      )JSON";

      app.clear();
      board.clear();
      app.setBoardId("myboard");
      board.loadByteArray( QByteArray(boardString), "function_uart" );
      app.loadByteArray(
               QByteArray(R"JSON(
               {
                   "name": "canio",
                   "periphery": [
                      { "type": "LED", "name": "1",
                           "required": {
                               "other": "physicalLed"
                           }
                      }
                    ]
               }
      )JSON" ), "intern" );

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

      CPeripheryPtr p=board.findPeripheryByPeripheryName( QString("PA3") );
      REQUIRE( p->isUsed() == true );

      REQUIRE( true == true );
   }

}


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