emil-e/rapidcheck

[Question] Why can't I call delete in this test?

TripleCometAndy opened this issue · 0 comments

Hi. Been working with your library (really like it btw), but I'm wondering if there's a way to call delete in a test. For some reason, I'm able to use free, but delete gives me the following error:

- RC_CLASSIFY
free(): invalid pointer

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
orionTestSuite is a Catch v2.11.1 host application.
Run with -? for options

-------------------------------------------------------------------------------
0 FPS Not Accepted
-------------------------------------------------------------------------------
/home/adny/tortoiseSoftworks/software/gamedev/tortoiseGamedev/test/testing/src/main.cpp:10
...............................................................................

/home/adny/tortoiseSoftworks/software/gamedev/tortoiseGamedev/test/testing/src/main.cpp:10: FAILED:
due to a fatal error condition:
  SIGABRT - Abort (abnormal termination) signal

For context, here is the test I have

#define CATCH_CONFIG_MAIN
#include "catch.hpp"
#include <rapidcheck/state.h>
#include "../../../include/Orion.h"
#include "../../../include/gameLoopInitializer.h"
#include "../include/mOptionCheckerFileHandler.h"
#include <iostream>


TEST_CASE( "0 FPS Not Accepted", "[gameLoopInitializer]" ) {
  //Set up mock
  mOptionCheckerFileHandler * mock = new mOptionCheckerFileHandler("TEST");
  optionCheckerFileParams params;
  params.FPS = 0;
  mock->setMock(&params);

  //Perform operation
  gameLoopInitializer * initializer = new gameLoopInitializer(mock);
  bool passed = false;

  try{
    initializer->getLoopFromOptions();
  }
  catch(IllegalArgumentException & ex){
    passed = true;
  }

  rc::check("RC_CLASSIFY",
    [](bool full, bool dMode, bool dSingle, bool dCouple, bool ai, bool log,
    bool single) {
      optionCheckerFileParams params;
      mOptionCheckerFileHandler * mock = new mOptionCheckerFileHandler("TEST");
      params.FPS = 0;
      params.fullscreen = full;
      params.debugMode = dMode;
      params.debugSingleStep = dSingle;
      params.decouple = dCouple;
      params.AI = ai;
      params.logKeys = log;
      params.singleThread = single;
      
      mock->setMock(&params);

      //Perform operation
      gameLoopInitializer * initializer = new gameLoopInitializer(mock);
      bool passed = false;

      try{
        initializer->getLoopFromOptions();
      }
      catch(IllegalArgumentException & ex){
        passed = true;
      }
      
      //free(mock);
      //free(initializer);
      delete(mock);
      delete(initializer);
      REQUIRE(passed == true);
      //delete(mock);
      /*delete(initializer);*/ });

  REQUIRE(passed == true);
}