<p>George Joseph has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/9361">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">test.c: Make output jUnit compatible<br><br>Separate "name" into "classname" and "name".<br>Use '.' for classname separator instead of '/'.<br>Prefix reserved words with '_'.<br>Wrap output with a top-level "testsuites" element.<br><br>Change-Id: Iec1a985eba1c478e5c1d65d5dfd95cb708442099<br>---<br>M main/test.c<br>1 file changed, 62 insertions(+), 10 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/61/9361/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/main/test.c b/main/test.c</span><br><span>index 3fb1074..d3688b6 100644</span><br><span>--- a/main/test.c</span><br><span>+++ b/main/test.c</span><br><span>@@ -269,21 +269,71 @@</span><br><span> test->state = state;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+static char *reserved_words[] = {</span><br><span style="color: hsl(120, 100%, 40%);">+ "abstract", "arguments", "as", "assert", "await",</span><br><span style="color: hsl(120, 100%, 40%);">+ "boolean", "break", "byte", "case", "catch", "char", "class",</span><br><span style="color: hsl(120, 100%, 40%);">+ "const", "continue", "debugger", "def", "default", "delete", "do",</span><br><span style="color: hsl(120, 100%, 40%);">+ "double", "else", "enum", "eval", "export", "extends", "false",</span><br><span style="color: hsl(120, 100%, 40%);">+ "final", "finally", "float", "for", "function", "goto", "if",</span><br><span style="color: hsl(120, 100%, 40%);">+ "implements", "import", "in", "instanceof", "int", "interface",</span><br><span style="color: hsl(120, 100%, 40%);">+ "let", "long", "native", "new", "null", "package", "private",</span><br><span style="color: hsl(120, 100%, 40%);">+ "protected", "public", "return", "short", "static", "strictfp",</span><br><span style="color: hsl(120, 100%, 40%);">+ "string", "super", "switch", "synchronized", "this", "throw", "throws",</span><br><span style="color: hsl(120, 100%, 40%);">+ "trait", "transient", "true", "try", "typeof", "var", "void",</span><br><span style="color: hsl(120, 100%, 40%);">+ "volatile", "while", "with", "yield" };</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static int is_reserved_word(const char *word) {</span><br><span style="color: hsl(120, 100%, 40%);">+ int i;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ for (i = 0; i < ARRAY_LEN(reserved_words); i++) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (strcmp(word, reserved_words[i]) == 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return 1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static void test_xml_entry(struct ast_test *test, FILE *f)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">- if (!f || !test || test->state == AST_TEST_NOT_RUN) {</span><br><span style="color: hsl(120, 100%, 40%);">+ /* We need a copy of the category skipping past the initial '/' */</span><br><span style="color: hsl(120, 100%, 40%);">+ char *tmp_cat = ast_strdupa(test->info.category + 1);</span><br><span style="color: hsl(120, 100%, 40%);">+ char *next_cat = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ char *tmp_name = (char *)test->info.name;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_str *category = ast_str_create(strlen(test->info.category) + 32);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!category || !f || !test || test->state == AST_TEST_NOT_RUN) {</span><br><span> return;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- fprintf(f, "\t<testcase time=\"%u.%u\" name=\"%s%s\"%s>\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ while((next_cat = ast_strsep(&tmp_cat, '/', AST_STRSEP_TRIM))) {</span><br><span style="color: hsl(120, 100%, 40%);">+ char *prefix = "";</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (is_reserved_word(next_cat)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ prefix = "_";</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_str_append(&category, 0, ".%s%s", prefix, next_cat);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ tmp_cat = ast_str_buffer(category);</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Skip past the initial '.' */</span><br><span style="color: hsl(120, 100%, 40%);">+ tmp_cat++;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (is_reserved_word(test->info.name)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ size_t name_length = strlen(test->info.name) + 2;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ tmp_name = ast_alloca(name_length);</span><br><span style="color: hsl(120, 100%, 40%);">+ snprintf(tmp_name, name_length, "_%s", test->info.name);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ fprintf(f, "\t\t<testcase time=\"%u.%u\" classname=\"%s\" name=\"%s\"%s>\n",</span><br><span> test->time / 1000, test->time % 1000,</span><br><span style="color: hsl(0, 100%, 40%);">- test->info.category, test->info.name,</span><br><span style="color: hsl(120, 100%, 40%);">+ tmp_cat, tmp_name,</span><br><span> test->state == AST_TEST_PASS ? "/" : "");</span><br><span> </span><br><span> if (test->state == AST_TEST_FAIL) {</span><br><span style="color: hsl(0, 100%, 40%);">- fprintf(f, "\t\t<failure><![CDATA[\n%s\n\t\t]]></failure>\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ fprintf(f, "\t\t\t<failure><![CDATA[\n%s\n\t\t]]></failure>\n",</span><br><span> S_OR(ast_str_buffer(test->status_str), "NA"));</span><br><span style="color: hsl(0, 100%, 40%);">- fprintf(f, "\t</testcase>\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ fprintf(f, "\t\t</testcase>\n");</span><br><span> }</span><br><span> </span><br><span> }</span><br><span>@@ -475,13 +525,14 @@</span><br><span> * http://confluence.atlassian.com/display/BAMBOO/JUnit+parsing+in+Bamboo</span><br><span> */</span><br><span> fprintf(f_xml, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");</span><br><span style="color: hsl(0, 100%, 40%);">- fprintf(f_xml, "<testsuite errors=\"0\" time=\"%u.%u\" tests=\"%u\" "</span><br><span style="color: hsl(120, 100%, 40%);">+ fprintf(f_xml, "<testsuites>\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ fprintf(f_xml, "\t<testsuite errors=\"0\" time=\"%u.%u\" tests=\"%u\" "</span><br><span> "name=\"AsteriskUnitTests\">\n",</span><br><span> last_results.total_time / 1000, last_results.total_time % 1000,</span><br><span> last_results.total_tests);</span><br><span style="color: hsl(0, 100%, 40%);">- fprintf(f_xml, "\t<properties>\n");</span><br><span style="color: hsl(0, 100%, 40%);">- fprintf(f_xml, "\t\t<property name=\"version\" value=\"%s\"/>\n", ast_get_version());</span><br><span style="color: hsl(0, 100%, 40%);">- fprintf(f_xml, "\t</properties>\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ fprintf(f_xml, "\t\t<properties>\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ fprintf(f_xml, "\t\t\t<property name=\"version\" value=\"%s\"/>\n", ast_get_version());</span><br><span style="color: hsl(120, 100%, 40%);">+ fprintf(f_xml, "\t\t</properties>\n");</span><br><span> }</span><br><span> </span><br><span> /* txt header information */</span><br><span>@@ -519,7 +570,8 @@</span><br><span> </span><br><span> done:</span><br><span> if (f_xml) {</span><br><span style="color: hsl(0, 100%, 40%);">- fprintf(f_xml, "</testsuite>\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ fprintf(f_xml, "\t</testsuite>\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ fprintf(f_xml, "</testsuites>\n");</span><br><span> fclose(f_xml);</span><br><span> }</span><br><span> if (f_txt) {</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/9361">change 9361</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/9361"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: Iec1a985eba1c478e5c1d65d5dfd95cb708442099 </div>
<div style="display:none"> Gerrit-Change-Number: 9361 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: George Joseph <gjoseph@digium.com> </div>