From 95c2c26747ad809e1312aa1107ff1f7dfdb3477d Mon Sep 17 00:00:00 2001 From: Christoph Hasse Date: Tue, 27 Jul 2021 18:23:54 +0200 Subject: [PATCH] Fixes for Max and Win --- src/makernote_int.cpp | 11 ++++++----- .../data/example_exiv2_config_file_for_lens_test | 0 tests/lens_tests/test_config_file.py | 12 ++++++++++++ 3 files changed, 18 insertions(+), 5 deletions(-) rename tests/lens_tests/.exiv2 => test/data/example_exiv2_config_file_for_lens_test (100%) diff --git a/src/makernote_int.cpp b/src/makernote_int.cpp index 3e29093e..35288eed 100644 --- a/src/makernote_int.cpp +++ b/src/makernote_int.cpp @@ -51,6 +51,7 @@ #include #else #include +#include // _getcwd #include /* older SDKs not have these */ # ifndef CSIDL_MYMUSIC @@ -113,12 +114,12 @@ namespace Exiv2 { // first lets get the current working directory to check if there is a config file #if defined(_MSC_VER) || defined(__MINGW__) - char path[MAX_PATH]; - if (SUCCEEDED(GetModuleFileNameA(NULL, path, MAX_PATH))) { - dir = std::string(path); - } + char buffer[MAX_PATH]; + auto path = _getcwd(buffer, sizeof(buffer)); + dir = std::string(path ? path : ""); #else - auto path = get_current_dir_name(); + char buffer[1024]; + auto path = getcwd(buffer, sizeof(buffer)); dir = std::string(path ? path : ""); #endif auto const filename = dir + EXV_SEPARATOR_CHR + inifile; diff --git a/tests/lens_tests/.exiv2 b/test/data/example_exiv2_config_file_for_lens_test similarity index 100% rename from tests/lens_tests/.exiv2 rename to test/data/example_exiv2_config_file_for_lens_test diff --git a/tests/lens_tests/test_config_file.py b/tests/lens_tests/test_config_file.py index 1e8a1037..667ca78d 100644 --- a/tests/lens_tests/test_config_file.py +++ b/tests/lens_tests/test_config_file.py @@ -2,7 +2,19 @@ import unittest import system_tests import os import shutil +import sys + +# copy the example config file into current working directory +# and name it ".exiv2" on linux or "exiv2.ini" on Win +class TmpConfigFile(system_tests.FileDecoratorBase): + def setUp_file_action(self, expanded_file_name): + config_file_path = os.path.dirname(os.path.abspath(__file__)) + fname = ".exiv2" if sys.platform == "linux" or sys.platform == "darwin" else "exiv2.ini" + return shutil.copyfile(expanded_file_name, os.path.join(config_file_path, fname)) + + +@TmpConfigFile("$data_path/example_exiv2_config_file_for_lens_test") class TestLensConfigFile(metaclass=system_tests.CaseMeta): """ Simple test for the configuration file based lens name resolution