Xml_Test.ts 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. ];
  36. for (const score of xmlTestset) {
  37. testFile(score);
  38. }
  39. // Generates a test for a mxl file name
  40. function testFile(scoreName: string): void {
  41. it(scoreName, (done: MochaDone) => {
  42. // Load the xml file content
  43. const score: Document = TestUtils.getScore(scoreName);
  44. const div: HTMLElement = document.createElement("div");
  45. const openSheetMusicDisplay: OpenSheetMusicDisplay =
  46. TestUtils.createOpenSheetMusicDisplay(div);
  47. openSheetMusicDisplay.load(score);
  48. done();
  49. }).timeout(10000);
  50. }
  51. it("test IXmlElement", (done: MochaDone) => {
  52. // Test name attribute
  53. chai.expect(documentElement.name).to.equal("score-partwise");
  54. // Test element method
  55. chai.should().exist(documentElement.element("identification"));
  56. // Test value attribute
  57. chai.expect(documentElement
  58. .element("identification")
  59. .element("encoding")
  60. .element("software").value).to.equal("Example Software name");
  61. done();
  62. });
  63. it("test IXmlAttribute", (done: MochaDone) => {
  64. // Test attributes method
  65. chai.expect(
  66. documentElement.element("credit").attributes()[0].name
  67. ).to.equal("page");
  68. const creditWords: IXmlElement =
  69. documentElement.element("credit").element("credit-words");
  70. // Test attributes method
  71. chai.expect(creditWords.attributes().length).to.equal(2);
  72. // Test value attribute
  73. chai.expect(creditWords.attribute("justify").value).to.equal("center");
  74. done();
  75. });
  76. });