diff options
Diffstat (limited to 'test/unit')
| -rw-r--r-- | test/unit/CMakeLists.txt | 8 | ||||
| -rw-r--r-- | test/unit/Makefile.am | 9 | ||||
| -rw-r--r-- | test/unit/pj_transform_test.cpp | 32 | ||||
| -rw-r--r-- | test/unit/proj_context_test.cpp | 146 |
4 files changed, 194 insertions, 1 deletions
diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index 09405147..a157f630 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -82,6 +82,14 @@ target_link_libraries(proj_angular_io_test ${PROJ_LIBRARIES}) add_test(NAME proj_angular_io_test COMMAND proj_angular_io_test) +add_executable(proj_context_test + main.cpp + proj_context_test.cpp) +target_link_libraries(proj_context_test + gtest + ${PROJ_LIBRARIES}) +add_test(NAME proj_context_test COMMAND proj_context_test) + if (MSVC AND BUILD_LIBPROJ_SHARED) # ph_phi2_test not compatible of a .dll build else() diff --git a/test/unit/Makefile.am b/test/unit/Makefile.am index e6d95e9c..34624b0d 100644 --- a/test/unit/Makefile.am +++ b/test/unit/Makefile.am @@ -13,6 +13,7 @@ noinst_PROGRAMS = pj_transform_test noinst_PROGRAMS += pj_phi2_test noinst_PROGRAMS += proj_errno_string_test noinst_PROGRAMS += proj_angular_io_test +noinst_PROGRAMS += proj_context_test noinst_PROGRAMS += test_cpp_api noinst_PROGRAMS += gie_self_tests noinst_PROGRAMS += include_proj_h_from_c @@ -41,6 +42,12 @@ proj_angular_io_test_LDADD = ../../src/libproj.la ../../test/googletest/libgtest proj_angular_io_test-check: proj_angular_io_test ./proj_angular_io_test +proj_context_test_SOURCES = proj_context_test.cpp main.cpp +proj_context_test_LDADD = ../../src/libproj.la ../../test/googletest/libgtest.la + +proj_context_test-check: proj_context_test + ./proj_context_test + test_cpp_api_SOURCES = test_util.cpp test_common.cpp test_crs.cpp test_metadata.cpp test_io.cpp test_operation.cpp test_datum.cpp test_factory.cpp test_c_api.cpp main.cpp test_cpp_api_LDADD = ../../src/libproj.la ../../test/googletest/libgtest.la @SQLITE3_LDFLAGS@ @@ -55,4 +62,4 @@ gie_self_tests-check: gie_self_tests include_proj_h_from_c_SOURCES = include_proj_h_from_c.c -check-local: pj_transform_test-check pj_phi2_test-check proj_errno_string_test-check proj_angular_io_test-check test_cpp_api-check gie_self_tests-check +check-local: pj_transform_test-check pj_phi2_test-check proj_errno_string_test-check proj_angular_io_test-check proj_context_test-check test_cpp_api-check gie_self_tests-check diff --git a/test/unit/pj_transform_test.cpp b/test/unit/pj_transform_test.cpp index ea9706dd..c2926df8 100644 --- a/test/unit/pj_transform_test.cpp +++ b/test/unit/pj_transform_test.cpp @@ -581,4 +581,36 @@ TEST(pj_transform_test, init_epsg) { pj_free(dst); } +// --------------------------------------------------------------------------- + +TEST(proj_api_h, pj_set_searchpath ) { + + const char* path = "/i_do/not/exit"; + pj_set_searchpath(1, &path); + { + auto info = proj_info(); + EXPECT_EQ(info.path_count, 1); + ASSERT_NE(info.paths, nullptr); + ASSERT_NE(info.paths[0], nullptr); + EXPECT_EQ(std::string(info.paths[0]), path); + } + + pj_set_searchpath(0, nullptr); + { + auto info = proj_info(); + EXPECT_EQ(info.path_count, 0); + EXPECT_EQ(info.paths, nullptr); + } +} + +// --------------------------------------------------------------------------- + +TEST(proj_api_h, pj_set_finder ) { + + const auto myfinder = [](const char*) -> const char* { return nullptr; }; + pj_set_finder(myfinder); + + pj_set_finder(nullptr); +} + } // namespace diff --git a/test/unit/proj_context_test.cpp b/test/unit/proj_context_test.cpp new file mode 100644 index 00000000..23c46f29 --- /dev/null +++ b/test/unit/proj_context_test.cpp @@ -0,0 +1,146 @@ +/****************************************************************************** + * + * Project: PROJ + * Purpose: Test functions in proj_context namespae + * Author: Even Rouault <even dot rouault at spatialys dot com> + * + ****************************************************************************** + * Copyright (c) 2019, Even Rouault <even dot rouault at spatialys dot com> + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + ****************************************************************************/ + +#include <stdlib.h> +#ifdef _MSC_VER +#include <io.h> +#else +#include <unistd.h> +#endif + +#include "proj.h" +#include "proj_internal.h" + +#include "gtest_include.h" + +namespace { + +static std::string createTempDict(std::string &dirname) { + const char *temp_dir = getenv("TEMP"); + if (!temp_dir) { + temp_dir = getenv("TMP"); + } +#ifndef WIN32 + if (!temp_dir) { + temp_dir = "/tmp"; + } +#endif + if (!temp_dir) + return std::string(); + + dirname = temp_dir; + + std::string tmpFilename; + tmpFilename = temp_dir; + tmpFilename += DIR_CHAR; + tmpFilename += "temp_proj_dic"; + + FILE *f = fopen(tmpFilename.c_str(), "wt"); + if (!f) + return std::string(); + fprintf( + f, + "<MY_PIPELINE> +proj=pipeline +step +proj=utm +zone=31 +ellps=GRS80\n"); + fclose(f); + return tmpFilename; +} + +// --------------------------------------------------------------------------- + +static int MyUnlink(const std::string &filename) { +#ifdef _MSC_VER + return _unlink(filename.c_str()); +#else + return unlink(filename.c_str()); +#endif +} + +// --------------------------------------------------------------------------- + +TEST(proj_context, proj_context_set_file_finder) { + + std::string dirname; + auto filename = createTempDict(dirname); + if (filename.empty()) + return; + + auto ctx = proj_context_create(); + + struct FinderData { + PJ_CONTEXT *got_ctx = nullptr; + std::string dirname{}; + std::string tmpFilename{}; + }; + + const auto finder = [](PJ_CONTEXT *got_ctx, const char *file, + void *user_data) -> const char * { + auto finderData = static_cast<FinderData *>(user_data); + finderData->got_ctx = got_ctx; + finderData->tmpFilename = finderData->dirname; + finderData->tmpFilename += DIR_CHAR; + finderData->tmpFilename += file; + return finderData->tmpFilename.c_str(); + }; + + FinderData finderData; + finderData.dirname = dirname; + proj_context_set_file_finder(ctx, finder, &finderData); + + auto P = proj_create(ctx, "+init=temp_proj_dic:MY_PIPELINE"); + EXPECT_NE(P, nullptr); + proj_destroy(P); + + EXPECT_EQ(finderData.got_ctx, ctx); + + proj_context_destroy(ctx); +} + +// --------------------------------------------------------------------------- + +TEST(proj_context, proj_context_set_search_paths) { + + std::string dirname; + auto filename = createTempDict(dirname); + if (filename.empty()) + return; + + auto ctx = proj_context_create(); + + const char *path = dirname.c_str(); + proj_context_set_search_paths(ctx, 1, &path); + + auto P = proj_create(ctx, "+init=temp_proj_dic:MY_PIPELINE"); + EXPECT_NE(P, nullptr); + proj_destroy(P); + + proj_context_destroy(ctx); + + MyUnlink(filename); +} + +} // namespace |
