Newer
Older
Import / applications / HighwayDash / ports / Framework / Context.cpp
// BlockyFroggy
// Created by John Ryland on 17/3/19
// Copyright © 2019 John Ryland. All rights reserved.
#include "Context.h"
#include "UnitTest.h"


#if ENABLE_UNIT_TESTS


//! @todo ensure context inherits correctly from parent object to child object (not just defaults)
class ChildClassInheritTest : public Context
{
public:
  //! @todo init Context from other Context during construction
};


//! @todo ensure context inherits correctly from parent object to child object (not just defaults)
class ChildClassCompositionTest
{
public:
  //! @todo init m_context from other Context during construction
  Context m_context;
  inline Context* getContext() { return &m_context; }
};


void funcThatWontLog()
{
  //! @todo Uncomment to test that this won't compile
  //! @todo Is it possible to make a unit test which tests that something can't compile?
  //LOG_X(1, "FileScopeContextTest");
}


// File level scope context (watch out for unity builds)
Context g_context;
inline Context* getContext() { return &g_context; }
const char* getLogTag() { return "FileScopeContextTest"; }
void funcThatLogs()
{
  LOG_X(1, "FileScopeContextTest");
}


namespace NamespaceLogTest
{
  Context m_context;
  inline Context* getContext() { return &m_context; }
  const char* getLogTag() { return "NamespaceContextTest"; }
  void funcThatLogs()
  {
    LOG_X(1, "NamespaceContextTest");
  }
}


class ContextInheritTest : public Context
{
public:
  const char* getLogTag() { return "ContextInheritTest"; }
  void funcThatLogs() {
    LOG_X(1, "ContextInheritTest");
  }
  
  ChildClassInheritTest     child1;
  ChildClassCompositionTest child2;
};


class DerivedContextInheritTest : public ContextInheritTest
{
public:
  const char* getLogTag() { return "DerivedContextInheritTest"; }
  void funcThatLogs() {
    LOG_X(1, "DerivedContextInheritTest");
  }

  ChildClassInheritTest     child1;
  ChildClassCompositionTest child2;
};


class ContextCompositionTest
{
public:
  const char* getLogTag() { return "ContextCompositionTest"; }
  void funcThatLogs() {
    LOG_X(1, "ContextCompositionTest");
  }

  Context m_context;
  inline Context* getContext() { return &m_context; }

  ChildClassInheritTest     child1;
  ChildClassCompositionTest child2;
};


class DerivedContextCompositionTest : public ContextCompositionTest
{
public:
  const char* getLogTag() { return "DerivedContextCompositionTest"; }
  void funcThatLogs() {
    LOG_X(1, "DerivedContextCompositionTest");
  }

  ChildClassInheritTest     child1;
  ChildClassCompositionTest child2;
};


DECLARE_UNIT_TEST(fooBar)
{
  ContextInheritTest t1;
  t1.funcThatLogs();
  DerivedContextInheritTest t2;
  t2.funcThatLogs();
  ContextCompositionTest t3;
  t3.funcThatLogs();
  DerivedContextCompositionTest t4;
  t4.funcThatLogs();
  
  NamespaceLogTest::funcThatLogs();
  funcThatLogs();

  LOG_X(1, "GlobalContextTest");
}


#endif // ENABLE_UNIT_TESTS