libextractor

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

test_gpx.c (6892B)


      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_gpx.c
     22  * @brief testcase for the gpx plugin
     23  * @author Christian Grothoff
     24  */
     25 #include "platform.h"
     26 #include "test_lib.h"
     27 
     28 
     29 /**
     30  * Main function for the gpx testcase.
     31  *
     32  * The expected values below all come from
     33  * `contrib/gen_gpx_testdata.sh'; see that script for how the file is
     34  * built.  The interesting assertions are the ones that prove the
     35  * scanner actually walked the track: the bounding box, the first
     36  * coordinate, the point counts, the duration between the first and the
     37  * last `<time>' and the haversine sum over the five points.
     38  *
     39  * @param argc number of arguments (ignored)
     40  * @param argv arguments (ignored)
     41  * @return 0 on success
     42  */
     43 int
     44 main (int argc, char *argv[])
     45 {
     46   struct SolutionData gpx_sol[] = {
     47     {
     48       EXTRACTOR_METATYPE_MIMETYPE,
     49       EXTRACTOR_METAFORMAT_UTF8,
     50       "text/plain",
     51       "application/gpx+xml",
     52       strlen ("application/gpx+xml") + 1,
     53       0
     54     },
     55     {
     56       EXTRACTOR_METATYPE_CREATED_BY_SOFTWARE,
     57       EXTRACTOR_METAFORMAT_UTF8,
     58       "text/plain",
     59       "Garmin eTrex 30",
     60       strlen ("Garmin eTrex 30") + 1,
     61       0
     62     },
     63     {
     64       EXTRACTOR_METATYPE_DEVICE_MODEL,
     65       EXTRACTOR_METAFORMAT_UTF8,
     66       "text/plain",
     67       "Garmin eTrex 30",
     68       strlen ("Garmin eTrex 30") + 1,
     69       0
     70     },
     71     {
     72       EXTRACTOR_METATYPE_FORMAT_VERSION,
     73       EXTRACTOR_METAFORMAT_UTF8,
     74       "text/plain",
     75       "1.1",
     76       strlen ("1.1") + 1,
     77       0
     78     },
     79     {
     80       EXTRACTOR_METATYPE_COORDINATE_SYSTEM,
     81       EXTRACTOR_METAFORMAT_UTF8,
     82       "text/plain",
     83       "WGS 84",
     84       strlen ("WGS 84") + 1,
     85       0
     86     },
     87     {
     88       EXTRACTOR_METATYPE_TITLE,
     89       EXTRACTOR_METAFORMAT_UTF8,
     90       "text/plain",
     91       "Zurich morning walk",
     92       strlen ("Zurich morning walk") + 1,
     93       0
     94     },
     95     /* the `&amp;' in the source must have come back out as `&' */
     96     {
     97       EXTRACTOR_METATYPE_DESCRIPTION,
     98       EXTRACTOR_METAFORMAT_UTF8,
     99       "text/plain",
    100       "Recorded on the way to the office & back",
    101       strlen ("Recorded on the way to the office & back") + 1,
    102       0
    103     },
    104     {
    105       EXTRACTOR_METATYPE_KEYWORDS,
    106       EXTRACTOR_METAFORMAT_UTF8,
    107       "text/plain",
    108       "walk,commute,zurich",
    109       strlen ("walk,commute,zurich") + 1,
    110       0
    111     },
    112     {
    113       EXTRACTOR_METATYPE_AUTHOR_NAME,
    114       EXTRACTOR_METAFORMAT_UTF8,
    115       "text/plain",
    116       "Anna Mueller",
    117       strlen ("Anna Mueller") + 1,
    118       0
    119     },
    120     /* <email id="anna.mueller" domain="example.com"/>, rejoined */
    121     {
    122       EXTRACTOR_METATYPE_AUTHOR_EMAIL,
    123       EXTRACTOR_METAFORMAT_UTF8,
    124       "text/plain",
    125       "anna.mueller@example.com",
    126       strlen ("anna.mueller@example.com") + 1,
    127       0
    128     },
    129     {
    130       EXTRACTOR_METATYPE_COPYRIGHT,
    131       EXTRACTOR_METAFORMAT_UTF8,
    132       "text/plain",
    133       "Anna Mueller",
    134       strlen ("Anna Mueller") + 1,
    135       0
    136     },
    137     {
    138       EXTRACTOR_METATYPE_LICENSE,
    139       EXTRACTOR_METAFORMAT_UTF8,
    140       "text/plain",
    141       "https://creativecommons.org/publicdomain/zero/1.0/",
    142       strlen ("https://creativecommons.org/publicdomain/zero/1.0/") + 1,
    143       0
    144     },
    145     /* <metadata><author><link href=> */
    146     {
    147       EXTRACTOR_METATYPE_URL,
    148       EXTRACTOR_METAFORMAT_UTF8,
    149       "text/plain",
    150       "https://example.com/~anna/",
    151       strlen ("https://example.com/~anna/") + 1,
    152       0
    153     },
    154     /* <metadata><link href=> */
    155     {
    156       EXTRACTOR_METATYPE_URL,
    157       EXTRACTOR_METAFORMAT_UTF8,
    158       "text/plain",
    159       "https://example.com/tracks/2024-03-15.gpx",
    160       strlen ("https://example.com/tracks/2024-03-15.gpx") + 1,
    161       0
    162     },
    163     /* <metadata><time> */
    164     {
    165       EXTRACTOR_METATYPE_CREATION_DATE,
    166       EXTRACTOR_METAFORMAT_UTF8,
    167       "text/plain",
    168       "2024-03-15T07:12:00Z",
    169       strlen ("2024-03-15T07:12:00Z") + 1,
    170       0
    171     },
    172     /* time of the first track point */
    173     {
    174       EXTRACTOR_METATYPE_CREATION_DATE,
    175       EXTRACTOR_METAFORMAT_UTF8,
    176       "text/plain",
    177       "2024-03-15T07:12:33Z",
    178       strlen ("2024-03-15T07:12:33Z") + 1,
    179       0
    180     },
    181     /* time of the last track point */
    182     {
    183       EXTRACTOR_METATYPE_MODIFICATION_DATE,
    184       EXTRACTOR_METAFORMAT_UTF8,
    185       "text/plain",
    186       "2024-03-15T07:24:53Z",
    187       strlen ("2024-03-15T07:24:53Z") + 1,
    188       0
    189     },
    190     /* west,south,east,north -- from the explicit <bounds> */
    191     {
    192       EXTRACTOR_METATYPE_BOUNDING_BOX,
    193       EXTRACTOR_METAFORMAT_UTF8,
    194       "text/plain",
    195       "8.541694,47.376890,8.552300,47.385100",
    196       strlen ("8.541694,47.376890,8.552300,47.385100") + 1,
    197       0
    198     },
    199     {
    200       EXTRACTOR_METATYPE_GPS_LATITUDE,
    201       EXTRACTOR_METAFORMAT_UTF8,
    202       "text/plain",
    203       "47.376890",
    204       strlen ("47.376890") + 1,
    205       0
    206     },
    207     {
    208       EXTRACTOR_METATYPE_GPS_LONGITUDE,
    209       EXTRACTOR_METAFORMAT_UTF8,
    210       "text/plain",
    211       "8.541694",
    212       strlen ("8.541694") + 1,
    213       0
    214     },
    215     {
    216       EXTRACTOR_METATYPE_ENTRY_COUNT,
    217       EXTRACTOR_METAFORMAT_UTF8,
    218       "text/plain",
    219       "5",
    220       strlen ("5") + 1,
    221       0
    222     },
    223     {
    224       EXTRACTOR_METATYPE_COMMENT,
    225       EXTRACTOR_METAFORMAT_UTF8,
    226       "text/plain",
    227       "5 track points, 2 waypoints, 2 route points",
    228       strlen ("5 track points, 2 waypoints, 2 route points") + 1,
    229       0
    230     },
    231     /* 07:12:33 to 07:24:53 */
    232     {
    233       EXTRACTOR_METATYPE_DURATION,
    234       EXTRACTOR_METAFORMAT_UTF8,
    235       "text/plain",
    236       "0:12:20",
    237       strlen ("0:12:20") + 1,
    238       0
    239     },
    240     {
    241       EXTRACTOR_METATYPE_LOCATION_ELEVATION,
    242       EXTRACTOR_METAFORMAT_UTF8,
    243       "text/plain",
    244       "408.2-430.7 m",
    245       strlen ("408.2-430.7 m") + 1,
    246       0
    247     },
    248     /* haversine sum over the five track points */
    249     {
    250       EXTRACTOR_METATYPE_DISTANCE,
    251       EXTRACTOR_METAFORMAT_UTF8,
    252       "text/plain",
    253       "1215 m",
    254       strlen ("1215 m") + 1,
    255       0
    256     },
    257     { 0, 0, NULL, NULL, 0, -1 }
    258   };
    259   struct ProblemSet ps[] = {
    260     { "testdata/gpx_test.gpx",
    261       gpx_sol },
    262     { NULL, NULL }
    263   };
    264 
    265   (void) argc;
    266   (void) argv;
    267   return ET_main ("gpx", ps);
    268 }
    269 
    270 
    271 /* end of test_gpx.c */