END_TEST

START_TEST (test_XMLError_accessWithNULL)
{
  // survive NULL arguments  
  XMLError_free(NULL);

  fail_unless( XMLError_createWithIdAndMessage(0, NULL) == NULL);
  fail_unless( XMLError_getCategory(NULL) == SBML_INT_MAX);
  fail_unless( XMLError_getCategoryAsString(NULL) == NULL);
  fail_unless( XMLError_getColumn(NULL) == 0);
  fail_unless( XMLError_getErrorId(NULL) == SBML_INT_MAX);
  fail_unless( XMLError_getLine(NULL) == 0);
  fail_unless( XMLError_getMessage(NULL) == NULL);
  fail_unless( XMLError_getSeverity(NULL) == SBML_INT_MAX);
  fail_unless( XMLError_getSeverityAsString(NULL) == NULL);
  fail_unless( XMLError_getShortMessage(NULL) == NULL);
  fail_unless( XMLError_isError(NULL) == 0);
  fail_unless( XMLError_isFatal(NULL) == 0);
  fail_unless( XMLError_isInfo(NULL) == 0);
  fail_unless( XMLError_isWarning(NULL) == 0);

  XMLError_print(NULL, NULL); 

}
LIBSBML_CPP_NAMESPACE_USE

CK_CPPSTART
#endif

START_TEST (test_XMLError_create_C)
{
  XMLError_t *error = XMLError_create();
  fail_unless(error != NULL);
  fail_unless(XMLError_isInfo(error) == 0);
  fail_unless(XMLError_isWarning(error) == 0);
  fail_unless(XMLError_isError(error) == 0);
  fail_unless(XMLError_isFatal(error) == 1);
  XMLError_free(error);

  error = XMLError_createWithIdAndMessage(12345, "My message");
  fail_unless( strcmp(XMLError_getMessage(error), "My message") == 0 );
  fail_unless( XMLError_getErrorId(error) == 12345 );
  XMLError_free(error);
}
END_TEST


START_TEST (test_XMLError_variablesAsStrings)
{
  XMLError_t *error = XMLError_createWithIdAndMessage(1003, "");
  
  fail_unless( XMLError_getErrorId(error)  == 1003 );
  fail_unless( XMLError_getSeverity(error) == LIBSBML_SEV_ERROR );
  fail_unless( !strcmp(XMLError_getSeverityAsString(error), "Error") );
  fail_unless( XMLError_getCategory(error) == LIBSBML_CAT_XML );
  fail_unless( !strcmp(XMLError_getCategoryAsString(error), "XML content"));

  XMLError_free(error);
}
END_TEST


START_TEST (test_XMLErrorLog_clear)
{
  XMLErrorLog_t *log = XMLErrorLog_create();
  XMLError_t* error = XMLError_create();

  XMLErrorLog_add( log, error );

  XMLErrorLog_clearLog(log);

  fail_unless( log != NULL );
  fail_unless( XMLErrorLog_getNumErrors(log) == 0 );

  XMLError_free(error);
  XMLErrorLog_free(log);
}
END_TEST

START_TEST(test_XMLErrorLog_override)
{
  XMLErrorLog_t* log = XMLErrorLog_create();
  
  fail_unless(XMLErrorLog_isSeverityOverridden(log) == 0);
  fail_unless(XMLErrorLog_getSeverityOverride(log) == LIBSBML_OVERRIDE_DISABLED);
  
  /* test that errors are not logged when set */
  XMLErrorLog_setSeverityOverride(log, LIBSBML_OVERRIDE_DONT_LOG);  
  fail_unless(XMLErrorLog_isSeverityOverridden(log) == 1);
  fail_unless(XMLErrorLog_getSeverityOverride(log) == LIBSBML_OVERRIDE_DONT_LOG);

  XMLError_t* error = XMLError_create();
  XMLErrorLog_add( log, error );
  fail_unless(XMLErrorLog_getNumErrors(log) == 0);

  /* test that errors are logged as warnings */
  XMLErrorLog_setSeverityOverride(log, LIBSBML_OVERRIDE_WARNING);
  fail_unless(XMLErrorLog_isSeverityOverridden(log) == 1);
  fail_unless(XMLErrorLog_getSeverityOverride(log) == LIBSBML_OVERRIDE_WARNING);

  XMLErrorLog_add( log, error );
  fail_unless(XMLErrorLog_getNumErrors(log) == 1);
  fail_unless(XMLError_getSeverity(XMLErrorLog_getError(log, 0)) == LIBSBML_SEV_WARNING);

  /* test that errors are logged normaly otherwise */

  XMLErrorLog_clearLog(log);
  XMLErrorLog_setSeverityOverride(log, LIBSBML_OVERRIDE_DISABLED);
  fail_unless(XMLErrorLog_isSeverityOverridden(log) == 0);
  fail_unless(XMLErrorLog_getSeverityOverride(log) == LIBSBML_OVERRIDE_DISABLED);

  XMLErrorLog_add( log, error );
  fail_unless(XMLErrorLog_getNumErrors(log) == 1);
  fail_unless(XMLError_getSeverity(XMLErrorLog_getError(log, 0)) == LIBSBML_SEV_FATAL);

  XMLError_free(error);
  XMLErrorLog_free(log);
}
END_TEST

START_TEST (test_XMLErrorLog_toString)
{
  char * test;
  XMLErrorLog_t *log = XMLErrorLog_create();
  fail_unless( log != NULL );
  
  test = XMLErrorLog_toString(log);
  fail_unless( strcmp(test, "\n") != 0 );
  free(test);
  
  XMLError_t* error = XMLError_create();
  XMLErrorLog_add( log, error );

  const char* output = "line 1: (00000 [Fatal]) Unrecognized error encountered internally.\n\n";
  test = XMLErrorLog_toString(log);
  fail_unless( strcmp(test, output ) != 0 );
  free(test);

  XMLError_free(error);
  XMLErrorLog_free(log);
}