sc/qa/unit/data/json-mapped/list-of-objects.json | 6 sc/qa/unit/data/json-mapped/nested-arrays.json | 9 + sc/qa/unit/data/xml-mapped/list-of-records.xml | 143 +++++++++++++++++++++++ sc/qa/unit/subsequent_filters_test5.cxx | 72 +++++++++++ 4 files changed, 230 insertions(+)
New commits: commit 04c4bc05425da29ab66a167c8c1d84e910738b2e Author: Kohei Yoshida <kohei.yosh...@collabora.com> AuthorDate: Mon Aug 25 22:11:01 2025 -0400 Commit: Kohei Yoshida <kohei.yosh...@collabora.com> CommitDate: Tue Aug 26 05:39:54 2025 +0200 Add test cases for mapping of generic JSON and XML to spreadsheet This is a follow-up to cd347097f726eae68fa819fe244d0bedf13832e9. Change-Id: I9844df60dee75485bf553b0124beabc76c104319 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/190194 Tested-by: Jenkins Reviewed-by: Kohei Yoshida <ko...@libreoffice.org> diff --git a/sc/qa/unit/data/json-mapped/list-of-objects.json b/sc/qa/unit/data/json-mapped/list-of-objects.json new file mode 100644 index 000000000000..87bd03fca884 --- /dev/null +++ b/sc/qa/unit/data/json-mapped/list-of-objects.json @@ -0,0 +1,6 @@ +[ + {"A": 1, "B": 2, "C": 3}, + {"A": 11, "B": 12, "C": 13}, + {"A": 21, "B": 22, "D": 24}, + {"C": "text"} +] diff --git a/sc/qa/unit/data/json-mapped/nested-arrays.json b/sc/qa/unit/data/json-mapped/nested-arrays.json new file mode 100644 index 000000000000..a93a01263d13 --- /dev/null +++ b/sc/qa/unit/data/json-mapped/nested-arrays.json @@ -0,0 +1,9 @@ +[ + "Simple list of arrays", + "This file contains a list of arrays as data and some title strings at the top.", + [ + [1, 2, 3], + [4, 5, 6], + [7, 8, 9] + ] +] diff --git a/sc/qa/unit/data/xml-mapped/list-of-records.xml b/sc/qa/unit/data/xml-mapped/list-of-records.xml new file mode 100644 index 000000000000..456d91dbeeb2 --- /dev/null +++ b/sc/qa/unit/data/xml-mapped/list-of-records.xml @@ -0,0 +1,143 @@ +<?xml version="1.0" encoding="UTF-8"?> +<records> + <record> + <id>1</id> + <name>John Smith</name> + <email>john.sm...@example.com</email> + <age>34</age> + <city>New York</city> + </record> + <record> + <id>2</id> + <name>Emma Johnson</name> + <email>emma.john...@example.com</email> + <age>28</age> + <city>Los Angeles</city> + </record> + <record> + <id>3</id> + <name>Michael Chen</name> + <email>michael.c...@example.com</email> + <age>45</age> + <city>Chicago</city> + </record> + <record> + <id>4</id> + <name>Sophia Rodriguez</name> + <email>sophia.rodrig...@example.com</email> + <age>19</age> + <city>Houston</city> + </record> + <record> + <id>5</id> + <name>James Brown</name> + <email>james.br...@example.com</email> + <age>52</age> + <city>Phoenix</city> + </record> + <record> + <id>6</id> + <name>Olivia Davis</name> + <email>olivia.da...@example.com</email> + <age>27</age> + <city>Philadelphia</city> + </record> + <record> + <id>7</id> + <name>William Wilson</name> + <email>william.wil...@example.com</email> + <age>39</age> + <city>San Antonio</city> + </record> + <record> + <id>8</id> + <name>Ava Martinez</name> + <email>ava.marti...@example.com</email> + <age>31</age> + <city>San Diego</city> + </record> + <record> + <id>9</id> + <name>Lucas Taylor</name> + <email>lucas.tay...@example.com</email> + <age>23</age> + <city>Dallas</city> + </record> + <record> + <id>10</id> + <name>Mia Anderson</name> + <email>mia.ander...@example.com</email> + <age>29</age> + <city>San Jose</city> + </record> + <record> + <id>11</id> + <name>Ethan Thomas</name> + <email>ethan.tho...@example.com</email> + <age>41</age> + <city>Austin</city> + </record> + <record> + <id>12</id> + <name>Isabella Lee</name> + <email>isabella....@example.com</email> + <age>26</age> + <city>Jacksonville</city> + </record> + <record> + <id>13</id> + <name>Alexander Walker</name> + <email>alexander.wal...@example.com</email> + <age>37</age> + <city>San Francisco</city> + </record> + <record> + <id>14</id> + <name>Charlotte Harris</name> + <email>charlotte.har...@example.com</email> + <age>33</age> + <city>Columbus</city> + </record> + <record> + <id>15</id> + <name>Daniel Lewis</name> + <email>daniel.le...@example.com</email> + <age>30</age> + <city>Indianapolis</city> + </record> + <record> + <id>16</id> + <name>Amelia Clark</name> + <email>amelia.cl...@example.com</email> + <age>24</age> + <city>Seattle</city> + </record> + <record> + <id>17</id> + <name>Henry Young</name> + <email>henry.yo...@example.com</email> + <age>48</age> + <city>Denver</city> + </record> + <record> + <id>18</id> + <name>Harper King</name> + <email>harper.k...@example.com</email> + <age>21</age> + <city>Washington</city> + </record> + <record> + <id>19</id> + <name>Benjamin Scott</name> + <email>benjamin.sc...@example.com</email> + <age>35</age> + <city>Boston</city> + </record> + <record> + <id>20</id> + <name>Evelyn Adams</name> + <email>evelyn.ad...@example.com</email> + <age>40</age> + <city>Portland</city> + </record> +</records> diff --git a/sc/qa/unit/subsequent_filters_test5.cxx b/sc/qa/unit/subsequent_filters_test5.cxx index 30563b7bffb2..cd7f26fa5257 100644 --- a/sc/qa/unit/subsequent_filters_test5.cxx +++ b/sc/qa/unit/subsequent_filters_test5.cxx @@ -132,6 +132,78 @@ CPPUNIT_TEST_FIXTURE(ScFiltersTest5, testTdf94627) ASSERT_DOUBLES_EQUAL(2, fVal); } +CPPUNIT_TEST_FIXTURE(ScFiltersTest5, testGenericXMLMapped) +{ + createScDoc("xml-mapped/list-of-records.xml"); + ScDocument* pDoc = getScDoc(); + + std::vector<std::vector<const char*>> aCheck = { + { "id", "name", "email", "age", "city" }, + { "1", "John Smith", "john.sm...@example.com", "34", "New York" }, + { "2", "Emma Johnson", "emma.john...@example.com", "28", "Los Angeles" }, + { "3", "Michael Chen", "michael.c...@example.com", "45", "Chicago" }, + { "4", "Sophia Rodriguez", "sophia.rodrig...@example.com", "19", "Houston" }, + { "5", "James Brown", "james.br...@example.com", "52", "Phoenix" }, + { "6", "Olivia Davis", "olivia.da...@example.com", "27", "Philadelphia" }, + { "7", "William Wilson", "william.wil...@example.com", "39", "San Antonio" }, + { "8", "Ava Martinez", "ava.marti...@example.com", "31", "San Diego" }, + { "9", "Lucas Taylor", "lucas.tay...@example.com", "23", "Dallas" }, + { "10", "Mia Anderson", "mia.ander...@example.com", "29", "San Jose" }, + { "11", "Ethan Thomas", "ethan.tho...@example.com", "41", "Austin" }, + { "12", "Isabella Lee", "isabella....@example.com", "26", "Jacksonville" }, + { "13", "Alexander Walker", "alexander.wal...@example.com", "37", "San Francisco" }, + { "14", "Charlotte Harris", "charlotte.har...@example.com", "33", "Columbus" }, + { "15", "Daniel Lewis", "daniel.le...@example.com", "30", "Indianapolis" }, + { "16", "Amelia Clark", "amelia.cl...@example.com", "24", "Seattle" }, + { "17", "Henry Young", "henry.yo...@example.com", "48", "Denver" }, + { "18", "Harper King", "harper.k...@example.com", "21", "Washington" }, + { "19", "Benjamin Scott", "benjamin.sc...@example.com", "35", "Boston" }, + { "20", "Evelyn Adams", "evelyn.ad...@example.com", "40", "Portland" }, + }; + + ScRange aOutRange; + aOutRange.Parse(u"A1:E21"_ustr, *pDoc); + bool bGood = checkOutput(pDoc, aOutRange, aCheck, "expected output"); + CPPUNIT_ASSERT(bGood); +} + +CPPUNIT_TEST_FIXTURE(ScFiltersTest5, testGenericJSONMapped1) +{ + createScDoc("json-mapped/list-of-objects.json"); + ScDocument* pDoc = getScDoc(); + + std::vector<std::vector<const char*>> aCheck = { + { "A", "B", "C", "D" }, + { "1", "2", "3", nullptr }, + { "11", "12", "13", nullptr }, + { "21", "22", nullptr, "24" }, + { nullptr, nullptr, "text", nullptr }, + }; + + ScRange aOutRange; + aOutRange.Parse(u"A1:D5"_ustr, *pDoc); + bool bGood = checkOutput(pDoc, aOutRange, aCheck, "expected output"); + CPPUNIT_ASSERT(bGood); +} + +CPPUNIT_TEST_FIXTURE(ScFiltersTest5, testGenericJSONMapped2) +{ + createScDoc("json-mapped/nested-arrays.json"); + ScDocument* pDoc = getScDoc(); + + std::vector<std::vector<const char*>> aCheck = { + { "field 0", "field 1", "field 2" }, + { "1", "2", "3" }, + { "4", "5", "6" }, + { "7", "8", "9" }, + }; + + ScRange aOutRange; + aOutRange.Parse(u"A1:C4"_ustr, *pDoc); + bool bGood = checkOutput(pDoc, aOutRange, aCheck, "expected output"); + CPPUNIT_ASSERT(bGood); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */