From 5c6f469c255bbf575c7aa3d0d7d30949aa3aa965 Mon Sep 17 00:00:00 2001 From: Anna Petrasova Date: Fri, 15 Dec 2023 14:31:45 -0500 Subject: [PATCH] g.proj: fix wkt output on Windows (#3306) Follows documentation of exportToWkt: Note that the returned WKT string should be freed with CPLFree() when no longer needed. It is the responsibility of the caller. --- general/g.proj/output.c | 6 +++++- general/g.proj/testsuite/test_g_proj.py | 27 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 general/g.proj/testsuite/test_g_proj.py diff --git a/general/g.proj/output.c b/general/g.proj/output.c index 365578ab527..33b7b6042d9 100644 --- a/general/g.proj/output.c +++ b/general/g.proj/output.c @@ -22,6 +22,10 @@ #include #include +#ifdef HAVE_OGR +#include +#endif + #include "local_proto.h" static int check_xy(int shell); @@ -274,7 +278,7 @@ void print_wkt(int esristyle, int dontprettify) if (outwkt != NULL) { fprintf(stdout, "%s\n", outwkt); - G_free(outwkt); + CPLFree(outwkt); } else G_warning(_("Unable to convert to WKT")); diff --git a/general/g.proj/testsuite/test_g_proj.py b/general/g.proj/testsuite/test_g_proj.py new file mode 100644 index 00000000000..4ef67e5781b --- /dev/null +++ b/general/g.proj/testsuite/test_g_proj.py @@ -0,0 +1,27 @@ +"""g.proj tests + +(C) 2023 by the GRASS Development Team +This program is free software under the GNU General Public +License (>=v2). Read the file COPYING that comes with GRASS +for details. + +:author: Anna Petrasova +""" + +from grass.gunittest.case import TestCase +from grass.gunittest.main import test +from grass.gunittest.gmodules import SimpleModule + + +class GProjWKTTestCase(TestCase): + """Test g.proj with WKT output""" + + def test_wkt_output(self): + """Test if g.proj returns WKT""" + module = SimpleModule("g.proj", flags="w") + self.assertModule(module) + self.assertIn("PROJCRS", module.outputs.stdout) + + +if __name__ == "__main__": + test()