Newer
Older
Import / applications / HighwayDash / ports / Framework / Common.cpp
//  BlockyFroggy
//  Copyright © 2017 John Ryland.
//  All rights reserved.
#include "Common.h"
#include <cassert>

  
Finalizable::~Finalizable()
{
  for (const auto& cleanupFunc : m_cleanupFunctions)
  {
    cleanupFunc();
  }
}


void Finalizable::addCleanupCallback(const CleanupFunction& a_callback)
{
  m_cleanupFunctions.push_back(a_callback);
}


#if ENABLE_UNIT_TESTS


void UnitTest::UnitTestAssert(bool a_expression, const char* a_expressionStr, const char* a_file, int a_line)
{
  if (!a_expression)
  {
    Log(LL_Error, "Test failed: %s\nFile: %s : [%i]", a_expressionStr, a_file, a_line);
    // If exceptions enabled, could throw and this can be catched where the test is run from
    assert(false);
  }
}

DECLARE_UNIT_TEST(fooBar)
{
  StackOnlyClass c1;
  //StackOnlyClass* c2 = new StackOnlyClass;  // not allowed
  assert(&c1);
  
  HeapOnlyClass* h2 = HeapOnlyClass::create();
  //HeapOnlyClass h1;   // not allowed
  //delete h2;          // not allowed
  HeapOnlyClass::destroy(h2);
}


#endif // ENABLE_UNIT_TESTS