< Summary - Igor Pro Universal Testing Framework

Information
Class: procedures.igortest-utils-xml
Assembly: procedures
File(s): /builds/mirror/igortest/procedures/igortest-utils-xml.ipf
Tag: 74147b3
Line coverage
65%
Covered lines: 27
Uncovered lines: 14
Coverable lines: 41
Total lines: 86
Line coverage: 65.8%
Branch coverage
50%
Covered branches: 2
Total branches: 4
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
IUTF_Utils_XML#ToXMLToken()100%263.64%
IUTF_Utils_XML#ToXMLCharacters()100%1100%
IUTF_Utils_XML#WriteXML()100%554.55%

File(s)

/builds/mirror/igortest/procedures/igortest-utils-xml.ipf

#LineLine coverage
 1#pragma rtGlobals=3
 2#pragma TextEncoding="UTF-8"
 3#pragma rtFunctionErrors=1
 4#pragma version=1.10
 5#pragma ModuleName=IUTF_Utils_XML
 6
 7// Helper functions to create XML files.
 8
 9/// XML properties
 10/// New Line is \n
 11/// The xs:int signed 32 bit Integer
 12/// The xs:decimal generic fp with max. 18 digits, exponential or scientific notation not supported.
 13/// The xs:string data type can contain characters, line feeds, carriage returns, and tab characters, needs also entity 
 14/// The xs:token data type also contains characters, but the XML processor will remove
 15/// line feeds, carriage returns, tabs, leading and trailing spaces, and multiple spaces.
 16/// it is a subtype of xs:string, entity escapes apply here
 17/// XML: Reduces a string to a xs:token
 40518static Function/S ToXMLToken(str)
 19  string   str
 40520  variable i
 21
 40522  str = ReplaceString("\n", str, "")
 40523  str = ReplaceString("\r", str, "")
 40524  str = ReplaceString("\t", str, "")
 25#if (IgorVersion() >= 7.0)
 40526  return (TrimString(str, 1))
 27#else
 028  for(i = 0; strsearch(str, "  ", 0) >= 0;)
 029    str = ReplaceString("  ", str, " ")
 030  endfor
 031  return (TrimString(str))
 32#endif
 40533End
 34
 35/// entity references
 36/// &lt;    <  less than
 37/// &gt;    >  greater than
 38/// &amp;   &  ampersand
 39/// &apos;  '  apostrophe
 40/// &quot;  "  quotation mark
 41/// XML: Escape Entity Replacer for strings
 57042static Function/S ToXMLCharacters(str)
 43  string str
 44
 57045  str = ReplaceString("&", str, "&amp;")
 57046  str = ReplaceString("<", str, "&lt;")
 57047  str = ReplaceString(">", str, "&gt;")
 57048  str = ReplaceString("'", str, "&apos;")
 57049  str = ReplaceString("\"", str, "&quot;")
 50
 57051  return str
 57052End
 53
 54/// Writes the report xml to a local file.
 55///
 56/// @param prefix   The name of the prefix which is prepended to the file name
 57/// @param content  The XML content that should be written
 58/// @param outDir   (optional, default: home directory) The output directory. It will use the home
 59///                 directory if this string is empty.
 560static Function WriteXML(prefix, content, [outDir])
 61  string prefix, content
 62  string outDir
 63
 564  string fileName, msg
 565  variable fnum
 66
 567  if(ParamIsDefault(outDir) || IUTF_Utils#IsEmpty(outDir))
 568    fileName = IUTF_Utils_Paths#AtHome(prefix + GetBaseFilename() + ".xml", unusedName = 1)
 069  else
 070    fileName = outDir + prefix + GetBaseFilename() + ".xml"
 071    fileName = IUTF_Utils_Paths#getUnusedFileName(fileName)
 072    if(IUTF_Utils#IsEmpty(fileName))
 073      sprintf msg, "Cannot determine unused file for %s at %s", fileName, outDir
 074      IUTF_Reporting#ReportErrorAndAbort(msg)
 075    endif
 576  endif
 77
 578  Open/Z fnum as fileName
 579  if(!V_flag)
 580    FBinWrite fnum, content
 581    Close fnum
 082  else
 083    sprintf msg, "Error: Could not create XML output file at %s", fileName
 084    IUTF_Reporting#IUTF_PrintStatusMessage(msg)
 585  endif
 586End