ff_i_expect

Testing functions.

This unit is useful only for testing.

int ExpectIdenticalTagAndResRef(object oObject)
Parameters:
  • oObject – The object

Returns:

TRUE if there’s an error

Expect tag to be identical to resref.

int IsTagUnique(object oObject)
Parameters:
  • oObject – The object

Returns:

TRUE if there’s an error

Expect tag to be unique.

int ExpectUniqueTag(object oObject)
Parameters:
  • oObject – The object

Returns:

TRUE if there’s an error

Expect tag to be unique.

int Assert(int nCheck, string sFile, int nLine, string sExtra = "")
Parameters:
  • nCheck – Result of a comparison

  • sFile – Constant

  • nLine – Constant

  • sExtra – Optional extra detail appended to the failure message. Defaults to “”.

Check assertion is TRUE, else print an error.

Source code

// @code

#include "ff_i_console"

// -----------------------------------------------------------------------------

//! @brief Expect tag to be identical to resref
//! @param oObject The object
//! @return TRUE if there's an error
int ExpectIdenticalTagAndResRef(object oObject);
int ExpectIdenticalTagAndResRef(object oObject)
{
  string sTag = GetTag(oObject);
  string sResRef = GetResRef(oObject);

  // If sResRef is empty, it was probably created with CreateArea
  if (sResRef == "")
    return FALSE;

  if (sTag != sResRef)
  {
    LogWarning(__FILE__ + ": Object " + GetName(oObject) + " must have identical resref and tag (" + GetResRef(oObject) + ", " + GetTag(oObject) + ")");
    return TRUE;
  }
  return FALSE;
}


// -----------------------------------------------------------------------------

//! @brief Expect tag to be unique
//! @param oObject The object
//! @return TRUE if there's an error
int IsTagUnique(object oObject);
int IsTagUnique(object oObject)
{
  string sTag = GetTag(oObject);
  object oOther = GetObjectByTag(sTag, 1);
  if (GetIsObjectValid(oOther))
    return FALSE;
  return TRUE;
}


// -----------------------------------------------------------------------------

//! @brief Expect tag to be unique
//! @param oObject The object
//! @return TRUE if there's an error
int ExpectUniqueTag(object oObject);
int ExpectUniqueTag(object oObject)
{
  if (!IsTagUnique(oObject))
  {
    LogWarning(__FILE__ + ": Object " + GetName(oObject) + " must have an unique tag (" + GetResRef(oObject) + ", " + GetTag(oObject) + ")");
    return TRUE;
  }
  return FALSE;
}


// -----------------------------------------------------------------------------

//! @brief Check assertion is TRUE, else print an error
//! @param nCheck Result of a comparison
//! @param sFile Constant __FILE__
//! @param nLine Constant __LINE__
//! @param sExtra Optional extra detail appended to the failure message. Defaults to "".
int Assert(int nCheck, string sFile, int nLine, string sExtra = "");
int Assert(int nCheck, string sFile, int nLine, string sExtra = "")
{
  if (nCheck)
    return TRUE;
  NWNX_Util_RawPrint(sFile + ": assertion failed on line " + IntToString(nLine) + ". " + sExtra);
  LogStackTrace(__FILE__, __FUNCTION__, __LINE__);
  return FALSE;
}