diff options
| -rw-r--r-- | include/junitxml.h | 67 | ||||
| -rw-r--r-- | src/junitxml.c | 23 | 
2 files changed, 72 insertions, 18 deletions
| diff --git a/include/junitxml.h b/include/junitxml.h index 430b627..290ce6f 100644 --- a/include/junitxml.h +++ b/include/junitxml.h @@ -1,54 +1,86 @@ -// @file junitxml.h +/// @file junitxml.h  #ifndef OMC_JUNITXML_H  #define OMC_JUNITXML_H  #include <libxml/xmlreader.h> +#define JUNIT_RESULT_STATE_NONE 0 +#define JUNIT_RESULT_STATE_FAILURE 1 +#define JUNIT_RESULT_STATE_SKIPPED 2 +#define JUNIT_RESULT_STATE_ERROR 2 + +/** + * Represents a failed test case + */  struct JUNIT_Failure { +    /// Error text +    char *message; +}; + +/** + * Represents a test case error + */ +struct JUNIT_Error { +    /// Error text      char *message;  }; +/** + * Represents a skipped test case + */  struct JUNIT_Skipped { +    /// Type of skip event      char *type; +    /// Reason text      char *message;  }; -#define JUNIT_RESULT_STATE_NONE 0 -#define JUNIT_RESULT_STATE_FAILURE 1 -#define JUNIT_RESULT_STATE_SKIPPED 2 +/** + * Represents a junit test case + */  struct JUNIT_Testcase { +    /// Class name      char *classname; +    /// Name of test      char *name; +    /// Test duration in fractional seconds      float time; +    /// Standard output message      char *message; +    /// Result type      int tc_result_state_type; +    /// Type container for result (there can only be one)      union tc_state_ptr {          struct JUNIT_Failure *failure;          struct JUNIT_Skipped *skipped; -    } result_state; +        struct JUNIT_Error *error; +    } result_state; ///< Result data  }; +/** + * Represents a junit test suite + */  struct JUNIT_Testsuite { -    //< Test suite name +    /// Test suite name      char *name; -    //< Total number of test terminated due to an error +    /// Total number of test terminated due to an error      int errors; -    //< Total number of failed tests +    /// Total number of failed tests      int failures; -    //< Total number of skipped tests +    /// Total number of skipped tests      int skipped; -    //< Total number of tests +    /// Total number of tests      int tests; -    //< Total duration in fractional seconds +    /// Total duration in fractional seconds      float time; -    //< Timestamp +    /// Timestamp      char *timestamp; -    //< Test runner host name +    /// Test runner host name      char *hostname; -    //< Array of test cases +    /// Array of test cases      struct JUNIT_Testcase **testcase; -    //< Total number of test cases in use +    /// Total number of test cases in use      size_t _tc_inuse; -    //< Total number of test cases allocated +    /// Total number of test cases allocated      size_t _tc_alloc;  }; @@ -68,6 +100,7 @@ struct JUNIT_Testsuite {   *         for (size_t i = 0; i < testsuite->_tc_inuse; i++) {   *             // Check result state (one of)   *             //   JUNIT_RESULT_STATE_FAILURE + *             //   JUNIT_RESULT_STATE_ERROR   *             //   JUNIT_RESULT_STATE_SKIPPED   *             struct JUNIT_Testcase testcase = testsuite->testcase[i];   *             if (testcase->tc_result_state_type) { @@ -86,8 +119,6 @@ struct JUNIT_Testsuite {   * } else {   *     // handle error   * } - * - *   * ~~~   *   * @param filename path to junit XML file diff --git a/src/junitxml.c b/src/junitxml.c index df0514b..c1bf1be 100644 --- a/src/junitxml.c +++ b/src/junitxml.c @@ -65,6 +65,23 @@ static struct JUNIT_Failure *testcase_failure_from_attributes(struct StrList *at      return result;  } +static struct JUNIT_Error *testcase_error_from_attributes(struct StrList *attrs) { +    struct JUNIT_Error *result; + +    result = calloc(1, sizeof(*result)); +    if(!result) { +        return NULL; +    } +    for (size_t x = 0; x < strlist_count(attrs); x += 2) { +        char *attr_name = strlist_item(attrs, x); +        char *attr_value = strlist_item(attrs, x + 1); +        if (!strcmp(attr_name, "message")) { +            result->message = strdup(attr_value); +        } +    } +    return result; +} +  static struct JUNIT_Skipped *testcase_skipped_from_attributes(struct StrList *attrs) {      struct JUNIT_Skipped *result; @@ -133,6 +150,7 @@ static int read_xml_data(xmlTextReaderPtr reader, struct JUNIT_Testsuite **tests      name = xmlTextReaderConstName(reader);      if (!name) { +        // name could not be converted to string          name = BAD_CAST "--";      }      value = xmlTextReaderConstValue(reader); @@ -171,6 +189,11 @@ static int read_xml_data(xmlTextReaderPtr reader, struct JUNIT_Testsuite **tests              struct JUNIT_Failure *failure = testcase_failure_from_attributes(attrs);              (*testsuite)->testcase[cur_tc]->tc_result_state_type = JUNIT_RESULT_STATE_FAILURE;              (*testsuite)->testcase[cur_tc]->result_state.failure = failure; +        } else if (!strcmp(node_name, "error")) { +            size_t cur_tc = (*testsuite)->_tc_inuse > 0 ? (*testsuite)->_tc_inuse - 1 : (*testsuite)->_tc_inuse; +            struct JUNIT_Error *error = testcase_error_from_attributes(attrs); +            (*testsuite)->testcase[cur_tc]->tc_result_state_type = JUNIT_RESULT_STATE_ERROR; +            (*testsuite)->testcase[cur_tc]->result_state.error = error;          } else if (!strcmp(node_name, "skipped")) {              size_t cur_tc = (*testsuite)->_tc_inuse > 0 ? (*testsuite)->_tc_inuse - 1 : (*testsuite)->_tc_inuse;              struct JUNIT_Skipped *skipped = testcase_skipped_from_attributes(attrs); | 
