END_TEST START_TEST (test_XMLOutputStream_PredefinedEntity) { XMLOutputStream_t *stream = XMLOutputStream_createAsString("", 0); XMLOutputStream_startElement(stream, "testpde"); XMLOutputStream_writeAttributeChars(stream, "amp", "&" ); XMLOutputStream_writeAttributeChars(stream, "apos", "'" ); XMLOutputStream_writeAttributeChars(stream, "gt", ">" ); XMLOutputStream_writeAttributeChars(stream, "lt", "<" ); XMLOutputStream_writeAttributeChars(stream, "quot", "\"" ); XMLOutputStream_writeAttributeChars(stream, "pdeamp", "&" ); XMLOutputStream_writeAttributeChars(stream, "pdeapos", "'"); XMLOutputStream_writeAttributeChars(stream, "pdegt", ">" ); XMLOutputStream_writeAttributeChars(stream, "pdelt", "<" ); XMLOutputStream_writeAttributeChars(stream, "pdequot", """); XMLOutputStream_endElement(stream, "testpde"); const char * expected = "<testpde amp=\"&\" apos=\"'\" gt=\">\" lt=\"<\" quot=\""\" pdeamp=\"&\" pdeapos=\"'\" pdegt=\">\" pdelt=\"<\" pdequot=\""\"/>"; const char * s = XMLOutputStream_getString(stream); fail_unless(!strcmp(s,expected)); XMLOutputStream_free(stream); }
END_TEST START_TEST (test_XMLOutputStream_Elements) { double d = 2.4; long l = 123456789; unsigned int ui = 5; int i = -3; XMLOutputStream_t *stream = XMLOutputStream_createAsString("", 0); XMLOutputStream_startElement(stream, "fred"); XMLOutputStream_writeAttributeChars(stream, "chars", "two"); XMLOutputStream_writeAttributeBool(stream, "bool", 1); XMLOutputStream_writeAttributeDouble(stream, "double", d); XMLOutputStream_writeAttributeLong(stream, "long", l); XMLOutputStream_writeAttributeUInt(stream, "uint", ui); XMLOutputStream_writeAttributeInt(stream, "int", i); XMLOutputStream_endElement(stream, "fred"); const char * expected = "<fred chars=\"two\" bool=\"true\" double=\"2.4\" long=\"123456789\" uint=\"5\" int=\"-3\"/>"; const char * s = XMLOutputStream_getString(stream); fail_unless(!strcmp(s,expected)); XMLOutputStream_free(stream); }
END_TEST START_TEST (test_XMLOutputStream_CharacterReference) { XMLOutputStream_t *stream = XMLOutputStream_createAsString("", 0); XMLOutputStream_startElement(stream, "testcr"); XMLOutputStream_writeAttributeChars(stream, "chars", "one" ); XMLOutputStream_writeAttributeChars(stream, "amp", "&" ); XMLOutputStream_writeAttributeChars(stream, "deccr", "¨" ); XMLOutputStream_writeAttributeChars(stream, "hexcr", "¨"); XMLOutputStream_writeAttributeChars(stream, "lhexcr", "¨"); XMLOutputStream_writeAttributeChars(stream, "nodeccr1", "ژ" ); XMLOutputStream_writeAttributeChars(stream, "nodeccr2", "&#;" ); XMLOutputStream_writeAttributeChars(stream, "nodeccr3", "�a8;" ); XMLOutputStream_writeAttributeChars(stream, "nodeccr4", "�A8;" ); XMLOutputStream_writeAttributeChars(stream, "nohexcr1", "&#x;" ); XMLOutputStream_writeAttributeChars(stream, "nohexcr2", "ꯍ" ); XMLOutputStream_endElement(stream, "testcr"); const char * expected = "<testcr chars=\"one\" amp=\"&\" deccr=\"¨\" hexcr=\"¨\" lhexcr=\"¨\" nodeccr1=\"&#01688\" nodeccr2=\"&#;\" nodeccr3=\"&#00a8;\" nodeccr4=\"&#00A8;\" nohexcr1=\"&#x;\" nohexcr2=\"&#xABCD\"/>"; const char * s = XMLOutputStream_getString(stream); fail_unless(!strcmp(s,expected)); XMLOutputStream_free(stream); }
END_TEST START_TEST (test_XMLOutputStream_accessWithNULL) { fail_unless( XMLOutputStream_createAsStdout(NULL, 0) == NULL ); fail_unless( XMLOutputStream_createAsStdoutWithProgramInfo(NULL, 0, NULL, NULL) == NULL ); fail_unless( XMLOutputStream_createAsString(NULL, 0) == NULL ); fail_unless( XMLOutputStream_createAsStringWithProgramInfo(NULL, 0, NULL, NULL) == NULL ); fail_unless( XMLOutputStream_createFile(NULL, NULL, 0) == NULL ); fail_unless( XMLOutputStream_createFileWithProgramInfo(NULL, NULL, 0, NULL, NULL) == NULL ); XMLOutputStream_downIndent(NULL); XMLOutputStream_endElement(NULL, NULL); XMLOutputStream_endElementTriple(NULL, NULL); XMLOutputStream_free(NULL); fail_unless( XMLOutputStream_getString(NULL) == NULL ); XMLOutputStream_setAutoIndent(NULL, 0); XMLOutputStream_startElement(NULL, NULL); XMLOutputStream_startElementTriple(NULL, NULL); XMLOutputStream_startEndElement(NULL, NULL); XMLOutputStream_startEndElementTriple(NULL, NULL); XMLOutputStream_upIndent(NULL); XMLOutputStream_writeAttributeBool(NULL, NULL, 0); XMLOutputStream_writeAttributeBoolTriple(NULL, NULL, 0); XMLOutputStream_writeAttributeChars(NULL, NULL, NULL); XMLOutputStream_writeAttributeCharsTriple(NULL, NULL, NULL); XMLOutputStream_writeAttributeDouble(NULL, NULL, 0.0); XMLOutputStream_writeAttributeDoubleTriple(NULL, NULL, 0.0); XMLOutputStream_writeAttributeInt(NULL, NULL, 0); XMLOutputStream_writeAttributeIntTriple(NULL, NULL, 0); XMLOutputStream_writeAttributeLong(NULL, NULL, 0); XMLOutputStream_writeAttributeLongTriple(NULL, NULL, 0); XMLOutputStream_writeAttributeUInt(NULL, NULL, 0); XMLOutputStream_writeAttributeUIntTriple(NULL, NULL, 0); XMLOutputStream_writeChars(NULL, NULL); XMLOutputStream_writeDouble(NULL, 0.0); XMLOutputStream_writeLong(NULL, 0); XMLOutputStream_writeXMLDecl(NULL); }