gnucash master: Fix test-userdata-dir on Mac.
John Ralls
jralls at code.gnucash.org
Sat Sep 16 17:50:53 EDT 2017
Updated via https://github.com/Gnucash/gnucash/commit/9dc8e6f4 (commit)
from https://github.com/Gnucash/gnucash/commit/42aa7344 (commit)
commit 9dc8e6f40a017ece80ac31ba5032068e86fa8611
Author: John Ralls <jralls at ceridwen.us>
Date: Sat Sep 16 14:50:27 2017 -0700
Fix test-userdata-dir on Mac.
diff --git a/configure.ac b/configure.ac
index 74e7eeb..3df34c4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -402,6 +402,7 @@ update to latest darwin])
if test "x$_gtk_mac" = xyes; then
GTK_MAC_LIBS="${GTK_MAC_LIBS} -lobjc -framework Cocoa"
GTK_MAC_CFLAGS="${GTK_MAC_CFLAGS} -xobjective-c"
+ GTK_MAC_CXXFLAGS="${GTK_MAC_CFLAGS} -xobjective-c++"
if test "`echo ${GCC_VERSION} | cut -d. -f1`" -eq 4; then
if test "`echo ${GCC_VERSION} | cut -d. -f2`" -ge 8; then
# This is gcc >= 4.8.x
@@ -412,6 +413,7 @@ update to latest darwin])
AC_MSG_RESULT(${_gtk_mac})
AC_SUBST(GTK_MAC_LIBS)
AC_SUBST(GTK_MAC_CFLAGS)
+ AC_SUBST(GTK_MAC_CXXFLAGS)
else
AC_MSG_RESULT(no)
fi
diff --git a/libgnucash/core-utils/Makefile.am b/libgnucash/core-utils/Makefile.am
index b54f2dd..b7da796 100644
--- a/libgnucash/core-utils/Makefile.am
+++ b/libgnucash/core-utils/Makefile.am
@@ -57,11 +57,13 @@ endif
AM_CPPFLAGS = \
${GUILE_CFLAGS} \
${GLIB_CFLAGS} \
- ${GTK_MAC_CFLAGS} \
-I${top_builddir}/common \
-I${top_srcdir}/common \
$(BOOST_CPPFLAGS)
+AM_CFLAGS = ${GTK_MAC_CFLAGS}
+AM_CXXFLAGS = ${GTK_MAC_CXXFLAGS}
+
gncscmmoddir = ${GNC_SCM_INSTALL_DIR}/gnucash
gncscmmod_DATA = core-utils.scm
diff --git a/libgnucash/core-utils/test/CMakeLists.txt b/libgnucash/core-utils/test/CMakeLists.txt
index a21fea0..f1aa444 100644
--- a/libgnucash/core-utils/test/CMakeLists.txt
+++ b/libgnucash/core-utils/test/CMakeLists.txt
@@ -5,8 +5,12 @@ SET(CORE_UTILS_TEST_INCLUDE_DIRS
${CMAKE_SOURCE_DIR}/libgnucash/core-utils
${CMAKE_SOURCE_DIR}/common/test-core
${GLIB2_INCLUDE_DIRS}
+ ${GTK_MAC_INCLUDE_DIRS}
)
SET(CORE_UTILS_TEST_LIBS gnc-core-utils test-core)
+IF (MAC_INTEGRATION)
+ LIST(APPEND CORE_UTILS_TEST_LIBS ${OSX_EXTRA_LIBRARIES})
+ENDIF()
MACRO(ADD_CORE_UTILS_TEST _TARGET _SOURCE_FILES)
GNC_ADD_TEST(${_TARGET} "${_SOURCE_FILES}" CORE_UTILS_TEST_INCLUDE_DIRS CORE_UTILS_TEST_LIBS)
@@ -15,7 +19,13 @@ ENDMACRO()
ADD_CORE_UTILS_TEST(test-gnc-glib-utils test-gnc-glib-utils.c)
ADD_CORE_UTILS_TEST(test-resolve-file-path test-resolve-file-path.c)
ADD_CORE_UTILS_TEST(test-userdata-dir test-userdata-dir.c)
-ADD_CORE_UTILS_TEST(test-userdata-dir-invalid-home test-userdata-dir-invalid-home.c)
+IF (NOT MAC_INTEGRATION AND NOT WIN32)
+ ADD_CORE_UTILS_TEST(test-userdata-dir-invalid-home test-userdata-dir-invalid-home.c)
+ENDIF()
+IF (MAC_INTEGRATION)
+ TARGET_COMPILE_OPTIONS(test-userdata-dir PRIVATE ${OSX_EXTRA_COMPILE_FLAGS})
+ TARGET_COMPILE_DEFINITIONS(test-userdata-dir PRIVATE ${GTK_MAC_CFLAGS_OTHER})
+ENDIF(MAC_INTEGRATION)
SET_DIST_LIST(test_core_utils_DIST CMakeLists.txt Makefile.am test-gnc-glib-utils.c
test-resolve-file-path.c test-userdata-dir.c test-userdata-dir-invalid-home.c)
diff --git a/libgnucash/core-utils/test/Makefile.am b/libgnucash/core-utils/test/Makefile.am
index cb1b269..7d8ba3d 100644
--- a/libgnucash/core-utils/test/Makefile.am
+++ b/libgnucash/core-utils/test/Makefile.am
@@ -11,12 +11,14 @@ AM_CPPFLAGS = \
-I${top_srcdir}/libgnucash/engine \
${GUILE_CFLAGS} \
${GLIB_CFLAGS} \
+ ${GTK_MAC_CFLAGS} \
$(BOOST_CPPFLAGS)
LDADD = \
../libgnc-core-utils.la \
${top_builddir}/common/test-core/libtest-core.la \
${GLIB_LIBS} \
+ ${GTK_MAC_LIBS} \
${BOOST_LDFLAGS}
# these tests are ordered kind more or less in the order
@@ -26,8 +28,13 @@ LDADD = \
TESTS = \
test-gnc-glib-utils \
test-resolve-file-path \
- test-userdata-dir \
- test-userdata-dir-invalid-home
+ test-userdata-dir
+
+if !PLATFORM_OSX_QUARTZ
+if !PLATFORM_WIN32
+TESTS += test-userdata-dir-invalid-home
+endif
+endif
GNC_TEST_DEPS = \
--library-dir ${top_builddir}/libgnucash/core-utils
diff --git a/libgnucash/core-utils/test/test-userdata-dir.c b/libgnucash/core-utils/test/test-userdata-dir.c
index 7046336..7970489 100644
--- a/libgnucash/core-utils/test/test-userdata-dir.c
+++ b/libgnucash/core-utils/test/test-userdata-dir.c
@@ -28,6 +28,9 @@
#include <glib.h>
#include "test-stuff.h"
#include "gnc-filepath-utils.h"
+#ifdef MAC_INTEGRATION
+#include <Foundation/Foundation.h>
+#endif
struct usr_confpath_strings_struct
{
@@ -55,13 +58,32 @@ usr_confpath_strings strs2[] =
{ 0, NULL, NULL },
};
+static char*
+test_get_userdatadir ()
+{
+#ifdef MAC_INTEGRATION
+ char *retval = NULL;
+ NSFileManager*fm = [NSFileManager defaultManager];
+ NSArray* appSupportDir = [fm URLsForDirectory:NSApplicationSupportDirectory
+ inDomains:NSUserDomainMask];
+ if ([appSupportDir count] > 0)
+ {
+ NSURL* dirUrl = [appSupportDir objectAtIndex:0];
+ NSString* dirPath = [dirUrl path];
+ retval = g_strdup([dirPath UTF8String]);
+ }
+ return retval;
+#else
+ return g_strdup(g_get_user_data_dir());
+#endif
+}
+
int
main(int argc, char **argv)
{
int i;
char *home_dir = NULL;
- const char *userdata_dir = NULL;
- const char *tmp_dir = g_get_tmp_dir();
+ char *userdata_dir = NULL;
char *gnc_data_home_dir = NULL;
if (argc > 1)
@@ -70,11 +92,14 @@ main(int argc, char **argv)
* used to pass invalid home directories manually. The
* test error messages should then show the system's temporary
* directory to be used instead */
- home_dir = argv[1];
+ home_dir = g_strdup(argv[1]);
else
/* Set up a fake home directory to play with */
+#ifdef MAC_INTEGRATION
+ home_dir = test_get_userdatadir();
+#else
home_dir = g_dir_make_tmp("gnucashXXXXXX", NULL);
-
+#endif
/* Run usr conf dir tests with a valid and writable homedir */
g_setenv("HOME", home_dir, TRUE);
@@ -86,25 +111,25 @@ main(int argc, char **argv)
if (strs2[i].func_num == 0)
{
- wantout = g_build_filename(tmp_dir, PACKAGE_NAME, "foo",
+ wantout = g_build_filename(home_dir, PACKAGE_NAME, "foo",
(gchar *)NULL);
daout = gnc_build_userdata_path("foo");
}
else if (strs2[i].func_num == 1)
{
- wantout = g_build_filename(tmp_dir, PACKAGE_NAME, strs2[i].output, "foo",
+ wantout = g_build_filename(home_dir, PACKAGE_NAME, strs2[i].output, "foo",
(gchar *)NULL);
daout = gnc_build_book_path("foo");
}
else if (strs2[i].func_num == 2)
{
- wantout = g_build_filename(tmp_dir, PACKAGE_NAME, strs2[i].output, "foo",
+ wantout = g_build_filename(home_dir, PACKAGE_NAME, strs2[i].output, "foo",
(gchar *)NULL);
daout = gnc_build_translog_path("foo");
}
else // if (strs2[i].prefix_home == 3)
{
- wantout = g_build_filename(tmp_dir, PACKAGE_NAME, strs2[i].output, "foo",
+ wantout = g_build_filename(home_dir, PACKAGE_NAME, strs2[i].output, "foo",
(gchar *)NULL);
daout = gnc_build_data_path("foo");
}
@@ -116,10 +141,10 @@ main(int argc, char **argv)
g_free(wantout);
g_free(daout);
}
-
+ g_free(home_dir);
/* Second run, after properly having called gnc_filepath_init */
gnc_filepath_init(TRUE);
- userdata_dir = g_get_user_data_dir();
+ userdata_dir = test_get_userdatadir();
for (i = 0; strs2[i].funcname != NULL; i++)
{
char *daout;
@@ -157,6 +182,7 @@ main(int argc, char **argv)
g_free(wantout);
g_free(daout);
}
+ g_free(userdata_dir);
/* Third run, after setting GNC_DATA_HOME gnc_filepath_init */
gnc_data_home_dir = g_build_filename(home_dir, "Test", NULL);
Summary of changes:
configure.ac | 2 ++
libgnucash/core-utils/Makefile.am | 4 ++-
libgnucash/core-utils/test/CMakeLists.txt | 12 ++++++-
libgnucash/core-utils/test/Makefile.am | 11 ++++--
libgnucash/core-utils/test/test-userdata-dir.c | 46 ++++++++++++++++++++------
5 files changed, 61 insertions(+), 14 deletions(-)
More information about the gnucash-changes
mailing list