From d49f395e51dd0a80e54e56be751d0b92815df380 Mon Sep 17 00:00:00 2001
From: Shenhao Wang <wangsh.fnst@fujitsu.com>
Date: Sun, 12 Sep 2021 14:52:34 +0800
Subject: [PATCH 3/3] WIP:add a canonicalize_path test

---
 src/test/modules/Makefile                     |  1 +
 src/test/modules/test_path/Makefile           | 23 +++++++++++
 src/test/modules/test_path/test_path--1.0.sql |  9 +++++
 src/test/modules/test_path/test_path.c        | 38 +++++++++++++++++++
 src/test/modules/test_path/test_path.control  |  5 +++
 5 files changed, 76 insertions(+)
 create mode 100644 src/test/modules/test_path/Makefile
 create mode 100644 src/test/modules/test_path/test_path--1.0.sql
 create mode 100644 src/test/modules/test_path/test_path.c
 create mode 100644 src/test/modules/test_path/test_path.control

diff --git a/src/test/modules/Makefile b/src/test/modules/Makefile
index dffc79b2d9..1317d97049 100644
--- a/src/test/modules/Makefile
+++ b/src/test/modules/Makefile
@@ -21,6 +21,7 @@ SUBDIRS = \
 		  test_integerset \
 		  test_misc \
 		  test_parser \
+		  test_path \
 		  test_pg_dump \
 		  test_predtest \
 		  test_rbtree \
diff --git a/src/test/modules/test_path/Makefile b/src/test/modules/test_path/Makefile
new file mode 100644
index 0000000000..67b2f6a80a
--- /dev/null
+++ b/src/test/modules/test_path/Makefile
@@ -0,0 +1,23 @@
+# src/test/modules/test_path/Makefile
+
+MODULE_big = test_path
+OBJS = \
+	$(WIN32RES) \
+	test_path.o
+PGFILEDESC = "test_path - test canonicalize_path"
+
+EXTENSION = test_path
+DATA = test_path--1.0.sql
+
+REGRESS = test_path
+
+ifdef USE_PGXS
+PG_CONFIG = pg_config
+PGXS := $(shell $(PG_CONFIG) --pgxs)
+include $(PGXS)
+else
+subdir = src/test/modules/test_parser
+top_builddir = ../../../..
+include $(top_builddir)/src/Makefile.global
+include $(top_srcdir)/contrib/contrib-global.mk
+endif
diff --git a/src/test/modules/test_path/test_path--1.0.sql b/src/test/modules/test_path/test_path--1.0.sql
new file mode 100644
index 0000000000..a6fd134439
--- /dev/null
+++ b/src/test/modules/test_path/test_path--1.0.sql
@@ -0,0 +1,9 @@
+/* src/test/modules/test_path/test_path--1.0.sql */
+
+-- complain if script is sourced in psql, rather than via CREATE EXTENSION
+\echo Use "CREATE EXTENSION test_path" to load this file. \quit
+
+CREATE FUNCTION test_canonicalize_path(text)
+RETURNS text
+AS 'MODULE_PATHNAME'
+LANGUAGE C STRICT;
diff --git a/src/test/modules/test_path/test_path.c b/src/test/modules/test_path/test_path.c
new file mode 100644
index 0000000000..7922b1f837
--- /dev/null
+++ b/src/test/modules/test_path/test_path.c
@@ -0,0 +1,38 @@
+/*-------------------------------------------------------------------------
+ *
+ * test_parser.c
+ *	  test canonicalize_path
+ *
+ * Copyright (c) 2007-2021, PostgreSQL Global Development Group
+ *
+ * IDENTIFICATION
+ *	  src/test/modules/test_path/test_path.c
+ *
+ *-------------------------------------------------------------------------
+ */
+#include "postgres.h"
+
+#include "fmgr.h"
+#include "utils/builtins.h"
+
+PG_MODULE_MAGIC;
+
+/*
+ * functions
+ */
+PG_FUNCTION_INFO_V1(test_canonicalize_path);
+
+Datum
+test_canonicalize_path(PG_FUNCTION_ARGS)
+{
+	char	   *path = strdup(text_to_cstring(PG_GETARG_TEXT_PP(0)));
+
+	if (!path)
+			ereport(ERROR,
+					(errcode(ERRCODE_OUT_OF_MEMORY),
+					 errmsg("out of memory")));
+
+	canonicalize_path(path);
+
+	PG_RETURN_TEXT_P(cstring_to_text(path));
+}
diff --git a/src/test/modules/test_path/test_path.control b/src/test/modules/test_path/test_path.control
new file mode 100644
index 0000000000..31ab323033
--- /dev/null
+++ b/src/test/modules/test_path/test_path.control
@@ -0,0 +1,5 @@
+# test_path extension
+comment = 'test canonicalize_path'
+default_version = '1.0'
+module_pathname = '$libdir/test_path'
+relocatable = true
-- 
2.26.2

