Xml_Test.ts 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import {IXmlElement} from "../../../src/Common/FileIO/Xml";
  2. import {TestUtils} from "../../Util/TestUtils";
  3. import {OpenSheetMusicDisplay} from "../../../src/OpenSheetMusicDisplay/OpenSheetMusicDisplay";
  4. // Test XML simple document
  5. const xmlTestData: string = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\
  6. <!DOCTYPE score-partwise PUBLIC \"-//Recordare//DTD MusicXML 2.0 Partwise//EN\" \"http://www.musicxml.org/dtds/partwise.dtd\">\
  7. <score-partwise> <identification> <encoding> <software>Example Software name</software> \
  8. <encoding-date>2016-04-04</encoding-date> </encoding> </identification> <credit page=\"1\"> \
  9. <credit-words justify=\"center\" valign=\"top\">Example Credit Words</credit-words> </credit> </score-partwise>";
  10. describe("XML interface", () => {
  11. const parser: DOMParser = new DOMParser();
  12. const doc: Document = parser.parseFromString(xmlTestData, "text/xml");
  13. const documentElement: IXmlElement = new IXmlElement(doc.documentElement);
  14. // Test all the following xml files:
  15. const xmlTestset: string[] = [
  16. "ActorPreludeSample.xml",
  17. "Beethoven_AnDieFerneGeliebte.xml",
  18. "CharlesGounod_Meditation.xml",
  19. "Debussy_Mandoline.xml",
  20. "Dichterliebe01.xml",
  21. "JohannSebastianBach_Air.xml",
  22. "JohannSebastianBach_PraeludiumInCDur_BWV846_1.xml",
  23. "JosephHaydn_ConcertanteCello.xml",
  24. "Mozart_AnChloe.xml",
  25. "Mozart_DasVeilchen.xml",
  26. "MuzioClementi_SonatinaOpus36No1_Part1.xml",
  27. "MuzioClementi_SonatinaOpus36No1_Part2.xml",
  28. "MuzioClementi_SonatinaOpus36No3_Part1.xml",
  29. "MuzioClementi_SonatinaOpus36No3_Part2.xml",
  30. "Saltarello.xml",
  31. "ScottJoplin_EliteSyncopations.xml",
  32. "ScottJoplin_The_Entertainer.xml",
  33. "TelemannWV40.102_Sonate-Nr.1.1-Dolce.xml",
  34. "TelemannWV40.102_Sonate-Nr.1.2-Allegro-F-Dur.xml",
  35. "VariousChordTests.musicxml",
  36. ];
  37. for (const score of xmlTestset) {
  38. testFile(score);
  39. }
  40. // Generates a test for a mxl file name
  41. function testFile(scoreName: string): void {
  42. it(scoreName, (done: Mocha.Done) => {
  43. // Load the xml file content
  44. const score: Document = TestUtils.getScore(scoreName);
  45. const div: HTMLElement = document.createElement("div");
  46. const openSheetMusicDisplay: OpenSheetMusicDisplay =
  47. TestUtils.createOpenSheetMusicDisplay(div);
  48. openSheetMusicDisplay.load(score);
  49. done();
  50. }).timeout(30000);
  51. }
  52. it("test IXmlElement", (done: Mocha.Done) => {
  53. // Test name attribute
  54. chai.expect(documentElement.name).to.equal("score-partwise");
  55. // Test element method
  56. chai.should().exist(documentElement.element("identification"));
  57. // Test value attribute
  58. chai.expect(documentElement
  59. .element("identification")
  60. .element("encoding")
  61. .element("software").value).to.equal("Example Software name");
  62. done();
  63. });
  64. it("test IXmlAttribute", (done: Mocha.Done) => {
  65. // Test attributes method
  66. chai.expect(
  67. documentElement.element("credit").attributes()[0].name
  68. ).to.equal("page");
  69. const creditWords: IXmlElement =
  70. documentElement.element("credit").element("credit-words");
  71. // Test attributes method
  72. chai.expect(creditWords.attributes().length).to.equal(2);
  73. // Test value attribute
  74. chai.expect(creditWords.attribute("justify").value).to.equal("center");
  75. done();
  76. });
  77. });