libextractor

GNU libextractor
Log | Files | Refs | Submodules | README | LICENSE

test_kml.c (5326B)


      1 /*
      2      This file is part of libextractor.
      3      Copyright (C) 2026 Vidyut Samanta and Christian Grothoff
      4 
      5      libextractor is free software; you can redistribute it and/or modify
      6      it under the terms of the GNU General Public License as published
      7      by the Free Software Foundation; either version 3, or (at your
      8      option) any later version.
      9 
     10      libextractor is distributed in the hope that it will be useful, but
     11      WITHOUT ANY WARRANTY; without even the implied warranty of
     12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     13      General Public License for more details.
     14 
     15      You should have received a copy of the GNU General Public License
     16      along with libextractor; see the file COPYING.  If not, write to the
     17      Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     18      Boston, MA 02110-1301, USA.
     19 */
     20 /**
     21  * @file plugins/test_kml.c
     22  * @brief testcase for the kml plugin
     23  * @author Christian Grothoff
     24  */
     25 #include "platform.h"
     26 #include "test_lib.h"
     27 
     28 
     29 /**
     30  * Main function for the kml testcase.
     31  *
     32  * The expected values come from `contrib/gen_kml_testdata.sh'.  The
     33  * assertions that prove the scanner did its job rather than just
     34  * recognising the magic are the bounding box (which is only correct if
     35  * the lon,lat tuple order was honoured), the first coordinate, the
     36  * placemark count, the description with its HTML stripped out of the
     37  * CDATA section, and the LookAt comment -- the viewer's position, which
     38  * must *not* have been reported as the data's position.
     39  *
     40  * @param argc number of arguments (ignored)
     41  * @param argv arguments (ignored)
     42  * @return 0 on success
     43  */
     44 int
     45 main (int argc, char *argv[])
     46 {
     47   struct SolutionData kml_sol[] = {
     48     {
     49       EXTRACTOR_METATYPE_MIMETYPE,
     50       EXTRACTOR_METAFORMAT_UTF8,
     51       "text/plain",
     52       "application/vnd.google-earth.kml+xml",
     53       strlen ("application/vnd.google-earth.kml+xml") + 1,
     54       0
     55     },
     56     {
     57       EXTRACTOR_METATYPE_COORDINATE_SYSTEM,
     58       EXTRACTOR_METAFORMAT_UTF8,
     59       "text/plain",
     60       "WGS 84",
     61       strlen ("WGS 84") + 1,
     62       0
     63     },
     64     {
     65       EXTRACTOR_METATYPE_TITLE,
     66       EXTRACTOR_METAFORMAT_UTF8,
     67       "text/plain",
     68       "Zurich morning walk",
     69       strlen ("Zurich morning walk") + 1,
     70       0
     71     },
     72     /* out of a CDATA section, with the HTML markup removed */
     73     {
     74       EXTRACTOR_METATYPE_DESCRIPTION,
     75       EXTRACTOR_METAFORMAT_UTF8,
     76       "text/plain",
     77       "Exported from the handheld on 2024-03-15. See the index for the"
     78       " other days.",
     79       strlen ("Exported from the handheld on 2024-03-15. See the index"
     80               " for the other days.") + 1,
     81       0
     82     },
     83     {
     84       EXTRACTOR_METATYPE_AUTHOR_NAME,
     85       EXTRACTOR_METAFORMAT_UTF8,
     86       "text/plain",
     87       "Anna Mueller",
     88       strlen ("Anna Mueller") + 1,
     89       0
     90     },
     91     /* <atom:link href=> */
     92     {
     93       EXTRACTOR_METATYPE_URL,
     94       EXTRACTOR_METAFORMAT_UTF8,
     95       "text/plain",
     96       "https://example.com/~anna/",
     97       strlen ("https://example.com/~anna/") + 1,
     98       0
     99     },
    100     /* <NetworkLink><Link><href> */
    101     {
    102       EXTRACTOR_METATYPE_URL,
    103       EXTRACTOR_METAFORMAT_UTF8,
    104       "text/plain",
    105       "https://tracker.example.net/live/anna.kml",
    106       strlen ("https://tracker.example.net/live/anna.kml") + 1,
    107       0
    108     },
    109     {
    110       EXTRACTOR_METATYPE_COMMENT,
    111       EXTRACTOR_METAFORMAT_UTF8,
    112       "text/plain",
    113       "1 NetworkLink element; opening this document fetches remote"
    114       " content",
    115       strlen ("1 NetworkLink element; opening this document fetches"
    116               " remote content") + 1,
    117       0
    118     },
    119     {
    120       EXTRACTOR_METATYPE_CREATION_DATE,
    121       EXTRACTOR_METAFORMAT_UTF8,
    122       "text/plain",
    123       "2024-03-15T07:12:00Z",
    124       strlen ("2024-03-15T07:12:00Z") + 1,
    125       0
    126     },
    127     {
    128       EXTRACTOR_METATYPE_LOCATION_NAME,
    129       EXTRACTOR_METAFORMAT_UTF8,
    130       "text/plain",
    131       "Home",
    132       strlen ("Home") + 1,
    133       0
    134     },
    135     /* west,south,east,north over all three Placemarks */
    136     {
    137       EXTRACTOR_METATYPE_BOUNDING_BOX,
    138       EXTRACTOR_METAFORMAT_UTF8,
    139       "text/plain",
    140       "8.541694,47.376890,8.552300,47.385100",
    141       strlen ("8.541694,47.376890,8.552300,47.385100") + 1,
    142       0
    143     },
    144     /* KML tuples are lon,lat -- getting this right is the whole test */
    145     {
    146       EXTRACTOR_METATYPE_GPS_LATITUDE,
    147       EXTRACTOR_METAFORMAT_UTF8,
    148       "text/plain",
    149       "47.376890",
    150       strlen ("47.376890") + 1,
    151       0
    152     },
    153     {
    154       EXTRACTOR_METATYPE_GPS_LONGITUDE,
    155       EXTRACTOR_METAFORMAT_UTF8,
    156       "text/plain",
    157       "8.541694",
    158       strlen ("8.541694") + 1,
    159       0
    160     },
    161     /* the viewer's position, kept apart from the data's */
    162     {
    163       EXTRACTOR_METATYPE_COMMENT,
    164       EXTRACTOR_METAFORMAT_UTF8,
    165       "text/plain",
    166       "LookAt viewpoint at 47.381000, 8.547000 (latitude, longitude)",
    167       strlen ("LookAt viewpoint at 47.381000, 8.547000"
    168               " (latitude, longitude)") + 1,
    169       0
    170     },
    171     {
    172       EXTRACTOR_METATYPE_ENTRY_COUNT,
    173       EXTRACTOR_METAFORMAT_UTF8,
    174       "text/plain",
    175       "3",
    176       strlen ("3") + 1,
    177       0
    178     },
    179     { 0, 0, NULL, NULL, 0, -1 }
    180   };
    181   struct ProblemSet ps[] = {
    182     { "testdata/kml_test.kml",
    183       kml_sol },
    184     { NULL, NULL }
    185   };
    186 
    187   (void) argc;
    188   (void) argv;
    189   return ET_main ("kml", ps);
    190 }
    191 
    192 
    193 /* end of test_kml.c */