|
| 1 | +/* |
| 2 | + * SPDX-License-Identifier: GPL-3.0-only |
| 3 | + * MuseScore-Studio-CLA-applies |
| 4 | + * |
| 5 | + * MuseScore Studio |
| 6 | + * Music Composition & Notation |
| 7 | + * |
| 8 | + * Copyright (C) 2025 MuseScore Limited |
| 9 | + * |
| 10 | + * This program is free software: you can redistribute it and/or modify |
| 11 | + * it under the terms of the GNU General Public License version 3 as |
| 12 | + * published by the Free Software Foundation. |
| 13 | + * |
| 14 | + * This program is distributed in the hope that it will be useful, |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | + * GNU General Public License for more details. |
| 18 | + * |
| 19 | + * You should have received a copy of the GNU General Public License |
| 20 | + * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 21 | + */ |
| 22 | + |
| 23 | +#include <gtest/gtest.h> |
| 24 | +#include "engraving/rw/xmlreader.h" |
| 25 | +#include "engraving/rw/xmlwriter.h" |
| 26 | +#include "thirdparty/kors_logger/src/log_base.h" |
| 27 | +#include "types/bytearray.h" |
| 28 | +#include "io/buffer.h" |
| 29 | + |
| 30 | +using namespace mu; |
| 31 | +using namespace mu::engraving; |
| 32 | +using namespace muse; |
| 33 | +using namespace muse::io; |
| 34 | + |
| 35 | +class Engraving_XMLTests : public ::testing::Test |
| 36 | +{ |
| 37 | +}; |
| 38 | + |
| 39 | +TEST_F(Engraving_XMLTests, readHTML) |
| 40 | +{ |
| 41 | + ByteArray data; |
| 42 | + Buffer buf(&data); |
| 43 | + static const String XML_TEXT_REF = u"<tag1><br/></tag1>"; |
| 44 | + static const String XML_TEXT_VERBOSE = u"<tag1><br></br></tag1>"; |
| 45 | + |
| 46 | + // Write |
| 47 | + { |
| 48 | + buf.open(IODevice::WriteOnly); |
| 49 | + XmlWriter xml(&buf); |
| 50 | + xml.startDocument(); |
| 51 | + xml.startElement("parent"); |
| 52 | + |
| 53 | + xml.writeXml(u"xmlTag", XML_TEXT_REF); |
| 54 | + xml.writeXml(u"xmlTag", XML_TEXT_VERBOSE); |
| 55 | + |
| 56 | + xml.endElement(); |
| 57 | + |
| 58 | + EXPECT_NE(data.size(), 0); |
| 59 | + buf.close(); |
| 60 | + |
| 61 | + LOGI() << buf.data().constChar(); |
| 62 | + } |
| 63 | + |
| 64 | + // Read |
| 65 | + { |
| 66 | + buf.open(IODevice::ReadOnly); |
| 67 | + XmlReader xml(&buf); |
| 68 | + |
| 69 | + EXPECT_TRUE(xml.readNextStartElement()); |
| 70 | + EXPECT_EQ(xml.name(), "parent"); |
| 71 | + |
| 72 | + EXPECT_TRUE(xml.readNextStartElement()); |
| 73 | + EXPECT_EQ(xml.name(), "xmlTag"); |
| 74 | + String xmlTag = xml.readXml(); |
| 75 | + LOGI() << xmlTag; |
| 76 | + |
| 77 | + // Expect that <br></br> is condensed to <br/> |
| 78 | + EXPECT_TRUE(xml.readNextStartElement()); |
| 79 | + EXPECT_EQ(xml.name(), "xmlTag"); |
| 80 | + String xmlTagVerbose = xml.readXml(); |
| 81 | + LOGI() << xmlTagVerbose; |
| 82 | + EXPECT_EQ(xmlTag, XML_TEXT_REF); |
| 83 | + } |
| 84 | +} |
0 commit comments