LCOV - code coverage report
Current view: top level - autotest/cpp - test_ogr_lgpl.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 66 66 100.0 %
Date: 2024-11-21 22:18:42 Functions: 4 4 100.0 %

          Line data    Source code
       1             : ///////////////////////////////////////////////////////////////////////////////
       2             : //
       3             : // Project:  C++ Test Suite for GDAL/OGR
       4             : // Purpose:  Test general OGR features.
       5             : // Author:   Simon South
       6             : //
       7             : // Note the LGPL license of that file. See
       8             : // https://github.com/OSGeo/gdal/issues/5198
       9             : //
      10             : ///////////////////////////////////////////////////////////////////////////////
      11             : // Copyright (c) 2019, Simon South
      12             : //
      13             : // This library is free software; you can redistribute it and/or
      14             : // modify it under the terms of the GNU Library General Public
      15             : // License as published by the Free Software Foundation; either
      16             : // version 2 of the License, or (at your option) any later version.
      17             : //
      18             : // This library is distributed in the hope that it will be useful,
      19             : // but WITHOUT ANY WARRANTY; without even the implied warranty of
      20             : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      21             : // Library General Public License for more details.
      22             : //
      23             : // You should have received a copy of the GNU Library General Public
      24             : // License along with this library; if not, write to the
      25             : // Free Software Foundation, Inc., 59 Temple Place - Suite 330,
      26             : // Boston, MA 02111-1307, USA.
      27             : ///////////////////////////////////////////////////////////////////////////////
      28             : 
      29             : #include "ogr_p.h"
      30             : #include "ogrsf_frmts.h"
      31             : 
      32             : #include <string>
      33             : 
      34             : #include "gtest_include.h"
      35             : 
      36             : namespace
      37             : {
      38             : 
      39           4 : TEST(test_ogr_lgpl, OGRGetXMLDateTime)
      40             : {
      41             :     OGRField sField;
      42             :     char *pszDateTime;
      43             : 
      44           1 :     sField.Date.Year = 2001;
      45           1 :     sField.Date.Month = 2;
      46           1 :     sField.Date.Day = 3;
      47           1 :     sField.Date.Hour = 4;
      48           1 :     sField.Date.Minute = 5;
      49             : 
      50             :     // Unknown time zone (TZFlag = 0), no millisecond count
      51           1 :     sField.Date.TZFlag = 0;
      52           1 :     sField.Date.Second = 6.0f;
      53           1 :     pszDateTime = OGRGetXMLDateTime(&sField);
      54           1 :     ASSERT_TRUE(nullptr != pszDateTime);
      55             :     // OGRGetXMLDateTime formats date/time field with
      56             :     // unknown time zone, no millisecond count
      57           1 :     EXPECT_STREQ("2001-02-03T04:05:06", pszDateTime);
      58           1 :     CPLFree(pszDateTime);
      59             : 
      60             :     // Unknown time zone (TZFlag = 0), millisecond count
      61           1 :     sField.Date.TZFlag = 0;
      62           1 :     sField.Date.Second = 6.789f;
      63           1 :     pszDateTime = OGRGetXMLDateTime(&sField);
      64           1 :     ASSERT_TRUE(nullptr != pszDateTime);
      65             :     // OGRGetXMLDateTime formats date/time field with
      66             :     // unknown time zone, millisecond count
      67           1 :     EXPECT_STREQ("2001-02-03T04:05:06.789", pszDateTime);
      68           1 :     CPLFree(pszDateTime);
      69             : 
      70             :     // Local time zone (TZFlag = 1), no millisecond count
      71           1 :     sField.Date.TZFlag = 1;
      72           1 :     sField.Date.Second = 6.0f;
      73           1 :     pszDateTime = OGRGetXMLDateTime(&sField);
      74           1 :     ASSERT_TRUE(nullptr != pszDateTime);
      75             :     // OGRGetXMLDateTime formats date/time field with
      76             :     // local time zone, no millisecond count
      77           1 :     EXPECT_STREQ("2001-02-03T04:05:06", pszDateTime);
      78           1 :     CPLFree(pszDateTime);
      79             : 
      80             :     // Local time zone (TZFlag = 1), millisecond count
      81           1 :     sField.Date.TZFlag = 1;
      82           1 :     sField.Date.Second = 6.789f;
      83           1 :     pszDateTime = OGRGetXMLDateTime(&sField);
      84           1 :     ASSERT_TRUE(nullptr != pszDateTime);
      85             :     // OGRGetXMLDateTime formats date/time field with
      86             :     // local time zone, millisecond count
      87           1 :     EXPECT_STREQ("2001-02-03T04:05:06.789", pszDateTime);
      88           1 :     CPLFree(pszDateTime);
      89             : 
      90             :     // GMT time zone (TZFlag = 100), no millisecond count
      91           1 :     sField.Date.TZFlag = 100;
      92           1 :     sField.Date.Second = 6.0f;
      93           1 :     pszDateTime = OGRGetXMLDateTime(&sField);
      94           1 :     ASSERT_TRUE(nullptr != pszDateTime);
      95             :     // OGRGetXMLDateTime formats date/time field with
      96             :     // GMT time zone, no millisecond count
      97           1 :     EXPECT_STREQ("2001-02-03T04:05:06Z", pszDateTime);
      98           1 :     CPLFree(pszDateTime);
      99             : 
     100             :     // GMT time zone (TZFlag = 100), millisecond count
     101           1 :     sField.Date.TZFlag = 100;
     102           1 :     sField.Date.Second = 6.789f;
     103           1 :     pszDateTime = OGRGetXMLDateTime(&sField);
     104           1 :     ASSERT_TRUE(nullptr != pszDateTime);
     105             :     // OGRGetXMLDateTime formats date/time field with
     106             :     // GMT time zone, millisecond count
     107           1 :     EXPECT_STREQ("2001-02-03T04:05:06.789Z", pszDateTime);
     108           1 :     CPLFree(pszDateTime);
     109             : 
     110             :     // Positive time-zone offset, no millisecond count
     111           1 :     sField.Date.TZFlag = 111;
     112           1 :     sField.Date.Second = 6.0f;
     113           1 :     pszDateTime = OGRGetXMLDateTime(&sField);
     114           1 :     ASSERT_TRUE(nullptr != pszDateTime);
     115             :     // OGRGetXMLDateTime formats date/time field with
     116             :     // positive time-zone offset, no millisecond count
     117           1 :     EXPECT_STREQ("2001-02-03T04:05:06+02:45", pszDateTime);
     118           1 :     CPLFree(pszDateTime);
     119             : 
     120             :     // Positive time-zone offset, millisecond count
     121           1 :     sField.Date.TZFlag = 111;
     122           1 :     sField.Date.Second = 6.789f;
     123           1 :     pszDateTime = OGRGetXMLDateTime(&sField);
     124           1 :     ASSERT_TRUE(nullptr != pszDateTime);
     125             :     // OGRGetXMLDateTime formats date/time field with
     126             :     //  positive time-zone offset, millisecond count
     127           1 :     EXPECT_STREQ("2001-02-03T04:05:06.789+02:45", pszDateTime);
     128           1 :     CPLFree(pszDateTime);
     129             : 
     130             :     // Negative time-zone offset, no millisecond count
     131           1 :     sField.Date.TZFlag = 88;
     132           1 :     sField.Date.Second = 6.0f;
     133           1 :     pszDateTime = OGRGetXMLDateTime(&sField);
     134           1 :     ASSERT_TRUE(nullptr != pszDateTime);
     135             :     // OGRGetXMLDateTime formats date/time field with
     136             :     // negative time-zone offset, no millisecond count
     137           1 :     EXPECT_STREQ("2001-02-03T04:05:06-03:00", pszDateTime);
     138           1 :     CPLFree(pszDateTime);
     139             : 
     140             :     // Negative time-zone offset, millisecond count
     141           1 :     sField.Date.TZFlag = 88;
     142           1 :     sField.Date.Second = 6.789f;
     143           1 :     pszDateTime = OGRGetXMLDateTime(&sField);
     144           1 :     ASSERT_TRUE(nullptr != pszDateTime);
     145             :     // OGRGetXMLDateTime formats date/time field with
     146             :     // negative time-zone offset, millisecond count
     147           1 :     EXPECT_STREQ("2001-02-03T04:05:06.789-03:00", pszDateTime);
     148           1 :     CPLFree(pszDateTime);
     149             : }
     150             : 
     151             : }  // namespace

Generated by: LCOV version 1.14